DM5816/DM6816
RTD Embedded Technologies, Inc.
35
What Exactly Happens When an Interrupt Occurs?
Understanding the sequence of events when an interrupt is triggered is necessary to properly
write software interrupt handlers. When an interrupt request line is driven high by a peripheral
device (such as the DM5816), the interrupt controller checks to see if interrupts are enabled for
that IRQ, and then checks to see if other interrupts are active or requested and determines
which interrupt has priority. The interrupt controller then interrupts the processor. The current
code segment (CS), instruction pointer (IP), and flags are pushed on the stack for storage, and
a new CS and IP are loaded from a table that exists in the lowest 1024 bytes of memory. This
table is referred to as the interrupt vector table and each entry is called an interrupt vector. Once
the new CS and IP are loaded from the interrupt vector table, the processor begins executing
the code located at CS:IP. When the interrupt routine is completed, the CS, IP, and flags that
were pushed on the stack when the interrupt occurred are now popped from the stack and
execution resumes from the point where it was interrupted.
Using Interrupts in Your Programs
Adding interrupts to your software is not as difficult as it may seem, and what they add in terms
of performance is often worth the effort. Note, however, that although it is not that hard to use
interrupts, the smallest mistake will often lead to a system hang that requires a reboot. This can
be both frustrating and time-consuming. But, after a few tries, you’ll get the bugs worked out and
enjoy the benefits of properly executed interrupts. In addition to reading the following
paragraphs, study the INTRPTS source code included on your DM5816 program disk for a
better understanding of interrupt program development.
Writing an Interrupt Service Routine (ISR)
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 specified 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 DM5816 and
write an end-of-interrupt command 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 automatically 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 Pascal and C
compilers allow 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
automatically 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.
There are a few cautions you must consider when writing your ISR. The most important is,
do
Содержание DM5816
Страница 1: ...BDM 610010027 Rev A DM5816 DM6816 Triggered User s Manual...
Страница 7: ...DM5816 DM6816 RTD Embedded Technologies Inc 7...
Страница 15: ...DM5816 DM6816 RTD Embedded Technologies Inc 15 Fig 1 7 Base Address Switch S1...
Страница 22: ...DM5816 DM6816 RTD Embedded Technologies Inc 22...
Страница 41: ...DM5816 DM6816 RTD Embedded Technologies Inc 41 Appendix B Connector Pin Assignments P2 Connector...
Страница 42: ...DM5816 DM6816 RTD Embedded Technologies Inc 42 P3 Connector P6 Connector...