0
0
FreeRTOSprogramming~5 mins

Deferred interrupt processing architecture in FreeRTOS

Choose your learning style9 modes available
Introduction

Deferred interrupt processing helps keep your system fast and responsive by quickly handling urgent tasks and delaying less urgent work.

When an interrupt needs to respond quickly but the full processing takes too long.
When you want to avoid blocking other important tasks during interrupt handling.
When you need to split interrupt work into a fast part and a slower part.
When your system has limited CPU time and you want to manage workload efficiently.
Syntax
FreeRTOS
void ISR_Handler(void) {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    // Quick interrupt handling code here
    xTaskNotifyFromISR(taskHandle, 0, eNoAction, &xHigherPriorityTaskWoken);
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

void Task_Function(void *pvParameters) {
    for(;;) {
        ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
        // Deferred processing here
    }
}

The ISR (interrupt service routine) does only quick work and notifies a task.

The task does the longer processing outside the interrupt.

Examples
This ISR reads data fast and notifies a task to process it later.
FreeRTOS
void ISR_Handler(void) {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    // Read data quickly
    xTaskNotifyFromISR(dataTaskHandle, 0, eNoAction, &xHigherPriorityTaskWoken);
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
The task waits for notification and then processes data outside the ISR.
FreeRTOS
void DataProcessingTask(void *pvParameters) {
    for(;;) {
        ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
        // Process data here
    }
}
Sample Program

This program creates a task that waits for an interrupt notification. The ISR quickly notifies the task, which then does the deferred processing and prints a message.

FreeRTOS
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include <stdio.h>

TaskHandle_t dataTaskHandle = NULL;

void ISR_Handler(void) {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    // Simulate quick interrupt work
    xTaskNotifyFromISR(dataTaskHandle, 0, eNoAction, &xHigherPriorityTaskWoken);
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

void DataProcessingTask(void *pvParameters) {
    for(;;) {
        ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
        // Deferred processing
        printf("Deferred interrupt processing done.\n");
    }
}

int main(void) {
    xTaskCreate(DataProcessingTask, "DataTask", 1000, NULL, 2, &dataTaskHandle);
    vTaskStartScheduler();
    return 0;
}
OutputSuccess
Important Notes

Always keep ISR code short to avoid delaying other interrupts.

Use FreeRTOS functions ending with 'FromISR' inside ISRs.

Deferred processing helps keep your system stable and responsive.

Summary

Deferred interrupt processing splits work between a fast ISR and a slower task.

Use task notifications or queues to signal tasks from ISRs.

This approach improves system responsiveness and reliability.