📄 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);
void Function(void);
void Eth0(void);
void init_adc(void);
//static int org = 1;
extern U32 downloadAddress, downloadFileSize;
U32 Console_Uart = 0;
U32 Console_Baud = 115200;
char boot_params[256];
static short DsAutoBoot;
static short NorFlashSupport = 0 ;
volatile int PwrKeyChkEnd;
//*****************************************************************************
/*__irq表示这个函数是外部中断处理函数*/
void __irq recieve(void)
{
printf("in interrupt handler now!!\n");
/*只处理串口的接收中断*/
if(BIT_SUB_RXD1)
{
/*等待接收缓冲为满*/
while(rUTRSTAT1 & 0X1 == 0)
;
/*打印从串口接收到的字符*/
/* if(org==1)
{
printf("receive = in interrupt handler now!\n");
org++;
}
*/
printf("receive = %c\n",(U8)rURXH1);
/*完成中断处理,在退出之前,清理干净中断寄存器的相关位,防止死循环*/
/*注意,在反复实验的过程中,发现应该先清理子中断源寄存器,再清理中断源 *寄存器,这样可以有效避免假中断。最后重新设置中断屏蔽位,屏蔽相应中断和*子中断
*/
// ClearSubPending(BIT_SUB_ERR1 | BIT_SUB_RXD1| BIT_SUB_TXD1);
ClearSubPending( BIT_SUB_RXD1| BIT_SUB_TXD1);
ClearPending(BIT_UART1);
DisableSubIrq( BIT_SUB_TXD1 | BIT_SUB_RXD1);
DisableIrq(BIT_UART1);
}
}
void uart_init2(void)
{
/*注册中断处理函数*/
pISR_UART1 = (U32)recieve;
rULCON1 = 0x3; //8位数据,无奇偶校验,非红外发送模式
rUCON1 = 0x25; //回环发送模式,接收和发送均为中断方式
rUBRDIV1 = 0x19; //设置波特率
rUFCON1 = 0x0; //非FIFO模式
EnableSubIrq( BIT_SUB_TXD1 | BIT_SUB_RXD1);
EnableIrq(BIT_UART1);
/*手工清理中断寄存器相关位*/
ClearSubPending( BIT_SUB_RXD1 | BIT_SUB_TXD1);
ClearPending(BIT_UART1);
}
void send(U8 data)
{
EnableSubIrq( BIT_SUB_TXD1 | BIT_SUB_RXD1);
EnableIrq(BIT_UART1);
/*往发送数据寄存器填值,该数据会自动发送出去*/
rUTXH1 = data;
}
void GetBootParam(void)
{
U16 cmd_cnt = 0;
char tmp[256] = {0};
puts("Set 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++)
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("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");
}
//*****************************************************************************
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"},
{SDRAM_Test, "test SDRAM Memory"},
{Function,"function test"},
{Eth0,"ethernet"},
{0, 0}
};
//*****************************************************************************
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;
int j;
// 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
//enable GPIO,UART0,PWM TIMER,NAND FLASH module clock
// DisableModuleClock(CLOCK_ALL);
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
LcdBackLightCtl(0, 60);
Test_Lcd_Tft_16Bpp_240_320();
// RequestBiosTimerEvent(50, AutoBoot); //reload value = 50, 10ms*50 = 500ms
//如果不做任何操作,自动启动linux
puts("************************************\n");
puts("************************************\n");
puts("********** Linux-Team2**************\n");
puts("************************************\n");
puts("************************************\n");
SetClockDivider(0, 1);
SetSysFclk(FCLK_96M); //to save power, use 96M
puts("************************************\n");
puts("************************************\n");
puts("Coder:XueTongtong.WangHuaqing,WangZhenhua\n");
puts("*****Tester:LiJiaojiao,YangYang\n*****");
puts("************************************\n\n");
uart_init2();
for(i='A';i<='z';i++)
{
send((U8)i);
Delay(1000);
}
/* sendmsg(); //向串口1 发R232 协议数据
receive_uart();
uart_init();
in_out();
*/
/* init_adc();
GetSysClock(); //输出主频
pISR_TIMER2 = (U32)timer_service ; //timer 中断
timer_init();
while(1);
tout_init(); //蜂鸣器
pISR_UART1 =(U32)in_out; //串口中断
uart_init();
IntInit(); //键盘中断
pISR_EINT0 =(U32)service;
pISR_EINT2 =(U32)service;
pISR_EINT8_23=(U32)service;
while(1);
*/
//****************************************************
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);
if ( (nor_flash_id==0x278200bf) | (nor_flash_id==0x234b00bf) )
{
NorFlashSupport = 1 ;
if(nor_flash_id==0x278200bf) puts("SST39VF160 found\n");
if(nor_flash_id==0x234b00bf) puts("SST39VF1601 found\n");
}
else
printf( "Not supported NorFlash 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);
idx = getch();
DsAutoBoot = 1; //when get a key press, disable auto boot
idx -= '0';
if(idx<i)
{
(*CmdTip[idx].fun)();
continue;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -