Bird
0
0

Examine the following ISR code snippet for deferring processing using a queue:

medium📝 Debug Q6 of 15
FreeRTOS - Interrupt Management
Examine the following ISR code snippet for deferring processing using a queue:
void ISR_Handler(void) {
  BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  xQueueSendFromISR(queueHandle, &data, &xHigherPriorityTaskWoken);
  portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
What is the main issue with this code?
AxQueueSendFromISR is used incorrectly without checking return value
BxQueueSend should be used instead of xQueueSendFromISR inside ISR
CportYIELD_FROM_ISR should not be called in ISR
DxHigherPriorityTaskWoken should be initialized to pdTRUE
Step-by-Step Solution
Solution:
  1. Step 1: Analyze API usage

    xQueueSendFromISR returns a BaseType_t indicating success or failure.
  2. Step 2: Identify missing check

    The code does not check if xQueueSendFromISR succeeded, which can cause lost data if the queue is full.
  3. Step 3: Confirm other options

    xQueueSend is not ISR safe, portYIELD_FROM_ISR is correct, and xHigherPriorityTaskWoken should start as pdFALSE.
  4. Final Answer:

    Missing return value check of xQueueSendFromISR -> Option A
  5. Quick Check:

    Always check ISR API return values [OK]
Quick Trick: Always verify ISR API return values [OK]
Common Mistakes:
  • Using non-ISR safe APIs inside ISR
  • Ignoring return values of ISR-safe functions
  • Incorrect initialization of xHigherPriorityTaskWoken

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes