简体   繁体   中英

Why a pointer to a 16-bit register is uword?

Have lots of 16-bit registers in a processor that are defined like

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

Why do we need (uword*) pointer if a register and its value is still 16-bit?

If you look into your data sheet you will recognize that the address of the CAN_REG01 is 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.

You have to tell the compiler that you want to write at the address 0x200000 so you have to treat it as a pointer. 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). 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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