Bird
0
0

Examine the following FreeRTOS ISR code snippet for nested interrupt handling:

medium📝 Debug Q6 of 15
FreeRTOS - Interrupt Management

Examine the following FreeRTOS ISR code snippet for nested interrupt handling:

void ISR_MediumPriority(void) {
  BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  xSemaphoreGiveFromISR(xSemaphore, &xHigherPriorityTaskWoken);
  if(xHigherPriorityTaskWoken) {
    taskYIELD();
  }
}

What is the main issue with this code?

AUsing xSemaphoreGiveFromISR() instead of xSemaphoreGive() in ISR
BNot initializing xHigherPriorityTaskWoken to pdTRUE before use
CCalling taskYIELD() inside an ISR instead of using portYIELD_FROM_ISR()
DFailing to check if the semaphore handle is NULL before giving
Step-by-Step Solution
Solution:
  1. Step 1: Identify the ISR context

    Inside an ISR, FreeRTOS requires special yield functions to safely switch tasks.
  2. Step 2: Check the yield function used

    The code calls taskYIELD(), which is intended for task context, not ISR context.
  3. Step 3: Correct function usage

    In ISR, portYIELD_FROM_ISR(xHigherPriorityTaskWoken) must be used to request a context switch.
  4. Final Answer:

    Calling taskYIELD() inside an ISR instead of using portYIELD_FROM_ISR() -> Option C
  5. Quick Check:

    ISR yield must use portYIELD_FROM_ISR() [OK]
Quick Trick: Use portYIELD_FROM_ISR() to yield inside ISRs [OK]
Common Mistakes:
  • Using taskYIELD() inside an ISR
  • Not using portYIELD_FROM_ISR() after ISR API calls
  • Assuming xHigherPriorityTaskWoken must be true initially

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes