CMSIS-RTOS
Version 1.03
Real-Time Operating System: API and RTX Reference Implementation.
|
Create and control timer and timer callback functions. More...
Macros | |
#define | osTimerDef(name, function) |
Define a Timer object. More... | |
#define | osTimer(name) &os_timer_def_##name |
Access a Timer definition. More... | |
Enumerations | |
enum | os_timer_type { osTimerOnce = 0, osTimerPeriodic = 1 } |
Functions | |
osTimerId | osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument) |
Create a timer. More... | |
osStatus | osTimerStart (osTimerId timer_id, uint32_t millisec) |
Start or restart a timer. More... | |
osStatus | osTimerStop (osTimerId timer_id) |
Stop the timer. More... | |
osStatus | osTimerDelete (osTimerId timer_id) |
Delete a timer that was created by osTimerCreate. 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.
Timers are handled in the thread osTimerThread. Callback functions run under control of this thread and may use other CMSIS-RTOS API calls.
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:
#define osTimer | ( | name | ) | &os_timer_def_##name |
Access to the timer definition for the function osTimerCreate.
name | name of the timer object. |
#define osTimerDef | ( | name, | |
function | |||
) |
Define the attributes of a timer.
name | name of the timer object. |
function | name of the timer call back function. |
enum os_timer_type |
Enumerator | |
---|---|
osTimerOnce |
one-shot timer |
osTimerPeriodic |
repeating timer |
osTimerId osTimerCreate | ( | const osTimerDef_t * | timer_def, |
os_timer_type | type, | ||
void * | argument | ||
) |
[in] | timer_def | timer object referenced with osTimer. |
[in] | type | osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. |
[in] | argument | argument to the timer call back function. |
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
[in] | timer_id | timer ID obtained by osTimerCreate. |
Delete the timer object.
Code Example
[in] | timer_id | timer ID obtained by osTimerCreate. |
[in] | millisec | time delay value of the timer. |
Start or restart the timer.
Code Example
[in] | timer_id | timer ID obtained by osTimerCreate. |
Stop the timer.
Code Example