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:

  1. 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.

  2. 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.

    • 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.

  3. Create and delete the mutex:

  4. Take and Release a mutex:

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”.