0
0
FreeRTOSprogramming~5 mins

ISR-safe API functions (FromISR suffix) in FreeRTOS - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: ISR-safe API functions (FromISR suffix)
O(1)
Understanding Time Complexity

When using ISR-safe API functions in FreeRTOS, it's important to know how their execution time changes as input grows.

We want to see how the cost of these functions scales when called from interrupts.

Scenario Under Consideration

Analyze the time complexity of this ISR-safe queue send function.


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

This code sends data to a queue safely from an interrupt service routine.

Identify Repeating Operations

Look for loops or repeated steps inside the ISR-safe function.

  • Primary operation: The queue send checks and updates queue state.
  • How many times: It runs a fixed number of steps, no loops over input size.
How Execution Grows With Input

The function's work stays about the same no matter how many items are in the queue.

Input Size (n)Approx. Operations
10Constant steps
100Constant steps
1000Constant steps

Pattern observation: The execution time stays constant regardless of input size.

Final Time Complexity

Time Complexity: O(1)

This means the function takes about the same time no matter how big the queue is.

Common Mistake

[X] Wrong: "The ISR-safe queue send takes longer if the queue has more items."

[OK] Correct: The function only updates pointers and flags, not scanning all items, so time stays constant.

Interview Connect

Understanding how ISR-safe functions behave helps you write reliable real-time code and explain your choices clearly.

Self-Check

"What if the ISR-safe function had to copy multiple items instead of one? How would the time complexity change?"