#include "iap.h" #include "CommandsDefine.h" #include "ProjectConfig.h" #include "usart.h" #include "string.h" #include "Helper.h" /* 进行更新,传送更新代码 正确的响应:烧写传过来的代码 发送格式: 包起始标识 +CMD0x06_Request_UpdateSend +[2字节的数据长度,=200或最后一帧的数据个数] +200字节的程序代码 +包尾标识 返回:握手包。 包起始标识 +CMD0xC0_Readback_CMDOK +[2字节的数据长度,=1] +CMD0x06_Request_UpdateSend +包尾标识 异常:如果程序在APP中,可能返回错误 Error0x01_CannotRunAtApp */ void CMD0x08_Request_UpdateSend_process(u8 *pData,u16 dataLen,u8 bIsContentBitInverted_Recv,u8 bIsContentBitInverted_SendBack) { #ifdef RUNNING_WHERE_AT_BOOT if(Updating==0) { Command_SendbackErrorMessage(Error0x06_CMD_UpdateNotStart,1); return ; } u8 responseResult=0; //write at u32 flashContentBytes=dataLen - sizeof(u32)-sizeof(u32);//format data...+offsetBytes[4bytes]+crcCode[4bytes] u32 offsetStartIndex=flashContentBytes; u32 offsetBytes=pData[offsetStartIndex] + (pData[offsetStartIndex+1]<<8) + (pData[offsetStartIndex+2]<<16)+ (pData[offsetStartIndex+3]<<24);; //Crc u32 CRCStartIndex = flashContentBytes + sizeof(u32); u32 getCRC32 = pData[CRCStartIndex] + (pData[CRCStartIndex+1]<<8) + (pData[CRCStartIndex+2]<<16)+ (pData[CRCStartIndex+3]<<24); u32 calcCRC32 = Helper_CRC_CalcBlockCRC8(pData,CRCStartIndex); if(getCRC32!=calcCRC32) { responseResult=0xff; } else { if (UpdateWhat==RUNNING_AT_APP) iap_write_appbin_at_tempArea(offsetBytes,pData,flashContentBytes); else iap_write_bootbin(offsetBytes,pData,flashContentBytes); UpdateRecvedContentBytes+=flashContentBytes; responseResult=0x00; } //response!!! u8 dataBytes=1; USART_WR_BUF[0]=responseResult; USART6_Send(CMD0x08_Request_UpdateSend,dataBytes,bIsContentBitInverted_SendBack); #else Command_SendbackErrorMessage(Error0x01_CannotRunAtApp,1); #endif }