01Event response
Responding to an interrupt
An interrupt lets a processor respond to an event without repeatedly checking for it. Noticing the event and completing its work are separate tasks.
The request and the response
A program can repeatedly inspect a device for changes: polling. With interrupts, hardware raises a request and the processor transfers control to a designated handler when conditions allow. Execution can then resume.
Masking and priorities can delay the response. Exact behavior depends on the processor and its configuration.
A short handoff
In a hypothetical instrument, a button requests a reading. The handler records the request, acknowledges its source and leaves the longer calculation to the main program. A brief handler helps other work proceed.
Shared data must remain consistent during this handoff. A flag can communicate that something happened, but may not preserve the number or order of several events.
- EventRequest raised
- HandlerRequest recorded
- Main programLonger work
Read the boundary
When reading an interrupt-based design, identify the event source, the condition that raises the request and the point at which the request is cleared. Then ask where deferred work happens and what occurs if another event arrives first.
Timing, lost events and shared information still need explicit attention.
Further reading: Microchip Technology: CPU Interrupt Controller overview.