Microchip Technology SW006023-2N Data Sheet
Interrupts
2012 Microchip Technology Inc.
DS51686E-page 141
11.5
EXCEPTION HANDLERS
The PIC32MX devices also have two exception vectors for non-interrupt exceptions.
These exceptions are grouped into bootstrap exceptions and general exceptions.
These exceptions are grouped into bootstrap exceptions and general exceptions.
11.5.1
Bootstrap Exception
A reset exception is any exception which occurs while bootstrap code is running
(Status
(Status
BEV
=1
). All reset exceptions are vectored to 0xBFC00380.
At this location, the 32-bit toolchain places a branch instruction targeting a function
named _bootstrap_exception_handler(). In the standard library, a default
weak version of this function is provided which merely goes into an infinite loop. If the
user application provides an implementation of
_bootstrap_exception_handler()
named _bootstrap_exception_handler(). In the standard library, a default
weak version of this function is provided which merely goes into an infinite loop. If the
user application provides an implementation of
_bootstrap_exception_handler()
, that implementation will be used instead.
11.5.2
General Exception
A general exception is any non-interrupt exception which occurs during program
execution outside of bootstrap code (Status
execution outside of bootstrap code (Status
BEV
=0
). General exceptions are vectored
to offset 0x180 from EBase.
At this location, the 32-bit toolchain places a branch instruction targeting a function
named _general_exception_context(). The provided implementation of this
function saves context, calls an application handler function, restores context and
performs a return from the exception instruction. The context saved is the hi and lo
registers and all General Purpose Registers except s0-s8, which are defined to be
preserved by all called functions and so are not necessary to actively save here again.
The values of the Cause and Status registers are passed to the application handler
function (_general_exception_handler()). If the user application provides an
implementation of _general_exception_context(), that implementation will be
used instead.
named _general_exception_context(). The provided implementation of this
function saves context, calls an application handler function, restores context and
performs a return from the exception instruction. The context saved is the hi and lo
registers and all General Purpose Registers except s0-s8, which are defined to be
preserved by all called functions and so are not necessary to actively save here again.
The values of the Cause and Status registers are passed to the application handler
function (_general_exception_handler()). If the user application provides an
implementation of _general_exception_context(), that implementation will be
used instead.
void _general_exception_handler (unsigned cause, unsigned status);
A weak default implementation of _general_exception_handler() is provided in
the standard library which merely goes into an infinite loop. If the user application
provides an implementation of _general_exception_handler(), that
implementation will be used instead.
the standard library which merely goes into an infinite loop. If the user application
provides an implementation of _general_exception_handler(), that
implementation will be used instead.
11.6
INTERRUPT SERVICE ROUTINE CONTEXT SWITCHING
The standard calling convention for C/C++ functions will already preserve zero,
s0-s7
s0-s7
, gp, sp, and fp. k0 and k1 are used by the compiler to access and preserve
non-GPR context, but are always accessed atomically (i.e., in sequences with global
interrupts disabled), so they need not be preserved actively. A handler function will
actively preserve the a0-a3, t0-t9, v0, v1 and ra registers in addition to the
standard registers.
interrupts disabled), so they need not be preserved actively. A handler function will
actively preserve the a0-a3, t0-t9, v0, v1 and ra registers in addition to the
standard registers.
An interrupt handler function will also actively save and restore processor status
registers that are utilized by the handler function. Specifically, the EPC, SR, hi and lo
registers are preserved as context.
registers that are utilized by the handler function. Specifically, the EPC, SR, hi and lo
registers are preserved as context.
Handler functions may use a shadow register set to preserve the General Purpose
Registers, enabling lower latency entry into the application code of the handler
function. On some devices, the shadow register set is assigned to an interrupt priority
level (IPL) using the device Configuration bit settings (e.g., #pragma config
FSRSSEL=PRIORITY_6
Registers, enabling lower latency entry into the application code of the handler
function. On some devices, the shadow register set is assigned to an interrupt priority
level (IPL) using the device Configuration bit settings (e.g., #pragma config
FSRSSEL=PRIORITY_6
). While on other devices, the shadow register set may be hard
wired to IPL7. Consult the target device’s data sheet for more information on the
shadow register set.
shadow register set.