Consider the following FreeRTOS configuration snippet and interrupt priority check:
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 5
void ISR_Handler(void) {
uint8_t priority = get_interrupt_priority();
if(priority >= configMAX_SYSCALL_INTERRUPT_PRIORITY) {
printf("Safe to call FreeRTOS API\n");
} else {
printf("Unsafe to call FreeRTOS API\n");
}
}
// Assume get_interrupt_priority() returns 4What will be printed when ISR_Handler() runs?
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 5 void ISR_Handler(void) { uint8_t priority = get_interrupt_priority(); if(priority >= configMAX_SYSCALL_INTERRUPT_PRIORITY) { printf("Safe to call FreeRTOS API\n"); } else { printf("Unsafe to call FreeRTOS API\n"); } } // get_interrupt_priority() returns 4
Remember lower numeric priority values mean higher urgency in FreeRTOS.
Since the interrupt priority (4) is less than configMAX_SYSCALL_INTERRUPT_PRIORITY (5), it is unsafe to call FreeRTOS API functions from this interrupt.
In FreeRTOS, what is the role of configMAX_SYSCALL_INTERRUPT_PRIORITY?
Think about which interrupts can safely use FreeRTOS API functions.
configMAX_SYSCALL_INTERRUPT_PRIORITY sets the highest (numerically lowest) interrupt priority that can safely call FreeRTOS API functions. Interrupts with higher priority (numerically lower) must not call FreeRTOS API.
Given this ISR code snippet:
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 3
void ISR_Handler(void) {
uint8_t priority = get_interrupt_priority(); // returns 2
vTaskNotifyGiveFromISR(taskHandle, NULL);
}Why might this cause a system crash?
Check the priority comparison rules for calling FreeRTOS API from interrupts.
Interrupts with priority numerically less than configMAX_SYSCALL_INTERRUPT_PRIORITY (meaning higher urgency) must not call FreeRTOS API functions. Here priority 2 is higher than 3, so the call is unsafe and causes a crash.
For a Cortex-M3 microcontroller with 4 bits of priority, which definition correctly sets configMAX_SYSCALL_INTERRUPT_PRIORITY to priority level 5?
Remember Cortex-M uses the top bits of the priority byte for priority levels.
Cortex-M3 uses 4 bits for priority, stored in the high bits of an 8-bit register. Shifting 5 left by (8 - 4) = 4 bits correctly positions the priority.
Assuming a system with 256 interrupt priority levels (0 highest, 255 lowest), and configMAX_SYSCALL_INTERRUPT_PRIORITY is set to 10, how many interrupt priority levels can safely call FreeRTOS API functions?
Count all priorities numerically greater than or equal to configMAX_SYSCALL_INTERRUPT_PRIORITY.
Interrupt priorities from 10 up to 255 inclusive can safely call FreeRTOS API. That is 246 levels total.