CME136686LX Hardware Manual - RTD Embedded Technologies ...
CME136686LX Hardware Manual - RTD Embedded Technologies ...
CME136686LX Hardware Manual - RTD Embedded Technologies ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Intel 8259 Programmable Interrupt Controller<br />
The chip responsible for handling interrupt requests in the PC is the Intel 8259 Programmable Interrupt<br />
Controller. To use interrupts, you need to know how to read and set the Intel 8259’s interrupt mask register (IMR)<br />
and how to send the end-of-interrupt (EOI) command to the Intel 8259.<br />
Each bit in the IMR contains the mask status of an IRQ line; bit 0 is for IRQ0, bit 1 is for IRQ1, and so on. If a bit is<br />
set (1), then the corresponding IRQ is masked and will not generate an interrupt. If a bit is clear (0), then the<br />
corresponding IRQ is unmasked and can generate interrupts. The IMR is programmed through port 21h.<br />
PCI Interrupts<br />
PCI devices can share interrupts. The BIOS or operating system may assign multiple PCI devices to the same IRQ<br />
line. Any interrupt service routine (ISR) written for PCI devices must be able to handle shared interrupts. Refer<br />
to Interrupt-Driven PC System Design (ISBN: 0-929392-50-7) for more information on PCI interrupts.<br />
Writing an Interrupt Service Routine (ISR)<br />
The first step in adding interrupts to your software is to write the ISR. This is the routine that will automatically<br />
be executed each time an interrupt request occurs on the specified IRQ. An ISR is different than standard<br />
routines that you write. First, on entrance, the processor registers should be pushed onto the stack BEFORE you<br />
do anything else. Second, just before exiting your ISR, you must clear the interrupt status flag and write an<br />
end-of-interrupt command to the Intel 8259 controller. Finally, when exiting the ISR, in addition to popping all<br />
the registers you pushed on entrance, you must use the IRET instruction and not a plain RET. The IRET<br />
automatically pops the flags, CS, and IP that were pushed when the interrupt was called.<br />
Most C compilers allow you to identify a procedure (function) as an interrupt type and will automatically add<br />
these instructions to your ISR, with one important exception: most compilers do not automatically add the<br />
end-of-interrupt command to the procedure; you must do this yourself. Other than this and the few exceptions<br />
discussed below, you can write your ISR just like any other routine. It can call other functions and procedures in<br />
your program and it can access global data. If you are writing your first ISR, <strong>RTD</strong> recommends focusing on the<br />
basics, such as incrementing a global variable.<br />
Most operating systems have restrictions on what instructions can be called in your ISR. Consult your OS<br />
documentation for details on writing your ISR.<br />
Note A complete explanation of interrupt programming is beyond the scope of this manual. For more<br />
information on interrupts, refer to the Appendix.<br />
Sample Code<br />
<strong>RTD</strong>’s drivers provide examples of ISR’s and interrupt handling. Refer to them as working examples. These drivers<br />
were shipped with your cpuModule, but they can also be downloaded from <strong>RTD</strong>’s website (www.rtd.com).<br />
BDM-610000065 Rev C Chapter 4: Using the cpuModule 89