0
0
FreeRTOSprogramming~10 mins

Nested interrupt handling in FreeRTOS - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Nested interrupt handling
Interrupt 1 occurs
Interrupt 1 handler starts
Interrupt 2 occurs (higher priority)
Interrupt 1 paused
Interrupt 2 handler runs
Interrupt 2 handler ends
Interrupt 1 resumes
Interrupt 1 handler ends
Return to main program
When a higher priority interrupt occurs during a lower priority interrupt, the lower one pauses, the higher runs, then the lower resumes.
Execution Sample
FreeRTOS
void ISR1() {
  // Start ISR1
  if (higher_priority_interrupt) {
    ISR2(); // Nested interrupt
  }
  // Finish ISR1
}

void ISR2() {
  // Handle higher priority interrupt
}
Shows ISR1 starting, then ISR2 interrupting it, then ISR1 resuming after ISR2 finishes.
Execution Table
StepEventCurrent ISRActionState
1Interrupt 1 occursNoneStart ISR1ISR1 running
2Interrupt 2 occurs (higher priority)ISR1Pause ISR1, start ISR2ISR1 paused, ISR2 running
3ISR2 completesISR2End ISR2, resume ISR1ISR1 running
4ISR1 completesISR1End ISR1No ISR running, return to main
5Main program resumesNoneContinue normal executionMain running
💡 All interrupts handled, system returns to main program
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
ISR StateNoneISR1 runningISR1 paused, ISR2 runningISR1 runningNo ISR runningNo ISR running
Key Moments - 3 Insights
Why does ISR1 pause when ISR2 starts?
Because ISR2 has higher priority, the system pauses ISR1 to handle ISR2 first, as shown in step 2 of the execution_table.
How does the system know to resume ISR1 after ISR2 finishes?
After ISR2 ends (step 3), the system resumes the paused ISR1 automatically, continuing from where it left off.
What happens if a lower priority interrupt occurs during ISR1?
Lower priority interrupts wait until ISR1 finishes; they do not interrupt ISR1, unlike higher priority interrupts.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the ISR state after step 2?
AISR1 running, ISR2 paused
BISR1 paused, ISR2 running
CNo ISR running
DISR2 paused, ISR1 running
💡 Hint
Check the 'State' column in row for step 2 in execution_table
At which step does ISR1 resume after being paused?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the 'Action' column in execution_table for when ISR1 resumes
If ISR2 had lower priority than ISR1, what would happen at step 2?
AISR2 waits until ISR1 finishes
BBoth ISR1 and ISR2 run simultaneously
CISR1 pauses and ISR2 runs
DISR2 cancels ISR1
💡 Hint
Recall that only higher priority interrupts can preempt lower ones, see key_moments explanation
Concept Snapshot
Nested interrupt handling allows higher priority interrupts to pause lower priority ones.
Lower priority interrupts wait until current ISR finishes.
ISR state changes: running -> paused -> resumed.
System returns to main program after all ISRs complete.
This ensures urgent tasks get immediate attention.
Full Transcript
Nested interrupt handling means when a higher priority interrupt happens during a lower priority interrupt, the lower one pauses and the higher one runs. After the higher priority interrupt finishes, the lower priority interrupt resumes. This process ensures urgent tasks are handled immediately without losing progress on the interrupted task. The execution table shows step-by-step how ISR1 starts, ISR2 interrupts it, ISR2 finishes, then ISR1 resumes and finishes, returning control to the main program.