我有一组用于嵌入式应用程序(ARM 裸机)中的外围设备的 32 位寄存器,具有以下字节地址。
CTL 0x0;
STAT 0x4
TXR 0x8 <-- 不连续地址
RXR 0x20
DAT1 0x30 <-- 不连续地址
DAT2 0x40 <-- 不连续地址
等等
我想将所有这些寄存器组合成一个 C 结构(它是一个打包结构)
struct my_peri {
uint32_t CTL;
uint32_t STAT;
uint32_t TXR;
uint32_t RXR;
uint32_t DAT1;
uint32_t DAT2;
};
struct my_peri* pPeri0 = (uint32_t*) (BASE_ADDRESS_OF_MY_PERI_0);
现在如果我访问
pPeri->RXR; // This will point to (BASE_ADDRESS + 0x10)
// But the actual address i want to refer is (BASE_ADDRESS + 0x20)
为了获得正确的地址,我手动添加了一些元素
struct my_peri {
uint32_t CTL;
uint32_t STAT;
uint32_t TXR;
uint32_t RESERVED[4]; // 0x10 to 0x1c
uint32_t RXR;
uint32_t RESERVED_1[3]; // 0x24-0x2c
uint32_t DAT1;
uint32_t RESERVED_2[3]; // 0x34-0x3c
uint32_t DAT2;
};
但是根据外围规范,对 RESERVED、RESERVED_1 和 RESERVED_2 的任何访问都会产生错误。
Is there a way to add address spacing between the struct elements?
Without adding RESERVED elements
If not, is there a way to group these registers into a single data structure?.
With each register pointing to the right address.
我正在使用 ARM-GCC 工具链。