⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 本程序是FS44B0XII V3.00开发板C57和G57液晶屏套件程序
💻 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<i)
			(*cmd_menu[sel].test_func)();
	}
}

#define	DFT_DOWNLOAD_ADDR	0x0c400000

U32 download_addr, download_len;

//中断入口内容不可确定,不要用中断
void LoadFromUart(void)
{
	int i, size;
	unsigned short dnCS, CheckSum;
	unsigned char *buf;
	unsigned char RxTmp[8];
	void (*fun)(void);
	
	download_addr = DFT_DOWNLOAD_ADDR;
	
	buf = (unsigned char *)download_addr;
	
	printf("Now download file from uart0 to 0x%x...\n", download_addr);
	
	i = 0;
	while(i<4)
		RxTmp[i++] = getch();
    
    i = 0;
    size = *(unsigned long *)RxTmp - 4;
	while(i<size)
		buf[i++] = getch();
	
	download_len = size-2;	
	
	dnCS = (buf[size-1]<<8)|buf[size-2];
	CheckSum = 0;
	for(size -= 3; size>=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;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -