0
0
Embedded Cprogramming~20 mins

Nested interrupts in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nested Interrupt Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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;
}
A
Main start
ISR2 start
ISR2 end
ISR1 start
ISR1 end
Main end
B
Main start
ISR1 start
ISR1 end
ISR2 start
ISR2 end
Main end
C
Main start
ISR1 start
ISR2 start
ISR2 end
ISR1 end
Main end
D
Main start
ISR1 start
ISR2 start
ISR1 end
ISR2 end
Main end
Attempts:
2 left
💡 Hint
Think about how ISR1 calls ISR2 before finishing.
🧠 Conceptual
intermediate
1:30remaining
Understanding interrupt priority in nested interrupts
In an embedded system with nested interrupts enabled, which statement about interrupt priority is true?
AInterrupts always execute in the order they are triggered regardless of priority.
BA higher priority interrupt can preempt a lower priority interrupt.
CA lower priority interrupt can preempt a higher priority interrupt.
DNested interrupts are disabled automatically when an interrupt occurs.
Attempts:
2 left
💡 Hint
Think about which interrupt can interrupt another.
🔧 Debug
advanced
2: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;
}
ANested interrupts are not enabled because the signal handlers do not re-enable signals inside ISR1.
BNested interrupts are disabled because the main loop is empty and blocks signals.
CNested interrupts fail because ISR2 is not called inside ISR1.
DNested interrupts are disabled because signal handlers are not registered correctly.
Attempts:
2 left
💡 Hint
Signals are blocked during their handler unless explicitly re-enabled.
📝 Syntax
advanced
1: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
}
A
void ISR1() {
    __enable_irq();
}
B
void ISR1() {
    enable_irq();
    // ISR code
}
C
void ISR1() {
    __enable_irq;
    // ISR code
}
D
void ISR1() {
    __enable_irq();
    // ISR code
}
Attempts:
2 left
💡 Hint
Check function call syntax carefully.
🚀 Application
expert
2: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?
A3
B4
C2
D1
Attempts:
2 left
💡 Hint
Count how many higher priority levels exist above priority 3.