#include <soft_timer.hpp>

Public Member Functions

 SoftTimer ()
 Default constructor. More...
 
 SoftTimer (uint32_t ms)
 Constructor to set timer while instantiating this object. More...
 
bool expired (void) const
 
void restart (void)
 
void reset (uint64_t ms)
 
void reset (void)
 Resets the timer from this point of time using the previous timeout interval. More...
 
void stop (void)
 Stops the timer. More...
 
bool isRunning (void) const
 
uint64_t getTimerValueMs (void) const
 
uint64_t getTargetTimerValueMs (void) const
 
uint64_t getTimeToExpirationMs (void) const
 
uint64_t getTimeSinceExpirationMs (void) const
 

Static Public Member Functions

static uint64_t getCurrentTimeMs (void)
 

Protected Attributes

uint64_t mTargetMs
 Expire time with respect to OS tick. More...
 
uint64_t mIntervalMs
 Timer interval. More...
 

Detailed Description

Soft timer class to provide thin layer of a timer. There is no hard-timer running in the background and this class imply relies on system timer to provide timer capability.

Warning
If you run FreeRTOS in "configUSE_TICKLESS_IDLE", then this timer will not work well since the OS ticks will not happen to drive the timer. In that case, you are better off using the true FreeRTOS timer which will not suppress the timer ticks if a timer expires.

Constructor & Destructor Documentation

SoftTimer::SoftTimer ( )
inline

Default constructor.

SoftTimer::SoftTimer ( uint32_t  ms)
inline

Constructor to set timer while instantiating this object.

Member Function Documentation

bool SoftTimer::expired ( void  ) const
inline
Returns
true if the timer has expired
static uint64_t SoftTimer::getCurrentTimeMs ( void  )
inlinestatic

Static function to get the timer value. This is the only method that is needed by the system.

Note
You can use this method without instantiating an object of the class:
uint64_t timer = SoftTimer::getCurrentTimeMs();
Returns
the current timer value of the system
uint64_t SoftTimer::getTargetTimerValueMs ( void  ) const
inline
Returns
the absolute time value when timer will expire with respect to system timer (in milliseconds)
uint64_t SoftTimer::getTimerValueMs ( void  ) const
inline
Returns
the timer value set by the constructor or reset(uint64_t)
uint64_t SoftTimer::getTimeSinceExpirationMs ( void  ) const
inline
Returns
the time value since expiration (in milliseconds)
Note
If timer hasn't expired, zero value is returned.
uint64_t SoftTimer::getTimeToExpirationMs ( void  ) const
inline
Returns
the time value until expiration (in milliseconds)
Note
If timer hasn't expired, zero value is returned.
bool SoftTimer::isRunning ( void  ) const
inline
Returns
true if the timer is set and running
void SoftTimer::reset ( uint64_t  ms)
inline

Resets the timer from this point of time using the new timer value given.

Parameters
msThe milliseconds at which timer should expire next.
void SoftTimer::reset ( void  )
inline

Resets the timer from this point of time using the previous timeout interval.

void SoftTimer::restart ( void  )
inline

Restarts the timer to provide consistent frequency of expired(). restart() is better suited to provide same frequency because in case we check for expired() at a later time that runs past our timer 3 times, then expired() in combination with restart() will return true 3 times. See example below :

timer.reset(10); // Init once
// After reset(), use this as recurring timer :
if (timer.expired()) {
timer.restart();
}
void SoftTimer::stop ( void  )
inline

Stops the timer.

Field Documentation

uint64_t SoftTimer::mIntervalMs
protected

Timer interval.

uint64_t SoftTimer::mTargetMs
protected

Expire time with respect to OS tick.

uint64_t is large enough such that timer will never overflow


The documentation for this class was generated from the following file:
  • /var/www/html/SJSU-DEV-Linux/firmware/default/lib/L3_Utils/soft_timer.hpp