Bird
0
0

Identify the error in this ISR code snippet:

medium📝 Debug Q14 of 15
FreeRTOS - Interrupt Management

Identify the error in this ISR code snippet:

void ISR_Handler(void) {
    BaseType_t higherPriorityTaskWoken = pdFALSE;
    xSemaphoreGive(semaphore);
    if (higherPriorityTaskWoken) {
        portYIELD_FROM_ISR();
    }
}

What is the problem here?

AThe variable <code>higherPriorityTaskWoken</code> should be global.
BThe semaphore is given twice causing overflow.
CThe <code>portYIELD_FROM_ISR()</code> call is outside the ISR.
DThe <code>higherPriorityTaskWoken</code> variable is not passed to <code>xSemaphoreGiveFromISR</code>.
Step-by-Step Solution
Solution:
  1. Step 1: Check function used for semaphore give

    The code uses xSemaphoreGive, which is not safe inside ISR context.
  2. Step 2: Correct ISR-safe function usage

    Inside ISR, xSemaphoreGiveFromISR must be used with higherPriorityTaskWoken passed by reference to track task wake.
  3. Final Answer:

    The higherPriorityTaskWoken variable is not passed to xSemaphoreGiveFromISR. -> Option D
  4. Quick Check:

    Use FromISR functions with higherPriorityTaskWoken [OK]
Quick Trick: Always pass higherPriorityTaskWoken to FromISR functions [OK]
Common Mistakes:
  • Using normal API functions inside ISR
  • Not passing higherPriorityTaskWoken pointer
  • Declaring higherPriorityTaskWoken as global unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes