Complete the code to create a binary semaphore.
SemaphoreHandle_t xSemaphore = [1]();The function xSemaphoreCreateBinary() creates a binary semaphore in FreeRTOS.
Complete the code to take (acquire) the binary semaphore with a block time of 100 ticks.
if (xSemaphoreTake(xSemaphore, [1]) == pdTRUE) { // Critical section }
The second parameter of xSemaphoreTake() is the block time in ticks. Using 100 means it waits up to 100 ticks to take the semaphore.
Fix the error in the code to give back (release) the binary semaphore.
xSemaphore[1](xSemaphore);The correct function to release a binary semaphore is xSemaphoreGive().
Fill both blanks to create a binary semaphore and check if creation was successful.
SemaphoreHandle_t xSemaphore = [1](); if (xSemaphore [2] NULL) { // Semaphore created successfully }
Use xSemaphoreCreateBinary() to create the semaphore and check if it is not equal to NULL to confirm success.
Fill all three blanks to take the semaphore with no wait and then give it back.
if (xSemaphore[1](xSemaphore, [2]) == pdTRUE) { xSemaphore[3](xSemaphore); }
Use xSemaphoreTake() with block time 0 to try taking the semaphore without waiting, then release it with xSemaphoreGive().
