Writing An Interrupt Service Routine (Isr) - Real Time Devices AD1200 User Manual

Table of Contents

Advertisement

tries, you'll get the bugs worked out and enjoy the benefits of properly executed intemrpts. In addition to reading the
following paragmphs, study the INTRPTS source code included on your 1200 program disk for a better understand-
ing of intemrptprc$am development.
. Writing an Interrupt Service Routine (ISR)
The first step in adding intemrps to your software is o write ttre intemrpt service routine (ISR). This is the
routine that will automatically be executed each time an intemrpt 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 intemrpt status of the
1200 and write an end-of-intemrpt command to the 8259 controller. Finally, when exiting the ISR, in addition o
popping all the registers you pushed on entrance, you must use tle IRET insfuction and not a plain RET. The IRET
automatically pops the flags, CS, and IP that were pushed when the intemrpt was called.
If you find yourself intimidated by intemrpt programming, take heart. Most Pascal and C compilers allow you
to identify a procedure (function) as an intemrpt type and will automatically add these instructions to your ISR, with
one important exception: most compilers do not auomatically add the end-of-intemrpt command to ttre procedure;
you must do this younelf. 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 not use any
DOS functions or routines that call DOS functions from within an ISR. DOS is not reentranq 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 intemrps? Then, you could have a situation such as this in your program. If DOS function X
is being executed when an intemrpt occurs and ttre int€rrupt routine makes a call to DOS function X, then function
X is essentially being called while it is already active. Such a recntrancy attempt spells disaster because DOS
functions:ue 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 orread the keyboard, and any disk VO routines use DOS and should
be avoided in your ISR.
The same problem of reentrancy exists for many floating point emulators as well, meaning you may have to
avoid floating point (real) math in your ISR.
Note that the problem of reentrancy exists, no matter what programming language you are using. Even if you
are writing your ISR in assembly language, DOS and many floating point emulators are not reentrant. Of course,
there are ways around this problem, such as those which involve checking to see if any DOS functions are currently
active when your ISR is called, but such solutions are well beyond the scope of this discussion.
The second major concern when writing your ISR is to make it as short as possible in terms of execution time.
Spending long periods of time in your ISR may mean that other important interrupts are being ignored. Also, if you
spend too long in your ISR, it may be called again before you have completed handling the first.run. This often ieads
to a hang that requires a reboot.
Your ISR should have this structure:
' Push any processor registers used in your ISR. Most C and Pascal intemrpt routines
automatically do this for
you.
. Put the body of your routine here.
. Clear the intemrpt bit on ttre 1200 by writing any value to BA + 2.
' Issue the EOI command to the 8259 int€rrupt controller by writing 20H to port 20H.
' Pop all registers pushed on entrance. Most C and Pascal intenupt routines automatically
do this for you.
4-17

Advertisement

Table of Contents
loading

This manual is also suitable for:

Ada1200

Table of Contents