In some applications, some specific addresses may need to be read from their physical locations each time they are accessed (e.g., a status register within FPGA).
The L2 controller offers registers that control whether certain ranges of memory are cacheable, and whether one or more requestors are actually permitted to access these ranges. The registers are referred to as MARs (memory attribute registers).
Note—Using the volatile keyword in the C language does not protect a variable from being cached. If an application uses a memory location periodically updated by external hardware, in order to protect this operation in C code follow these two steps:
• Use the volatile keyword to prevent the code generation tools from incorrectly optimizing the variable.
• You must program the MAR register of the range containing the variable to prevent caching.
c代码中volatile关键字的作用,除了阻止cpu直接使用寄存器和cache中变量,只有可能在其它模块中被修改的全局符号,只有在编写并发程序时,才可能出现使用volatile的必要性。