- Introduction
- What are Nested Interrupts?
- Why Nested Interrupts are Needed
- Basic Working Principle
- Interrupt Nesting Flow
- Priority-Based Nesting
- Hardware Support for Nesting
- Software Handling
- Nested Interrupt Example
- Advantages
- Disadvantages
- Common Mistakes
- Applications
- Interview Questions
- Real-World Examples
- Summary
Nested Interrupts are a mechanism where an interrupt can be interrupted by another interrupt of higher priority.
This is widely used in:
- embedded systems
- microcontrollers
- real-time operating systems (RTOS)
- safety-critical applications
Nested interrupts allow:
a higher-priority interrupt to interrupt a currently executing lower-priority ISR
Without nesting:
- high-priority events must wait for low-priority ISR to finish
- response time becomes slow
With nesting:
✔ critical events are handled immediately ✔ better real-time responsiveness ✔ improved system determinism
When an interrupt occurs:
CPU starts ISR (low priority)
→ higher priority interrupt arrives
→ CPU pauses current ISR
→ executes higher priority ISR
→ resumes previous ISR
Example:
Main program
↓
ISR (Timer interrupt)
↓ (paused)
ISR (UART interrupt - higher priority)
↓
Return to Timer ISR
↓
Return to Main
Nesting is controlled by priority levels:
| Interrupt | Priority |
|---|---|
| UART | High |
| Timer | Medium |
| GPIO | Low |
Rule:
Higher priority interrupts can preempt lower priority ISRs
Most modern CPUs support:
✔ interrupt priority registers ✔ nested vectored interrupt controller (NVIC) ✔ automatic context saving
Example:
- ARM Cortex-M uses NVIC for nesting
Software responsibilities:
- enable interrupt nesting
- manage shared resources safely
- avoid race conditions
- minimize ISR execution time
Scenario:
- Timer ISR is running
- UART interrupt occurs
- UART ISR preempts Timer ISR
- UART ISR completes
- Timer ISR resumes
This ensures UART (urgent) is handled immediately
✔ faster response for critical interrupts ✔ better real-time performance ✔ improved system efficiency ✔ supports priority-based scheduling
❌ complex system design ❌ harder debugging ❌ risk of stack overflow ❌ race conditions in shared data ❌ increased latency for low-priority ISR completion
❌ deep nesting without limits ❌ long ISR execution ❌ not protecting shared resources ❌ ignoring stack usage ❌ enabling nesting without priority design
- real-time operating systems
- automotive ECUs
- robotics control systems
- aerospace systems
- industrial automation
- communication systems
Interrupts that can interrupt other lower-priority interrupts.
To improve response time for high-priority events.
Interrupt priority levels.
Stack overflow and race conditions.
Embedded systems and RTOS-based systems.
- airbag deployment interrupt overriding sensor ISR
- CPU handling network packet interrupt during timer ISR
- motor control emergency stop interrupt
- robotic collision detection interrupt
- industrial safety shutdown systems
Nested interrupts allow:
higher-priority interrupts to preempt lower-priority ISRs
Key points:
✔ improves responsiveness ✔ priority-based execution ✔ widely used in RTOS and embedded systems ✔ must be carefully designed
They are essential in:
real-time, safety-critical, and embedded computing systems