Challenge - 5 Problems
Nested Interrupt Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of nested interrupt simulation
Consider the following embedded C code simulating nested interrupts. What will be the output printed to the console?
Embedded C
#include <stdio.h> volatile int flag = 0; void ISR1() { printf("ISR1 start\n"); if (flag == 0) { flag = 1; ISR2(); } printf("ISR1 end\n"); } void ISR2() { printf("ISR2 start\n"); printf("ISR2 end\n"); } int main() { printf("Main start\n"); ISR1(); printf("Main end\n"); return 0; }
Attempts:
2 left
💡 Hint
Think about how ISR1 calls ISR2 before finishing.
✗ Incorrect
ISR1 starts and prints 'ISR1 start'. Since flag is 0, it sets flag to 1 and calls ISR2. ISR2 prints its start and end messages. Then ISR1 resumes and prints 'ISR1 end'. Finally, main prints 'Main end'.
🧠 Conceptual
intermediate1:30remaining
Understanding interrupt priority in nested interrupts
In an embedded system with nested interrupts enabled, which statement about interrupt priority is true?
Attempts:
2 left
💡 Hint
Think about which interrupt can interrupt another.
✗ Incorrect
Higher priority interrupts can preempt lower priority ones, allowing nested interrupts. Lower priority interrupts cannot preempt higher priority ones.
🔧 Debug
advanced2:30remaining
Identify the error causing nested interrupt failure
This code is intended to enable nested interrupts, but nested interrupts never occur. What is the main reason?
Embedded C
#include <stdio.h> #include <signal.h> void ISR1(int signum) { printf("ISR1 start\n"); // Nested interrupts should be enabled here printf("ISR1 end\n"); } void ISR2(int signum) { printf("ISR2 executed\n"); } int main() { signal(SIGINT, ISR1); signal(SIGTERM, ISR2); while(1) {} return 0; }
Attempts:
2 left
💡 Hint
Signals are blocked during their handler unless explicitly re-enabled.
✗ Incorrect
In many systems, signals are blocked during their handler execution. To allow nested interrupts, the handler must re-enable signals or use special flags. Here, ISR1 does not re-enable signals, so nested interrupts do not occur.
📝 Syntax
advanced1:30remaining
Identify the syntax error preventing nested interrupt simulation
Which option contains the correct syntax to enable nested interrupts in this embedded C snippet?
Embedded C
void ISR1() {
// Enable nested interrupts here
__enable_irq();
// ISR code
}Attempts:
2 left
💡 Hint
Check function call syntax carefully.
✗ Incorrect
Option D correctly calls the function __enable_irq() with parentheses. Option D uses a wrong function name. Option D misses parentheses, causing a syntax error. Option D is correct syntax but incomplete as it lacks ISR code, so A is the best complete option.
🚀 Application
expert2:00remaining
Calculate the number of nested interrupt levels possible
An embedded system supports 4 levels of interrupt priority (0 highest, 3 lowest). Nested interrupts are enabled so that higher priority interrupts can preempt lower ones. If an interrupt of priority 3 is running, how many more nested interrupts can occur before the CPU stops nesting?
Attempts:
2 left
💡 Hint
Count how many higher priority levels exist above priority 3.
✗ Incorrect
Priority levels are 0 (highest), 1, 2, 3 (lowest). If priority 3 interrupt is running, interrupts with priority 0, 1, and 2 can preempt it, so 3 more nested interrupts can occur.