Documentation

This class implements a logical timer based on the Stratify OS system timer.

Physical timers are controlled using the hal::Tmr class.

Here is an example of using the timer to time events.

#include <stfy/Sys.hpp>
int main(int argc, char * argv[]){
Timer t;
t.start(); //start
t.stop();
printf("Timer value after 500usec is %d\n", t.usec());
}

The output of the above code varies depending on the MCU clock cycles and the scheduler. The following is a sample output.

Timer value after 500usec is 502

Public Member Functions

u32 calc_msec () const
 
u32 calc_sec () const
 
u32 calc_usec () const
 
bool is_reset () const
 
bool is_running () const
 
bool is_started () const
 
bool is_stopped () const
 
u32 msec () const
 
void reset ()
 
void restart ()
 
void resume ()
 
u32 sec () const
 
void start ()
 
void stop ()
 
u32 usec () const
 

Static Public Member Functions

static int get_clock_msec ()
 
static int get_clock_sec ()
 
static int get_clock_usec ()
 
static void wait_msec (u32 timeout)
 
static void wait_sec (u32 timeout)
 
static void wait_usec (u32 timeout)
 

Member Function Documentation

u32 sys::Timer::calc_msec ( ) const

Timer value in milliseconds

Returns
The number of milliseconds that have elapsed since start. This value can be read when the timer is running to get a live value or after it has been stopped to get the time elapsed between start() and stop()
u32 sys::Timer::calc_sec ( ) const

Timer value in seconds. This is similar to calc_msec() but returns the value in seconds rather than milliseconds.

Returns
The number of seconds that have elapsed since start.
u32 sys::Timer::calc_usec ( ) const

Timer value in microseconds. This is similar to calc_msec() but returns the value in microseconds rather than milliseconds.

Returns
The number of microseconds that have elapsed since start.
static int sys::Timer::get_clock_msec ( )
static

The the milliseconds on the real-time clock (starts counting on reset)

static int sys::Timer::get_clock_sec ( )
static

The the seconds on the real-time clock (starts counting on reset)

static int sys::Timer::get_clock_usec ( )
static

The the microseconds on the real-time clock (starts counting on reset)

bool sys::Timer::is_reset ( ) const
inline

This method returns true if the timer is in a reset state.

bool sys::Timer::is_running ( ) const
inline

This method returns true if the timer is currently counting meaning it has been started but has not been stopped. If the timer has been stopped and resumed, this method will return true;

bool sys::Timer::is_started ( ) const
inline

This method returns true if the timer has been started. It the timer has been started and stopped, this method will return true. If the timer has been reset() or never started, this method will return false.

bool sys::Timer::is_stopped ( ) const
inline

This method returns true if the timer is stopped. If the timer has not yet been started or has been reset(), this method will return true. If the timer is currently running, this method will return false.

u32 sys::Timer::msec ( ) const
inline

Shortcut for calc_msec();

void sys::Timer::reset ( )

Reset the value of the timer After calling this method, is_running(), and is_started() will both all return false;

void sys::Timer::restart ( )

This method restarts the timer. If the timer is currently running, it starts over. If it is not running, it is started.

void sys::Timer::resume ( )

This resumes counting after a stop(). If the timer is currently running this method has no effect. If the timer has not been started, this method will start the timer.

u32 sys::Timer::sec ( ) const
inline

Shortcut for calc_sec();

void sys::Timer::start ( )

This starts the timer. If the timer is currently running, this method has no effect. If the timer has been stopped, it will restart. Use resume() to resume running a stopped timer.

void sys::Timer::stop ( )

Stop the current timer.

This stops the timer from counting. Subsequent calls to value() will return the same number. Once the timer has been stopped(), a call to resume() will resume counting and a call to start() or restart() will restart counting from zero.

u32 sys::Timer::usec ( ) const
inline

Shortcut for calc_usec();

static void sys::Timer::wait_msec ( u32  timeout)
static

This method will delay the specified number of milliseconds.

Parameters
timeoutTime to wait in milliseconds
static void sys::Timer::wait_sec ( u32  timeout)
static

This method will delay the specified number of seconds.

Parameters
timeoutTime to wait in seconds
static void sys::Timer::wait_usec ( u32  timeout)
static

This method will delay the specified number of microseconds.

Parameters
timeoutTime to wait in microseconds