Why is it important to keep Interrupt Service Routines (ISRs) short in embedded C programming?
Think about how long the CPU is busy inside an ISR and how it affects other tasks.
Keeping ISRs short reduces the time the CPU spends handling interrupts, which lowers latency and prevents blocking other interrupts.
What is the output of this embedded C code snippet after the ISR runs?
volatile int flag = 0; void ISR_Handler() { flag = 1; // Clear interrupt flag here } int main() { flag = 0; ISR_Handler(); if(flag == 1) { printf("Interrupt handled\n"); } else { printf("No interrupt\n"); } return 0; }
Consider what the ISR does to the flag variable and how main checks it.
The ISR sets the flag to 1, so main prints "Interrupt handled".
Which option shows the bug that can cause missed interrupts in this ISR code?
volatile int count = 0; void ISR_Handler() { count++; // Missing interrupt flag clear }
Think about what happens if the interrupt flag is not cleared inside the ISR.
If the interrupt flag is not cleared, the interrupt may not trigger again, causing missed interrupts.
Which option shows the correct way to declare an ISR function in embedded C?
Check the placement of the __interrupt keyword and function signature.
The correct syntax places __interrupt before the function name with void parameter list.
Given this embedded C code, how many times will the ISR increment the counter if the interrupt triggers 5 times rapidly?
volatile int counter = 0; void ISR_Handler() { counter++; // Interrupt flag cleared here } int main() { // Simulate 5 rapid interrupts for(int i=0; i<5; i++) { ISR_Handler(); } printf("Counter: %d\n", counter); return 0; }
Consider how many times the ISR is called and how it increments the counter.
The ISR is called 5 times in the loop, so the counter increments 5 times.