Interrupt

From SEGGER Knowledge Base
Jump to navigation Jump to search

In the context of an embedded system, an interrupt is an interruption of the program flow by the hardware. Interrupts are widely used in almost all embedded systems. Most systems use a timer to trigger a periodic interrupt so that the system can keep track of its "up time," which is the time from the point the system is started to the time after it has been reset.

Another very common use of an interrupt is for communication. Typically, when data is received, an interrupt is issued, causing the CPU to jump into the Interrupt Service Routine (ISR) that handles the data received. This is the scheme used for almost all data, regardless of whether it is a single byte (as with UART), or a packet, as with Ethernet or CAN.

How interrupts are handled

The way interrupts are handled across different CPUs differs greatly according to architectures. Typically, interrupts are disabled during program start-up, so they first need to be enabled—typically in 3 places: The CPU has a general interrupt-enable (or -disable) flag, and interrupts need to be enabled, generally speaking. The peripheral that is supposed to generate an interrupt needs to be "told" to do so, and the interrupt controller, which is also typically part of the CPU, needs to also be "told" to enable this particular interrupt. Most modern CPUs come with an interrupt vector table.