Atmel CAVR-4 ユーザーズマニュアル
CAVR-4
Part 1. Using the compiler
Placing code and data
49
Example
_ _no_init int alpha @ "MYSEGMENT"; /* OK */
#pragma location="MYSEGMENT"
const int beta=5;
/* OK */
const int gamma @ "MYSEGMENT" = 3;
/* OK */
int delta @ "MYSEGMENT";
/* Error, neither */
/* "_ _no_init" nor "const" */
Function placement into named segments
It is possible to place functions into named segments using either the
@
operator or the
#pragma
location
directive. When placing functions into segments, the segment is
specified as a string literal.
Example
void f(void) @ "MYSEGMENT";
void g(void) @ "MYSEGMENT"
{
}
#pragma location="MYSEGMENT"
void h(void);
Declaring located variables extern
Using IAR extensions in C, read-only SFRs—for instance, in header files—can be
declared like this:
declared like this:
volatile const _ _no_init int x @ 0x100;
In C++,
const
variables are static (module local), which means that each module with
this declaration will contain a separate variable. When you link an application with
several such modules, the linker will report that there are more than one variable located
at address
several such modules, the linker will report that there are more than one variable located
at address
0x100
.
To avoid this problem and have it work the same way in C and C++, you should declare
these SFRs
these SFRs
extern
, for example:
extern volatile const _ _no_init int x @ 0x100;
USING USER-DEFINED SEGMENTS
In addition to the predefined segments, you can use your own segments. This is useful
if you need to have precise control of placement of individual variables or functions.
if you need to have precise control of placement of individual variables or functions.