Atmel CAVR-4 Manuale Utente

Pagina di 323
CAVR-4
80
Checking module consistency
AVR® IAR C/C++ Compiler
Reference Guide
Examples
For an example of using the runtime model attribute 
_ _rt_version
 for checking 
module consistency on used calling convention, see Hints for using the new calling 
convention
, page 100.
The following assembler source code provides a function, 
part2
, that counts the 
number of times it has been called by increasing the register 
R4
. The routine assumes 
that the application does not use 
R4
 for anything else, that is, the register has been locked 
for usage. To ensure this, a runtime module attribute, 
_ _reg_r4
, has been defined with 
a value 
counter
. This definition will ensure that this specific module can only be linked 
with either other modules containing the same definition, or with modules that do not 
set this attribute. Note that the compiler sets this attribute to 
free
, unless the register is 
locked.
RTMODEL
"RTMODEL "__reg_r4", "counter"
MODULE
myCounter
PUBLIC
myCounter
RSEG
CODE:CODE:NOROOT(1)
myCounter:
INC
R4
RET
ENDMOD
END
If this module is used in an application that contains modules where the register 
R4
 has 
not been locked, an error is issued by the linker:
Error[e117]: Incompatible runtime models. Module myCounter 
specifies that '_ _reg_r4' must be 'counter', but module part1 
has the value 'free'
USER-DEFINED RUNTIME MODEL ATTRIBUTES
In cases where the predefined runtime model attributes are not sufficient, you can define 
your own attributes by using the 
RTMODEL
 assembler directive. For each property, select 
a key and a set of values that describe the states of the property that are incompatible. 
Note that key names that start with two underscores are reserved by IAR Systems.
For example, if you have a UART that can run in two modes, you can specify a runtime 
model attribute, for example 
uart
. For each mode, specify a value, for example 
mode1
 
and 
mode2
. You should declare this in each module that assumes that the UART is in a 
particular mode. This is how it could look like in one of the modules:
#pragma rtmodel="UART", "mode1"