app_uplat7d.c
来自「最新版IAR FOR ARM(EWARM)5.11中的代码例子」· C语言 代码 · 共 1,435 行 · 第 1/4 页
C
1,435 行
if (rtnVal == OK) {
debug_msg(_3_LED_OK, "PIO sample application is end by OK.\n");
}
else {
debug_msg(_3_LED_NG, "PIO sample application is end by NG.\n");
}
return rtnVal;
}
#if defined(__arm)
static int16_t Xbus_By_8(const uint32_t *addr_start,
const uint32_t *addr_end) {
#else
int16_t Xbus_By_8(const uint32_t *addr_start,
const uint32_t *addr_end) {
#endif
int16_t rtnVal = OK;
int16_t handle_xbus = HANDLE_ID_INIT;
uPLAT_XbusParam xbus_init_param;
uint8_t pattern[] = {
0x00, 0x55, 0xAA, 0xFF
}; /* writing patterns */
uint16_t led_num[] = {
_7_LED1_NUM_1, _7_LED1_NUM_2, _7_LED1_NUM_3, _7_LED1_NUM_4
}; /* LED kinds */
uint32_t address; /* address of read/write area */
uint16_t i;
/* Initialize xbus. */
xbus_init_param.rombw = BWC_ROMBW_16;
xbus_init_param.srambw = BWC_SRAMBW_16;
xbus_init_param.iobw = BWC_IOBW_16;
xbus_init_param.romtype = ROMAC_ROMTYPE_0;
xbus_init_param.rombrst = ROMAC_ROMBRST_off;
xbus_init_param.sramtype = RAMAC_RAMTYPE_1;
xbus_init_param.srambrst = RAMAC_RAMBRST_off;
xbus_init_param.iotype = IOAC_IOTYPE_2;
xbus_init_param.sdrambw = DBWC_DBDRAM16;
xbus_init_param.standby = FALSE;
handle_xbus = smpDrv_open(DRVNO_XBUS, (uint32_t)(&xbus_init_param));
if (handle_xbus == HANDLE_ID_1) {
/* SRAM */
i = 0;
while ((i < 4) && (rtnVal != ERROR) ) {
/* write data to all region of external SRAM */
for (address = addr_start[0]; address < addr_end[0]; address++) {
OkiCLib_write8(address, pattern[i]);
}
/* check data of all region of external SRAM */
address = addr_start[0];
while ((address < addr_end[0]) && (rtnVal != ERROR)) {
/* check data */
if (OkiCLib_read8(address) != pattern[i]) {
/* Turn on LEDs. */
debug_msg(led_num[i], NULL);
rtnVal = ERROR;
}
address++;
}
i++;
}
if (rtnVal == OK) {
/* SDRAM */
i = 0;
while ((i < 4) && (rtnVal != ERROR)) {
/* write data to all region of external SRAM */
for (address = addr_start[1]; address < addr_end[1]; address++) {
OkiCLib_write8(address, pattern[i]);
}
/* check data of all region of external SRAM */
address = addr_start[1];
while ((address < addr_end[1]) && (rtnVal != ERROR)) {
/* check data */
if (OkiCLib_read8(address) != pattern[i]) {
/* Turn on LEDs and decimal point. */
debug_msg((uint16_t)(led_num[i] | _7_LED1_NUM_POINT), NULL);
rtnVal = ERROR;
}
address++;
}
i++;
}
} /* end of if */
} /* end of if */
/* Close xbus. */
smpDrv_close(DRVNO_XBUS, handle_xbus);
return rtnVal;
}
#if defined(__arm)
static int16_t Xbus_By_16(const uint32_t *addr_start,
const uint32_t *addr_end) {
#else
int16_t Xbus_By_16(const uint32_t *addr_start,
const uint32_t *addr_end) {
#endif
int16_t rtnVal = OK;
int16_t handle_xbus = HANDLE_ID_INIT;
uPLAT_XbusParam xbus_init_param;
uint16_t pattern[] = {
0x0000, 0x5555, 0xAAAA, 0xFFFF
}; /* writing patterns */
uint16_t led_num[] = {
_7_LED1_NUM_5, _7_LED1_NUM_6, _7_LED1_NUM_7, _7_LED1_NUM_8
}; /* LED kinds */
uint32_t address; /* address of read/write area */
uint16_t i;
/* Initialize xbus. */
xbus_init_param.rombw = BWC_ROMBW_16;
xbus_init_param.srambw = BWC_SRAMBW_16;
xbus_init_param.iobw = BWC_IOBW_16;
xbus_init_param.romtype = ROMAC_ROMTYPE_0;
xbus_init_param.rombrst = ROMAC_ROMBRST_off;
xbus_init_param.sramtype = RAMAC_RAMTYPE_1;
xbus_init_param.srambrst = RAMAC_RAMBRST_off;
xbus_init_param.iotype = IOAC_IOTYPE_2;
xbus_init_param.sdrambw = DBWC_DBDRAM16;
xbus_init_param.standby = FALSE;
handle_xbus = smpDrv_open(DRVNO_XBUS, (uint32_t)(&xbus_init_param));
if (handle_xbus == HANDLE_ID_1) {
/* SRAM */
i = 0;
while ((i < 4) && (rtnVal != ERROR)) {
/* write data to all region of external SRAM */
for (address = addr_start[0]; address < addr_end[0]; address += 2) {
OkiCLib_write16(address, pattern[i]);
}
/* check data of all region of external SRAM */
address = addr_start[0];
while ((address < addr_end[0]) && (rtnVal != ERROR)) {
if (OkiCLib_read16(address) != pattern[i]) { /* check data */
/* Turn on LEDs. */
debug_msg(led_num[i], NULL);
rtnVal = ERROR;
}
address += 2;
}
i++;
}
if (rtnVal == OK) {
/* SDRAM */
i = 0;
while ((i < 4) && (rtnVal != ERROR)) {
/* write data to all region of external SRAM */
for (address = addr_start[1]; address < addr_end[1]; address += 2) {
OkiCLib_write16(address, pattern[i]);
}
/* check data of all region of external SRAM */
address = addr_start[1];
while ((address < addr_end[1]) && (rtnVal != ERROR)) {
if (OkiCLib_read16(address) != pattern[i]) { /* check data */
/* Turn on LEDs and decimal point. */
debug_msg((uint16_t)(led_num[i] | _7_LED1_NUM_POINT), NULL);
rtnVal = ERROR;
}
address += 2;
}
i++;
}
} /* end of if */
} /* end of if */
/* Close xbus. */
smpDrv_close(DRVNO_XBUS, handle_xbus);
return rtnVal;
}
#if defined(__arm)
static int16_t Xbus_By_32(const uint32_t *addr_start,
const uint32_t *addr_end) {
#else
int16_t Xbus_By_32(const uint32_t *addr_start,
const uint32_t *addr_end) {
#endif
int16_t rtnVal = OK;
int16_t handle_xbus = HANDLE_ID_INIT;
uPLAT_XbusParam xbus_init_param;
uint32_t pattern[] = {
0x00000000, 0x55555555, 0xAAAAAAAA, 0xFFFFFFFF
}; /* writing patterns */
uint16_t led_num[] = {
_7_LED1_NUM_9, _7_LED1_NUM_A, _7_LED1_NUM_b, _7_LED1_NUM_C
}; /* LED kinds */
uint32_t address; /* address of read/write area */
uint16_t i;
/* Initialize xbus. */
xbus_init_param.rombw = BWC_ROMBW_16;
xbus_init_param.srambw = BWC_SRAMBW_16;
xbus_init_param.iobw = BWC_IOBW_16;
xbus_init_param.romtype = ROMAC_ROMTYPE_0;
xbus_init_param.rombrst = ROMAC_ROMBRST_off;
xbus_init_param.sramtype = RAMAC_RAMTYPE_1;
xbus_init_param.srambrst = RAMAC_RAMBRST_off;
xbus_init_param.iotype = IOAC_IOTYPE_2;
xbus_init_param.sdrambw = DBWC_DBDRAM16;
xbus_init_param.standby = FALSE;
handle_xbus = smpDrv_open(DRVNO_XBUS, (uint32_t)(&xbus_init_param));
if (handle_xbus == HANDLE_ID_1) {
/* SRAM */
i = 0;
while ((i < 4) && (rtnVal != ERROR)) {
/* write data to all region of external SRAM */
for (address = addr_start[0]; address < addr_end[0]; address += 4) {
OkiCLib_write32(address, pattern[i]);
}
/* check data of all region of external SRAM */
address = addr_start[0];
while ((address < addr_end[0]) && (rtnVal != ERROR)) {
if (OkiCLib_read32(address) != pattern[i]) { /* check data */
/* Turn on LEDs. */
debug_msg(led_num[i], NULL);
rtnVal = ERROR;
}
address += 4;
}
i++;
}
if (rtnVal == OK) {
/* SDRAM */
i = 0;
while ((i < 4) && (rtnVal != ERROR)) {
/* write data to all region of external SRAM */
for (address = addr_start[1]; address < addr_end[1]; address += 4) {
OkiCLib_write32(address, pattern[i]);
}
/* check data of all region of external SRAM */
address = addr_start[1];
while ((address < addr_end[1]) && (rtnVal != ERROR)) {
if (OkiCLib_read32(address) != pattern[i]) { /* check data */
/* Turn on LEDs and decimal point. */
debug_msg((uint16_t)(led_num[i] | _7_LED1_NUM_POINT), NULL);
rtnVal = ERROR;
}
address += 4;
}
i++;
}
} /* end of if */
} /* end of if */
/* Close xbus. */
smpDrv_close(DRVNO_XBUS, handle_xbus);
return rtnVal;
}
/************************************************************************/
/* */
/* Function Name : uPLATsmpAP_Xbus */
/* Input : void */
/* Output : int16_t OK(1) */
/* ERROR(-1) */
/* */
/* Note : Sample program of xbus. */
/* */
/************************************************************************/
int16_t uPLATsmpAP_Xbus(void) {
int16_t rtnVal = OK;
uint32_t addr_start[2] = {XBUS_SRAM_START_ADDR, XBUS_SDRAM_START_ADDR};
uint32_t addr_end[2] = {XBUS_SRAM_END_ADDR, XBUS_SDRAM_END_ADDR};
smpDrvInitPeripheral init_peripheral;
/* Initialize peripheral. */
init_peripheral.init_xbus.rombw = BWC_ROMBW_16;
init_peripheral.init_xbus.srambw = BWC_SRAMBW_16;
init_peripheral.init_xbus.iobw = BWC_IOBW_16;
init_peripheral.init_xbus.romtype = ROMAC_ROMTYPE_0;
init_peripheral.init_xbus.rombrst = ROMAC_ROMBRST_off;
init_peripheral.init_xbus.sramtype = RAMAC_RAMTYPE_1;
init_peripheral.init_xbus.srambrst = RAMAC_RAMBRST_off;
init_peripheral.init_xbus.iotype = IOAC_IOTYPE_2;
init_peripheral.init_xbus.sdrambw = DBWC_DBDRAM16;
init_peripheral.init_xbus.standby = FALSE;
init_peripheral.cache_mode = CACHE_WRITE_BACK;
init_peripheral.init_port.port_sel1 = PORT_CR1_INIT_VALUE;
init_peripheral.init_port.port_sel2 = PORT_CR2_INIT_VALUE;
init_peripheral.init_port.port_sel3 = PORT_CR3_INIT_VALUE;
init_peripheral.init_port.port_sel4 = PORT_CR4_INIT_VALUE;
rtnVal = smpDrv_reset(&init_peripheral);
if (rtnVal != OK) {
return rtnVal;
}
/* 3 bit LED start. */
debug_msg(_3_LED_START, "XBUS sample application is start.\n");
/* 7 segment LED1 : OFF */
debug_msg(_7_LED1_OFF, NULL);
/* Access size is 8 bit. */
rtnVal = Xbus_By_8(addr_start, addr_end);
if (rtnVal != OK) {
return rtnVal;
}
/* Access size is 16 bit. */
rtnVal = Xbus_By_16(addr_start, addr_end);
if (rtnVal != OK) {
return rtnVal;
}
/* Access size is 32 bit. */
rtnVal = Xbus_By_32(addr_start, addr_end);
if (rtnVal != OK) {
return rtnVal;
}
if (rtnVal == OK) {
debug_msg(_3_LED_OK, "XBUS sample application is end by OK.\n");
}
else {
debug_msg(_3_LED_NG, "XBUS sample application is end by NG.\n");
}
return rtnVal;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?