📄 2460mon.nor.cpp
字号:
{
printf("USB host is not connected yet.\n");
}
while(downloadFileSize==0)
{
if(first==1 && isUsbdSetConfiguration!=0)
{
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_DMA_SBUS);
rINTSUBMSK&=~(BIT_SUB_DMA2);
ClearEp3OutPktReady();
// indicate the first packit is processed.
// has been delayed for DMA2 cofiguration.
if(downloadFileSize>EP3_PKT_SIZE)
{
if(downloadFileSize<=(0x80000))
{
// *.bin format : [0:3]=downloadAddress, [4:7]=download file size , [....]=data, [..:..]=checksum
// downloadaddres+EP3_PKT_SIZE-8 means that next 64FIFO pointed the DMA dst addr( -8 add downloadAddress & filesize)
//. after first 64 OUT_FIFO read(EP3_PKT_SIZE)
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);
#if USBDMA_BURST
rDCON2=rDCON2&~(0xfffff)|(0x20000);
#else
rDCON2=rDCON2&~(0xfffff)|(0x80000);
#endif
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. initial dst address
rDIDSTC2=(0<<1)|(0<<0); // write AHB, increment addr.
#if USBDMA_BURST
rDCON2=rDCON2&~(0xfffff)|((downloadFileSize-0x80000)/4+1);
#else
rDCON2=rDCON2&~(0xfffff)|(downloadFileSize-0x80000);
#endif
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
printf("\nNow, Downloading [ADDRESS:%xh,TOTAL:%d]\n",
downloadAddress,downloadFileSize);
printf("RECEIVED FILE SIZE:%8d",0);
#if USBDMA
j=0x10000;
while(1)
{
if( (rDCDST2-(unsigned int)downloadAddress+8)>=j)
{
printf("\b\b\b\b\b\b\b\b%8d",j);
j+=0x10000;
}
if(totalDmaCount>=downloadFileSize)break;
}
#else
j=0x10000;
while(((unsigned int)downPt-downloadAddress)<(downloadFileSize-8))
{
if( ((unsigned int)downPt-downloadAddress)>=j)
{
printf("\b\b\b\b\b\b\b\b%8d",j);
j+=0x10000;
}
}
#endif
time=Timer_StopEx();
printf("\b\b\b\b\b\b\b\b%8d",downloadFileSize);
printf("(%5.1fKB/S,%3.1fS)\n",(float)(downloadFileSize/time/1000.),time);
#if USBDMA
/*******************************/
/* Verify check sum */
/*******************************/
printf("Now, Checksum calculation\n");
cs=0;
i=(downloadAddress);
j=(downloadAddress+downloadFileSize-10)&0xfffffffc;
while(i<j)
{
temp=*((unsigned int *)i);
i+=4;
cs+=(unsigned short)(temp&0xff);
cs+=(unsigned short)((temp&0xff00)>>8);
cs+=(unsigned short)((temp&0xff0000)>>16);
cs+=(unsigned short)((temp&0xff000000)>>24);
}
i=(downloadAddress+downloadFileSize-10)&0xfffffffc;
j=(downloadAddress+downloadFileSize-10);
while(i<j)
{
cs+=*((unsigned char *)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);
printf("\nChecksum Value => MEM:%x DN:%x\n\n",checkSum,dnCS);
if(checkSum!=dnCS)
{
printf("Checksum Error!!!");
//return;
}
else
{
printf("Download O.K.\n\n");
}
// Uart_TxEmpty(consoleNum);
if(download_run==1)
{
rINTMSK=BIT_ALLMSK;
run=(void (*)(void))downloadAddress;
MMU_DisableICache();
Delay(0);
run();
}
}
/*
void Check_SleepKey(void)
{
//printf("Check SRAM Keys\n");
if( rALIVECON & ~0x7 )
{
//printf("rALIVECON=0x%x\n", rALIVECON);
if( rALIVECON & 1<<3 )//Sleep mode wake-up
{
if(!(SRAMKey_OnTest==0xaaaa5555))
rALIVECON &= ~(1<<3);
printf("\nSLEEP mode Wake-up\n\n");
run=(void (*)(void))SRAMKey_Run;
MMU_DisableICache();
Delay(0);
run();
}
else if( rALIVECON & 1<<4 )
{
if(!(SRAMKey_OnTest==0xaaaa5555))
rALIVECON &= ~(1<<4);
printf("\nWarm Reset\n\n");
run=(void (*)(void))SRAMKey_Run;
MMU_DisableICache();
Delay(0);
run();
}
else if( rALIVECON & 1<<5 )
{
if(!(SRAMKey_OnTest==0xaaaa5555))
rALIVECON &= ~(1<<5);
printf("\nWatch-dog Reset\n\n");
run=(void (*)(void))SRAMKey_Run;
MMU_DisableICache();
Delay(0);
run();
}
else if( rALIVECON & 1<<6 )
{
if(!(SRAMKey_OnTest==0xaaaa5555))
rALIVECON &= ~(1<<6);
printf("\nSoft Reset\n\n");
run=(void (*)(void))SRAMKey_Run;
MMU_DisableICache();
Delay(0);
run();
}
else if( rALIVECON & 1<<7 )
{
if(!(SRAMKey_OnTest==0xaaaa5555))
rALIVECON &= ~(1<<7);
printf("\nBattery Fault\n\n");
run=(void (*)(void))SRAMKey_Run;
MMU_DisableICache();
Delay(0);
run();
}
}
else
{
printf("Power-on Reset\n");
Clear_SleepKey();
}
}
void Clear_SleepKey(void)
{
int i;
int error=0;
//SRAMKey_Sleep0 = 0;
//SRAMKey_Sleep1 = 0;
SRAMKey_Count = 0;
SRAMKey_Run = 0;
SRAMKey_OnTest = 0;
}
*/
void Isr_Init(void)
{
pISR_UNDEF=(unsigned)HaltUndef;
pISR_SWI =(unsigned)HaltSwi;
pISR_PABORT=(unsigned)HaltPabort;
pISR_DABORT=(unsigned)HaltDabort;
pISR_IRQ = (unsigned)IsrIRQ;
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_USB =(unsigned)IsrUsbd;
pISR_DMA_SBUS =(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_DMA_SBUS);
ClearPending(BIT_USB);
rSUBSRCPND=BIT_SUB_USBD;
rSUBSRCPND=BIT_SUB_DMA2;
//External interrupt will be falling edge triggered.
rEINTCON0 = 0x22222222; //EINT2~0
rEINTCON1 = 0x22222222; //EINT10~3
CLR_IF();
//pISR_FIQ,pISR_IRQ must be initialized
}
void Usb_On(void)
{
rGPJDAT|=(1<<2);
rGPJCON=rGPJCON&~(3<<4)|(1<<4);
}
void Usb_Off(void)
{
rGPJDAT&=~(1<<2);
rGPJCON=rGPJCON&~(3<<4)|(1<<4);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -