📄 u241mon.c
字号:
//====================================================================
// File Name : MAIN.c
// Function : M-3004 Function Module Test Program
//
// Program : 辫剧宽
// Date :
// Version : 0.1
// History
// 距埃 颊阑 措芭唱 何盒利栏肺 扁粮 内靛甫 惑炔俊 嘎霸 函版矫难 柳青
// 乐促. 吝侩茄巴篮 NAND FLASH何泼捞促绰巴捞促. 盔贰家胶绰 OS阑
// SDRAM俊 肺歹窍绰巴烙.
//====================================================================
//葛电窃荐甫 捞镑俊 沥狼秦 初疽澜.
#include "..\inc\main.h"
volatile U32 downloadAddress = 0;
volatile unsigned char *downPt;
volatile U32 downloadFileSize = 0;
volatile U32 totalDmaCount;
volatile U16 checkSum;
volatile int isUsbdSetConfiguration;
volatile unsigned int err=0;
int download_run=0;
U32 tempDownloadAddress;
void Temp_function() { Uart_Printf("\nPlease input 1-16 to select test!!!\n"); }
struct {
void (*fun)(void);
char *tip;
}CmdTip[] = {
{ Temp_function, "Please input 1-16 to select test" } ,
{ BUZZER_PWM_Test, "Buzzer & Timer PWM" } ,
{ MemoryTest, "Memory Test" } ,
{ RTC_Display, "RTC time display" } ,
//{ Test_Adc, "Test ADC" } ,
{ KeyScan_Test, "Test External Interrupt and key scan" } ,
{ Fnd_Init, "FND Display" } ,
{ Test_Touchpanel, "Test Touch panel" } ,
{ Lcddemo, "Test LCD OGM-CM5702T-NF010" } ,
//{ nf_checkId, "Test nand flash" } ,
{ Down_run, "BIOS or Application Download and run " } ,
{ 0, 0}
};
void Main(void)
{
char *mode;
int i;
ChangeClockDivider(1,1); // 1:2:4
ChangeMPllValue(0x5c,4,0); //FCLK=200.0Mhz
//ChangeMPllValue(82,2,1); //FCLK=135.0Mhz
rGPHCON = rGPHCON&~(0xf<<18)|(0x5<<18);
//To enhance the USB signal quality.
//CLKOUT 0,1=OUTPUT to reduce the power consumption.
rGPGCON &=0xfff3ffff;//GPG9 input
Port_Init();
Isr_Init();
Uart_Init(0,115200);
Uart_Select(0);
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;
//UsbdMain();
//MMU_Init(); //MMU should be reconfigured or turned off for the debugger,
MMU_EnableICache();
UsbdMain();
pISR_SWI=(_ISR_STARTADDRESS+0xf0); //for pSOS
Led_Display(0x6);
//Timer0_Init();
//Beep(2000, 100);
Delay(0); //calibrate Delay()
#if USBDMA
mode="DMA";
#else
mode="Int";
#endif
Uart_Printf("\n\n");
Uart_Printf("\n******************************************************");
Uart_Printf("\n # ######### ### ###");
Uart_Printf("\n ### ## ## #### ####");
Uart_Printf("\n ## ## ## ### ## ## ## ##");
Uart_Printf("\n ## ## ## ## ## ## ## ##");
Uart_Printf("\n ######### ######### ## ### ##");
Uart_Printf("\n ## ## ## ## ## # ##");
Uart_Printf("\n ## ## ## ## ## ##");
Uart_Printf("\n #### #### #### #### #### ####");
Uart_Printf("\n******************************************************\n\n");
Uart_Printf("+---------------------------------------------+\n");
Uart_Printf("| M-3004 LCD Display Kernel ver R1.12 |\n");
Uart_Printf("| Programmed by KimYangWook RFMedical co. ltd |\n");
Uart_Printf("+---------------------------------------------+\n");
Uart_Printf("FCLK=%dMHz,%s mode\n",FCLK/1000000,mode);
Uart_Printf("System Com Configuratuon : 115.2kbps,8Bit,NP,UART0\n");
//if(GetByte1() == '\r') { Down_run(); }
download_run=1; //The default menu is the Download & Run mode.
while(1)
{
U8 idx;
Uart_Printf("\nPlease select function : \n");
for(i=0; CmdTip[i].fun!=0; i++)
Uart_Printf("[%d] : %s\n", i, CmdTip[i].tip);
idx = Uart_GetIntNum_GJ() ;
if(idx<i)
{
(*CmdTip[idx].fun)();
Delay(20);
Uart_Init( 0,115200 );
}
}
}
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.
rINTSUBMSK = BIT_SUB_ALLMSK; //眠啊
#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);
}
void Down_run(void)
{
U8 key;
Uart_Printf("\n###### Select Operation Mode ######\n");
Uart_Printf(" [0] Download & Run\n");
Uart_Printf(" [1] Download Only\n");
while(1)
{
key=Uart_Getch();
if(key == '\r' || !key ){ continue; }
else{break;}
}
switch(key)
{
case '0':
Uart_Printf("\nDownload&Run is selected.\n\n");
download_run=1;
break;
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);
break;
default:
break;
}
WaitDownload();
}
void WaitDownload(void)
{
U32 i,j;
U16 cs,dnCS;
U32 temp;
int first=1;
float time;
U8 key,tempMem[16];
checkSum=0;
downloadAddress=(U32)tempMem; //_RAM_STARTADDRESS;
downPt=(unsigned char *)downloadAddress;
//This address is used for receiving first 8 byte.
downloadFileSize=0;
/*******************************/
/* 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)
{
// Down_run();
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);
//wait until DMA reload occurs.
while((rDSTAT2&0xfffff)==0);
//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);
//wait until DMA reload occurs.
while((rDSTAT2&0xfffff)==0);
if(downloadFileSize>(0x80000*2))//for 1st autoreload
{
rDIDST2=(downloadAddress+0x80000-8); //for 1st autoreload.
rDIDSTC2=(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=(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("(%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(0);
if(download_run==1)
{
rINTMSK=BIT_ALLMSK;
run=(void (*)(void))downloadAddress;
run();
}
}
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 Timer0_Isr(void)
{
rSRCPND=BIT_TIMER0; // Clear pending bits
rINTPND=BIT_TIMER0;
} // end of __irq Timer0_Isr(...)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -