![]() |
CMSIS-RTOS2
Version 2.0.0
Real-Time Operating System: API and RTX Reference Implementation
|
Create and control timer and timer callback functions. More...
Data Structures | |
struct | osTimerAttr_t |
Attributes structure for timer. More... | |
Typedefs | |
typedef void * | osTimerId_t |
typedef void(* | os_timer_func_t )(void *argument) |
Entry point of a timer call back function. More... | |
Enumerations | |
enum | osTimerType_t { osTimerOnce = 0, osTimerPeriodic = 1 } |
Timer type. More... | |
Functions | |
osTimerId_t | osTimerNew (os_timer_func_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr) |
Create and Initialize a timer. More... | |
const char * | osTimerGetName (osTimerId_t timer_id) |
Get name of a timer. More... | |
osStatus_t | osTimerStart (osTimerId_t timer_id, uint32_t ticks) |
Start or restart a timer. More... | |
osStatus_t | osTimerStop (osTimerId_t timer_id) |
Stop a timer. More... | |
uint32_t | osTimerIsRunning (osTimerId_t timer_id) |
Check if a timer is running. More... | |
osStatus_t | osTimerDelete (osTimerId_t timer_id) |
Delete a timer. More... | |
In addition to the Generic Wait Functions CMSIS-RTOS also supports virtual timer objects. These timer objects can trigger the execution of a function (not threads). When a timer expires, a callback function is executed to run associated code with the timer. The timer number is passed as a parameter to the callback function. Each timer can be configured as a one-shot or a periodic timer. A periodic timer repeats its operation until it is deleted or stopped. All timers can be started, restarted, or stopped.
The figure below shows the behavior of a periodic timer. For one-shot timers, the timer stops after execution of the callback function.
The following steps are required to use a timer:
struct osTimerAttr_t |
Timer ID identifies the timer.
Instances of this type hold a reference to a timer object.
void(* os_timer_func_t)(void *argument) |
enum osTimerType_t |
The osTimerType_t specifies the a repeating (periodic) or one-shot timer for the function osTimerNew.
Enumerator | |
---|---|
osTimerOnce |
One-shot timer. |
osTimerPeriodic |
Repeating timer. |
osTimerId_t osTimerNew | ( | os_timer_func_t | func, |
osTimerType_t | type, | ||
void * | argument, | ||
const osTimerAttr_t * | attr | ||
) |
[in] | func | start address of a timer call back function. |
[in] | type | osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. |
[in] | argument | argument to the timer call back function. |
[in] | attr | timer attributes; NULL: default values. |
Create a one-shot or periodic timer and associate it with a callback function argument. The timer is in stopped until it is started with osTimerStart.
Code Example
*const char * osTimerGetName | ( | osTimerId_t | timer_id | ) |
[in] | timer_id | timer ID obtained by osTimerNew. |
osStatus_t osTimerStart | ( | osTimerId_t | timer_id, |
uint32_t | ticks | ||
) |
[in] | timer_id | timer ID obtained by osTimerNew. |
[in] | ticks | time ticks value of the timer. |
Start or restart the timer.
osStatus_t return values:
Code Example
osStatus_t osTimerStop | ( | osTimerId_t | timer_id | ) |
[in] | timer_id | timer ID obtained by osTimerNew. |
Stop the timer.
osStatus_t return values:
Code Example
uint32_t osTimerIsRunning | ( | osTimerId_t | timer_id | ) |
[in] | timer_id | timer ID obtained by osTimerNew. |
Test if timer is running. Returns 0 if timer is stopped. Returns 1 if timer is running.
osStatus_t osTimerDelete | ( | osTimerId_t | timer_id | ) |
[in] | timer_id | timer ID obtained by osTimerNew. |
Delete the timer object.
osStatus_t return values:
Code Example