6-22
SC100 C Compiler
Runtime Environment
6.4.5 Interrupt Handlers
Functions which require no parameters and return no result can be designated as interrupt handler
functions. The process of creating an interrupt handler function includes:
Defining the function as an interrupt handler
Linking the function to the appropriate interrupt vector entry
An interrupt handler can be be defined in one of two ways:
Using
#pragma interrupt
in the source code. For more detail about this pragma, refer to
Section 3.4.5.3.4,
“
Defining a function as an interrupt handler,
”
on page 3-58.
Defining an interrupt entry point in the application, by editing the schedule section of the application
configuration file, as described in
Section 6.3.5,
“
Application Configuration File.
”
To create the link between the function and the interrupt vector entry, you can use any one of the following
options:
In the code that calls the function, place a call to the handler function in the interrupt vector entry.
Use the
signal.h
library function to insert a call to the interrupt handler function into the required
interrupt vector entry. For syntax details, see
Section 7.7,
“
Signal Handling (signal.h),
”
on page
7-10.
If the function is very small, you can embed it in the interrupt vector entry, by modifying the startup
code file,
crtsc100.asm
. The size of each interrupt vector entry is 64 bytes. With this option, there
is no need for an explicit call from the vector to the function.
Interrupt handler functions always follow the stack-based calling convention. When an interrupt function
is called, the interrupt handler saves all registers and all other resources that are modified by the function.
Upon returning from the function all registers and hardware loop state saved at entry are restored to their
original state.
Local variables are saved on the stack. Interrupt handlers that are known to be non-interruptible may also
allocate data statically.
Return from interrupt is implemented using an RTE instruction.
6.4.6 Frame Pointer and Argument Pointer
The compiler does not use a frame pointer or an argument pointer.
If, however, the use of a frame pointer or an argument pointer is required by external code,
r7
may be
allocated as a frame pointer and
r6
as an argument pointer. When these registers are allocated as frame
pointer and/or argument pointer they should be saved and restored as part of the function prolog/epilog
code.
6.4.7 Hardware Loops
All hardware loop resources are available for use by the compiler. It is assumed that no nesting occurs
when entering a function. As a result, a function may use all 4 nesting levels for its own use. An additional
side effect of this assumption is that loops that include a function call as part of the loop code cannot be
implemented using hardware loops, unless the compiler can infer the nesting level of the called function
from static variables known at compilation time.
Loops are nested beginning with loop counter 3 at the innermost nesting level.