TASKING VX-toolset for TriCore User Guide
To declare and initialize a string in A0 memory: char __a0 string[] = "TriCore";
If you use the
__near
memory qualifier, the compiler generates faster access code for those (frequently used) variables. Pointers are always 32-bit.
Functions are by default allocated in ROM. In this case you can omit the a memory qualifier. You cannot use memory qualifiers for function return values.
Some examples of using pointers with memory qualifiers: int __near *p; /* pointer to int in __near memory
(pointer has 32-bit size) */ int __far *g; /* pointer to int in __far memory
(pointer has 32-bit size) */ g = p; /* the compiler issues a warning */
You cannot use memory qualifiers in structure declarations: struct S {
__near int i; /* put an integer in near
memory: Incorrect ! */
__far int *p; /* put an integer pointer in
far memory: Incorrect ! */
}
If a library function declares a variable in near memory and you try to redeclare the variable in far memory, the linker issues an error: extern int __near foo; /* extern int in near memory*/ int __far foo; /* int in far memory */
The usage of the variables is always without a storage specifier: char __near example; example = 2;
The generated assembly would be: mov16 d15,2 st.b example,d15
All allocations with the same storage specifiers are collected in units called 'sections'. The section with the
__near
attribute will be located within the first 16 kB of each 256 MB block.
1.2.2. Placing an Object at an Absolute Address: __at() and __atbit()
Just like you can declare a variable in a specific part of memory (using memory qualifiers), you can also place an object at an absolute address in memory.
8
C Language
With the attribute
__at()
you can specify an absolute address. The address is a 32-bit linear address.
If you use this keyword on
__bit
objects, the address is a bit address.
Examples
unsigned char Display[80*24] __at( 0x2000 );
The array
Display
is placed at address 0x2000. In the generated assembly, an absolute section is created. On this position space is reserved for the variable
Display
.
int i __at(0x1000) = 1;
Restrictions
Take note of the following restrictions if you place a variable at an absolute address:
• The argument of the
__at()
attribute must be a constant address expression.
• You can place only global variables at absolute addresses. Parameters of functions, or automatic variables within functions cannot be placed at absolute addresses.
• You cannot place functions at absolute addresses.
• A variable that is declared extern
, is not allocated by the compiler in the current module. Hence it is not possible to use the keyword
__at()
on an external variable. Use
__at()
at the definition of the variable.
• You cannot place structure members at an absolute address.
• Absolute variables cannot overlap each other. If you declare two absolute variables at the same address, the assembler and/or linker issues an error. The compiler does not check this.
Declaring a bit variable with __atbit()
If you have defined a 32-bit base variable ( int
, long
) you can declare a single bit of that variable as a bit variable with the keyword
__atbit()
. The syntax is:
__atbit(name,offset) where, name is the name of an integer variable in which the bit is located. offset (range 0-31) is the bit-offset within the variable.
If you have defined an absolute integer variable with the keyword
__at()
, you can declare a single bit of that variable as an absolute bit variable with
__atbit()
.
The following restrictions apply:
• This keyword can only be applied to
__bit
type symbols.
• When a variable is
__atbit()
qualified it represents an alias of a bit in another variable. Therefore, it cannot be initialized.
• You can only use the
__atbit()
qualifier on variables which have either a global scope or file scope.
9