📄 main.c
字号:
#endif
// Delay(0); //calibrate Delay()
//find_camera(); //hzh
rGPGCON &= ~(3<<24);
rGPGCON |= (1<<24); // output
rGPGUP |= (1<<12); // pullup disable
rGPGDAT |= (1<<12); // output
pISR_SWI=(_ISR_STARTADDRESS+0xf0); //for pSOS
Led_Display(0x6);
//#if USBDMA
//mode="DMA";
//#else
//mode="Int";
//#endif
// CLKOUT0/1 select.
//Uart_Printf("CLKOUT0:MPLL in, CLKOUT1:RTC clock.\n");
//Clk0_Enable(0); // 0:MPLLin, 1:UPLL, 2:FCLK, 3:HCLK, 4:PCLK, 5:DCLK0
//Clk1_Enable(2); // 0:MPLLout, 1:UPLL, 2:RTC, 3:HCLK, 4:PCLK, 5:DCLK1
Clk0_Disable();
Clk1_Disable();
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.03 2004 Jan |\n");
Uart_Printf("+---------------------------------------------+\n");
Uart_Printf("FCLK=%4.1fMHz\n",FCLK/1000000);
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.
while(1)
{
if(menuUsed==1)Menu();
WaitDownload();
}
}
void Temp_function() { Uart_Printf("\nPlease input 1-11 to select test!!!\n"); }
void Exit() {;}
struct {
void (*fun)(void);
char *tip;
}CmdTip[] = {
{ Temp_function, "Please input 1-11 to select test" } ,
{ BUZZER_PWM_Test, "Test PWM" } ,
{ RTC_Display, "RTC time display" } ,
{ Test_Adc, "Test ADC" } ,
{ KeyScan_Test, "Test interrupt and key scan" } ,
{ Test_Touchpanel, "Test Touchpanel" } ,
{ Lcd_Tft_NEC35_Test, "Test 3.5 NEC LCD" } ,
{ Test_Lcd_TFT_640_480, "Test LCD TFT 640x480" } ,
{ Test_Iic, "Test IIC EEPROM" } ,
{ PlayMusicTest, "UDA1341 play music" } ,
{ RecordTest, "UDA1341 record voice" } ,
{ Test_SDI, "Test SD Card" } ,
{ Exit, "EXIT"}
};
void TestBoard(void)
{
U8 i;
U8 idx;
while(1)
{
Uart_Printf("\nPlease select function : \n");
for(i=0; i<=12; i++)
Uart_Printf("%d : %s\n", i, CmdTip[i].tip);
idx = Uart_GetIntNum_GJ() ;
if(idx<12)
{
(*CmdTip[idx].fun)();
Delay(20);
Uart_Init( 0,115200 );
}
if (idx == 12)
{
break;
}
}
}
void Menu(void)
{
int Ret;
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] Download From UART\n");
Uart_Printf(" [3] Write File to SST39VF160\n");
Uart_Printf(" [4] Write File to NAND Flash\n");
Uart_Printf(" [5] Boot OS\n");
Uart_Printf(" [6] Erase NAND Flash Partition\n");
Uart_Printf(" [7] Config parameters\n");
Uart_Printf(" [8] Relocate NK.bin\n");
Uart_Printf(" [9] Run Eboot\n");
Uart_Printf(" [A] Start module Test");
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=0x32001000;//Uart_GetIntNum();
download_run=0;
Uart_Printf("The temporary download address is 0x%x.\n\n",tempDownloadAddress);
return;
case '2':
comdownload();
break;
case '3':
//if(downloadFileSize)
// SectorProg(0, (U16 *)downloadAddress, downloadFileSize);
break;
case '4':
if(downloadFileSize)
Ret = NandWrite();
break;
case '5':
NandLoadRun();
break;
case '6':
NandErase();
break;
case '7':
set_params();
break;
case '8':
//case 'A':
{
U32 launch;
if(!RelocateNKBIN(downloadAddress, (U32 *)&downloadAddress, (U32 *)&downloadFileSize, &launch)) {
boot_params.run_addr.val = launch;
boot_params.initrd_addr.val = downloadAddress;
boot_params.initrd_len.val = downloadFileSize;
save_params(); //save initrd_len.val
}
}
break;
case '9':
LoadRunEboot();
break;
case 'A':
TestBoard();
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(autorun_trig)
NandLoadRun(); //run it in svc mode
if(key!=0)
{
autorun_ds = 1;
//printf("disable autorun\n");
Menu();
first=1; //To display the message,"USB host ...."
//在串口下载返回后downloadFileSize不为0,因此不能再执行USB下载! hzh
}
}
autorun_ds = 1;
//printf("disable autorun\n");
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);
//2440比2410的DIDSTCx寄存器多了中断产生条件的控制位,USB的DMA传输为字节计数
//防止高频开cache运行时下载大于0x80000字节文件时IsrDma2出错!!! hzh
//while((rDSTAT2&0xfffff)==(0x80000-EP3_PKT_SIZE));
while(!(rDSTAT2&(1<<20))); //防止DMA传输尚未开始就写入下一次重装值!!! hzh
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);
#if USBDMA
j=0x10000;
while(1)
{
if( (rDCDST2-(U32)downloadAddress+8)>=j)
{
Uart_Printf("\b\b\b\b\b\b\b\b%8d",j);
j+=0x10000;
}
if(totalDmaCount>=downloadFileSize)break;
}
#else
j=0x10000;
while(((U32)downPt-downloadAddress)<(downloadFileSize-8))
{
if( ((U32)downPt-downloadAddress)>=j)
{
Uart_Printf("\b\b\b\b\b\b\b\b%8d",j);
j+=0x10000;
}
}
#endif
time=Timer_StopEx();
Uart_Printf("\b\b\b\b\b\b\b\b%8d",downloadFileSize);
Uart_Printf("\n(%5.1fKB/S,%3.1fS)\n",(float)(downloadFileSize/time/1000.),time);
#if USBDMA
/*******************************/
/* Verify check sum */
/*******************************/
Uart_Printf("Now, Checksum calculation\n");
cs=0;
i=(downloadAddress);
j=(downloadAddress+downloadFileSize-10)&0xfffffffc;
while(i<j)
{
temp=*((U32 *)i);
i+=4;
cs+=(U16)(temp&0xff);
cs+=(U16)((temp&0xff00)>>8);
cs+=(U16)((temp&0xff0000)>>16);
cs+=(U16)((temp&0xff000000)>>24);
}
i=(downloadAddress+downloadFileSize-10)&0xfffffffc;
j=(downloadAddress+downloadFileSize-10);
while(i<j)
{
cs+=*((U8 *)i++);
}
checkSum=cs;
#else
//checkSum was calculated including dnCS. So, dnCS should be subtracted.
checkSum=checkSum - *((unsigned char *)(downloadAddress+downloadFileSize-8-2))
- *( (unsigned char *)(downloadAddress+downloadFileSize-8-1) );
#endif
dnCS=*((unsigned char *)(downloadAddress+downloadFileSize-8-2))+
(*( (unsigned char *)(downloadAddress+downloadFileSize-8-1) )<<8);
if(checkSum!=dnCS)
{
Uart_Printf("Checksum Error!!! MEM:%x DN:%x\n",checkSum,dnCS);
return;
}
Uart_Printf("Download O.K.\n\n");
Uart_TxEmpty(consoleNum);
if(download_run==1)
{
register void(*run)(void); //hzh,使用寄存器变量以防止禁止DCACHE后数据不一致!!!
rINTMSK=BIT_ALLMSK;
run=(void (*)(void))downloadAddress; //使用DCACHE且RW区也在CACHE区间downloadAddress会在cache中
{ //hzh
MMU_DisableDCache(); //download program must be in
MMU_DisableICache(); //non-cache area
MMU_InvalidateDCache(); //使所有DCACHE失效,本程序的MMU_Init中将会刷新DCACHE到存储器,
//为使应用此MMU_Init方式的程序能被正确运行必须先使DCACHE失效!!!
MMU_DisableMMU();
//call_linux(0, 193, downloadAddress); //或不用上面3个函数而直接使用call_linux
}
run();
}
}
void Isr_Init(void)
{
pISR_UNDEF=(unsigned)HaltUndef;
pISR_SWI =(unsigned)HaltSwi;
pISR_PABORT=(unsigned)HaltPabort;
pISR_DABORT=(unsigned)HaltDabort;
rINTMOD=0x0; // All=IRQ mode
rINTMSK=BIT_ALLMSK; // All interrupt is masked.
//pISR_URXD0=(unsigned)Uart0_RxInt;
//rINTMSK=~(BIT_URXD0); //enable UART0 RX Default value=0xffffffff
#if 1
pISR_USBD =(unsigned)IsrUsbd;
pISR_DMA2 =(unsigned)IsrDma2;
#else
pISR_IRQ =(unsigned)IsrUsbd;
//Why doesn't it receive the big file if use this. (???)
//It always stops when 327680 bytes are received.
#endif
ClearPending(BIT_DMA2);
ClearPending(BIT_USBD);
//rINTMSK&=~(BIT_USBD);
//pISR_FIQ,pISR_IRQ must be initialized
}
void HaltUndef(void)
{
Uart_Printf("Undefined instruction exception!!!\n");
while(1);
}
void HaltSwi(void)
{
Uart_Printf("SWI exception!!!\n");
while(1);
}
void HaltPabort(void)
{
Uart_Printf("Pabort exception!!!\n");
while(1);
}
void HaltDabort(void)
{
Uart_Printf("Dabort exception!!!\n");
while(1);
}
void ClearMemory(void)
{
int i;
U32 data;
int memError=0;
U32 *pt;
//
// memory clear
//
Uart_Printf("Clear Memory (%xh-%xh):WR",_RAM_STARTADDRESS,HEAPEND);
pt=(U32 *)_RAM_STARTADDRESS;
while((U32)pt < HEAPEND)
{
*pt=(U32)0x0;
pt++;
}
if(memError==0)Uart_Printf("\b\bO.K.\n");
}
void Clk0_Enable(int clock_sel)
{ // 0:MPLLin, 1:UPLL, 2:FCLK, 3:HCLK, 4:PCLK, 5:DCLK0
rMISCCR = rMISCCR&~(7<<4) | (clock_sel<<4);
rGPHCON = rGPHCON&~(3<<18) | (2<<18);
}
void Clk1_Enable(int clock_sel)
{ // 0:MPLLout, 1:UPLL, 2:RTC, 3:HCLK, 4:PCLK, 5:DCLK1
rMISCCR = rMISCCR&~(7<<8) | (clock_sel<<8);
rGPHCON = rGPHCON&~(3<<20) | (2<<20);
}
void Clk0_Disable(void)
{
rGPHCON = rGPHCON&~(3<<18); // GPH9 Input
}
void Clk1_Disable(void)
{
rGPHCON = rGPHCON&~(3<<20); // GPH10 Inpu
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -