📄 2410bios.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"
void call_linux(U32 a0, U32 a1, U32 a2);
void UsbMain(void);
void comdownload(void);
void NandWrite(void);
void NandLoadRun(void);
void NandErase(void);
extern U32 downloadAddress, downloadFileSize;
static EnvParams Env;
U32 Console_Uart = 0;
U32 Console_Baud = 115200;
char boot_params[256];
static short DsAutoBoot; //AutoBoot 荤侩陛瘤 敲贰弊 1 - AutoBoot吝瘤, 0 - AutoBoot
static short NorFlashSupport = 0 ;
volatile int PwrKeyChkEnd;
//*****************************************************************************
void GetBootParam(void)
{
U16 cmd_cnt = 0;
char tmp[256] = {0};
puts("设M-3004 Front Panel Bootloader,ESC Stop\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++)
boot_params[cmd_cnt] = tmp[cmd_cnt];
boot_params[cmd_cnt] = 0;
}
//*****************************************************************************
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("Test Memory (%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\bFailure:0x%x=0x%x\n",i,data);
break;
}
pt++;
}
if(memError==0)printf("\b\bSucess\n");
}
/****************** by chang *****************************/
static void Set_Auto_Run(void)
{
printf("箭磊甫 涝仿窍矫坷:");
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"}, //USB download file
{comdownload, "Uart(COM) Download"},
{NandWrite, "Writing NanFlash"},
{NandLoadRun, "Writing & Run NanFlash"},
{NandErase, "Erasing NanFlash"},
//{ProgNorFlash, "Download & Run NorFlash"},
{GetBootParam, "Parameter Setting"},
//{NandLoadRunW,"Run Wince"},
{Set_Auto_Run,"Auto Configure,1:Linux 2:Wince"},
//{EnterPowerOff, "Test Power off"},
//{SDRAM_Test, "Test SDRAM Memory"},
{0, 0}
};
static int Wince_Run=0; //Wince 角青 敲贰弊 1 - 角青,0 - 陛瘤
//*****************************************************************************
static void AutoBoot(U32 i)
{
static cnt = 10; //5s
if(!--cnt)
{
ReleaseBiosTimerEvent(i);
if((!DsAutoBoot)&&(Env.Os_Auto_Flag==1))NandLoadRun();
if(Env.Os_Auto_Flag==2)Wince_Run=1;
}
rGPFDAT ^= 1<<5;
}
/******************************************************************************
扁瓷汲疙 : 林窃荐
******************************************************************************/
int Main(U32 RstStat)
{
int i;
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
EnableModuleClock(CLOCK_ALL);
LcdBackLightOff();
Delay( 0 ) ;
putch('\n');
PwrKeyChkInit();
if(RstStat&1) {
puts("Cold Reset \n");
}
if(RstStat&4) {
puts("WatchDog Reset\n");
}
if(RstStat&2)
{
puts("PowerOff 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( 60 ) ;
Test_Lcd_Tft_16Bpp_320_240();
Beep( 2000, 500 ) ;
RequestBiosTimerEvent(50, AutoBoot); //reload value = 50, 10ms*50 = 500ms
NFSearchParams((char *)&Env);
printf("Env.Os_Auto_Flag=%x\n",Env.Os_Auto_Flag);
puts("*************************************\n");
puts("* M-3004 Front Bootloader *\n");
puts("* RFMedical Co. Ltd *\n");
puts("* Programed by KimYangWook *\n");
puts("*************************************\n");
while(1)
{
U8 idx=0;
//Test_Lcd_Tft_16Bpp_320_240();
puts("\nSelect Test Function: \n");
for(i=0; CmdTip[i].fun!=0; i++)
printf("%d : %s\n", i, CmdTip[i].tip);
while((!idx)&&(Wince_Run!=1)) //涝仿捞 绝芭唱 Wince_Run捞 SET登瘤 臼疽促搁
{ //何飘 皋春甫 谎妨霖促.
idx=getkey();
if((idx==0)&&(Wince_Run==1))NandLoadRunW();//皋春急琶捞 绝绊 Wince_Run捞 角青登搁
//敲贰浆狼 单捞鸥甫 佬绢辑 角青茄促.
}
DsAutoBoot = 1; //虐涝仿捞 乐栏搁 AutoBoot甫 陛瘤窍绊 皋春 荐青茄促.
idx -= '0';
printf("%x\n",idx); //Echo
if(idx<i)
{
(*CmdTip[idx].fun)();
}
Wince_Run=0; //WinCE 角青 陛瘤
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -