Page 430 - Programming Microcontrollers in C
P. 430
Handling Interrupts 415
The FF1 instruction returns a 0 if bit 31 is set and 31 if bit 0 is
set. It also returns a 32 if no bit is set in the designated memory
location. Therefore, if the PIT is the highest requested interrupt, the
contents of the FIPND register are stored in R3, and the instruction
FF1 R3
is executed, R3 will contain the numeric value 24. We can use this
sequence to vector to the correct interrupt service routine. Consider
the code shown in Listing 8-9. This function is a general-purpose
interrupt handler to control the autovector access. The program starts
with the normal file inclusions. In this case, the interrupt controller
is being used so the header intctl.h is included. The code that
follows must access the contents of the fast pending interrupt register
FPIND. The address of this register is placed into the location fIpnd1
for convenient access by the assembly program that is generated later.
The next entry defines a struct Table, which contains an array of
32 pointers to functions that require no parameters and return the type
void. An instance of this structure is created and named table. The
32 entries in the array are each filled with a pointer to the function
unused_vector(). It is difficult to decide what to fill unused vectors
with. The choice of zero is not realistic. When an interrupt occurs that
needs one of these vectors, control is passed to the address contained
in the vector. If the vector contains zero, the computer goes to zero and
starts executing instructions found there. The program will surely run
amuck until who knows when if it is told to execute the code found at
zero! I usually create a simple interrupt service routine that does nothing
to help here. The function in the listing below is called
unused_vector(). In this case, if an uninitialized interrupt occurs,
it will be ignored and control will be passed back to the executing
program. This particular approach has the drawback that you are never
aware of the occurrence of uninitialized interrupts unless you put a
break of some sort in the unused_vector() routine.
In practice, you will need to place the names of interrupt service
routines in the proper vector locations shown below. We will do this
in later code to show you how.
#include “mmc2001.h”
#include “intctl.h”
UWORD const fIpnd1=INTCTL_+0X10;