简体   繁体   English

为什么指向16位寄存器的指针是uword?

[英]Why a pointer to a 16-bit register is uword?

Have lots of 16-bit registers in a processor that are defined like 处理器中有许多16位寄存器,其定义如下

#define CAN_REG01              (*((uword volatile far *) 0x200000))

Why do we need (uword*) pointer if a register and its value is still 16-bit? 如果寄存器及其值仍为16位,为什么需要(uword *)指针?

If you look into your data sheet you will recognize that the address of the CAN_REG01 is 0x200000 . 如果看一下数据手册,您会发现CAN_REG01的地址是0x200000

To provide you with something readable that you can use to write to (and read from) this special function register (SFR) someone created that define that let you use the name CAN_REG01 like some ordinary variable. 为了给您提供可读性,您可以使用它们来写入(或读取)该特殊功能寄存器(SFR),此人创建的定义可以让您像使用一些普通变量一样使用名称CAN_REG01

You have to tell the compiler that you want to write at the address 0x200000 so you have to treat it as a pointer. 您必须告诉编译器您要在地址0x200000处编写,因此必须将其视为指针。 Additionally you have to tell the compiler about the size of the data that is behind this pointer. 此外,您还必须告诉编译器该指针后面的数据大小。 Obviously the CAN_REG01 register has the size of an uword (whatever that does that mean on your specific platform). 显然,CAN_REG01寄存器的大小为uword (在您的特定平台上意味着什么)。 The volatile have to be added to force the compiler not to optimize out access to this address because some processor internals or Interrupts may change it independently from your code. 必须添加volatile以强制编译器不优化对该地址的访问,因为某些处理器内部或中断可能会独立于代码而对其进行更改。 Also otherwise the compiler may remove consecutive assignments to this register, because he thinks that only the last one does matter.. 另外,否则编译器可能会删除对该寄存器的连续分配,因为他认为只有最后一个才有意义。

Defining SFRs this way is very common on embedded platform bare metal compilers. 以这种方式定义SFR在嵌入式平台裸机编译器中非常普遍。

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

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