* Question
When Does a CPU Accept an Interrupt?
* Answer
A CPU accepts an interrupt when it receives a valid interrupt request and determines that the request can be serviced based on its current operating state, interrupt settings, and priority rules.
Interrupts allow a processor to temporarily pause its normal program execution and handle urgent events from hardware devices, internal peripherals, or software. For reliable operation, the CPU does not accept every interrupt immediately. It follows a set of conditions before transferring control to the Interrupt Service Routine (ISR).
What Conditions Must Be Met for a CPU to Accept an Interrupt?
1. A Valid Interrupt Request Is Generated
The CPU must first receive an interrupt request from an interrupt source.
Common interrupt sources include:
- External devices
- Sensors
- Network controllers
- Input devices
- Internal peripherals
- Timers
- UART communication modules
- DMA controllers
- System events
- Hardware errors
- Software-triggered interrupts
If no interrupt request is generated, the CPU continues executing the current program normally.
2. The Interrupt Must Be Enabled
The CPU or interrupt controller must allow the specific interrupt request to be processed.
Most processors use interrupt control registers to manage interrupt permissions, including:
- Global interrupt enable/disable settings
- Individual interrupt masks
- Peripheral interrupt configuration
If an interrupt is disabled or masked, the CPU will not accept it even if the request signal is present.
3. The Interrupt Priority Must Be Allowed
Modern CPUs and microcontrollers often support multiple interrupt sources with different priority levels.
The CPU accepts an interrupt when:
- The interrupt has a higher priority than the current task.
- It is not blocked by a higher-priority interrupt already being executed.
- The interrupt controller allows it according to the configured priority scheme.
Priority management ensures that time-critical events receive faster responses.
4. The CPU Must Reach an Interruptible State
The processor must be in a state where interrupts are allowed.
Interrupt acceptance may be temporarily prevented during:
- Critical code execution
- Protected operations
- Reset procedures
- Certain exception-handling processes
Once the CPU returns to an interrupt-enabled state, pending interrupt requests can be processed.
5. The Current Instruction Must Be Completed
In most CPU architectures, the processor does not interrupt an instruction halfway through execution.
Instead, the CPU typically:
- Completes the current instruction.
- Saves the necessary execution context.
- Identifies the interrupt source.
- Jumps to the corresponding interrupt service routine.
This ensures that the interrupted program can continue correctly after the interrupt is handled.
What Happens After a CPU Accepts an Interrupt?
Once an interrupt is accepted, the CPU performs an interrupt handling sequence:
- Save the current program state
- Program counter (PC)
- Status registers
- Required CPU registers
- Find the interrupt vector address
- Execute the Interrupt Service Routine (ISR)
- Restore the previous execution context
- Resume the interrupted program
This process allows the CPU to respond quickly to external events without continuously checking each device.
Why Are Interrupts Important in Embedded Systems?
Interrupt mechanisms are essential in embedded systems because they enable processors to respond efficiently to real-time events.
Compared with continuously polling devices, interrupts provide:
- Faster event response
- Lower CPU workload
- Improved real-time performance
- Better power efficiency
They are widely used in:
- Microcontrollers (MCUs)
- Industrial controllers
- Automotive electronic systems
- Communication devices
- IoT products
