C語言 : AVR@IAR中memory 如何分配
ABSOLUTE LOCATION
It is possible to specify the location of a variable (its absolute address)using either of the following two constructs:
1) The @ operator followed by a constant-expression.
example: The following declaration locates PIND at address 10h
__no_init __io char PIND @ 0x10;
The following declaration locates i at address 20 with the value 10:
const int i@20=10;
2) The #pragma location directive followed by a constant-expression.
example : The following declarations are equivalent to the previousdeclarations
#pragma location=0x10
__no_init __io char PIND;
#pragma location=20
const int i=10;
/********************************************************************************/
C語言 : AVR@IAR中memory 如何分配
#include <ioavr.h>
__root char index_b=0x10; // NEAR_I 0x00000223
__root __no_init char index_c; // NEAR_N 0x0000028A
__root __no_init char index_d @0x100; // ABSOLUTE 0x00000100
__root __no_init char index_e @0x101; // ABSOLUTE 0x00000101
__root const char index_g @0x102=0x10; // ABSOLUTE 0x00000102
// 初始值=0x10
__root char index_a=0x00; // NEAR_Z 0x00000224
__root char index_f; // NEAR_Z 0x00000225
char array[100]; // NEAR_Z 0x00000226 - 0x00000289
int main(void)
{
int i;
for(i=0;i<10;i++)
{
array[i] = 123;
}
}
complier 完成後 segment map
****************************************
* *
* SEGMENTS IN ADDRESS ORDER *
* *
****************************************
說明 :
--root : Use this option to apply the __root extended keyword to all global and static variables. This will make sure that the variables are not removed by the IAR XLINK Linker.(保證沒有使用的函數或者變數也能夠包含在目標代碼中, 不會被IAR XLINK Linker 移走)
__no_init : the keyword no_init is used for specifying that an object is not initialized. In ICCAVR __no_init can be used together with a keyword specifying any memory location, for example:
__near __no_init char buffer [1000];
ABSOLUTE 位址: 0X00000100 - 0X00000102
ABSOLUTE : Used for located variables. (指定的絕對位址)
NEAR_Z 位址: 0X00000224 - 0X00000289
NEAR_Z : Holds static and global __near variables that have been declared without initial value or with zero initial values. (沒有初始值或具有"0"初始值)
NEAR_I 位址 :0X00000223
NEAR_I : Holds static and global __near variables that have been declared with non-zero initial values.(具有非"0"初始值)
NEAR_N 位址 : 0X0000028A
NEAR_N : Holds static and global __near to be placed in non-volatile memory. (存放具有非揮發性記憶體)
CSTACK 位址 : 0X00000103 - 0X00000202 //256 Bytes
CSTACK : CSTACK 資料堆疊,存放局部變數
RCSTACK位址 : 0X00000203 - 0X00000222 //32 Bytes
RCSTACK : 位址返回堆疊,堆疊函數和中斷的返回位址。
CSTACK/ RCSTACK設定
應用:
__root __no_init char index_d @0x100; // ABSOLUTE 0x00000100
這種 ABSOLUTE addressing 可用于擴充I/O acceess, 亦可用于memory mapping I/O 用法。
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。