Bird
Raised Fist0
FreeRTOSprogramming~20 mins

Deferred interrupt processing architecture in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Deferred Interrupt Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of Deferred Interrupt Handler Execution

Consider a FreeRTOS system where an interrupt service routine (ISR) defers processing to a task using a queue. What will be the output of the following code snippet when the interrupt triggers?

FreeRTOS
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"

QueueHandle_t xQueue;

void vDeferredTask(void *pvParameters) {
    int receivedValue;
    while(1) {
        if(xQueueReceive(xQueue, &receivedValue, portMAX_DELAY) == pdPASS) {
            printf("Processed value: %d\n", receivedValue);
        }
    }
}

void vISR_Handler(void) {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    int valueToSend = 42;
    xQueueSendFromISR(xQueue, &valueToSend, &xHigherPriorityTaskWoken);
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

int main() {
    xQueue = xQueueCreate(5, sizeof(int));
    xTaskCreate(vDeferredTask, "DeferredTask", 1000, NULL, 1, NULL);
    vISR_Handler();
    vTaskStartScheduler();
    return 0;
}
ARuntime error: Queue not created
BNo output, task never receives data
CCompilation error due to missing ISR attribute
DProcessed value: 42
Attempts:
2 left
💡 Hint

Think about how the ISR sends data to the queue and how the task waits for data.

🧠 Conceptual
intermediate
1:30remaining
Understanding Deferred Interrupt Processing Benefits

Which of the following is the main advantage of using deferred interrupt processing in an embedded system?

AIt guarantees that all interrupts are processed in the order they occur.
BIt reduces ISR execution time by deferring heavy processing to tasks, improving system responsiveness.
CIt eliminates the need for interrupt priorities in the system.
DIt allows the ISR to execute lengthy code without blocking other interrupts.
Attempts:
2 left
💡 Hint

Consider how deferring work affects interrupt latency and system responsiveness.

🔧 Debug
advanced
2:30remaining
Debugging Deferred Interrupt Queue Overflow

In a FreeRTOS system, a deferred interrupt processing task reads from a queue filled by an ISR. The system sometimes crashes with a stack overflow error. Which code snippet below most likely causes this issue?

FreeRTOS
void vISR_Handler(void) {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    int valueToSend = 100;
    for(int i = 0; i < 10; i++) {
        xQueueSendFromISR(xQueue, &valueToSend, &xHigherPriorityTaskWoken);
    }
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
AThe ISR sends multiple items without checking if the queue is full, causing overflow.
BThe ISR uses a local variable for xHigherPriorityTaskWoken, which is incorrect.
CThe ISR does not call portYIELD_FROM_ISR, so the task never runs.
DThe task reading the queue uses a blocking call with zero timeout.
Attempts:
2 left
💡 Hint

Think about what happens if the ISR sends more items than the queue can hold.

📝 Syntax
advanced
1:30remaining
Identify Syntax Error in Deferred Interrupt Code

Which option contains a syntax error that prevents the deferred interrupt processing code from compiling?

FreeRTOS
void vISR_Handler(void) {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE
    int valueToSend = 10;
    xQueueSendFromISR(xQueue, &valueToSend, &xHigherPriorityTaskWoken);
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
AMissing semicolon after initializing xHigherPriorityTaskWoken.
BUsing xQueueSend instead of xQueueSendFromISR inside ISR.
CIncorrect function return type for ISR handler.
DIncorrect pointer usage in xQueueSendFromISR call.
Attempts:
2 left
💡 Hint

Look carefully at each line for missing punctuation.

🚀 Application
expert
3:00remaining
Designing Deferred Interrupt Processing with Multiple Priorities

You need to design a deferred interrupt processing system in FreeRTOS where two ISRs with different priorities defer work to tasks. The high priority ISR defers critical data, and the low priority ISR defers less critical data. Which design approach below best ensures that critical data is processed first without blocking the system?

AUse one queue and one task; the task uses a priority field in data to decide processing order.
BUse a single queue for both ISRs and one task that processes data in the order received.
CUse two separate queues and two tasks with different priorities; the high priority task processes critical data, the low priority task processes less critical data.
DUse two queues but a single low priority task that processes both queues alternately.
Attempts:
2 left
💡 Hint

Consider how task priorities and separate queues affect processing order and responsiveness.

Practice

(1/5)
1. What is the main purpose of deferred interrupt processing in FreeRTOS?
easy
A. To disable all interrupts during task execution
B. To execute all interrupt code inside the ISR for speed
C. To split interrupt handling between a fast ISR and a slower task
D. To avoid using queues or notifications in interrupt handling

Solution

  1. Step 1: Understand ISR limitations

    ISRs should be short to keep system responsive and avoid blocking other interrupts.
  2. Step 2: Role of deferred processing

    Deferred processing moves longer work to a task, improving system reliability and responsiveness.
  3. Final Answer:

    To split interrupt handling between a fast ISR and a slower task -> Option C
  4. Quick Check:

    Deferred interrupt processing = splitting work [OK]
Hint: Remember: ISR is fast, task does the heavy work [OK]
Common Mistakes:
  • Thinking all work should be done inside ISR
  • Believing interrupts are disabled during task execution
  • Ignoring the use of task notifications or queues
2. Which of the following is the correct way to notify a task from an ISR in FreeRTOS?
easy
A. xTaskNotifyGiveFromISR(taskHandle, &higherPriorityTaskWoken);
B. xTaskNotifyGive(taskHandle);
C. vTaskDelay(10);
D. xQueueSend(queueHandle, &data, portMAX_DELAY);

Solution

  1. Step 1: Identify ISR-safe notification function

    Only functions ending with 'FromISR' are safe to call inside ISRs.
  2. Step 2: Check options

    xTaskNotifyGiveFromISR is designed for ISR context; others are not ISR-safe or unrelated.
  3. Final Answer:

    xTaskNotifyGiveFromISR(taskHandle, &higherPriorityTaskWoken); -> Option A
  4. Quick Check:

    ISR notification uses FromISR functions [OK]
Hint: Use 'FromISR' functions inside ISRs only [OK]
Common Mistakes:
  • Using normal task notification functions inside ISR
  • Calling blocking functions like vTaskDelay in ISR
  • Using queue send with infinite block time inside ISR
3. Given the following code snippet, what will be the output?
void ISR_Handler() {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    xTaskNotifyGiveFromISR(taskHandle, &xHigherPriorityTaskWoken);
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

void TaskFunction(void *pvParameters) {
    for(;;) {
        ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
        printf("Task notified\n");
    }
}
medium
A. Task notified printed only once
B. No output because task is never notified
C. Compilation error due to missing parameters
D. Task notified printed each time ISR runs

Solution

  1. Step 1: Analyze ISR notification

    ISR calls xTaskNotifyGiveFromISR which increments the task's notification count and may cause context switch.
  2. Step 2: Analyze task behavior

    Task blocks on ulTaskNotifyTake until notified, then prints "Task notified" and loops back to wait again.
  3. Final Answer:

    Task notified printed each time ISR runs -> Option D
  4. Quick Check:

    ISR notifies task -> task prints [OK]
Hint: ISR notification wakes task repeatedly [OK]
Common Mistakes:
  • Assuming task never wakes up
  • Confusing notification count with binary flag
  • Thinking task prints only once
4. Identify the error in this deferred interrupt processing code snippet:
void ISR_Handler() {
    xQueueSend(queueHandle, &data, portMAX_DELAY);
}

void TaskFunction(void *pvParameters) {
    for(;;) {
        if(xQueueReceive(queueHandle, &receivedData, portMAX_DELAY) == pdPASS) {
            process(receivedData);
        }
    }
}
medium
A. xQueueReceive should be called from ISR
B. Using portMAX_DELAY in ISR causes a blocking call
C. ISR should not send data to queue
D. Task should not block on queue receive

Solution

  1. Step 1: Check ISR queue send parameters

    portMAX_DELAY causes blocking; ISRs must never block or wait.
  2. Step 2: Correct usage in ISR

    Use xQueueSendFromISR with zero block time to avoid blocking in ISR.
  3. Final Answer:

    Using portMAX_DELAY in ISR causes a blocking call -> Option B
  4. Quick Check:

    ISRs must not block = no portMAX_DELAY in ISR [OK]
Hint: Never block inside ISR; use FromISR functions with zero wait [OK]
Common Mistakes:
  • Using blocking calls inside ISR
  • Calling task functions from ISR
  • Confusing ISR and task context functions
5. You want to design a deferred interrupt processing system where multiple ISRs notify a single task to process different events. Which approach best ensures the task processes all events without missing any notifications?
hard
A. Use a queue to send event data from each ISR to the task
B. Use xTaskNotifyGiveFromISR from each ISR without data
C. Use global flags set by ISRs and polled by the task
D. Disable interrupts while the task processes events

Solution

  1. Step 1: Understand notification limitations

    xTaskNotifyGiveFromISR increments a count but cannot carry event data, risking lost info if multiple events occur quickly.
  2. Step 2: Use queue for event data

    Queues can hold multiple event messages safely, ensuring the task processes all events without loss.
  3. Final Answer:

    Use a queue to send event data from each ISR to the task -> Option A
  4. Quick Check:

    Queues hold multiple events safely [OK]
Hint: Use queues to handle multiple event data safely [OK]
Common Mistakes:
  • Relying on notifications without event data
  • Using global flags causing race conditions
  • Disabling interrupts too long hurting responsiveness
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard