#include "iap.h"
#include "CommandsDefine.h"
#include "ProjectConfig.h"
#include "usart.h"
#include "string.h"
#include "iap.h"
#include "Helper.h"
/* 
   检查从FLASH_ADDR_UPDATE_TEMP 开始的值写入到FLASH_ADDR_APP 的内容是否相等
*/
void CMD0x0D_Request_UpdateVerifyStage2_process(u8 *pData,u16 dataLen,u8 bIsContentBitInverted_Recv,u8 bIsContentBitInverted_SendBack)
{
#ifdef RUNNING_WHERE_AT_BOOT
		u32Byte4 dwordDest,dwordSrc;
		u32 u32Count=(UpdateRecvedContentBytes+sizeof(u32)-1)/sizeof(u32);
		u8 errorExists=0;
		for(int i=0;i<u32Count;i++)
		{
			dwordDest.u32_Data=(*(vu32*)(FLASH_ADDR_APP+i*sizeof(u32)));
			dwordSrc.u32_Data=(*(vu32*)(FLASH_ADDR_UPDATE_TEMP_AREA+i*sizeof(u32)));
			if (dwordDest.u32_Data!=dwordSrc.u32_Data)
			{
				for(int j=i*sizeof(u32);j<((i+1)*sizeof(u32));j++)
				{
					if (j<UpdateRecvedContentBytes)
					{
						errorExists=1;
						break;
					}
					else
						break;
				}
			}
			if (errorExists==1)
				break;
		}
		//response!!!
		u8 dataBytes=1;
		USART_WR_BUF[0]=errorExists;
	
		USART6_Send(CMD0x0D_Request_UpdateVerifyStage2,dataBytes,bIsContentBitInverted_SendBack);	
#else
		Command_SendbackErrorMessage(Error0x01_CannotRunAtApp,1);
#endif
}



