Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 551 of 9367. Real-Time Operating Systems (RTOS)Free lesson

Implementing Deferred Interrupt Processing Patterns

Learners will decouple time-critical hardware response from non-critical processing by offloading logic to tasks using semaphores or task notifications.

Implementing Deferred Interrupt Processing Patterns

In this lesson, you will learn how to maintain system responsiveness by moving heavy-duty logic out of time-critical Interrupt Service Routines (ISRs) and into background tasks.

The Problem: ISR Bloat

When a hardware interrupt triggers, the CPU suspends all other task execution to run your ISR. If your ISR performs complex tasks—like processing a data packet, updating a display, or writing to a file system—it blocks the rest of your system. This "interrupt latency" can cause your RTOS to miss deadlines for other critical tasks, leading to instability or jitter.

The Solution: Deferred Processing

To keep your ISR lean, use the Deferred Interrupt Processing pattern. The ISR does the absolute minimum required: it clears the hardware interrupt flag and "signals" a high-priority task to handle the actual work. By offloading the processing to a task, you allow the RTOS scheduler to manage execution, ensuring that the interrupt-handling work doesn't starve other critical system components.

Implementation Example

Typically, you use a binary semaphore or a task notification to wake the worker task.

// High-priority worker task
void ProcessingTask(void *pvParameters) {
    while(1) {
        // Task blocks here until the ISR "gives" the semaphore
        if (xSemaphoreTake(xInterruptSemaphore, portMAX_DELAY)) {
            // Perform complex processing here
            HandleData(buffer);
        }
    }
}

// ISR (Minimal execution)
void Hardware_IRQHandler(void) {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    
    // Clear hardware interrupt flag
    ClearHardwareFlag();

    // Wake the processing task
    xSemaphoreGiveFromISR(xInterruptSemaphore, &xHigherPriorityTaskWoken);

    // Request context switch if the task we just woke has higher priority
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

In this model, the ISR runs for only a few microseconds, while the ProcessingTask runs whenever the scheduler permits. This architectural choice prevents your hardware interrupts from becoming bottlenecks and makes your real-time system significantly more predictable and robust under heavy load.

Key Takeaway: Never perform complex logic inside an ISR; use semaphores or notifications to hand off work to a dedicated task to ensure system-wide responsiveness.