Consider a FreeRTOS system with two interrupts: ISR1 with priority 3 and ISR2 with priority 2 (lower number means higher priority). ISR1 triggers ISR2. What will be the output sequence?
#include "FreeRTOS.h" #include "task.h" #include <stdio.h> volatile int output = 0; void ISR2_Handler(void) { output = output * 10 + 2; } void ISR1_Handler(void) { output = output * 10 + 1; // Simulate triggering ISR2 ISR2_Handler(); output = output * 10 + 3; } int main() { output = 0; ISR1_Handler(); printf("%d", output); return 0; }
Think about the order in which the interrupts execute and how nested interrupts affect the output.
ISR1 starts and appends '1'. Then it triggers ISR2 which appends '2'. After ISR2 finishes, ISR1 resumes and appends '3'. So the output is '123'.
In FreeRTOS, if two interrupts have priorities 5 and 7 (lower number means higher priority), which interrupt can preempt the other during nested interrupt handling?
Remember that lower priority number means higher priority in FreeRTOS.
In FreeRTOS, lower priority number means higher priority. So priority 5 is higher than 7 and can preempt it.
What error will occur with this nested interrupt code snippet in FreeRTOS?
void ISR1_Handler(void) {
portDISABLE_INTERRUPTS();
// Critical section
portENABLE_INTERRUPTS();
ISR2_Handler();
}
void ISR2_Handler(void) {
// Nested interrupt code
}
Check when interrupts are enabled or disabled during nested calls.
Interrupts are disabled before ISR2 is called, so ISR2 cannot run as a nested interrupt.
Which option contains a syntax error in declaring nested interrupt handlers in FreeRTOS?
void ISR1_Handler(void) __attribute__((interrupt)); void ISR2_Handler(void) __attribute__((interrupt));
Look carefully at the attribute syntax and function declaration.
Option C has incorrect syntax: the attribute is followed by braces which is invalid.
Given a FreeRTOS system with 8 interrupt priority levels (0 highest, 7 lowest), and nested interrupts allowed only if the new interrupt has higher priority, what is the maximum possible nested interrupt depth starting from priority 7?
Think about how many higher priority interrupts exist above priority 7.
Starting from priority 7, interrupts with priorities 6,5,4,3,2,1,0 can preempt, so maximum nested depth is 7.