0
0
FreeRTOSprogramming~5 mins

FreeRTOS interrupt priority restrictions - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: FreeRTOS interrupt priority restrictions
O(n)
Understanding Time Complexity

When working with FreeRTOS, interrupt priority rules affect how often and how quickly interrupts run.

We want to understand how the number of interrupt priority checks grows as more interrupts are used.

Scenario Under Consideration

Analyze the time complexity of the following code snippet.


// Example ISR with priority check
void vExampleISR(void) {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    if (uxInterruptPriority <= configMAX_SYSCALL_INTERRUPT_PRIORITY) {
        // Safe to call FreeRTOS API
        xSemaphoreGiveFromISR(xSemaphore, &xHigherPriorityTaskWoken);
    }
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
    

This code checks if the interrupt priority is allowed to call FreeRTOS APIs and then signals a semaphore.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: The priority check and semaphore give happen every time the interrupt fires.
  • How many times: Once per interrupt occurrence, which depends on hardware events.
How Execution Grows With Input

As the number of interrupts increases, the system must handle more priority checks and context switches.

Input Size (number of interrupts)Approx. Operations
1010 priority checks and possible semaphore signals
100100 priority checks and possible semaphore signals
10001000 priority checks and possible semaphore signals

Pattern observation: The operations grow linearly with the number of interrupts handled.

Final Time Complexity

Time Complexity: O(n)

This means the time spent checking priorities and handling interrupts grows directly with how many interrupts occur.

Common Mistake

[X] Wrong: "Interrupt priority checks happen only once regardless of interrupt count."

[OK] Correct: Each interrupt triggers its own priority check, so more interrupts mean more checks.

Interview Connect

Understanding how interrupt priority checks scale helps you design responsive and safe real-time systems.

Self-Check

"What if we decreased configMAX_SYSCALL_INTERRUPT_PRIORITY to allow more interrupts to call FreeRTOS APIs? How would the time complexity change?"