在flash程序中,有这样的一段语句: int DownloadData(void) { int i; U16 checkSum=0,dnCS; U32 fileSize=10; U8 *downPt;
downPt=(U8 *)downloadAddress; Uart_Printf("downloadAddress=%x\n",downloadAddress);
Uart_Printf("Download the plain binary file(.BHC) to be written\n"); Uart_Printf(".BHC file format: <n+6>(4)+(n)+CS(2)\n"); Uart_Printf("To transmit .BHC file : wkocm2 xxx.BHC /1 /g /d:1\n"); Uart_Printf("Or, to transmit .BIN file: wkocm2 xxx.BIN /1 /d:1\n"); Uart_Printf("Download methods: COM:8Bit,NP,1STOP\n"); Uart_Printf("\nSTATUS:"); rINTMSK=~BIT_GLOBAL; RdURXH0(); //To remove overrun error state.
i=0; while(i<fileSize) { while(!(rUTRSTAT0&0x1)); *(downPt+i)=RdURXH0(); if(i==3) { fileSize=*((U8 *)(downloadAddress+0))+ (*((U8 *)(downloadAddress+1))<<8)+ (*((U8 *)(downloadAddress+2))<<16)+ (*((U8 *)(downloadAddress+3))<<24); } if((i%1000)==0) WrUTXH0('#'); i++; }
downloadProgramSize=fileSize-6;
for(i=4;i<(fileSize-2);i++) { checkSum+=*((U8 *)(i+downloadAddress)); }
dnCS=*((U8 *)(downloadAddress+fileSize-2))+ (*( (U8 *)(downloadAddress+fileSize-1) )<<8);
if(checkSum!=dnCS) { Uart_Printf("Checksum Error!!! MEM:%x DN:%x\n",checkSum,dnCS); return 0; }
Uart_Printf("\nDownload O.K.\n"); return 1; } 这个是把串口数据传到内存中的一短代码,对吧? 可是里面的这个语句确定了文件大小: fileSize=*((U8 *)(downloadAddress+0))+ (*((U8 *)(downloadAddress+1))<<8)+ (*((U8 *)(downloadAddress+2))<<16)+ (*((U8 *)(downloadAddress+3))<<24); 也就是说BIN文件的前四位包含了文件的大小信息?请高手回答对不对! 而语句: dnCS=*((U8 *)(downloadAddress+fileSize-2))+ (*( (U8 *)(downloadAddress+fileSize-1) )<<8); 说明了BIN文件的后两位包含了文件的相加和信息,对不对,请指教!!!
|