📄 u2440mon.c
字号:
/****************************************************************
NAME: u2440mon.c
DESC: u2440mon entry point,menu,download
HISTORY:
Mar.25.2002:purnnamu: S3C2400X profile.c is ported for S3C2410X.
Mar.27.2002:purnnamu: DMA is enabled.
Apr.01.2002:purnnamu: isDownloadReady flag is added.
Apr.10.2002:purnnamu: - Selecting menu is available in the waiting loop.
So, isDownloadReady flag gets not needed
- UART ch.1 can be selected for the console.
Aug.20.2002:purnnamu: revision number change 0.2 -> R1.1
Sep.03.2002:purnnamu: To remove the power noise in the USB signal, the unused CLKOUT0,1 is disabled.
****************************************************************/
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "profile.h"
#include "usbmain.h"
#include "usbout.h"
#include "usblib.h"
#include "2440usb.h"
#include "nand.h"
#include "Samsunggpio.h" // xm.hu
#include "wm8753.h"
#include "iis.h"
#include "fmd.h"
#include "bootpart.h"
#define FROM_BCD(n) ((((n) >> 4) * 10) + ((n) & 0xf))
#define TO_BCD(n) ((((n) / 10) << 4) | ((n) % 10))
#define ram_nand 1
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *LPSYSTEMTIME;
void __RdPage2048(UCHAR *bufPt);
void Gpio_Init(void);
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
void WaitDownload(void);
void Menu(void);
void ClearMemory(void);
void LoadWince(void);
void ReserveBlock(void);
BOOL UGBoot_GetRealTime(LPSYSTEMTIME lpst);
BOOL UGBoot_SetRealTime(LPSYSTEMTIME lpst);
DWORD UGBoot_GetSecs( void );
int UGBoot_ReadDebugByte();
void MemoryTest(void);
//#define DOWNLOAD_ADDRESS _RAM_STARTADDRESS
volatile U32 downloadAddress;
void (*restart)(void)=(void (*)(void))0x0;
void (*run)(void);
volatile unsigned char *downPt;
volatile U32 downloadFileSize;
volatile U16 checkSum;
volatile unsigned int err=0;
volatile U32 totalDmaCount;
volatile int isUsbdSetConfiguration;
int download_run=0;
int download_update_wince = 0;
int download_update_ugboot = 0;
U32 tempDownloadAddress;
int menuUsed=0;
int JumpAddr=0;
//extern char Image$$RW$$Limit[];
extern char Image_RW_Limit[]; /* End of ROM code (=start of ROM data) */
//U32 *pMagicNum=(U32 *)Image$$RW$$Limit;
U32 *pMagicNum=(U32 *)Image_RW_Limit;
int consoleNum;
void Main(void)
{
Gpio_Init();
// ISR init
Isr_Init();
// UART debug init
consoleNum=2;
Uart_Init(PCLK, 115200);
Uart_Select(consoleNum);
// timer setting for delay 100us unit.
//Delay(1); //calibrate Delay()
Delay(0);
#if ram_nand
Test_Nand();
#endif
while(1)
{
Radio_IIS();
}
//use for power on pda
// rGPFCON &= ~(0x3<<0); //EINT0 as input,to know if the powerbutton be pressed long enough
// rGPFUP |= (0x1<<0);
if(rGPFDAT & 0x1) //be pressed
{
Delay(10000); //delay 1.5second
if(rGPFDAT & 0x1)
{
Uart_Printf("power on and Load WinCE...\r\n");
//backlight on
rGPBUP = rGPBUP&(~(1<<0));
rGPBCON=rGPBCON&(~(3<<0))|(1<<0);
rGPBDAT = rGPBDAT&(~(1<<0))|(1<<0);
rGPFUP &= ~(0x1<<0); //needed do not delete
ClearMemory();
LoadWince();
}
else
{
Uart_Printf("short pressed.\r\n");
rGPACON &= ~(0x1<<16);
rGPADAT &= ~(0x1<<16);
}
}
else
{
char *mode;
int i;
int cKeySelect = 0;
U8 key;
U32 mpll_val, divn_upll=0;
DWORD dwStartTime, dwPrevTime, dwCurrTime;
DWORD dwBootDelay = 4; // seconds. N.B: change for retail device!
SYSTEMTIME st;
SYSTEMTIME defst = {2002, 1, 0, 1, 12, 0, 0, 0};
//USB init
//USB device detection controlUSB_REC
rGPHCON &= ~(3<<18);
rGPHCON |= (1<<18); // output
rGPHUP |= (1<<9); // pullup disable
rGPHDAT |= (1<<9); // output
rMISCCR=rMISCCR&~(1<<3); // USBD is selected instead of USBH1
rMISCCR=rMISCCR&~(1<<13); // USB port 1 is enabled.
//
// USBD should be initialized first of all.
//
isUsbdSetConfiguration=0;
#if 0
UsbdMain();
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();
UsbdMain();
#endif
Delay(0); //calibrate Delay()
pISR_SWI=(_ISR_STARTADDRESS+0xf0); //for pSOS
#if USBDMA
mode="DMA";
#else
mode="Int";
#endif
mpll_val = rMPLLCON;
Uart_Printf("DIVN_UPLL%x\n", divn_upll);
Uart_Printf("MPLLVal [M:%xh,P:%xh,S:%xh]\n", (mpll_val&(0xff<<12))>>12,(mpll_val&(0x3f<<4))>>4,(mpll_val&0x3));
Uart_Printf("CLKDIVN:%xh\n", rCLKDIVN);
Uart_Printf("\n\n");
Uart_Printf("+---------------------------------------------+\n");
Uart_Printf("| S3C2440A USB Downloader ver R0.05 2006 Oct |\n");
Uart_Printf("+---------------------------------------------+\n");
Uart_Printf("FCLK=%4.1fMHz,%s mode\n",FCLK/1000000.,mode);
Uart_Printf("USB: IN_ENDPOINT:1 OUT_ENDPOINT:3\n");
Uart_Printf("FORMAT: <ADDR(DATA):4>+<SIZE(n+10):4>+<DATA:n>+<CS:2>\n");
Uart_Printf("NOTE: 1. Press [ENTER] to Boot Wince form NandFlash or\n");
Uart_Printf(" Press [SPACE] to enter monitor.\n");
Uart_Printf(" 2. For additional menu, Press any key in %d seconds. ", (dwBootDelay--));
UGBoot_GetRealTime(&st);
if ((st.wYear < 2000) ||
(st.wMonth < 1) ||
(st.wMonth > 12) ||
(st.wDay < 1) ||
(st.wDay > 31) ||
(st.wHour > 23) ||
(st.wMinute > 59) ||
(st.wSecond > 59) ||
(st.wMilliseconds > 999))
{
UGBoot_SetRealTime(&defst);
}
else {
UGBoot_SetRealTime(&st);
}
dwStartTime = UGBoot_GetSecs();
dwPrevTime = dwStartTime;
dwCurrTime = dwStartTime;
while((dwCurrTime - dwStartTime) < dwBootDelay)
{
cKeySelect = UGBoot_ReadDebugByte();
if((cKeySelect == 0x20)||(cKeySelect == 0x0d))
break;
dwCurrTime = UGBoot_GetSecs();
if(dwCurrTime > dwPrevTime)
{
int i=0, j;
// 1 Second has elapsed - update the countdown timer.
dwPrevTime = dwCurrTime;
if (dwBootDelay < 9)
i = 11;
else if (dwBootDelay < 99)
i = 12;
else if (dwBootDelay < 999)
i = 13;
for(j = 0; j < i; j++)
Uart_SendByte((BYTE)0x08); // print back space
Uart_Printf ( "%d seconds. ", (dwBootDelay--));
}
}
download_run=1; //The default menu is the Download & Run mode.
download_update_wince= 0;
download_update_ugboot = 0;
switch(cKeySelect)
{
case 0x20:
while(1)
{
if(menuUsed == 1) Menu();
WaitDownload();
}
break;
case 0x0d:
Uart_Printf("Boot and Load WinCE...\r\n");
ClearMemory();
LoadWince();
break;
case 0x00:
default:
Uart_Printf("delay for long .\r\n");
rGPACON &= ~(0x1<<16);
rGPADAT &= ~(0x1<<16);
// should never came here.
break;
}
}
}
void Menu(void)
{
int i;
U8 key;
menuUsed=1;
while(1)
{
Uart_Printf("\n###### Select Menu ######\n");
Uart_Printf(" [0] Download & Run\n");
Uart_Printf(" [1] Download Only\n");
Uart_Printf(" [2] Test SDRAM \n");
Uart_Printf(" [3] Change The Console UART Ch.\n");
Uart_Printf(" [4] Clear unused area in SDRAM \n");
Uart_Printf(" [5] Download & update wince \n");
Uart_Printf(" [6] Download & update UGBoot \n");
Uart_Printf(" [7] Boot and load WinCE \n");
Uart_Printf(" [8] Reserv the UGBoot&Wince\n");
Uart_Printf(" [F] Format the Nandflash for fatfs\n");
key=Uart_Getch();
switch(key)
{
case '0':
Uart_Printf("\nDownload&Run is selected.\n\n");
download_run=1;
return;
case '1':
Uart_Printf("\nDownload Only is selected.\n");
Uart_Printf("Enter a new temporary download address(0x3...):");
tempDownloadAddress=Uart_GetIntNum();
download_run=0;
Uart_Printf("The temporary download address is 0x%x.\n\n",tempDownloadAddress);
return;
case '2':
Uart_Printf("\nMemory Test is selected.\n");
MemoryTest();
Menu();
return;
break;
case '3':
Uart_Printf("\nWhich UART channel do you want to use for the console?[0/1]\n");
if(Uart_Getch()!='1')
{
*pMagicNum=0x0;
Uart_Printf("UART ch.0 will be used for console at next boot.\n");
}
else
{
*pMagicNum=0x12345678;
Uart_Printf("UART ch.1 will be used for console at next boot.\n");
Uart_Printf("UART ch.0 will be used after long power-off.\n");
}
Uart_Printf("System is waiting for a reset. Please, Reboot!!!\n");
while(1);
break;
case '4':
Uart_Printf("\nMemory clear is selected.\n");
ClearMemory();
break;
case '5':
Uart_Printf("\n Download & Program is selected.\n");
download_update_wince= 1;
return;
case '6':
Uart_Printf("\n Download & update UGBoot is selected.\n");
download_update_ugboot = 1;
return;
case '7':
LoadWince();
Uart_Printf("\n Boot and load WinCE is selected.\n");
break;
case '8':
Uart_Printf("\n reserve the UGBoot & WinCE.\n");
if (!FMD_Init ())//lpActiveReg, pRegIn, pRegOut))
return;
ReserveBlock();
break;
case '9':
Test_Nand();
break;
case 'f':
case 'F':
Format_Nand();
break;
default:
break;
}
}
}
void WaitDownload(void)
{
U32 i;
U32 j;
U16 cs;
U32 temp;
U16 dnCS;
int first=1;
float time;
U8 tempMem[16];
U8 key;
checkSum=0;
downloadAddress=(U32)tempMem; //_RAM_STARTADDRESS;
downPt=(unsigned char *)downloadAddress;
//This address is used for receiving first 8 byte.
downloadFileSize=0;
#if 0
MMU_DisableICache();
//For multi-ICE.
//If ICache is not turned-off, debugging is started with ICache-on.
#endif
/*******************************/
/* Test program download */
/*******************************/
j=0;
if(isUsbdSetConfiguration==0)
{
Uart_Printf("USB host is not connected yet.\n");
}
while(downloadFileSize==0)
{
if(first==1 && isUsbdSetConfiguration!=0)
{
Uart_Printf("USB host is connected. Waiting a download.\n");
first=0;
}
// if(j%0x50000==0)Led_Display(0x6);
// if(j%0x50000==0x28000)Led_Display(0x9);
j++;
key=Uart_GetKey();
if(key!=0)
{
Menu();
first=1; //To display the message,"USB host ...."
}
}
Timer_InitEx();
Timer_StartEx();
#if USBDMA
rINTMSK&=~(BIT_DMA2);
ClearEp3OutPktReady();
// indicate the first packit is processed.
// has been delayed for DMA2 cofiguration.
if(downloadFileSize>EP3_PKT_SIZE)
{
if(downloadFileSize<=(0x80000))
{
ConfigEp3DmaMode(downloadAddress+EP3_PKT_SIZE-8,downloadFileSize-EP3_PKT_SIZE);
//will not be used.
/* rDIDST2=(downloadAddress+downloadFileSize-EP3_PKT_SIZE);
rDIDSTC2=(0<<1)|(0<<0);
rDCON2=rDCON2&~(0xfffff)|(0);
*/
}
else
{
ConfigEp3DmaMode(downloadAddress+EP3_PKT_SIZE-8,0x80000-EP3_PKT_SIZE);
if(downloadFileSize>(0x80000*2))//for 1st autoreload
{
rDIDST2=(downloadAddress+0x80000-8); //for 1st autoreload.
rDIDSTC2=(1<<2)|(0<<1)|(0<<0);
rDCON2=rDCON2&~(0xfffff)|(0x80000);
while(rEP3_DMA_TTC<0xfffff)
{
rEP3_DMA_TTC_L=0xff;
rEP3_DMA_TTC_M=0xff;
rEP3_DMA_TTC_H=0xf;
}
}
else
{
rDIDST2=(downloadAddress+0x80000-8); //for 1st autoreload.
rDIDSTC2=(1<<2)|(0<<1)|(0<<0);
rDCON2=rDCON2&~(0xfffff)|(downloadFileSize-0x80000);
while(rEP3_DMA_TTC<0xfffff)
{
rEP3_DMA_TTC_L=0xff;
rEP3_DMA_TTC_M=0xff;
rEP3_DMA_TTC_H=0xf;
}
}
}
totalDmaCount=0;
}
else
{
totalDmaCount=downloadFileSize;
}
#endif
Uart_Printf("\nNow, Downloading [ADDRESS:%xh,TOTAL:%d]\n",
downloadAddress,downloadFileSize);
Uart_Printf("RECEIVED FILE SIZE:%8d",0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -