📄 2410test.c
字号:
#include "def.h"
#include "2410addr.h"
#include "2410lib.h"
#include "2410slib.h"
#include "mmu.h"
#include "uart.h"
#include "timer.h"
#include "rtcapi.h"
U32 Console_Uart = 0;
U32 Console_Baud = 115200;
//======================================================
void HaltUndef(void)
{
printf("Undefined instruction exception!!!\n");
while(1);
}
void HaltSwi(void)
{
printf("SWI exception!!!\n");
while(1);
}
void HaltPabort(void)
{
printf("Pabort exception!!!\n");
while(1);
}
void HaltDabort(void)
{
printf("Dabort exception!!!\n");
while(1);
}
void Isr_Init(void)
{
pISR_UNDEF = (U32)HaltUndef;
pISR_SWI = (U32)HaltSwi;
pISR_PABORT = (U32)HaltPabort;
pISR_DABORT = (U32)HaltDabort;
rINTMOD = 0x0; // All=IRQ mode
rINTMSK = BIT_ALLMSK; // All interrupt is masked.
}
//==========================================================
static void ChgBeepFreq(U32 no)
{
U16 freq = (PCLK>>7)/rTCNTB0;
if(freq>=10000)
freq = 500;
freq += 100;
rTCNTB0 = (PCLK>>7)/freq;
rTCMPB0 = rTCNTB0>>1; // 50%
rTCON &= ~0x1f;
rTCON |= 0xb; //disable deadzone, auto-reload, inv-off, update TCNTB0&TCMPB0, start timer 0
rTCON &= ~2; //clear manual update bit
}
static void BeepTest(void)
{
int this_tm_event;
rGPBCON &= ~3; //set GPB0 as tout0, pwm output
rGPBCON |= 2;
rTCFG0 &= ~0xff;
rTCFG0 |= 15; //prescaler = 15+1
rTCFG1 &= ~0xf;
rTCFG1 |= 2; //mux = 1/8
rTCNTB0 = (PCLK>>7)/100;
rTCMPB0 = rTCNTB0>>2; // 50%
rTCON &= ~0x1f;
rTCON |= 0xb; //disable deadzone, auto-reload, inv-off, update TCNTB0&TCMPB0, start timer 0
rTCON &= ~2; //clear manual update bit
this_tm_event = RequestBiosTimerEvent(100, ChgBeepFreq);
puts("Beep test, press ESC to exit\n");
while(1) {
if(getch()==0x1b)
break;
}
ReleaseBiosTimerEvent(this_tm_event);
rGPBCON &= ~3; //set GPB0 as tout0, pwm output
rGPBCON |= 1;
rGPBDAT &= ~1;
}
/************************************************************/
extern U32 downloadAddress, downloadFileSize;
void UsbMain(void);
void comdownload(void);
void DownloadFileSel(void)
{
puts("Please select which way to download file\n1 : USB\n2 : COM\n");
while(1) {
U8 s = getch();
if(s=='1') {
UsbMain();
break;
}
if(s=='2') {
comdownload();
break;
}
}
}
void Test_Lcd_Tft_TX06D18(int mode);
void SDI_test(void);
void UDA1341_test(void);
void LCD_test(void);
void RtcTest(void);
void DmaTest(void);
void Test_IrDA_Tx(void);
void call_linux(U32 a0, U32 a1, U32 a2);
void run_prog(void)
{
call_linux(0, 193, downloadAddress);
}
struct {
void (*fun)(void);
char *tip;
}CmdTip[] = {
{DownloadFileSel, "Download file from PC via USB or COM"},
{SDI_test, "SD/MMC Card test"},
{UDA1341_test, "UDA1341 test"},
{LCD_test, "LCD and touchpanel test"},
{RtcTest, "Real time clock test"},
{Test_IrDA_Tx, "Test IRDA"},
{BeepTest, "Buzzer test\n"},
// {DmaTest, "DMA test"},
{0, 0}
};
static void Led1Flash(U32 i)
{
static cnt = 30;
if(!--cnt) {
ReleaseBiosTimerEvent(i);
// ChangeSlowMode(CLKSLOW_PLL_ON);
// Uart_Init(0, Console_Baud);
}
rGPFDAT ^= 0x80;
}
static void Led2Flash(U32 i)
{
rGPFDAT ^= 0x40;
}
static void Led3Flash(U32 i)
{
rGPFDAT ^= 0x20;
}
static void Led4Flash(U32 i)
{
rGPFDAT ^= 0x10;
}
/************************************************************/
void KeyScanInit(void);
int Main()
{
int i;
#if 1 //bank0 modified to RO_START
MMU_Init(); //MMU should be reconfigured or turned off for the debugger,
//After downloading, MMU should be turned off for the MMU based program,such as WinCE.
#else
MMU_EnableICache();
#endif
// ChangeClockDivider(1, 1); // 1:2:4
// ChangeMPllValue(192, 4, 1); //FCLK=180.0Mhz
SetClockDivider(1, 1);
SetSysFclk(DFT_FCLK_VAL);
Port_Init();
Isr_Init();
Uart_Select(Console_Uart);
Uart_Init(0, Console_Baud);
/* Slow mode test */
/* puts("Prepare to enter slow mode, set baud rate to 9600 and press any key to continue\n");
SetSysFclk(FCLK_48M);
SetClockDivider(0, 0);
ChangeSlowMode(CLKSLOW_PLL_OFF); //disable MPLL and UPLL, enter slow mode
Console_Baud = 9600;
Uart_Init(0, Console_Baud);
getch();
printf("Enter slow mode FCLK = %d, HCLK = %d, PCLK = %d\n", SYS_FCLK, SYS_HCLK, SYS_PCLK);
*/
// DisableUPLL();
/* timer test */
// OpenOsTimer(10);
RequestBiosTimerEvent(10, Led1Flash); //when request, auto open bios timer
RequestBiosTimerEvent(20, Led2Flash);
RequestBiosTimerEvent(50, Led3Flash);
RequestBiosTimerEvent(100, Led4Flash);
//GPIO,UART0,PWM TIMER,NAND FLASH
// DisableModuleClock(CLOCK_ALL);
EnableModuleClock(CLOCK_UART0|CLOCK_TIMER|CLOCK_GPIO|CLOCK_NAND|CLOCK_LCD);
/* RtcOpenTick();
{
U32 led_r1, led_r2, ticks;
BYTE vary;
led_r1 = led_r2 = rGPFDAT&0x80;
while(1)
{
led_r2 = rGPFDAT&0x80;
if(led_r2!=led_r1)
{
led_r1 = led_r2;
vary = RtcReadTick(&ticks);
printf("%d, Now ticks = %d\n", vary, ticks);
if(ticks>1000)
RtcCloseTick();
}
}
}*/
// UsbMain();
Test_Lcd_Tft_TX06D18(0);
putch('\n');
puts("***********************************\n");
puts("* *\n");
puts("* FS2410 board demo programe *\n");
puts("* *\n");
puts("* Http://www.uCdragon.com *\n");
puts("***********************************\n");
{
DATETIME_T dt1;
RtcGetDate(&dt1);
printf("Now date is %4d-%2d-%2d week %d, time is %2d:%2d:%2d\n",
dt1.year, dt1.month, dt1.day, dt1.week, dt1.hour, dt1.minute, dt1.second);
}
printf("CS8900 sig = 0x%08x\n", *(volatile U16 *)(0x19000300+0xa));
*(volatile U16 *)(0x19000300+0xa) = 0;
printf("CS8900 eisa = 0x%08x\n", *(volatile U16 *)(0x19000300+0xc));
*(volatile U16 *)(0x19000300+0xa) = 0x0114;
*(volatile U16 *)(0x19000300+0xc) = 0x0040;
while(1) {
U16 i;
*(volatile U16 *)(0x19000300+0xa) = 0x0136;
i = *(volatile U16 *)(0x19000300+0xc);
printf("0x%08x\n", i);
if(i&0x80)
break;
}
KeyScanInit();
while(1)
{
U8 idx;
puts("\nPlease select function : \n");
for(i=0; CmdTip[i].fun!=0; i++)
printf("%d : %s\n", i, CmdTip[i].tip);
idx = getch()-'0';
if(idx<i)
{
(*CmdTip[idx].fun)();
// ChangeMPllValue(192, 4, 1); //FCLK=180.0Mhz
Delay(2000);
SetSysFclk(DFT_FCLK_VAL);
Uart_Init(0, Console_Baud);
}
}
while(1)
{
Led_Display(0xf);
Delay(10000);
Led_Display(0);
Delay(10000);
putch('@');
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -