SW006012 Microchip Technology, SW006012 Datasheet - Page 98

C COMPILER FOR DSPIC30F FAMILY

SW006012

Manufacturer Part Number
SW006012
Description
C COMPILER FOR DSPIC30F FAMILY
Manufacturer
Microchip Technology
Type
MPLAB® C30 Compilerr
Series
PIC24 & DsPICr
Datasheets

Specifications of SW006012

Supported Families
PIC24, DsPIC30F And DsPIC33F
Core Architecture
PIC, DsPIC
Kit Contents
Software And Docs
Mcu Supported Families
PIC24 MCUs And DsPIC DSCs
Tool Type
Compiler
Processor Series
PIC24, dsPIC
Lead Free Status / RoHS Status
Not applicable / Not applicable
For Use With/related Products
dsPIC30F
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
MPLAB
7.3
DS51284F-page 92
WRITING AN INTERRUPT SERVICE ROUTINE
®
C30 User’s Guide
Following the guidelines in this section, you can write all of your application code,
including your interrupt service routines, using only C language constructs.
7.3.1
The guidelines for writing ISR’s are:
• declare ISR’s with no parameters and a void return type (mandatory)
• do not let ISR’s be called by main line code (mandatory)
• do not let ISR’s call other functions (recommended)
An MPLAB C30 ISR is like any other C function in that it can have local variables and
access global variables. However, an ISR needs to be declared with no parameters
and no return value. This is necessary because the ISR, in response to a hardware
interrupt or trap, is invoked asynchronously to the mainline C program (that is, it is not
called in the normal way, so parameters and return values don’t apply).
ISR’s should only be invoked through a hardware interrupt or trap and not from other
C functions. An ISR uses the return from interrupt (RETFIE) instruction to exit from the
function rather than the normal RETURN instruction. Using a RETFIE instruction out of
context can corrupt processor resources, such as the Status register.
Finally, ISR’s should not call other functions. This is recommended because of latency
issues. See Section 7.6 “Latency” for more information.
7.3.2
To declare a C function as an interrupt handler, tag the function with the interrupt
attribute (see § 2.3 for a description of the __attribute__ keyword). The syntax of
the interrupt attribute is:
__
The interrupt attribute name and the parameter names may be written with a pair
of underscore characters before and after the name. Thus, interrupt and
__interrupt__ are equivalent, as are save and __save__.
The optional save parameter names a list of one or more variables that are to be
saved and restored on entry to and exit from the ISR. The list of names is written inside
parentheses, with the names separated by commas.
You should arrange to save global variables that may be modified in an ISR if you do
not want the value to be exported. Global variables modified by an ISR should be
qualified volatile.
The optional irq parameter allows you to place an interrupt vector at a specific
interrupt, and the optional altirq parameter allows you to place an interrupt vector
at a specified alternate interrupt. Each parameter requires a parenthesized interrupt ID
number. (See Section 7.4 “Writing the Interrupt Vector” for a list of interrupt ID’s.)
The optional preprologue parameter allows you to insert assembly-language
statements into the generated code immediately before the compiler-generated
function prologue.
attribute
Guidelines for Writing ISR’s
Syntax for Writing ISR’s
__
))
((interrupt [(
[ save(symbol-list)]
[, irq(irqid)]
[, altirq(altirqid)]
[, preprologue(asm)]
)]
© 2007 Microchip Technology Inc.

Related parts for SW006012