
ECAN1000 User’s Manual
23
BDM-610020026 rev B
There are a few precautions you must consider when writing ISRs. 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 inter-
rupts? Consider then the following situation in your program: If DOS func-
tion X is being executed when an interrupt occurs and the interrupt rou-
tine makes a call to the same DOS function X, then function X is essen-
tially 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 ISRs.
The same problem of reentrancy also exists for many floating-point emu-
lators. 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 lan-
guage, 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.
The second major concern when writing ISRs is to make them as short
as possible in term of execution time. Spending long times in interrupt
service routines may mean that other important interrupts are not ser-
viced. Also, if you spend too long in your ISR, it may be called again be-
fore you have exited. This will lead to your computer hanging up and will
require a reboot.
Your ISR should have the following structure:
•
Push any processor registers used in your ISR. Most C com-
piler do this automatically
•
Put the body of your routine here
•
Read interrupt status register of the SJA1000 chip on your
ECAN1000HR board
•
Clear the interrupt bit by writing to the SJA1000 CAN control-
ler
•
Issue the EOI command to the 8259 by writing 20h to address
20h
•
Pop all registers. Most C compilers do this automatically