Restoring The Startup Imr And Interrupt Vector - Real Time Devices AD1200 User Manual

Table of Contents

Advertisement

The following C and Pascal examples show what the shell of your ISR should be like:
In C:
v o i d
i n t e r r u p t
f S R ( v o i d )
{
, / * Y o u r c o d e g o e s h e r e .
D o n o t
u s e a n y D O S f u n c t i o n s !
* /
o u t p o r t b ( B a s e A d d r e s s
+ 2 ,
0 ) ;
/ *
C l e a r
1 2 0 0 i n t e r r u p t
* /
o u t p o r t b ( j x 2 j ,
0 x 2 0 ) ;
/ *
S e n d E O r c o m m a n d t o
g 2 \ g * /
)
In Pascal:
P r o c e d u r e
I S R ;
I n t e r r u p t ;
begin
{ Y o u r c o d e g o e s h e r e .
D o n o t
P o r t l B a s e A d d r e s s
+ 2 ]
: = 0 ;
P o r t [ $ 2 0 ]
: = 9 2 0 ;
o n d .
u s e a n y D O S f u n c t i o n s
! l
{ C f e a r
1 2 0 0 i n t e r r u p t
}
{ S e n d E O f c o n m a n d t o
8 2 5 9 }
. Saving the Startup Interrupt Mask Register (IMR) and Interrupt Vector
The next step after writing the ISR is to save the startup state of the interrupt mask register and the intemrpt
vertor that you will be using. The IMR is located at VO port 21H. The intemrpt vector you will be using is located
in the intemrpt, vector table which is simply an array of 256-bit (a-byte) pointers and is located in ttre fint 1024
bytes of memory (Segment = 0, Offset = 0). You can read this value directly, but it is a better practice to use DOS
function 35H (get intenupt vector). Most C and Pascal compilers provide a library routine for reading the value of a
vector. The vectors for the hardware intemrpts are vec0ors 8 through 15, where IRQ0 uses vector 8, IRel uses
vector 9, and so on. Thus, if the 1200 will be using IRQ3, you should save the value of intemrpt vector 11.
Before you install your ISR, temporarily mask out the IRQ you will be using. This prevents ttre IRe from
requesting an intemrpt while you are installing and initializing your ISR. To mask the IRQ, read in the current IMR
at I/O port 21H and set the bit that corresponds to your IRQ (remember, setting a bit disables interrupts on that IRe
while clearing a bit enables them). The IMR is ananged so that bit 0 is for IRQO, bit I is for IRel, and so on. See
the paragraph entrtled Interrupt Mask Register (IMR) earlier in this chapter for help in determining your IRe's bit.
After setting ttre bit, write the new value to I/O port 2ilt.
Wiot the startup IMR saved and the intemrps on your tRQ temporarily disabled, you can assign ttre intemrpt
vector to point to your ISR. Again, you can overwrite ttre appropriate entry in the vector table with a direct memory
write, but this is a bad practice. Instead, use either DOS function 25H (set intemrpt vector) or, if your compiler
provides it, the library routine for setting an intemrpt vector. Remember that vector 8 is for IReO, vector 9is for
IRQI, and so on.
If you need to program the source of your interrupts, do ttrat nexl For example, if you are using the program-
mable interval timer to generate interrupts, you must program it o run in the proper mode and at the proper iate.
Finally, clear the bit in the IMR for the IRQ you are using. This enables inremrprs on rhe IRe.
. Restoring the Startup IMR and Interrupt Vector
Before exiting your progam, you must. restore the intemrpt mask register and intemrpt vectors to the state they
were in when your prog&m stafied. To restore the IMR, write the value that was saved when your pro$am started
to I/O port 21H. Restore the intemrpt vector that was saved at startup wittr either DOS function f SH
Get interrupt
vecfor), or use the library routine supplied with your compiler. Performing these two steps will guarantee that gri
interrupt status of your computer is the same after running your progam as it was before your program started
running.
4-18

Advertisement

Table of Contents
loading

This manual is also suitable for:

Ada1200

Table of Contents