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

Utilizing Deferred Procedure Calls for Background Tasks

Learners will configure software interrupts or deferred procedure call mechanisms to handle post-interrupt processing at lower priority levels than the kernel.

In this lesson, you will learn how to shift time-consuming, non-critical processing out of high-priority Interrupt Service Routines (ISRs) and into background tasks using Deferred Procedure Calls (DPCs).

The Interrupt Bottleneck

When an interrupt occurs, the CPU halts its current task to execute an ISR. Because ISRs often run at a higher priority than the RTOS scheduler itself, keeping them brief is critical to maintaining system responsiveness. If an ISR performs heavy data processing or complex logic, it blocks the scheduler, leading to increased interrupt latency and jitter.

Implementing Deferred Processing

A Deferred Procedure Call (or "Bottom Half" processing) acts as a bridge. The ISR performs only the absolute minimum work required—such as acknowledging the hardware and capturing a raw pointer or timestamp—and then triggers a deferred task to handle the "heavy lifting."

By offloading this work, the ISR exits almost immediately, allowing the RTOS to resume its scheduling duties. The deferred task, which runs at a lower priority than the ISR, then processes the captured data when the CPU is free.

Conceptual Implementation

In an RTOS environment, you typically signal a background task using a semaphore or a message queue:

// High-priority ISR
void Hardware_ISR(void) {
    // 1. Capture data quickly
    uint32_t data = Hardware_ReadRegister();
    
    // 2. Signal the background task to process it
    xSemaphoreGiveFromISR(xProcessingSemaphore, NULL);
    
    // ISR exits immediately, keeping latency low
}

// Low-priority Background Task
void Background_Processing_Task(void *pvParameters) {
    while(1) {
        // Wait for the ISR to signal that data is ready
        if (xSemaphoreTake(xProcessingSemaphore, portMAX_DELAY)) {
            // Perform complex calculations here (e.g., filtering or formatting)
            ProcessData(); 
        }
    }
}

By separating the "Top Half" (the ISR) from the "Bottom Half" (the background task), you ensure that your system remains responsive to new external events while still managing heavy computational loads in a structured, thread-safe manner. This pattern is the primary defense against the performance degradation caused by bloated interrupt handlers.

Key Takeaway: Deferred Procedure Calls maintain system determinism by restricting ISRs to minimal hardware interaction and offloading complex processing to background tasks.