Chapter 9. Interrupt Handling
Interrupts are the ultimate resource for hardware management. We all know that a device uses interrupts to let the software know it is ready to be acted upon. Linux offers a good interface for interrupt handling. In fact, it’s so good that writing and installing an interrupt handler is almost as easy as writing any other kernel function. A few caveats nonetheless apply, because the interrupt handler runs asynchronously from the rest of the system.
The sample code in this chapter uses the parallel port to generate real interrupts, as this task can’t be accomplished with software-only techniques. Therefore, if you want to run the test programs, you need to plug in the soldering iron, even if you refused to do so for the examples in the last chapter.
To demonstrate interrupt management, we’ll use the short module from the last chapter. Its name, short, actually means short int (it is C, isn’t it?), to remind us that it handles interrupts.
Preparing the Parallel Port
Although the parallel interface is simple, as I’ve shown in Section 8.2 in Chapter 8, it can trigger interrupts. This capability is used by the printer to notify the lp driver that it is ready to accept the next character in the buffer.
The interface doesn’t actually generate interrupts before it’s instructed to do so; the parallel standard states that setting bit 4 of port 2 (0x37a, 0x27a, or whatever) enables interrupt reporting. The simple outb, which sets the bit, is performed by ...
Get Linux Device Drivers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.