CMX47786HX
RTD Embedded Technologies, Inc.
73
8259 Programmable Interrupt Controller:
The chip responsible for handling interrupt requests in the PC is the 8259 Programmable Interrupt
Controller. To use interrupts, you need to know how to read and set the 8259’s interrupt mask reg-
ister (IMR) and how to send the end-of-interrupt (EOI) command to the 8259.
Interrupt Mask Register (IMR):
Each bit in the interrupt mask register (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 set (equal to 1), then the corresponding IRQ is masked
and it will not generate an interrupt. If a bit is clear (equal to 0), then the corresponding IRQ is un-
masked and can generate interrupts. The IMR is programmed through port 21H.
Writing an Interrupt Service Routine:
The first step in adding interrupts to your software is to write the interrupt service routine (ISR). This
is the routine that will automatically be executed each time an interrupt request occurs on the spec-
ified IRQ. An ISR is different than standard routines that you write. First, on entrance, the processor
registers should be pushed onto the stack BEFORE you do anything else. Second, just before exiting
your ISR, you must clear the interrupt status flag of the DM5812 and write an end-of-interrupt com-
mand to the 8259 controller. Finally, when exiting the ISR, in addition to popping all the registers
you pushed on entrance, you must use the IRET instruction and not a plain RET. The IRET automat-
ically pops the flags, CS, and IP that were pushed when the interrupt was called.
If you find yourself intimidated by interrupt programming, take heart. Most C compilers al-
low you to identify a procedure (function) as an interrupt type and will automatically add
these instructions to your ISR, with one important exception: most compilers do not auto-
matically add the end-of-interrupt
command to the procedure; you must do this yourself. Other
than this and the few exceptions discussed below, you can write your ISR just like any other routine.
It can call other functions and procedures in your program and it can access global data. If you are
writing your first ISR, we recommend that you stick to the basics; just something that will convince
you that it works, such as incrementing a global variable.
NOTE:
If you are writing an ISR using assembly language, you are responsible for pushing and
popping registers and using IRET instead of RET.
Writing a DOS Interrupt service routine (ISR):
There are a few cautions you must consider when writing your ISR. The most important is, do not
use any DOS functions or routines that call DOS functions from within an ISR. DOS is not reentrant;
that is, a DOS function cannot call itself. In typical programming, this will not happen because of
the way DOS is written. But what about when using interrupts? Then, you could have a situation
such as this in your program. If DOS function X is being executed when an interrupt occurs and the
interrupt routine makes a call to DOS function X, then function X is essentially being called while
it is already active. Such a reentrance attempt spells disaster because DOS functions are not written
to support it. This is a complex concept and you do not need to understand it. Just make sure that
you do not call any DOS functions from within your ISR. The one wrinkle is that, unfortunately, it
is not obvious which library routines included with your compiler use DOS functions. A rule of
thumb is that routines which write to the screen, or check the status of or read the keyboard, and any
disk I/O routines use DOS and should be avoided in your ISR.
The same problem of reentrance exists for many floating point emulators as well, meaning you may
have to avoid floating point math in your ISR.
Содержание cpuModule CMX47786HX
Страница 1: ...CMX47786HX cpuModuleTM User s Manual RTD Enhanced Award BIOS Versions 6 00 xx BDM 610000038 Rev A...
Страница 2: ......
Страница 8: ......
Страница 10: ......
Страница 60: ...CMX47786HX RTD Embedded Technologies Inc 52...
Страница 108: ...CMX47786HX RTD Embedded Technologies Inc 100...