Kernel interruption mechanism
An interrupt is the way a device halts the kernel, telling it that something interesting or important has happened. These are called IRQs on Linux systems. The main advantage interrupts offer is to avoid device polling. It is up to the device to announce any change in its state; it is not up to us to poll it.
In order to get notified when an interrupt occurs, you need to register to that IRQ, providing a function called an interrupt handler that will be called every time that interrupt is raised.
Registering an interrupt handler
You can register a callback to be run when the interruption (or interrupt line) you are interested in gets fired. You can achieve that with the request_irq()
function, declared in<linux/interrupt.h>
:
int request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags, const char *name, void *dev)
request_irq()
may fail, and returns 0
on success. Other elements of the preceding code are outlined in detail as follows:
flags...