[previous] [index] [next]

Example 5: Interrupt Service Routines

This example demonstrates how to attach a function to an interrupt, so that it is called whenever the interrupt is triggered. These functions are commonly known as "interrupt service routines" (ISRs), and are used to handle interrupts from hardware such as timer chips, printers, disk drives, Ethernet controllers, etc. Refer to the commented source code of the example for the details.

Principle of Operation

In this example the interrupt source is the PC parallel port. Extensive documentation on programming and using the PC parallel port for data acquisition and control can be found on the Web. Briefly,

Setting up the Parallel Port

Setting up a hardware device and writing an ISR depends almost entirely on the device. RT Linux gives the facilities to connect a particular interrupt to a particular ISR, but that's it.

Defining the ISR

Associating the ISR to the Interrupt

A Note on Re-Entrancy

Running the Demo

To run the demo, change to the 'ex05_isr' subdirectory of the top-level tutorial directory, and run the 'run' script by typing
./run
Alternatively, change to the top-level tutorial directory and run the 'runall' script there by typing
./runall
and selecting the "Interrupt Service Routine" button.

You'll have 10 seconds to short pin 10 to any of pins 19 through 25. During this time, you'll see messages like "cumulative interrupts: 123" printing out as you short the pins. Note that many interrupts are generated each time you short the pins, due to the noisy nature of the wires touching together.

See the Code


Next: Example 6, Shared Memory Communication

Back: Example 4, FIFOs