FreeRTOS interrupt priority restrictions - Time & Space 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.
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 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.
As the number of interrupts increases, the system must handle more priority checks and context switches.
| Input Size (number of interrupts) | Approx. Operations |
|---|---|
| 10 | 10 priority checks and possible semaphore signals |
| 100 | 100 priority checks and possible semaphore signals |
| 1000 | 1000 priority checks and possible semaphore signals |
Pattern observation: The operations grow linearly with the number of interrupts handled.
Time Complexity: O(n)
This means the time spent checking priorities and handling interrupts grows directly with how many interrupts occur.
[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.
Understanding how interrupt priority checks scale helps you design responsive and safe real-time systems.
"What if we decreased configMAX_SYSCALL_INTERRUPT_PRIORITY to allow more interrupts to call FreeRTOS APIs? How would the time complexity change?"
Practice
What does configMAX_SYSCALL_INTERRUPT_PRIORITY control in FreeRTOS?
Solution
Step 1: Understand FreeRTOS interrupt priority limits
FreeRTOS restricts API calls to interrupts at or below a certain priority level to maintain system stability.Step 2: Role of
This configuration sets the highest interrupt priority that can safely call FreeRTOS API functions.configMAX_SYSCALL_INTERRUPT_PRIORITYFinal Answer:
The highest interrupt priority that can safely call FreeRTOS API functions -> Option CQuick Check:
configMAX_SYSCALL_INTERRUPT_PRIORITY = highest safe ISR priority [OK]
- Confusing highest with lowest priority
- Thinking it limits number of interrupts
- Assuming it sets task priorities
Which of the following is the correct way to define configMAX_SYSCALL_INTERRUPT_PRIORITY in FreeRTOSConfig.h?
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( ??? )
Solution
Step 1: Understand priority values in FreeRTOS
Lower numeric values represent higher priorities; 0x00 is highest, 0xFF is lowest.Step 2: Correct format for configMAX_SYSCALL_INTERRUPT_PRIORITY
This macro must be a numeric value representing the highest interrupt priority allowed to call FreeRTOS API, typically a mid-level priority like 0x80.Final Answer:
0x80 // Mid-level priority -> Option AQuick Check:
Priority value must be numeric, not string [OK]
- Using string instead of numeric value
- Setting priority to 0x00 (too high)
- Using lowest priority 0xFF which disables API calls
Given configMAX_SYSCALL_INTERRUPT_PRIORITY is set to 0x50, which ISR priority can safely call FreeRTOS API functions?
ISR Priority Options:
A) 0x40
B) 0x50
C) 0x60
D) 0x30
Solution
Step 1: Compare ISR priorities with configMAX_SYSCALL_INTERRUPT_PRIORITY
Only ISRs with priority equal or numerically higher (lower urgency) than 0x50 can call FreeRTOS API.Step 2: Evaluate each option
0x40 and 0x30 are higher priority (lower number) than 0x50, so cannot call API. 0x50 equals limit, allowed. 0x60 is lower priority (higher number), also allowed.Final Answer:
0x50 and 0x60 -> Option DQuick Check:
ISR priority must be >= configMAX_SYSCALL_INTERRUPT_PRIORITY [OK]
- Confusing numeric priority order
- Allowing higher urgency ISRs to call API
- Ignoring equal priority as allowed
Identify the error in this ISR code snippet if configMAX_SYSCALL_INTERRUPT_PRIORITY is set to 0x60:
void ISR_Handler(void) {
NVIC_SetPriority(IRQn, 0x40);
vTaskNotifyGiveFromISR(taskHandle, NULL);
}Solution
Step 1: Check ISR priority against configMAX_SYSCALL_INTERRUPT_PRIORITY
Priority 0x40 is higher urgency (lower number) than 0x60, so ISR cannot safely call FreeRTOS API.Step 2: Analyze API call in ISR
CallingvTaskNotifyGiveFromISRrequires ISR priority at or below 0x60, which is violated here.Final Answer:
ISR priority 0x40 is higher than allowed to call FreeRTOS API -> Option AQuick Check:
ISR priority must not exceed configMAX_SYSCALL_INTERRUPT_PRIORITY [OK]
- Ignoring priority set inside ISR
- Thinking API calls are always allowed in ISR
- Confusing priority numeric order
You have two ISRs: ISR_A with priority 0x70 and ISR_B with priority 0x40. configMAX_SYSCALL_INTERRUPT_PRIORITY is set to 0x60. Which statement is true?
Solution
Step 1: Compare ISR priorities with configMAX_SYSCALL_INTERRUPT_PRIORITY
Only ISRs with priority numerically equal or higher (lower urgency) than 0x60 can call FreeRTOS API.Step 2: Evaluate ISR_A and ISR_B priorities
ISR_A priority 0x70 is lower urgency than 0x60, so it can call API. ISR_B priority 0x40 is higher urgency, so it cannot.Final Answer:
ISR_A can call FreeRTOS API, ISR_B cannot -> Option BQuick Check:
Only ISRs with priority >= configMAX_SYSCALL_INTERRUPT_PRIORITY call API [OK]
- Assuming higher urgency ISRs can call API
- Confusing numeric priority order
- Thinking all ISRs can call API regardless of priority
Ready to prove it?
Pass the test and this pattern moves unknown
