MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip
MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip
MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Differences Between 16-Bit Device C <strong>and</strong> ANSI C<br />
Access entry points facilitate the creation of application segments from different vendors<br />
that are combined at run time. They can be specified <strong>for</strong> external functions as well<br />
as locally defined functions. For example:<br />
/* an external function that we wish to call */<br />
extern void __attribute__((boot(3))) boot_service3();<br />
/* local function callable from other segments */<br />
void __attribute__((secure(4))) secure_service4()<br />
{<br />
boot_service3();<br />
}<br />
To specify a secure interrupt h<strong>and</strong>ler, use the secure attribute in combination with the<br />
interrupt attribute:<br />
void __attribute__((secure,interrupt)) secure_interrupts();<br />
When an access entry point is specified <strong>for</strong> an external secure function, that function<br />
need not be included in the project <strong>for</strong> a successful link. All references to that function<br />
will be resolved to a fixed location in Flash, depending on the security model selected<br />
at link time.<br />
When an access entry point is specified <strong>for</strong> a locally defined function, the linker will<br />
insert a branch instruction into the secure segment access area. The exception is <strong>for</strong><br />
access entry 16, which is represented as a vector (i.e, an instruction address) rather<br />
than an instruction. The actual function definition will be located beyond the access<br />
area; there<strong>for</strong>e the access area will contain a jump table through which control can be<br />
transferred from another security segment to functions with defined entry points.<br />
Automatic variables are owned by the enclosing function <strong>and</strong> do not need the secure<br />
attribute. They may be assigned initial values, as shown:<br />
void __attribute__((secure)) chuck_cookies()<br />
{<br />
int hurl;<br />
int them = 55;<br />
char *where = "far";<br />
splat(where);<br />
/* ... */<br />
}<br />
Note that the initial value of where is based on a string literal which is allocated in the<br />
PSV constant section .secure_const. The compiler will set PSVPAG to the correct<br />
value upon entrance to the function. If necessary, the compiler will also restore<br />
PSVPAG after the call to splat().<br />
shadow<br />
The shadow attribute causes the compiler to use the shadow registers rather than the<br />
software stack <strong>for</strong> saving registers. This attribute is usually used in conjunction with the<br />
interrupt attribute.<br />
void __attribute__ ((interrupt, shadow)) _T1Interrupt (void);<br />
unused<br />
This attribute, attached to a function, means that the function is meant to be possibly<br />
unused. The compiler will not produce an unused function warning <strong>for</strong> this function.<br />
user_init<br />
The user_init attribute may be applied to any non-interrupt function with void<br />
parameter <strong>and</strong> return types. Applying this attribute will cause default C start-up modules<br />
to call this function be<strong>for</strong>e the user main is executed. There is no guarantee of<br />
© 2008 <strong>Microchip</strong> Technology Inc. DS51284H-page 25