📄 u241mon.c
字号:
/****************************************************************
NAME: u241mon.c
DESC: u241mon 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 "2410addr.h"
#include "2410lib.h"
#include "2410slib.h"
#include "mmu.h"
#include "profile.h"
#include "memtest.h"
#include "usbmain.h"
#include "usbout.h"
#include "usblib.h"
#include "2410usb.h"
#include "yaffsfs.h"
#include "usb_implement.h"
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
void Lcd_Off(void);
void WaitDownload(void);
void Menu(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 rx_index=0;
int download_run=0;
U32 tempDownloadAddress;
int menuUsed=0;
extern char Image$$RW$$Limit[];
U32 *pMagicNum=(U32 *)Image$$RW$$Limit;
int consoleNum;
extern int file_info_len;
extern char usb_rdfile_buf[];
extern char usb_rdfile_path[];
extern char dump_dir_path[];
extern int usb_rdfile_length;
extern unsigned int cmd_ext;
extern int usb_wd_flag;
extern char usb_dlfile_path[];
int dumpDir(const char * path);
int crtFile(const char * path,int s);
void Main(void)
{
int i;
char str[64];
char *mode;
U8 key;
//init the CPU
// MMU_Init();
// ChangeClockDivider(1,1); // 1:2:4
// ChangeMPllValue(0xa1,0x3,0x1); // FCLK=202.8MHz
//Port_Init();
// Uart_Select(0);
// Uart_Init(0,115200);
// Uart_Select(0);
// #if ADS10
//__rt_lib_init(); //for ADS 1.0
// #endif
ChangeClockDivider(1,1); // 1:2:4
//ChangeMPllValue(82,2,1); //FCLK=135.0Mhz
ChangeMPllValue(82,1,1); //FCLK=180.0Mhz
//ChangeMPllValue(161,3,1); //FCLK=202.8Mhz
Port_Init();
rGPHCON = rGPHCON&~(0xf<<18)|(0x5<<18);
//To enhance the USB signal quality.
//CLKOUT 0,1=OUTPUT to reduce the power consumption.
Isr_Init();
if(*pMagicNum!=0x12345678)
consoleNum=0;
else
consoleNum=1;
Uart_Init(0,115200);
Uart_Select(consoleNum);
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();
MMU_Init(); //MMU should be reconfigured or turned off for the debugger,
UsbdMain();
#endif
Delay(0); //calibrate Delay()
#if 1
#if 1
Uart_Printf("Enter the main Routine\n");
k9_test();
Uart_Printf("Exit the main Routine\n");
//return 0;
#endif
yaffs_StartUp();
yaffs_mount("/boot");
//yaffs_format("/boot");
dumpDir("/boot");
crtFile("/boot/test_file_a",5);
crtFile("/boot/test_file_b",5);
#if 0
usb_rdfile("/boot/test_file_b");
while(usb_rdfile_length !=0)
{
usb_rdfile("/boot/test_file_b");
}
#endif
//rdfile("/boot/test_file_b");
yaffs_mkdir("/boot/test_dir",0);
crtFile("/boot/test_dir/test_file_c",44);
yaffs_symlink("/boot/test_file_a","/boot/test_dir/test_symlink_a");
dumpDir("/boot");
Uart_Printf("\n");
#if 0
usb_dump_dir("/boot");
while(file_info_len !=0)
usb_dump_dir("/boot");
#endif
dumpDir("/boot/test_dir");
yaffs_readlink("/boot/test_dir/test_symlink_a",str,64);
Uart_Printf("the real file of test_symlink_a is %s\n",str);
Uart_Printf("free spaces %d left in /boot\n",yaffs_freespace("/boot"));
yaffs_unlink("/boot/test_file_a");
//yaffs_unlink("/boot/test_dir/test_symlink_a");
Uart_Printf("\n");
dumpDir("/boot");
Uart_Printf("\n");
dumpDir("/boot/test_dir");
yaffs_readlink("/boot/test_dir/test_symlink_a",str,64);
Uart_Printf("the real file of test_symlink_a is %s\n",str);
Uart_Printf("free spaces %d left in /boot\n",yaffs_freespace("/boot"));
#endif
#if 1
pISR_SWI=(_ISR_STARTADDRESS+0xf0); //for pSOS
Led_Display(0x6);
#if USBDMA
mode="DMA";
#else
mode="Int";
#endif
Uart_Printf("\n\n");
Uart_Printf("+---------------------------------------------+\n");
Uart_Printf("| S3C2410X USB Downloader ver R1.11 SEP/03/02 |\n");
Uart_Printf("+---------------------------------------------+\n");
Uart_Printf("FCLK=%dMHz,%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. Power off/on or press the reset button for 1 sec\n");
Uart_Printf(" in order to get a valid USB device address.\n");
Uart_Printf(" 2. For additional menu, Press any key. \n");
Uart_Printf("\n");
download_run=1; //The default menu is the Download & Run mode.
Uart_Init(0,115200);
Uart_Select(consoleNum);
while(1)
{
if(menuUsed==1)Menu();
WaitDownload();
}
#endif
}
void Menu(void)
{
int i;
U8 key=0;
//char str[64];
//init the CPU
// MMU_Init();
// ChangeClockDivider(1,1); // 1:2:4
// ChangeMPllValue(0xa1,0x3,0x1); // FCLK=202.8MHz
// Port_Init();
#if 1
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");
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 data.\n");
}
else
{
*pMagicNum=0x12345678;
Uart_Printf("UART ch.1 will be used for console at next data.\n");
Uart_Printf("UART ch.0 will be used after long power-off.\n");
}
Uart_Printf("System is waiting for a reset. Please, Redata!!!\n");
while(1);
break;
default:
break;
}
}
#endif
}
void Cmd_Receive(unsigned char * Cmd_Buf,unsigned int Cmd_Len)
{
int i;
rx_index++;
Uart_Init(0,115200);
Uart_Select(0);
Uart_Printf("received %d times %d bytes data is:\n",rx_index,Cmd_Len);
#if 0
for(i=0; i<Cmd_Len; i++)
{
Uart_Printf("%c",Cmd_Buf[i]);
}
#endif
Uart_Printf("1Cmd_Receive\n");
switch(cmd_ext)
{
case USB_DUMP_DIR:
sprintf((char*)dump_dir_path,"%s",(char*)Cmd_Buf);
Uart_Printf("%s\n",dump_dir_path);
break;
case USB_READ_FILE:
sprintf((char*)usb_rdfile_path,"%s",(char*)Cmd_Buf);
Uart_Printf("%s\n",usb_rdfile_path);
break;
case USB_DELETE_FILE:
#if 1
Uart_Printf("in the USB_DELETE_FILE Cmd_Receive \r\n");
sprintf((char*)usb_dlfile_path,"%s",(char*)Cmd_Buf);
Uart_Printf("%s\n",usb_dlfile_path);
#endif
break;
default:
break;
}
Uart_Printf("%s\n",Cmd_Buf);
#if 0
usb_rdfile(usb_rdfile_path);
while(usb_rdfile_length !=0)
{
usb_rdfile(usb_rdfile_path);
}
#endif
Uart_Printf("2Cmd_Receive\n");
}
void WaitDownload(void)
{
U32 i;
U32 j;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -