CMSIS-RTOS2  Version 2.1.0
Real-Time Operating System: API and RTX Reference Implementation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Generic Wait Functions

Wait for a certain period of time. More...

Functions

osStatus_t osDelay (uint32_t ticks)
 Wait for Timeout (Time Delay). More...
 
osStatus_t osDelayUntil (uint64_t ticks)
 Wait until specified time. More...
 

Description

The generic wait functions provide means for a time delay.

Note
Generic wait functions cannot be called from Interrupt Service Routines.

Function Documentation

osStatus_t osDelay ( uint32_t  ticks)
Parameters
[in]tickstime ticks value
Returns
status code that indicates the execution status of the function.

The function osDelay waits for a time period specified in kernel ticks. For a value of 1, the system waits until the next timer tick occurs. That means that the actual time delay may be up to one timer tick less.

Possible osStatus_t return values:

Note
This function cannot be called from Interrupt Service Routines.

Code Example

#include "cmsis_os2.h"
void Thread_1 (void *arg) { // Thread function
osStatus_t status; // capture the return status
uint32_t delayTime; // delay time in milliseconds
delayTime = 1000; // delay 1 second
status = osDelay (delayTime); // suspend thread execution
}
osStatus_t osDelayUntil ( uint64_t  ticks)
Parameters
[in]ticksabsolute time in ticks
Returns
status code that indicates the execution status of the function.

The function osDelayUntil waits until an absolute time (specified in kernel ticks) is reached.

Possible osStatus_t return values:

  • osOK: the time delay is executed.
  • osParameter: the time is either in the past or cannot be handled (out of bounds).
  • osErrorISR: osDelayUntil cannot be called from Interrupt Service Routines.
Note
This function cannot be called from Interrupt Service Routines.

Code Example

#include "cmsis_os2.h"
void Thread_1 (void *arg) { // Thread function
uint64_t tick;
tick = osKernelGetTickCount(); // retrieve the number of system ticks
for (;;) {
tick += 1000; // delay 1000 ticks periodically
osDelayUntil(tick);
// ...
}
}