OS  v1.7.5
Documentation
Loading...
Searching...
No Matches
qOS::timer Class Reference

A non-blocking Timer object. More...

#include <timer.hpp>

Public Member Functions

 timer ()
 
 timer (const qOS::duration_t tTime)
 Initializes the instance of the timer with the specified expiration time. Timer will start armed.
 
bool set (const qOS::duration_t tTime) noexcept
 Set the expiration time for a timer. On success, the timer gets armed immediately.
 
void disarm (void) noexcept
 Disarms the timer object.
 
void reload (void) noexcept
 Reload the timer with the previous specified time.
 
bool status (void) const noexcept
 Get the current status of the Timer (Armed or Disarmed)
 
bool freeRun (const qOS::duration_t tTime) noexcept
 Non-Blocking timer check with automatic arming.
 
qOS::clock_t remaining (void) const noexcept
 Retrieve the remaining time in epochs.
 
qOS::clock_t elapsed (void) const noexcept
 Retrieve the elapsed time in epochs.
 
bool expired (void) const noexcept
 Non-Blocking timer check.
 
bool deadLineCheck (void) const noexcept
 Check if the specified deadline for has been reached.
 
qOS::clock_t getInterval (void) const noexcept
 Retrieve the timer interval value.
 
timeroperator= (const qOS::duration_t tTime)
 Set the expiration time for a timer and gets armed immediately.
 
timeroperator= (const bool en)
 Disarm or reload the timer.
 
bool operator() (void) const
 Non-Blocking timer check.
 
bool operator() (const qOS::duration_t tTime)
 Set the expiration time for a timer and gets armed immediately.
 
void operator() (const bool en)
 Disarm or reload the timer.
 

Static Public Attributes

static const bool ARMED
 Constant that defines the status of an armed timer.
 
static const bool DISARMED
 Constant that defines the status of a disarmed timer.
 
static const qOS::clock_t DISARM_VALUE
 Constant that defines the value of a disarmed timer.
 
static const qOS::clock_t REMAINING_IN_DISARMED_STATE
 Constant that defines the value that a disarmed timer returns when the remaining time is requested.
 

Detailed Description

A non-blocking Timer object.

Timers are an essential extension as they allow for accurate and efficient timekeeping without blocking tasks. Using timers enables the embedded application to perform other critical tasks while the timer is running in the background. Timers also provide flexibility in the event that the timer needs to be paused, restarted, or adjusted on the fly. This can be particularly useful in applications that require dynamic timing or have unpredictable event intervals.

Constructor & Destructor Documentation

◆ timer() [1/2]

qOS::timer::timer ( )

◆ timer() [2/2]

qOS::timer::timer ( const qOS::duration_t tTime)
inlineexplicit

Initializes the instance of the timer with the specified expiration time. Timer will start armed.

Note
The OS must be running before using timers.
The expiration time should be at least, two times greater than the clock-Tick.
Parameters
[in]tTimeThe expiration time given in milliseconds.

Member Function Documentation

◆ deadLineCheck()

bool qOS::timer::deadLineCheck ( void ) const
noexcept

Check if the specified deadline for has been reached.

Returns
true if the deadline has been reached, otherwise, returns false.

◆ disarm()

void qOS::timer::disarm ( void )
noexcept

Disarms the timer object.

◆ elapsed()

qOS::clock_t qOS::timer::elapsed ( void ) const
noexcept

Retrieve the elapsed time in epochs.

Returns
The Elapsed time specified in epochs.

◆ expired()

bool qOS::timer::expired ( void ) const
noexcept

Non-Blocking timer check.

Returns
Returns true when timer expires, otherwise, returns false.
Note
A disarmed timer also returns false.

◆ freeRun()

bool qOS::timer::freeRun ( const qOS::duration_t tTime)
noexcept

Non-Blocking timer check with automatic arming.

Behavior: If disarmed, it gets armed immediately with the specified time.

If armed, the time argument is ignored and the API only checks for expiration. When the time expires, the timer gets armed immediately taking the specified time.

Note
After the timer expiration, this method re-arms the timer
The OS must be running before using a timer.
The expiration time should be at least, two times greater than the clock-Tick.
Parameters
[in]tTimeThe expiration time given in milliseconds.
Returns
Returns true on success, otherwise, returns false.
Note
A disarmed timer also returns false.

◆ getInterval()

qOS::clock_t qOS::timer::getInterval ( void ) const
noexcept

Retrieve the timer interval value.

Returns
The interval value in epochs.

◆ operator()() [1/3]

void qOS::timer::operator() ( const bool en)

Disarm or reload the timer.

Note
The OS must be running before using timers.
The expiration time should be at least, two times greater than the clock-Tick.
Parameters
[in]entrue for reload of false to disarm.

◆ operator()() [2/3]

bool qOS::timer::operator() ( const qOS::duration_t tTime)

Set the expiration time for a timer and gets armed immediately.

Note
The OS must be running before using timers.
The expiration time should be at least, two times greater than the clock-Tick.
Parameters
[in]tTimeThe expiration time given in milliseconds.

◆ operator()() [3/3]

bool qOS::timer::operator() ( void ) const

Non-Blocking timer check.

Returns
Returns true when timer expires, otherwise, returns false.
Note
A disarmed timer also returns false.

◆ operator=() [1/2]

timer & qOS::timer::operator= ( const bool en)

Disarm or reload the timer.

Note
The OS must be running before using timers.
The expiration time should be at least, two times greater than the clock-Tick.
Parameters
[in]entrue for reload of false to disarm.

◆ operator=() [2/2]

timer & qOS::timer::operator= ( const qOS::duration_t tTime)

Set the expiration time for a timer and gets armed immediately.

Note
The OS must be running before using timers.
The expiration time should be at least, two times greater than the clock-Tick.
Parameters
[in]tTimeThe expiration time given in milliseconds.

◆ reload()

void qOS::timer::reload ( void )
noexcept

Reload the timer with the previous specified time.

Note
Timer should be armed before this operation

◆ remaining()

qOS::clock_t qOS::timer::remaining ( void ) const
noexcept

Retrieve the remaining time in epochs.

Returns
The remaining time specified in epochs.

◆ set()

bool qOS::timer::set ( const qOS::duration_t tTime)
noexcept

Set the expiration time for a timer. On success, the timer gets armed immediately.

Note
The OS must be running before using timers.
The expiration time should be at least, two times greater than the clock-Tick.
Parameters
[in]tTimeThe expiration time given in milliseconds.
Returns
Returns true on success, otherwise, returns false.

◆ status()

bool qOS::timer::status ( void ) const
noexcept

Get the current status of the Timer (Armed or Disarmed)

Returns
true when armed, otherwise false when disarmed.

Member Data Documentation

◆ ARMED

const bool qOS::timer::ARMED
static

Constant that defines the status of an armed timer.

◆ DISARM_VALUE

const qOS::clock_t qOS::timer::DISARM_VALUE
static

Constant that defines the value of a disarmed timer.

◆ DISARMED

const bool qOS::timer::DISARMED
static

Constant that defines the status of a disarmed timer.

◆ REMAINING_IN_DISARMED_STATE

const qOS::clock_t qOS::timer::REMAINING_IN_DISARMED_STATE
static

Constant that defines the value that a disarmed timer returns when the remaining time is requested.