Bird
0
0

In a system using FreeRTOS, you want to safely give a mutex from an ISR and ensure the highest priority task runs immediately if unblocked. Which code snippet correctly implements this?

hard📝 Application Q9 of 15
FreeRTOS - Interrupt Management
In a system using FreeRTOS, you want to safely give a mutex from an ISR and ensure the highest priority task runs immediately if unblocked. Which code snippet correctly implements this?
ABaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(xMutex, &xHigherPriorityTaskWoken); portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
BxSemaphoreGive(xMutex); vTaskDelay(1);
CBaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGive(xMutex); portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
DxSemaphoreGiveFromISR(xMutex, NULL);
Step-by-Step Solution
Solution:
  1. Step 1: Use FromISR function to give mutex inside ISR

    Use xSemaphoreGiveFromISR with a pointer to xHigherPriorityTaskWoken.
  2. Step 2: Call portYIELD_FROM_ISR with the wake flag

    This triggers a context switch if a higher priority task was unblocked.
  3. Final Answer:

    BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(xMutex, &xHigherPriorityTaskWoken); portYIELD_FROM_ISR(xHigherPriorityTaskWoken); -> Option A
  4. Quick Check:

    Mutex give from ISR with yield flag = BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(xMutex, &xHigherPriorityTaskWoken); portYIELD_FROM_ISR(xHigherPriorityTaskWoken); [OK]
Quick Trick: Always pass wake flag pointer and yield after FromISR mutex give [OK]
Common Mistakes:
  • Using normal xSemaphoreGive inside ISR
  • Not passing wake flag pointer
  • Calling yield without checking flag

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes