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

📄 2410bios.c

📁 驱动芯片为ILI9320的TFT LCD 在s3c2410下的应用
💻 C
字号:
#include "def.h"
#include "2410addr.h"
#include "2410lib.h"
#include "2410slib.h"
#include "mmu.h"
#include "uart.h"
#include "timer.h"
#include "39vf160.h"
#include "LCD.h"
#include "PowerManage.h"
#include "Spi.h"

void call_linux(U32 a0, U32 a1, U32 a2);
void UsbMain(void);
void comdownload(void);

void NandWrite(void);
void NandLoadRun(void);
void NandRunSystem(void);
void NandErase(void);
// GPB1/TOUT1 for Backlight control(PWM)
#define GPB1_TO_OUT()   (rGPBUP &= 0xfffd, rGPBCON &= 0xfffffff3, rGPBCON |= 0x00000004)
#define GPB1_TO_1()     (rGPBDAT |= 0x0002)
#define GPB1_TO_0()     (rGPBDAT &= 0xfffd)
    
//qjy: special power on timing, please research it!
void Lcd_Port_Init(void);
void Lcd_Init(void);

extern U32 downloadAddress, downloadFileSize;
//static EnvParams Env;
U32	Console_Uart = 0;
U32	Console_Baud = 115200;

static short DsAutoBoot;
static short NorFlashSupport = 0 ;

volatile int PwrKeyChkEnd;

//*****************************************************************************
void GetBootParam(void)
{
	U16 cmd_cnt = 0;
	char tmp[256] = {0};
	
	NFSearchParams((char *)&Env);
	if(Env.boot_params[0]=='r')
		printf("\n%s", Env.boot_params);
	puts("\nSet boot params, press Enter to finish, Esc to abort\n");
	while(1) {
		char c = getch();
		if(c==0x1b) 
			return;
		
		if(c==0xd)
			break;
		if((c==0x8)&&(cmd_cnt)) {			
			cmd_cnt -= 1;
			tmp[cmd_cnt] = 0;
			putch(c);
			putch(' ');
			putch(c);
		}
		else {
			if(cmd_cnt<255) {
				putch(c);
				tmp[cmd_cnt++] = c;
				tmp[cmd_cnt]   = 0;
			}
		}		
	}

	for(cmd_cnt=0; tmp[cmd_cnt]; cmd_cnt++)
		Env.boot_params[cmd_cnt] = tmp[cmd_cnt];
	Env.boot_params[cmd_cnt] = 0;			

	NFSaveParams((char *)&Env);
}

//*****************************************************************************
static __inline int RtcAlmWake(void)
{	
	return ((rBCDHOUR==rALMHOUR)&&(rBCDMIN==rALMMIN));
}

//*****************************************************************************
static void ProgNorFlash(void)
{
	if(NorFlashSupport) {
		SectorProg(0, (U16 *)downloadAddress, downloadFileSize);
	}
}

//*****************************************************************************
void SDRAM_Test(void)
{
    int i;
    U32 data;
    int memError=0;
    U32 *pt;
    
    printf("Memory Test(%xh-%xh):WR",_RAM_STARTADDRESS,(_ISR_STARTADDRESS&0xfff0000));

    pt=(U32 *)_RAM_STARTADDRESS;
    while((U32)pt<(_ISR_STARTADDRESS&0xffff0000))
    {
	*pt=(U32)pt;
	pt++;
    }

    printf("\b\bRD");
    pt=(U32 *)_RAM_STARTADDRESS;
	
    while((U32)pt<(_ISR_STARTADDRESS&0xffff0000))
    {
	data=*pt;
	if(data!=(U32)pt)
	{
	    memError=1;
	    printf("\b\bFAIL:0x%x=0x%x\n",i,data);
	    break;
	}
	pt++;
    }

    if(memError==0)printf("\b\bO.K.\n");
}
/****************** by chang *****************************/
static void Set_Auto_Run(void)
{
	printf("\nPlease Input Number:");
	Env.Os_Auto_Flag=getch()-'0';
	//Env.Os_Auto_Flag=1;
	printf("%x\n",Env.Os_Auto_Flag);
	NFSaveParams((char *)&Env);
}
/***************** by chang *****************************/
struct {
	void (*fun)(void);
	char *tip;
}CmdTip[] = {
				{UsbMain, "USB download file"},
				{comdownload, "Uart download file"},
				{NandWrite, "Write Nand flash with download file"},
				{NandRunSystem, "Load Pragram from Nand flash and run"},
				{NandErase, "Erase Nand flash regions"},
				{ProgNorFlash, "Write NOR flash with download file"},
				{GetBootParam, "Set boot params"},
				//{NandLoadRunW,"Run Wince"},
				{Set_Auto_Run,"Set AutoBoot parameter,1:linux 2:wince"},
				//{EnterPowerOff, "Test Power off"},
				//{SDRAM_Test, "test SDRAM Memory"},
				{0, 0}						
			};

static int Wince_Run=0;	
//*****************************************************************************
static void AutoBoot(U32 i)
{
	static cnt = 10;		//5s

	if(!--cnt) {
		ReleaseBiosTimerEvent(i);
//		if(!DsAutoBoot)
//			(*CmdTip[3].fun)();
	if((!DsAutoBoot)&&(Env.Os_Auto_Flag==1))NandLoadRun();
	if((!DsAutoBoot)&&(Env.Os_Auto_Flag==2))Wince_Run=1;
	}
	rGPBDAT ^= 1<<5;
}
/*
static void Led1Flash(U32 i)
{	
	static cnt = 30;
	
	if(!--cnt) {
		ReleaseBiosTimerEvent(i);
//		ChangeSlowMode(CLKSLOW_PLL_ON);		
//		Uart_Init(0, UART_BAUD);
	}
	rGPFDAT ^= 0x80;
}
static void Led2Flash(U32 i)
{	
	rGPFDAT ^= 0x40;	
}
static void Led3Flash(U32 i)
{	
	rGPFDAT ^= 0x20;	
}
static void Led4Flash(U32 i)
{		
	rGPFDAT ^= 0x10;	
}
*/
/******************************************************************************
【功能说明】系统主函数
******************************************************************************/
int Main(U32 RstStat)
{
	unsigned int i,j;
	U16 x;
	SetClockDivider(1, 1);
	SetSysFclk(FCLK_200M);		//to save power, use 50M
	
	/* This codede by myself!!!!!!!*/
	Port_Init();
	
	Isr_Init();

	Uart_Init(0, Console_Baud);
	Uart_Select(Console_Uart);	
	
#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();
	UsbMain();
#endif
	
	//enable GPIO,UART0,PWM TIMER,NAND FLASH module clock
	EnableModuleClock(CLOCK_ALL);	

	LcdBackLightOff();

	putch('\n');

	PwrKeyChkInit();
	
	if(RstStat&1) {
		puts("Power on reset\n");
		//EnterPowerOff();
	}
	if(RstStat&4) {
		puts("Watchdog reset\n");
		//EnterPowerOff();
	}
	if(RstStat&2) {
		puts("Power-off reset\n");
		if(RtcAlmWake()) {
			puts("Alarm wake up\n");
			printf("RTC hr : %d, min : %d\nALM hr : %d, min : %d\n", rBCDHOUR, rBCDMIN, rALMHOUR, rALMMIN);
		} else if( PwrKeyWake() ) {			
			PwrKeyChkEnd = 1;
			RequestBiosTimerEvent(1, PwrKeyChk);	//reload value = 1, 10ms*1 = 10ms
			while(PwrKeyChkEnd>0);
			if(PwrKeyChkEnd!=0)
				EnterPowerOff();
			puts("Power key wake up\n");
		}
	}	
		
	rMISCCR &= ~(0x3007);		//USB port0,1 = normal, D0~D31 pull-up enable

	Set_Tout1_Pwm( 100 ) ;
	
	
	//turn on the LCD blacklight!
    GPB1_TO_OUT();
    GPB1_TO_1();
    
	//special power on timing, please research it!
    Lcd_Port_Init();
    Lcd_Init();
    
    SPI_Interface();
    //SpiConfig();
    //SpiTest();

	//Beep( 2000, 1000 ) ;
	
	RequestBiosTimerEvent(30, Led4Flash);	//when request, auto open bios timer
	
	NFSearchParams((char *)&Env);
	printf("Env.Os_Auto_Flag=%x\n",Env.Os_Auto_Flag);
	
	Lcd_EnvidOnOff(1);      //不能少
	ILI9320_Init();
	//rLCDCON5 = 0x14f48;
	/*   //这一块是用不同颜色清屏,能够实现的,初始化是寄存器配置要改为
	#if0
	LCD_WriteReg(0x000c,0x0000);	//RGB interface setting
	LCD_WriteReg(0x000d,0x0000);	//Frame marker Position
	LCD_WriteReg(0x000f,0x0000);	//RGB interface polarity
	#endif
	
	Lcd_Write_Start();
	for(i=0;i<320;i++)
	{
		for(j=0;j<240;j++)
		{
			if(i>279)LCD_WriteData(0x0000);
			else if(i>239)LCD_WriteData(0x001f);
			else if(i>199)LCD_WriteData(0x07e0);
			else if(i>159)LCD_WriteData(0x07ff);
			else if(i>119)LCD_WriteData(0xf800);
			else if(i>79)LCD_WriteData(0xf81f);
			else if(i>39)LCD_WriteData(0xffe0);
			else LCD_WriteData(0xffff);
		}
	}	
	Lcd_Write_End();
	*/
	
	Delay(1000);
	//LCD_WriteReg(1,0x0022);
	Lcd_ClearScr(RED);      //RGB接口
	//Screen_Clear(RED);
	Delay(1000);
	Lcd_ClearScr(GREEN);    //RGB接口
	//Screen_Clear(GREEN);
	Delay(1000);
	Lcd_ClearScr(BLUE);     //RGB接口
	
	Beep(200, 500);
	
	
	    Uart_Printf( "\nrGPBCON=0x%x\n", rGPBCON );
    	Uart_Printf( "\trGPBUP=0x%x\n", rGPBUP );
    	Uart_Printf( "rGPCCON=0x%x\n", rGPCCON );
    	Uart_Printf( "\trGPCUP=0x%x\n", rGPCUP );
    	Uart_Printf( "rGPDCON=0x%x\n", rGPDCON );
    	Uart_Printf( "\trGPDUP=0x%x\n", rGPDUP );
    	Uart_Printf( "rGPGCON=0x%x\n", rGPGCON );
    	Uart_Printf( "\trGPGUP=0x%x\n\n", rGPGUP );

    	Uart_Printf( "rLCDCON1=0x%x\n", rLCDCON1 );
    	Uart_Printf( "rLCDCON2=0x%x\n", rLCDCON2 );
    	Uart_Printf( "rLCDCON3=0x%x\n", rLCDCON3 );
    	Uart_Printf( "rLCDCON4=0x%x\n", rLCDCON4 );
    	Uart_Printf( "rLCDCON5=0x%x\n\n", rLCDCON5 );

    	Uart_Printf( "rLCDSADDR1=0x%x\n", rLCDSADDR1 );
    	Uart_Printf( "rLCDSADDR2=0x%x\n", rLCDSADDR2 );
    	Uart_Printf( "rLCDSADDR3=0x%x\n\n", rLCDSADDR3 );
    	
    	Uart_Printf( "rLCDINTMSK=0x%x\n", rLCDINTMSK );
    	Uart_Printf( "rLPCSEL=0x%x\n", rLPCSEL );
    	Uart_Printf( "rTPAL=0x%x\n\n", rTPAL );
	
	while(1)
	{
		Lcd_ClearScr(RED);
		Delay(1000);
		Lcd_ClearScr(GREEN);
		Delay(1000);
		Lcd_ClearScr(BLUE);
		Delay(1000);
		//for( x = 0 ; x < 65000 ; x++ )
    	//{
		//	Lcd_ClearScr1(x);
    	//}
		Lcd_ClearScr1();
		Delay(1000);
	}
	
	return 0;
}

⌨️ 快捷键说明

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