Interrupt Subroutines
7-11
Interrupts
7.5
Interrupt Subroutines
The interrupt subroutine (ISR) is simply the routine, or function, that is called
by an interrupt. The ’C6000 provides hardware to automatically branch to this
routine when an interrupt is received based on an interrupt service table. (See
the
Interrupt Service Table in the TMS320C6000 CPU and Instruction Set Ref-
erence Guide.) Once the branch is complete, execution begins at the first exe-
cute packet of the ISR.
Certain state must be saved upon entry to an ISR in order to ensure program
accuracy upon return from the interrupt. For this reason, all registers that are
used by the ISR must be saved to memory, preferably a stack pointed to by
a general purpose register acting as a stack pointer. Then, upon return, all val-
ues must be restored. This is all handled automatically by the C/C++ compiler,
but must be done manually when writing hand-coded assembly.
7.5.1
ISR with the C/C++ Compiler
The C/C++ compiler automatically generates ISRs with the keyword
interrupt.
The interrupt function must be declared with no arguments and should return
void. For example:
interrupt void int_handler()
{
unsigned int flags;
...
}
Alternatively, you can use the interrupt pragma to define a function to be an
ISR:
#pragma INTERRUPT(func);
The result of either case is that the C/C++ compiler automatically creates a
function that obeys all the requirements for an ISR. These are different from
the calling convention of a normal C/C++ function in the following ways:
-
All general purpose registers used by the subroutine must be saved to the
stack. If another function is called from the ISR, then all the registers
(A0–A15, B0–B15 for ’C62x and ’C67x, and A0–A31, B0–B31 for ’C64x)
are saved to the stack.
-
A B IRP instruction is used to return from the interrupt subroutine instead
of the B B3 instruction used for standard C/C++ functions
-
A function cannot return a value and thus, must be declared void.
See the section on
Register Conventions in the TMS320C6000 Optimizing
C/C++ Compiler User’s Guide for more information on standard function call-
ing conventions.