CMSIS-RTOS2
Version 2.1.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(* | osTimerFunc_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 (osTimerFunc_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. 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(* osTimerFunc_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 | ( | osTimerFunc_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. |
The function osTimerNew creates an one-shot or periodic timer and associates it with a callback function with argument. The timer is in stopped state until it is started with osTimerStart.
The parameter func specifies the start address of the timer callback function.
The parameter type specifies the type of the timer (refer to osTimerType_t).
The parameter attr sets the timer attributes (refer to osTimerAttr_t). Default attributes will be used if set to NULL.
The function osTimerNew returns the pointer to the timer object identifier or NULL in case of an error.
Code Example
*const char * osTimerGetName | ( | osTimerId_t | timer_id | ) |
[in] | timer_id | timer ID obtained by osTimerNew. |
The function osTimerGetName returns the pointer to the name string of the timer identified by parameter timer_id or NULL in case of an error.
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. |
The function osTimerStart starts or restarts a timer specified by the parameter timer_id. The parameter ticks specifies the value of the timer in time ticks.
Possible osStatus_t return values:
Code Example
osStatus_t osTimerStop | ( | osTimerId_t | timer_id | ) |
[in] | timer_id | timer ID obtained by osTimerNew. |
The function osTimerStop stops a timer specified by the parameter timer_id.
Possible osStatus_t return values:
Code Example
uint32_t osTimerIsRunning | ( | osTimerId_t | timer_id | ) |
[in] | timer_id | timer ID obtained by osTimerNew. |
the function osTimerIsRunning checks whether a timer specified by parameter timer_id is running. It returns 1 if the timer is running and 0 if the timer is stopped or an error occurred.
osStatus_t osTimerDelete | ( | osTimerId_t | timer_id | ) |
[in] | timer_id | timer ID obtained by osTimerNew. |
The function osTimerDelete deletes the timer specified by parameter timer_id.
Possible osStatus_t return values:
Code Example