English
Language : 

GPS140 Datasheet, PDF (29/38 Pages) List of Unclassifed Manufacturers – GPS Positioning Module
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 GPS140HR 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 call to the same DOS function X, then function X is essentially being called while
active. Such cases will cause the computer to crash. DOS does not support such
operations. The general rule is that do not call any functions that use the screen, read
keyboard input or any file I/O routines, these should not be used in ISR's.
The same problem of re-entrancy also exists for many floating point emulators. This
effectively means that you should also avoid floating point mathematical operations in
your ISR.
Note that the problem of reentrancy exists, no matter what programming language you
use. Even, if you are writing your ISR in Assembly language, DOS and many floating
point emulators are not re-entrant. Of course there are ways to avoid this problem,
such as those which activate when your ISR is called. Such solutions are, however,
beyond the scope of this manual.
GPS140HR
29
RTD Embedded Technologies, Inc.