繁体   English   中英

在嵌入式 32 位上指定绝对地址

[英]Specify absolute address on embedded 32bit

我正在尝试在 32 位嵌入式设备上开发一个写入 C 的 memory 区域,其中数据将存储在特定地址上。

我目前在一个部分中有 memory 区域,假设在 0x1000-0x2000 之间,但我需要在特定地址中指定数据。

uint8_t data[0x100]; /* This should be stored at eg. 0x1020 */
uint8_t data2[0x100]; /* This should be stored at eg. 0x1500 */
uint8_t data3[0x100]; /* This should be stored at 0x1F00 */
 

我想到的解决方案是在数据块之间创建保留块。

typedef struct data_t
{
 uint8_t reserved1[0x1020]; /* Used for padding */
 uint8_t data[0x100]; /* This should be stored at eg. 0x1020 */
 uint8_t reserved2[0x3E0]; /* Used for padding */
 uint8_t data2[0x100]; /* This should be stored at eg. 0x1500 */
}

我很确定有更好的解决方案或者更智能的解决方案。 我正在为具有 GCC 技巧的编译器使用 GHS 编译器。

为此使用 linker 脚本。 将节放在地址处,然后将变量放在该节中。

其它的办法:

typedef struct
{
 uint8_t reserved1[0x1020]; /* Used for padding */
 uint8_t data[0x100]; /* This should be stored at eg. 0x1020 */
 uint8_t reserved2[0x3E0]; /* Used for padding */
 uint8_t data2[0x100]; /* This should be stored at eg. 0x1500 */
}data_t;

#define DATA1 ((volatile data_t *)0x1020)

//usage
void foo()
{
    DATA1 -> data[5] = 4;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM