www.pudn.com > USBdiskRW.rar > Main.c


#include "def.h" 
#include "44b.h" 
#include "utils.h" 
 
#define	BAUD_RATE	115200 
 
static void SwiHandler(void) 
{ 
	puts("Swi Interrupt detected\n"); 
		while(1); 
} 
 
static void DataAbortHandler(void)  
{ 
	puts("Data Abort detected\n"); 
	while (1); 
} 
 
static void FetchAbortHandler(void) 
{ 
	puts("Prefetch Abort detected\n"); 
	while (1); 
} 
 
static void UndefHandler()  
{ 
	puts("Halt on Undefined instruction\n"); 
	while (1); 
} 
 
#ifndef	INTERRUPT_SUPPORT 
static void IrqHandler(void) 
{ 
	puts("Halt on IRQ!\n"); 
	while(1); 
} 
#endif 
 
static void FiqHandler(void) 
{ 
	puts("Halt on FIQ!\n"); 
	while(1); 
} 
 
volatile char which_int_key=0; 
static void Key_Interrupt(void) 
{	 
    which_int_key = rEXTINTPND; 
    rEXTINTPND = 0xf;		//clear EXTINTPND reg.		 
    rI_ISPC=BIT_EINT4567;	//clear pending_bit 
 
    switch(which_int_key) 
   { 
        	case 1: 
        	    printf("EINT4 had been occured...\n"); 
				LedSet(0x1); 
        	    which_int_key=0; 
        	    break; 
        	case 2: 
        	    printf("EINT5 had been occured...\n"); 
				LedSet(0x2); 
        	    which_int_key=0; 
        	    break; 
        	case 4: 
        	    printf("EINT6 had been occured...\n"); 
				LedSet(0x4); 
        	    which_int_key=0; 
        	    break; 
        	case 8: 
        	    printf("EINT7 had been occured...\n"); 
				LedSet(0x8); 
        	    which_int_key=0; 
        	    break; 
        	default : 
        	    break; 
    } 
  
} 
 
extern U32 SysRstVector; 
extern U32 UdfInsVector; 
extern U32 SwiSvcVector; 
extern U32 InsAbtVector; 
extern U32 DatAbtVector; 
extern U32 ReservedVector; 
extern U32 IrqSvcVector; 
extern U32 FiqSvcVector; 
 
extern U32 pIrqHandler; 
 
static __inline void VectorInit(void) 
{ 
	UdfInsVector = (U32)UndefHandler; 
	SwiSvcVector = (U32)SwiHandler; 
	InsAbtVector = (U32)FetchAbortHandler; 
	DatAbtVector = (U32)DataAbortHandler; 
#ifndef	INTERRUPT_SUPPORT 
	IrqSvcVector = (U32)IrqHandler; 
#endif 
	FiqSvcVector = (U32)FiqHandler; 
 
	rINTCON = 0x5 ;		//无向量中断模式 
	rINTMOD = 0x0 ;		//All=IRQ mode 
 
//	rEXTINT=0x22222222;		//Falling edge mode  
	rEXTINT=0x0;		//"0" level mode 
 
    rPCONG = 0xff00;		//EINT7~4 
    rPUPG = 0x0;		//pull up enable 
 
	pIrqHandler = (U32)Key_Interrupt ; 
	 
    //pISR_EINT4567 = (unsigned)Key_Interrupt ; 
    //rINTMSK = ~(BIT_GLOBAL|BIT_EINT4567);	//start INT 
} 
 
void LedDisp(void) 
{ 
	LedSet(0x08);		//LED点亮/熄灭状态设置 
	Delay(150); 
	LedSet(0x04);		//LED点亮/熄灭状态设置 
	Delay(150); 
	LedSet(0x02);		//LED点亮/熄灭状态设置 
	Delay(150); 
	LedSet(0x01);		//LED点亮/熄灭状态设置 
	Delay(150); 
	LedSet(0x02);		//LED点亮/熄灭状态设置 
	Delay(150); 
	LedSet(0x04);		//LED点亮/熄灭状态设置 
	Delay(150); 
	LedSet(0x08);		//LED点亮/熄灭状态设置 
	Delay(150); 
	LedSet(0x00);		//LED点亮/熄灭状态设置 
} 
 
TIME_STRUC SysTime; 
char *WeekDay[7] = {"MON", "TUES", "WED", "THURS","FRI", "SAT", "SUN"}; 
 
void Main(void) 
{ 
	BoardInitStart(); 
	 
	SystemClockInit(); 
	 
	TimerInit(1000); 
	 
	MemCfgInit(); 
	 
	PortInit(); 
	 
	VectorInit(); 
	 
	NandFlashInit();	 
		 
	CacheDisable(); 
	CacheFlush(); 
	CacheEnable(); 
	 
	BoardInitEnd(); 
		 
	Beep(2000, 200); 
	LedDisp();		//LED来回闪烁显示 
	 
	SerialSwitch(0); 
	SerialChgBaud(BAUD_RATE); 
	 
	ShowBootInfo(); 
	NandFlashStatusRep(); 
	//GetIdeInfo();		//获取IDE硬盘信息 
	 
	printf("Build  date : %s--%s\n", __DATE__, __TIME__); 
	printf("Serial baud : %d\n", BAUD_RATE); 
	printf("CPU clock is %dHz, Master clock is %dHz\n", GetCpuClock(), GetMasterClock()); 
	 
	RtcGetTime(&SysTime); 
	printf("Current date is %x-%x-%x [%s]\n", SysTime.year, SysTime.month, SysTime.day, WeekDay[(SysTime.weekday-1U)%7U]); 
	printf("Current time is %2x:%2x:%2x\n", SysTime.hour, SysTime.min, SysTime.sec); 
	 
	while(1) 
	{ 
		U16 i, sel;		 
		 
		putch('\n'); 
	 
		for(i=0; cmd_menu[i].test_func; i++) 
		{ 
			printf("%d : %s\n", i, cmd_menu[i].string); 
		} 
		 
		while(!kbhit()) 
			LedSet(GetKeyStatus()); 
		 
		sel = Uart_GetIntNum_GJ() ; 
		 
		if(sel=0; size--) 
		CheckSum += buf[size]; 
	if(dnCS!=CheckSum) { 
//		printf("get CS=0x%08x, cal CS=0x%08x\n", dnCS, CheckSum); 
		puts("\nCheckSum error!\n"); 
		download_len = 0; 
	} else { 
		printf("\nReceived %x bytes success\n", download_len); 
		puts("Do you want to run it?"); 
		if(getyorn()) { 
			fun = (void (*)(void))download_addr;		 
			CacheDisable(); 
			CacheFlush(); 
			(*fun)(); 
		} 
	} 
	 
	return; 
}