CMSIS-RTOS  Version 1.03
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 time period or unspecified events. More...

Macros

#define osFeature_Wait   1
 osWait function: 1=available, 0=not available More...
 

Functions

osStatus osDelay (uint32_t millisec)
 Wait for Timeout (Time Delay). More...
 
osEvent osWait (uint32_t millisec)
 Wait for Signal, Message, Mail, or Timeout. More...
 

Description

The Generic Wait function group provides means for a time delay and allow to wait for unspecified events.

Macro Definition Documentation

#define osFeature_Wait   1

A CMSIS-RTOS implementation may support the generic wait function osWait.

CMSIS-RTOS RTX Setting: osFeature_Wait is 0

Function Documentation

osStatus osDelay ( uint32_t  millisec)
Parameters
[in]millisectime delay value
Returns
status code that indicates the execution status of the function.

Wait for a specified time period in millisec.

The millisec value specifies the number of timer ticks and is therefore an upper bound. The exact time delay depends on the actual time elapsed since the last timer tick.

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.

Status and Error Codes

  • osEventTimeout: the time delay is executed.
  • osErrorISR: osDelay cannot be called from interrupt service routines.
Note
Cannot be called from Interrupt Service Routines.

Code Example

#include "cmsis_os.h"
void Thread_1 (void const *arg) { // Thread function
osStatus status; // capture the return status
uint32_t delayTime; // delay time in milliseconds
delayTime = 1000; // delay 1 second
:
status = osDelay (delayTime); // suspend thread execution
// handle error code
:
}
osEvent osWait ( uint32_t  millisec)
Parameters
[in]millisecTimout Value or 0 in case of no time-out
Returns
event that contains signal, message, or mail information or error code.
Note
MUST REMAIN UNCHANGED: osWait shall be consistent in every CMSIS-RTOS.

Wait for any event of the type Signal, Message, Mail for a specified time period in millisec. While the system waits, the thread that is calling this function is put into the state WAITING. When millisec is set to osWaitForever, the function will wait for an infinite time until an event occurs.

The osWait function puts a thread into the state WAITING and waits for any of the following events:

  • A signal sent to that thread explicitly
  • A message from a message object that is registered to that thread
  • A mail from a mail object that is registered to that thread
Note
This function is optional and may not be provided by all CMSIS-RTOS implementations.

Status and Error Codes

  • osEventSignal: a signal event occurred and is returned.
  • osEventMessage: a message event occurred and is returned.
  • osEventMail: a mail event occurred and is returned.
  • osEventTimeout: the time delay is executed.
  • osErrorISR: osDelay cannot be called from interrupt service routines.
Note
Cannot be called from Interrupt Service Routines.

Code Example

#include "cmsis_os.h"
void Thread_1 (void const *arg) { // Thread function
osEvent Event; // capture the event
uint32_t waitTime; // wait time in milliseconds
:
waitTime = osWaitForever; // special "wait" value
Event = osWait (waitTime); // wait forever and until an event occurred
switch (Event.status) {
case osEventSignal: // Signal arrived
: // Event.value.signals contains the signal flags
break;
case osEventMessage: // Message arrived
: // Event.value.p contains the message pointer
: // Event.def.message_id contains the message Id
break;
case osEventMail: // Mail arrived
: // Event.value.p contains the mail pointer
: // Event.def.mail_id contains the mail Id
break;
case osEventTimeout: // Timeout occurred
break;
default: // Error occurred
break;
}
:
}