Appearance
Timer & Delay
Software millisecond/microsecond timer and delay functions.
all "Timer" functions can be used to execute code periodically in millisecond intervals. Please be aware, that the timer thread runs at the lowest priority and uses the SysTick Interrupt to time thing. Therefore, this API should not be used for time-critical code that requires millisecond-precision but more for delayed one-time execution or periodic tasks that need to be performed, but don't suffer from a slight tolerance in the 1digit millisecond region.
Types
| Name | |
|---|---|
| struct | osTimerAttr_t Attributes structure for timer. |
| enum | osTimerType_t Timer type. |
| typedef void(*)(void *argument) | osTimerFunc_t Timer callback function. |
Functions Overview
| Name | |
|---|---|
| osTimerId_t | osTimerNew(osTimerFunc_t func, osTimerType_t type, void * argument, const osTimerAttr_t * attr) Create and Initialize a timer. |
| const char * | osTimerGetName(osTimerId_t timer_id) Get name of a timer. |
| osStatus_t | osTimerStart(osTimerId_t timer_id, uint32_t ticks) Start or restart a timer. |
| osStatus_t | osTimerStop(osTimerId_t timer_id) Stop a timer. |
| uint32_t | osTimerIsRunning(osTimerId_t timer_id) Check if a timer is running. |
| osStatus_t | osTimerDelete(osTimerId_t timer_id) Delete a timer. |
| osStatus_t | osDelay(uint32_t ticks) Wait for Timeout (Time Delay). |
| osStatus_t | osDelayUntil(uint32_t ticks) Wait until specified time. |
| osStatus_t | osDelayUs(uint32_t microseconds) Wait for Timeout (Microsecond Delay). |
Types Documentation
enum osTimerType_t
| Enumerator | Description |
|---|---|
| osTimerOnce | One-shot timer. |
| osTimerPeriodic | Repeating timer. |
Timer type.
typedef osTimerFunc_t
cpp
typedef void(* osTimerFunc_t) (void *argument);Timer callback function.
Function Details
function osTimerNew
cpp
osTimerId_t osTimerNew(
osTimerFunc_t func,
osTimerType_t type,
void * argument,
const osTimerAttr_t * attr
)Create and Initialize a timer.
Parameters:
- func function pointer to callback function.
- type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior.
- argument argument to the timer callback function.
- attr timer attributes; NULL: default values.
Return: timer ID for reference by other functions or NULL in case of error.
function osTimerGetName
cpp
const char * osTimerGetName(
osTimerId_t timer_id
)Get name of a timer.
Parameters:
- timer_id timer ID obtained by osTimerNew.
Return: name as null-terminated string.
function osTimerStart
cpp
osStatus_t osTimerStart(
osTimerId_t timer_id,
uint32_t ticks
)Start or restart a timer.
Parameters:
- timer_id timer ID obtained by osTimerNew.
- ticks millisecond tick value of the timer.
Return: status code that indicates the execution status of the function.
function osTimerStop
cpp
osStatus_t osTimerStop(
osTimerId_t timer_id
)Stop a timer.
Parameters:
- timer_id timer ID obtained by osTimerNew.
Return: status code that indicates the execution status of the function.
function osTimerIsRunning
cpp
uint32_t osTimerIsRunning(
osTimerId_t timer_id
)Check if a timer is running.
Parameters:
- timer_id timer ID obtained by osTimerNew.
Return: 0 not running, 1 running.
function osTimerDelete
cpp
osStatus_t osTimerDelete(
osTimerId_t timer_id
)Delete a timer.
Parameters:
- timer_id timer ID obtained by osTimerNew.
Return: status code that indicates the execution status of the function.
function osDelay
cpp
osStatus_t osDelay(
uint32_t ticks
)Wait for Timeout (Time Delay).
Parameters:
- ticks milliseconds to delay current execution.
Return: status code that indicates the execution status of the function.
function osDelayUntil
cpp
osStatus_t osDelayUntil(
uint32_t ticks
)Wait until specified time.
Parameters:
- ticks absolute time in ticks
Return: status code that indicates the execution status of the function.
function osDelayUs
cpp
osStatus_t osDelayUs(
uint32_t microseconds
)Wait for Timeout (Microsecond Delay).
Parameters:
- microseconds microseconds to delay current execution
Return: status code that indicates the execution status of the function.