Control access to shared resources.
More...
Description
The Semaphore Management function group is used to manage and protect access to shared resources. For example, with a Semaphore the access to a group of identical peripherals can be managed. The number of available resources is specified as parameter of the osSemaphoreCreate function.
Each time a Semaphore token is obtained with osSemaphoreWait the semaphore count is decremented. When the semaphore count is 0, no Semaphore token can be obtained. Semaphores are released with osSemaphoreRelease; this function increments the semaphore count.
CMSIS-RTOS Semaphore
Define Documentation
#define osFeature_Semaphore 30 |
A CMSIS-RTOS implementation may support semaphores. The value osFeature_Semaphore indicates the maximum index count for a semaphore.
#define osSemaphore |
( |
|
name | ) |
&os_semaphore_def_##name |
Access to semaphore object for the functions osSemaphoreCreate.
- Parameters:
-
name | name of the semaphore object. |
- Note:
- CAN BE CHANGED: The parameter to osSemaphore shall be consistent but the macro body is implementation specific in every CMSIS-RTOS.
Define a semaphore object that is referenced by osSemaphore.
- Parameters:
-
name | name of the semaphore object. |
- Note:
- CAN BE CHANGED: The parameter to osSemaphoreDef shall be consistent but the macro body is implementation specific in every CMSIS-RTOS.
Function Documentation
- Parameters:
-
[in] | semaphore_def | semaphore definition referenced with osSemaphore. |
[in] | count | number of available resources. |
- Returns:
- semaphore ID for reference by other functions or NULL in case of error.
- Note:
- MUST REMAIN UNCHANGED: osSemaphoreCreate shall be consistent in every CMSIS-RTOS.
Create and initialize a Semaphore object that is used to manage access to shared resources. The parameter count specifies the number of available resources. The count value 1 creates a binary semaphore.
- Parameters:
-
[in] | semaphore_id | semaphore object referenced with osSemaphore. |
- Returns:
- status code that indicates the execution status of the function.
- Note:
- MUST REMAIN UNCHANGED: osSemaphoreRelease shall be consistent in every CMSIS-RTOS.
Release a Semaphore token. This increments the count of avaiable semaphore tokens.
- Note:
- osSemaphoreRelease can be called also from interrupt service routines.
Status and Error Codes
- osOK: the semaphore has been released.
- osErrorResource: all tokens have already been released.
- osErrorParameter: the parameter semaphore_id is incorrect.
int32_t osSemaphoreWait |
( |
osSemaphoreId |
semaphore_id, |
|
|
uint32_t |
millisec |
|
) |
| |
- Parameters:
-
[in] | semaphore_id | semaphore object referenced with osSemaphore. |
[in] | millisec | timeout value or 0 in case of no time-out. |
- Returns:
- number of available tokens, or -1 in case of incorrect parameters.
- Note:
- MUST REMAIN UNCHANGED: osSemaphoreWait shall be consistent in every CMSIS-RTOS.
Wait until a Semaphore token becomes available. When no Semaphore token is available, the function waits for the time specified with the parameter millisec. When millisec is set to osWaitForever, the function will wait for an infinite time until a Semaphore token becomes available. The return value indicates the number of available tokens (the semaphore count value). If 0 is returned, then no semaphore was available.