be80be
Well-Known Member
Have you read this it part of CC5X
// INT16CXX.H: saving and restoring registers during interrupt
/*
IMPORTANT: CC5X will AUTOMATICALLY check that the registers W,
STATUS, PCLATH and FSR are saved and restored during interrupt.
CC5X also supports CUSTOM save and restore sequences. If you want
to use your own register save and restore during interrupt, please
read the following CUSTOM INTERRUPT SAVE AND RESTORE section.
// DEFAULT INTERRUPT STRUCTURE (RECOMMENDED)
#include "int16CXX.h"
#pragma origin 4
interrupt serverX( void)
{
/* W and STATUS are saved by the next macro. PCLATH is also
saved if necessary. The code produced is CPU-dependent. */
int_save_registers // W, STATUS (and PCLATH if required)
//char sv_FSR = FSR; // save FSR if required
// handle the interrupt (insert application code here)
//FSR = sv_FSR; // restore FSR if saved
int_restore_registers // W, STATUS (and PCLATH if required)
/* IMPORTANT : GIE should normally NOT be set or cleared in
the interrupt routine. GIE is AUTOMATICALLY cleared on
interrupt entry by the CPU and set to 1 on exit (by
RETFIE). Setting GIE to 1 inside the interrupt service
routine will cause nested interrupts if an interrupt is
pending. Too deep nesting may crash the program ! */
/* IMPORTANT : It is NOT recommended to specify the interrupt
save style (i.e. INT_xxx_style) in the application. This
is done in the chip HEADER file (f.ex. 16F877.h). Wrong
register save style may cause strange problems and is very
difficult to trace. */
}
The compiler will detect if the FSR register is modified during
interrupt processing without being saved and restored. The
supplied macros for saving and restoring registers will not save
FSR. This have to be done by user code when needed. If FSR is
modified by a table or pointer access, or by direct writing, the
compiler will check that FSR is saved and restored, also in
nested function calls. Note that the FSR saving and restoring
can be done in a local region surrounding the indexed access,
and does not need to be done in the beginning and end of the
interrupt routine.
A warning is printed if FSR is saved but not changed.
The error and warning messages printed can be removed:
#pragma interruptSaveCheck n // no warning or error
#pragma interruptSaveCheck w // warning only
#pragma interruptSaveCheck e // error and warning (default)
Note that the above pragma also change the checking done on W,
STATUS and PCLATH.
// CUSTOM INTERRUPT SAVE AND RESTORE:
It is not required to use the above save and restore macros. CC5X
also supports custom interrupt structures.
A) You may want to use your own save and restore sequence. This
can be done by inline assembly. Take a look at the macros at
the end of this file to get an idea on how to do this. If CC5X
does not accept your code, just insert (on your own risk):
#pragma interruptSaveCheck n // no warning or error
B) No registers need to be saved when using the following
instructions in the interrupt routine. The register save
checking should NOT be disabled.