我有以下 C 源文件,需要删除一些代码并添加一些代码以绕过 Nios_2_r2c 处理器上的数据缓存。我不知道该怎么做。
文件:switch.c
#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);
}
文件:ledr.c
#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 读取和写入的内联汇编获得它:
文件:switch.c
#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);
}
文件:ledr.c
#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));
}