CMSIS-RTOS  Version 1.02
CMSIS-RTOS API: Generic RTOS interface for Cortex-M processor-based devices.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Signal Management

Control or wait for signal flags. More...

Macros

#define osFeature_Signals   8
 maximum number of Signal Flags available per thread More...
 

Functions

int32_t osSignalSet (osThreadId thread_id, int32_t signals)
 Set the specified Signal Flags of an active thread. More...
 
int32_t osSignalClear (osThreadId thread_id, int32_t signals)
 Clear the specified Signal Flags of an active thread. More...
 
osEvent osSignalWait (int32_t signals, uint32_t millisec)
 Wait for one or more Signal Flags to become signaled for the current RUNNING thread. More...
 

Description

The Signal Management function group allows to control or wait signal flags. Each thread has assigned signal flags.

Macro Definition Documentation

#define osFeature_Signals   8

The CMSIS-RTOS API may support a variable number of signal flags. This define specifies the number of signal flags available per thread. The maximum value is 31 signal flags per thread.

Function Documentation

int32_t osSignalClear ( osThreadId  thread_id,
int32_t  signals 
)
Parameters
[in]thread_idthread ID obtained by osThreadCreate or osThreadGetId.
[in]signalsspecifies the signal flags of the thread that shall be cleared.
Returns
previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
Note
MUST REMAIN UNCHANGED: osSignalClear shall be consistent in every CMSIS-RTOS.

Clear the signal flags of an active thread. This function may be used also within interrupt service routines.

Example

void Thread_2 (void const *arg);
osThreadDef (Thread_2, osPriorityHigh, 1, 0);
static void EX_Signal_1 (void) {
int32_t signals;
osThreadId thread_id;
thread_id = osThreadCreate (osThread(Thread_2), NULL);
if (thread_id == NULL) {
// Failed to create a thread.
}
else {
f :
signals = osSignalClear (thread_id, 0x01);
}
}
int32_t osSignalSet ( osThreadId  thread_id,
int32_t  signals 
)
Parameters
[in]thread_idthread ID obtained by osThreadCreate or osThreadGetId.
[in]signalsspecifies the signal flags of the thread that should be set.
Returns
previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
Note
MUST REMAIN UNCHANGED: osSignalSet shall be consistent in every CMSIS-RTOS.

Set the signal flags of an active thread. This function may be used also within interrupt service routines.

Example

void Thread_2 (void const *arg);
osThreadDef (Thread_2, osPriorityHigh, 1, 0);
static void EX_Signal_1 (void) {
int32_t signals;
uint32_t exec;
osThreadId thread_id;
thread_id = osThreadCreate (osThread(Thread_2), NULL);
if (thread_id == NULL) {
// Failed to create a thread.
}
else {
signals = osSignalSet (thread_id, 0x00000005); // Send signals to the created thread
}
}
osEvent osSignalWait ( int32_t  signals,
uint32_t  millisec 
)
Parameters
[in]signalswait until all specified signal flags set or 0 for any single signal flag.
[in]millisectimeout value or 0 in case of no time-out.
Returns
event flag information or error code.
Note
MUST REMAIN UNCHANGED: osSignalWait shall be consistent in every CMSIS-RTOS.

Suspend the execution of the current RUNNING thread until all specified signal flags with the parameter signals are set. When this signal flags are already set, the function returns instantly. Otherwise the thread is put into the state WAITING. Signal flags that are reported as event are automatically cleared.

The argument millisec specifies how long the system waits for the specified signal flags. While the system waits the tread calling this function is put into the state WAITING. The timeout value can have the following values:

  • when millisec is 0, the function returns instantly.
  • when millisec is set to osWaitForever the function will wait for an infinite time until a specified signal is set.
  • all other values specify a time in millisecond for a timeout.

Status and Error Codes

  • osOK: no signal received when the timeout value millisec was 0.
  • osEventTimeout: signal not occurred within timeout
  • osEventSignal: signal occurred, value.signals contains the signal flags; these signal flags are cleared.
  • osErrorValue: the value signals is outside of the permitted range.
  • osErrorISR: osSignalWait cannot be called from interrupt service routines.

Example

void Thread_2 (void const *arg);
osThreadDef (Thread_2, osPriorityHigh, 1, 0);
static void EX_Signal_1 (void) {
osThreadId thread_id;
osEvent evt;
thread_id = osThreadCreate (osThread(Thread_2), NULL);
if (thread_id == NULL) {
// Failed to create a thread.
}
else {
:
// wait for a signal
evt = osSignalWait (0x01, 100);
if (evt.status == osEventSignal) {
// handle event status
}
}
}