📄 2410bios.c
字号:
//Signal : KBDSPIMISO LCD_PWREN EINT11 nSS_SPI IRQ_LAN IRQ_PCMCIA
//Setting: SPIMISO1 LCD_PWRDN EINT11 nSS0 EINT9 EINT8
//Binary : 11 11 , 10 11 , 10 10
rGPGCON = 0x0;
rGPGUP = 0xffff; // The pull up function is disabled GPG[15:0]
//*** PORT H GROUP
//Ports : GPH10 GPH9 GPH8 GPH7 GPH6 GPH5 GPH4 GPH3 GPH2 GPH1 GPH0
//Signal : CLKOUT1 CLKOUT0 UCLK nCTS1 nRTS1 RXD1 TXD1 RXD0 TXD0 nRTS0 nCTS0
//Binary : 10 , 10 10 , 11 11 , 10 10 , 10 10 , 10 10
rGPHCON = 0x0;
rGPHUP = 0x7ff; // The pull up function is disabled GPH[10:0]
LcdBackLightOff();
}
static void EnterPowerOff(void)
{
U32 r;
Uart_Printf("Enter Power-off mode, press Reset or K4 key to wake up\n");
Uart_TxEmpty(0); //Wait until UART0 Tx buffer empty.
ConfigPowerOffGPIO();
PwrKeyChkInit();
rEINTPEND = 1<<11; //clear EINT11
rEXTINT1 = 0; //EINT11 low-level interrupt
rEINTMASK = rEINTMASK&~(1<<11); //SRCPND:EINT8_23 will be set by EINT19 after wake-up.
ClearPending(BIT_EINT8_23|BIT_RTC);
rINTMSK = BIT_ALLMSK;
rRTCCON = 0x0; //R/W disable, 1/32768, Normal(merge), No reset
rADCCON |= (1<<2); //ADC additional power down
rGSTATUS3 = (U32)StartPointAfterPowerOffWakeUp;
rGSTATUS4 = 0xbe50dead;
//MISCCR[13:12] set usb port0,1 suspend
//MISCCR[2] Previous state at STOP(?) mode (???)
//MISCCR[1:0] D0~D31 pull-up disable
rMISCCR |= 0x3007;
rLCDCON1 &= ~1; //Before entering STOP mode, LCD must be off
//=================================================================
// VERY IMPORTANT NOTE
// To enter STOP/SLIDLE mode, MMU TLB-fill operation should be prohibited
// because MTT table is in SDRAM and SDRAM is in the self-refresh mode.
// So, we will fill TLB before entering SDRAM self-refresh
// instead of disabling MMU.
r = rREFRESH; //To fill TLB for the special register used in EnterPWDN
r = rCLKCON;
//=================================================================
//EnterPWDN(0x7fff8); //POWER_OFF mode
rCLKCON = 0x7fff8; //needn't set sdram sel-refresh, directly power-down
//Never return here.
}
//==========================================================
static void ProgNorFlash(void)
{
if(NorFlashSupport) {
SectorProg(0, (U16 *)downloadAddress, downloadFileSize);
}
}
//==========================================================
struct {
void (*fun)(void);
char *tip;
}CmdTip[] = {
{UsbMain, "USB download file"},
{comdownload, "Uart download file"},
{NandWrite, "Write Nand flash with download file"},
{NandLoadRun, "Load Pragram from Nand flash and run"},
{NandErase, "Erase Nand flash regions"},
{ProgNorFlash, "Write NOR flash with download file"},
{GetBootParam, "Set boot params"},
{EnterPowerOff, "Test Power off"},
{0, 0}
};
/*
static void Led1Flash(U32 i)
{
static cnt = 100;
if(!--cnt)
ReleaseBiosTimerEvent(i);
rGPFDAT ^= 0x10;
}
static void Led2Flash(U32 i)
{
rGPFDAT ^= 0x20;
}
static void Led3Flash(U32 i)
{
rGPFDAT ^= 0x40;
}
static void Led4Flash(U32 i)
{
rGPFDAT ^= 0x80;
}*/
static void AutoBoot(U32 i)
{
static cnt = 10; //5s
if(!--cnt) {
ReleaseBiosTimerEvent(i);
if(!DsAutoBoot)
NandLoadRun();
}
rGPBDAT ^= 1<<5;
}
/************************************************************/
int Main(U32 RstStat)
{
int i;
// char upgrade[] = {'u', 'p', 'g', 'r', 'a', 'd', 'e', 0};
// ChangeClockDivider(1, 1); // 1:2:4
// ChangeMPllValue(172,4,1); //FCLK=180.0Mhz
SetClockDivider(0, 1);
SetSysFclk(FCLK_96M); //to save power, use 48M
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
/* 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);
*/
/* timer test */
/* OpenOsTimer(10);
RequestBiosTimerEvent(10, Led1Flash); //when request, auto open bios timer
RequestBiosTimerEvent(20, Led2Flash);
RequestBiosTimerEvent(50, Led3Flash);
RequestBiosTimerEvent(100, Led4Flash);
*/
//enable GPIO,UART0,PWM TIMER,NAND FLASH module clock
// DisableModuleClock(CLOCK_ALL);
EnableModuleClock(CLOCK_ALL);
/* 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();
}
}
}*/
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
//LCD背光亮,并显示蓝 红 绿三色
LcdBackLightCtl(0, 60);
Test_Lcd_Tft_LTS350Q1_PE1();
RequestBiosTimerEvent(50, AutoBoot); //reload value = 50, 10ms*50 = 500ms
puts("************************************\n");
puts("* *\n");
puts("* FS2410 Board BIOS V20 *\n");
puts("* Http://www.ucdragon.com *\n");
puts("* *\n");
puts("************************************\n");
// puts("Please visit Http://www.uCdragon.com for more details\n");
/* i = 0;
while(i<2) {
U8 c;
c = getch();
putch(c);
if(c==upgrade[i])
i++;
else
NandLoadRun();
}
DsAutoBoot = 1;*/ //don't check "up" any more
if(rBWSCON&6) {
U32 nor_flash_id;
nor_flash_id = GetFlashID();
puts("NOR Flash Boot, ");
printf("Read ID is : 0x%x\n", nor_flash_id);
NorFlashSupport = nor_flash_id==0x278200bf;
if(!NorFlashSupport)
puts("No ");
puts("SST39VF160 found\n");
}
else
puts("NAND Flash Boot\n");
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);
// puts("Press '+' or '-' to control LCD backlight\n");
//GetSelAgn:
idx = getch();
DsAutoBoot = 1; //when get a key press, disable auto boot
/* if(idx=='+')
LcdBackLightCtl(1, 1);
if(idx=='-')
LcdBackLightCtl(1, 0);*/
idx -= '0';
if(idx<i) {
(*CmdTip[idx].fun)();
// ChangeMPllValue(192, 4, 1); //FCLK=180.0Mhz
// Delay(1000);
// SetSysFclk(FCLK_96M);
// Uart_Init(0, Console_Baud);
} //else
//goto GetSelAgn;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -