即使申明Volatile,编译器仅仅认为该地址易失,不会当做外设
- UID
- 872235
|
即使申明Volatile,编译器仅仅认为该地址易失,不会当做外设
在嵌入式系统C语言开发中,为了保持可读行,经常用访问内存的方式来访问外设的寄存器,典型的语句如下:
#define PIO *((volatile unsigned int *)(PIO_BASE))
int main()
{
PIO = 0;
return 0;
}
这在没有Data cache的处理器里面是没有问题的,在有Data cache的处理器里面,即使申明Volatile,编译器仅仅认为该地址易失,每次都回去读或写这个地址,不会把读写的动作优化掉,但绝不会把这个地址当成外设寄存器地址。
在NiosII处理器中,访问内存指令为ldw/stw;访问外设IO寄存器为ldwio/stwio
In processors with a data cache, this instruction may retrieve the desired data from the cache
instead of from memory. Use the ldwio instruction for peripheral I/O. In processors with a data
cache, ldwio bypasses the cache and memory. Use the ldwio instruction for peripheral I/O. In
processors with a data cache, ldwio bypasses the cache and is guaranteed to generate an
Avalon-MM data transfer. In processors without a data cache, ldwio acts like ldw.
所以,在有Data cache的NiosII中,还是老老实实用
IOWR_ALTERA_AVALON_PIO_DATA 和 IORD_ALTERA_AVALON_PIO_DATA吧
|
|
|
|
|
|