HAL FreeRTOS How to Use ¶
- group OS_How_To_Use
-
How to use the OS HAL module driver ¶
The OS HAL driver can be used as follows:
Create and delete a Semaphore:
To Create a new semaphore instance, use the HAL_OS_SemaphoreCreate() function.
The HAL_OS_SemaphoreCreate() API allows to:
create a binary semaphore using xSemaphoreCreateBinary() when configSUPPORT_DYNAMIC_ALLOCATION is equal to 1.
ensure that the semaphore instance is free.
To Delete a semaphore instance, use the HAL_OS_SemaphoreDelete() function.
The HAL_OS_SemaphoreCreate() API allows to delete the semaphore using vSemaphoreDelete() function when the the processor is not in interrupt mode.
Take and Release a Semaphore:
To Take a semaphore that have previously been created with a call to HAL_OS_SemaphoreCreate(), use the HAL_OS_SemaphoreTake() function.
The HAL_OS_SemaphoreTake() API allows to wait until a semaphore is free and take it or a timeout.
In case of HAL_OS_SemaphoreTake is called from a thread, it calls xSemaphoreTake() FreeRTOS function with the user given semaphore object and timeout.
In case of HAL_OS_SemaphoreTake frm an ISR, it calls xSemaphoreTakeFromISR() FreeRTOS function with the user given semaphore object.
if the timeout is different from zero the HAL_OS_SemaphoreTake return HAL_OS_ERROR as the usage of a timeout within an ISR is forbidden.
To Release a semaphore, use the HAL_OS_SemaphoreRelease() function.
In case of HAL_OS_SemaphoreRelease is called from a thread, it calls xSemaphoreGive() FreeRTOS function with the user given semaphore object.
If it is called from an ISR, the HAL_OS_SemaphoreRelease calls xSemaphoreGiveFromISR() FreeRTOS function.
Create and delete the mutex:
To Create a new mutex instance, use the HAL_OS_MutexCreate() function that calls xSemaphoreCreateMutex() FreeRTOS function.
To Delete a mutex instance, use the HAL_OS_MutexDelete() function.
The HAL_OS_MutexDelete() API allows to delete the mutex using FreeRTOS function “vSemaphoreDelete”.
Take and Release a mutex:
To Take a mutex have previously been created with a call to HAL_OS_MutexTake(), use the HAL_OS_MutexTake() function.
The HAL_OS_MutexTake() allows to obtain the mutex using FreeRTOS function “xSemaphoreTake”.
To Release a mutex, use the HAL_OS_MutexRelease() function.
The HAL_OS_MutexRelease() allows to free the mutex using FreeRTOS function “xSemaphoreGive”.
Note ¶
Mutex services are forbidden under ISR, HAL mutex APIs return HAL_OS_ERROR if called from an ISR.
The OS FreeRTOS Abstraction layer can be used only with the config configSUPPORT_DYNAMIC_ALLOCATION set to “1”.