
ECAN1000 User’s Manual
22
BDM-610020026 rev B
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 automati-
cally 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
ECAN1000HR by writing to the SJA1000 CAN controller, and write the
EOI command to the interrupt controller. Finally, when exiting the inter-
rupt routine the processor registers must be popped from the system
stack and you must execute the IRET assembly instruction. This instruc-
tion 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 func-
tion, you must do it yourself. Other than this and a few exceptions dis-
cussed 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 ba-
sics; 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 in-
struction instead of the RET instruction.