Complete the code to create a mutex in FreeRTOS.
SemaphoreHandle_t xMutex = [1]();The function xSemaphoreCreateMutex() creates a mutex in FreeRTOS.
Complete the code to take a mutex with a block time of 100 ticks.
if(xSemaphoreTake(xMutex, [1]) == pdTRUE) { // Critical section }
The second parameter is the block time in ticks. Here, 100 ticks means wait up to 100 ticks to take the mutex.
Fix the error in the code to release the mutex correctly.
xSemaphore[1](xMutex);To release a mutex, use xSemaphoreGive().
Fill both blanks to create a priority inheritance scenario: Task A takes the mutex, Task B has higher priority and waits.
xTaskCreate(TaskA, "TaskA", 1000, NULL, [1], NULL); xTaskCreate(TaskB, "TaskB", 1000, NULL, [2], NULL);
Task A has lower priority (1), Task B has higher priority (3) to demonstrate priority inheritance.
Fill all three blanks to implement priority inheritance: Task A takes mutex, Task B waits, and priority is temporarily boosted.
void TaskA(void *pvParameters) {
xSemaphoreTake([1], portMAX_DELAY);
// Critical section
vTaskDelay([2]);
xSemaphoreGive([3]);
vTaskDelete(NULL);
}Task A takes the mutex xMutex, delays for 100 ticks simulating work, then gives back the mutex.
