app_uplat7d.c
来自「最新版IAR FOR ARM(EWARM)5.11中的代码例子」· C语言 代码 · 共 1,435 行 · 第 1/4 页
C
1,435 行
/**************************************************************************/
/* */
/* Copyright (C) 2006 Oki Electric Industry Co., LTD. */
/* */
/* System Name : uPLAT7D series */
/* Module Name : uPLAT7D application layer sample program */
/* File Name : app_uplat7d.c */
/* Revision : 01.00 */
/* Date : 2006/1/1 initial version */
/* */
/**************************************************************************/
#include "common.h"
#if defined(__arm)
#include "ml675050.h"
#else
#include "ml675050sim.h"
#endif
#include "hal_api.h"
#include "drv_timer.h"
#include "drv_api.h"
#include "app_uplat7d.h"
#include "countup.h"
#include "drv_sio.h"
#include "drv_uart.h"
#include <string.h>
const int8_t title_message[]={"\nOKI ML675050 CPU BOARD\n"};
const int8_t overrun_error_message[]={"\nOERR\n"}; /* overrun error */
const int8_t parity_error_message[]={"\nPERR\n"}; /* parity error */
const int8_t framing_error_message[]={"\nFERR\n"}; /* framing error */
const int8_t overflow_error_message[]={"\nOFERR\n"}; /* overflow error */
uint32_t image_bank0_base;
uint32_t image_bank0_limit;
extern volatile uint16_t count_interval;
extern void update_count(uint16_t);
/************************************************************************/
/* Function Prototype Declaration */
/************************************************************************/
#if defined(__arm)
static int16_t Xbus_By_8(const uint32_t *addr_start,const uint32_t *addr_end);
static int16_t Xbus_By_16(const uint32_t *addr_start,const uint32_t *addr_end);
static int16_t Xbus_By_32(const uint32_t *addr_start,const uint32_t *addr_end);
static void CopyCode_bank0tobank10(void);
static void PM_DIV_APB_CLK_LED_DISPLY( int32_t div_clock, int32_t apb_clock);
#else
int16_t Xbus_By_8(const uint32_t *addr_start,const uint32_t *addr_end);
int16_t Xbus_By_16(const uint32_t *addr_start,const uint32_t *addr_end);
int16_t Xbus_By_32(const uint32_t *addr_start,const uint32_t *addr_end);
void CopyCode_bank0tobank10(void);
void PM_DIV_APB_CLK_LED_DISPLY( int32_t div_clock, int32_t apb_clock);
#endif
/************************************************************************/
/* */
/* Function Name : uPLATsmpAP_Timer */
/* Input : void */
/* Output : int16_t OK(1) */
/* ERROR(-1) */
/* */
/* Note : Sample program of system timer. */
/* */
/************************************************************************/
int16_t uPLATsmpAP_Timer(void) {
int16_t rtnVal = OK;
int16_t handle_timer = HANDLE_ID_INIT;
uint16_t reverse_flag = 0;
uint16_t reverse_times = 0;
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_3;
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, "System timer sample application is start.\n");
/* 7 segment LED1 : OFF */
debug_msg(_7_LED1_OFF, NULL);
/* Initailize timer. */
handle_timer = smpDrv_open(DRVNO_TIMER, TIMER_TIME_INTERVAL);
if (handle_timer == HANDLE_ID_1) {
/* Timer start. */
rtnVal = smpDrv_ioctl(DRVNO_TIMER, UPLAT7D_HAL_TIMER_SET_START, 1, handle_timer);
if (rtnVal == OK) {
/* 7 segment LED1 : OFF */
debug_msg(_7_LED1_OFF, NULL);
while (reverse_times < TIMER_REVERSE_TIMES) {
/* Waiting for 3s (= 10ms * 300). */
smpDrv_poll(DRVNO_TIMER, 0, 300, handle_timer);
if (reverse_flag == 0) {
/* 7 segment LED1 : ALL */
debug_msg(_7_LED1_ALL, NULL);
reverse_flag = 1;
}
else {
/* 7 segment LED1 : OFF */
debug_msg(_7_LED1_OFF, NULL);
reverse_flag = 0;
}
reverse_times++;
} /* end of while */
} /* end of if */
} /* end of if */
/* Close timer. */
smpDrv_close(DRVNO_TIMER, handle_timer);
if (rtnVal == OK) {
debug_msg(_3_LED_OK, "System timer sample application is end by OK.\n");
}
else {
debug_msg(_3_LED_NG, "System timer sample application is end by NG.\n");
}
return rtnVal;
}
/************************************************************************/
/* */
/* Function Name : uPLATsmpAP_FIQ */
/* Input : void */
/* Output : int16_t OK(1) */
/* ERROR(-1) */
/* */
/* Note : Sample program of FIQ. */
/* */
/************************************************************************/
int16_t uPLATsmpAP_FIQ(void) {
int16_t rtnVal = OK;
int16_t handle_fiq = HANDLE_ID_INIT;
int16_t handle_timer = HANDLE_ID_INIT;
uint16_t led[18] = {
_7_LED1_NUM_0, _7_LED1_NUM_1, _7_LED1_NUM_2, _7_LED1_NUM_3,
_7_LED1_NUM_4, _7_LED1_NUM_5, _7_LED1_NUM_6, _7_LED1_NUM_7,
_7_LED1_NUM_8, _7_LED1_NUM_9, _7_LED1_NUM_A, _7_LED1_NUM_b,
_7_LED1_NUM_C, _7_LED1_NUM_d, _7_LED1_NUM_E, _7_LED1_NUM_F,
_7_LED1_ALL, _7_LED1_OFF
};
uint16_t i = 0;
uPLAT_InterruptParam int_param;
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, "FIQ sample application is start.\n");
/* 7 segment LED1 : OFF */
debug_msg(_7_LED1_OFF, NULL);
/* Initailize FIQ . */
int_param.primary = INT_FIQ;
int_param.callback = update_count;
handle_fiq = smpDrv_open(DRVNO_INTFIQ, (uint32_t)(&int_param));
if (handle_fiq == HANDLE_ID_1) {
/* Initailize timer. */
handle_timer = smpDrv_open(DRVNO_TIMER, FIQ_TIME_INTERVAL);
if (handle_timer == HANDLE_ID_1) {
/* Timer start. */
rtnVal = smpDrv_ioctl(DRVNO_TIMER, UPLAT7D_HAL_TIMER_SET_START, 1, handle_timer);
if (rtnVal == OK) {
/* Initialize timer interrupt interval. */
count_interval = FIQ_MIN_COUNT_INTERVAL;
while (count_interval <= FIQ_MAX_COUNT_INTERVAL) {
/* Turn on 7 segment LED from 0 to off. */
debug_msg(led[i], NULL);
/* Waiting for (10ms * count_interval). */
smpDrv_poll(DRVNO_TIMER, 0, count_interval, handle_timer);
i++;
if (i == 18) {
i = 0;
}
}
/* 7 segment LED1 : OFF */
debug_msg(_7_LED1_OFF, NULL);
/* Timer stop. */
rtnVal = smpDrv_ioctl(DRVNO_TIMER, UPLAT7D_HAL_TIMER_SET_START, 0, handle_timer);
} /* end of if */
} /* end of if */
/* Close timer. */
smpDrv_close(DRVNO_TIMER, handle_timer);
} /* end of if */
/* Close FIQ. */
smpDrv_close(DRVNO_INTFIQ, handle_fiq);
if (rtnVal == OK) {
debug_msg(_3_LED_OK, "FIQ sample application is end by OK.\n");
}
else {
debug_msg(_3_LED_NG, "FIQ sample application is end by NG.\n");
}
return rtnVal;
}
/************************************************************************/
/* */
/* Function Name : uPLATsmpAP_PIO */
/* Input : void */
/* Output : int16_t OK(1) */
/* ERROR(-1) */
/* */
/* Note : Sample program of PIO. */
/* */
/************************************************************************/
int16_t uPLATsmpAP_PIO(void) {
int16_t rtnVal = OK;
int16_t handle_timer = HANDLE_ID_INIT;
uint16_t led[18] = {
_7_LED1_NUM_0, _7_LED1_NUM_1, _7_LED1_NUM_2, _7_LED1_NUM_3,
_7_LED1_NUM_4, _7_LED1_NUM_5, _7_LED1_NUM_6, _7_LED1_NUM_7,
_7_LED1_NUM_8, _7_LED1_NUM_9, _7_LED1_NUM_A, _7_LED1_NUM_b,
_7_LED1_NUM_C, _7_LED1_NUM_d, _7_LED1_NUM_E, _7_LED1_NUM_F,
_7_LED1_ALL, _7_LED1_OFF
};
uint16_t i = 0;
uint16_t times = 0;
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 = 0X7 ; //ROMAC_ROMTYPE_3; // 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, "PIO sample application is start.\n");
/* 7 segment LED1 : OFF */
debug_msg(_7_LED1_OFF, NULL);
/* Initailize timer. */
handle_timer = smpDrv_open(DRVNO_TIMER, PIO_TIME_INTERVAL);
if (handle_timer == HANDLE_ID_1) {
/* Timer start. */
rtnVal = smpDrv_ioctl(DRVNO_TIMER, UPLAT7D_HAL_TIMER_SET_START, 1, handle_timer);
if (rtnVal == OK) {
while (times < PIO_DISPLAY_TIMES) {
/* Turn on 7 segment LED from 0 to off. */
debug_msg(led[i], NULL);
/* Waiting for 500ms (= 10ms * 50). */
smpDrv_poll(DRVNO_TIMER, 0, 50, handle_timer);
i++;
if (i == 18) {
i = 0;
times++;
}
}
/* Timer stop. */
rtnVal = smpDrv_ioctl(DRVNO_TIMER, UPLAT7D_HAL_TIMER_SET_START, 0, handle_timer);
} /* end of if */
} /* end of if */
/* Close timer. */
smpDrv_close(DRVNO_TIMER, handle_timer);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?