Atmel CAVR-4 Manual De Usuario

Descargar
Página de 323
CAVR-4
48
Efficient usage of segments and memory
AVR® IAR C/C++ Compiler
Reference Guide
Note: Take care when explicitly placing a variable or function in a predefined segment 
other than the one used by default. This is possible and useful in some situations, but 
incorrect placement can result in anything from error messages during compilation and 
linking to a malfunctioning application. Carefully consider the circumstances; there 
might be strict requirements on the declaration and use of the function or variable.
C++ static member variables can be placed at an absolute address or in named segments, 
just like any other static variable.
Variables and functions can also be placed into named segments using the 
--segment
 
option, in which case you can override the default segment base name. Note that if you 
use this method, the object does not need to be declared neither 
_ _no_init
 nor 
const
 
as it is only the segment name that will be modified.
Data placement at an absolute location
To place a variable at an absolute address, the argument to the operator 
@
 and the 
#pragma
 
location
 directive should be a literal number, representing the actual 
address.
Example
_ _no_init char alpha @ 0x2000;
/* OK */
#pragma location=0x2002
const int beta=5;
/* OK */
const int gamma @ 0x2004 = 3;
/* OK */
int delta @ 0x2006;
/* Error, neither */
                               
/* "_ _no_init" nor "const".*/
See Located data, page 46 for information about how to handle this in the linker 
command file.
Note: A variable placed in an absolute location should be defined in an include file, to 
be included in every module that uses the variable. An unused definition in a module 
will be ignored. A normal 
extern
 declaration—one that does not use an absolute 
placement directive—can refer to a variable at an absolute address; however, 
optimizations based on the knowledge of the absolute address cannot be performed.
Data placement into named segments
It is possible to place variables into named segments using either the 
@
 operator or the 
#pragma
 
location
 directive. A string should be used for specifying the segment name.