我有以下C源文件,需要删除一些代码并添加一些代码以绕过Nios_2_r2c处理器上的数据缓存。我不知道如何做到这一点。
#include "system.h"
#include "pio_regs.h"
#include "bsu_macros.h"
#include "switches.h"
static struct pio_regs *SW = (struct pio_regs *)SWITCH_BASE;
static REGISTER SH_SW;
bits get_RUN ( void ) {
SH_SW = SW->data;
return getbit(SH_SW, 17);
}
#include "system.h"
#include "pio_regs.h"
#include "bsu_macros.h"
#include "ledr.h"
static struct pio_regs *LEDR = (struct pio_regs *)LEDR_BASE;
static REGISTER SH_LEDR;
void LEDR_Init ( void ) {
SH_LEDR = 0;
LEDR->data = 0;
}
void show_RUN ( bits RUN ) {
SH_LEDR = putbit (SH_LEDR, RUN, 12);
LEDR->data = SH_LEDR;
}
使用I / O读写的内联汇编得到它:
#include "system.h"
#include "pio_regs.h"
#include "bsu_macros.h"
#include "switches.h"
static struct pio_regs *SW = (struct pio_regs *)SWITCH_BASE;
static REGISTER SH_SW;
bits get_RUN ( void ) {
//SH_SW = SW->data;
__asm("ldwio %0, %1" : "=r"(SH_SW) : "m"(SW->data));
return getbit(SH_SW, 17);
}
#include "system.h"
#include "pio_regs.h"
#include "bsu_macros.h"
#include "ledr.h"
static struct pio_regs *LEDR = (struct pio_regs *)LEDR_BASE;
static REGISTER SH_LEDR;
void LEDR_Init ( void ) {
SH_LEDR = 0;
//LEDR->data = 0;
__asm("stwio %0, %1" : "=r"(SH_LEDR) : "m"(SW->data));
}
void show_RUN ( bits RUN ) {
SH_LEDR = putbit (SH_LEDR, RUN, 12);
//LEDR->data = SH_LEDR;
__asm("stwio %0, %1" : "=r"(SH_SW) : "m"(SW->data));
}
答案 0 :(得分:0)
您可以使用-mno-cache-volatile
并将变量声明为volatile
。 IO是通过读/写一些寄存器实现的,寄存器访问应始终是易失性的。
https://gcc.gnu.org/onlinedocs/gcc/Nios-II-Options.html
另一个选项始终是-mbypass-cache