I'm flipping through some C header files for a microcontroller, and I keep seeing register addresses initialized as vuint. I haven't come across this data type before, so I did a bit of searching, with no real results. The closest I got was from https://stackoverflow.com/a/12855989, which tells me that v stands for "volatile". So, I have volatile unsigned ints holding hardware register addresses. As in, I have a data type that explicitly states "This address is subject to change", representing registers that are hard-wired, and cannot change, like, ever. Is my understanding of vuint incorrect? If not, why are we representing addresses this way?
问问题
2256 次
2 回答
5
内存映射寄存器设置为易失性,因为它们中的值可能由于编译器不知道的外部原因(硬件中断等)而改变。这意味着编译器应避免某些优化并确保实际读取地址(而不是针对缓存值等进行优化)。
快速示例,包含一些标志的内存映射寄存器。
read flags
set bit in flags
interrupt sets another bit
<compiler optimizes and cached flags from before>
read flags <contains incorrect cached value>
于 2013-09-16T18:21:01.327 回答
2
我认为您误解了类型。它很可能是指向易失性无符号整数的指针,表明无符号整数是易失性的,而不是指针。这在通过结构描述硬件寄存器时很典型。每个结构成员将是一个易失性无符号整数,并且在某处将定义一个基地址,指示寄存器在内存映射中的起始位置。
于 2013-09-16T18:49:56.770 回答