![Real Time Devices GSM35 Скачать руководство пользователя страница 27](http://html1.mh-extra.com/html/real-time-devices/gsm35/gsm35_user-manual_1425296027.webp)
User’s Manual
GSM35
27
RTD Finland Oy
Using Interrupts in your Program
Adding interrupt support to your program is not as difficult as it may seem
especially when programming under DOS. The following discussion will
cover programming under DOS. Note that even the smallest mistake in
your interrupt program may cause the computer to hang up and will only
restart after a reboot. This can be frustrating and time-consuming.
Writing an Interrupt Service Routine (ISR)
The first step in adding interrupts to your software is to write an interrupt
service routine (ISR). This is the routine that will be executed
automatically each time an interrupt request occurs for the specified IRQ.
An ISR is different from other sub-routines or procedures. First on
entrance the processor registers must be pushed onto the stack before
anything else! Second, just before exiting the routine, you must clear the
interrupt on the GSM35 by writing to the Status register, and write the EOI
command to the interrupt controller. Finally, when exiting the interrupt
routine the processor registers must be popped from the system stack and
you must execute the IRET assembly instruction. This instruction pops the
CS, IP and processor flags from the system stack. These were pushed
onto the stack when entering the ISR.
Most compilers allow you to identify a function as an interrupt type and will
automatically add these instructions to your ISR with one exception: most
compilers do not automatically add the EOI command to the function, you
must do it yourself. Other than this and a few exceptions discussed below,
you can write your ISR as any code 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 you stick to the basics; just
something that enables you to verify you have entered the ISR and
executed it successfully. For example: set a flag in your ISR and in your
main program check for the flag.
Note:
If you choose to write your ISR in in-line Assembly, you must push
and pop registers correctly and exit the routine with the IRET
instruction instead of the RET instruction.
There are a few precautions you must consider when writing ISR's. The
most important is, do not use any DOS functions or functions that call
DOS functions from an interrupt routine. DOS is not re-entrant; 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 using interrupts?
Consider then the following situation in your program: If DOS function X is
being executed when an interrupt occurs and the interrupt routine makes a