CMSIS-RTOS  Version 1.00
CMSIS-RTOS API: Generic RTOS interface for Cortex-M processor-based devices.
Timer Management

Create and control timer and timer callback functions. More...

Defines

#define osTimerDef(name, function)
 Define a Timer object.
#define osTimer(name)   &os_timer_def_##name
 Access a Timer definition.

Enumerations

enum  os_timer_type {
  osTimerOnce = 0,
  osTimerPeriodic = 1
}

Functions

osTimerId osTimerCreate (osTimerDef_t *timer_def, os_timer_type type, void *argument)
 Create a timer.
osStatus osTimerStart (osTimerId timer_id, uint32_t millisec)
 Start or restart a timer.
osStatus osTimerStop (osTimerId timer_id)
 Stop the timer.

Description

The Timer Management function group allow creating and controlling of timers and callback functions in the system. A callback function is called when a time period expires whereby both one-shot and periodic timers are possible. A timer 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.

Timer.png
Behavior of a Periodic Timer

Define Documentation

#define osTimer (   name)    &os_timer_def_##name

Access to the timer definition for the function osTimerCreate.

Parameters:
namename of the timer object.
Note:
CAN BE CHANGED: The parameter to osTimer shall be consistent but the macro body is implementation specific in every CMSIS-RTOS.
#define osTimerDef (   name,
  function 
)

Define the attributes of a timer.

Parameters:
namename of the timer object.
functionname of the timer call back function.
Note:
CAN BE CHANGED: The parameter to osTimerDef shall be consistent but the macro body is implementation specific in every CMSIS-RTOS.

Enumeration Type Documentation

Note:
MUST REMAIN UNCHANGED: os_timer_type shall be consistent in every CMSIS-RTOS. The os_timer_type specifies the a repeating (periodic) or one-shot timer for the function osTimerCreate.
Enumerator:
osTimerOnce 

one-shot timer

osTimerPeriodic 

repeating timer


Function Documentation

osTimerId osTimerCreate ( osTimerDef_t timer_def,
os_timer_type  type,
void *  argument 
)
Parameters:
[in]timer_deftimer object referenced with osTimer.
[in]typeosTimerOnce for one-shot or osTimerPeriodic for periodic behavior.
[in]argumentargument to the timer call back function.
Returns:
timer ID for reference by other functions or NULL in case of error.
Note:
MUST REMAIN UNCHANGED: osTimerCreate shall be consistent in every CMSIS-RTOS.

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.

osStatus osTimerStart ( osTimerId  timer_id,
uint32_t  millisec 
)
Parameters:
[in]timer_idtimer ID obtained by osTimerCreate.
[in]millisectime delay value of the timer.
Returns:
status code that indicates the execution status of the function.
Note:
MUST REMAIN UNCHANGED: osTimerStart shall be consistent in every CMSIS-RTOS.

Start or restart the timer.

Status and Error Codes

  • osOK: the specified timer has been started or restarted.
  • osErrorParameter: timer_id is incorrect.
osStatus osTimerStop ( osTimerId  timer_id)
Parameters:
[in]timer_idtimer ID obtained by osTimerCreate.
Returns:
status code that indicates the execution status of the function.
Note:
MUST REMAIN UNCHANGED: osTimerStop shall be consistent in every CMSIS-RTOS.

Stop the timer.

Status and Error Codes

  • osOK: the specified timer has been stopped.
  • osErrorParameter: timer_id is incorrect.
  • osErrorResource: the timer is not started.