#include "upper_com_iap_pro.h" #include "upper_com.h" #include "flash.h" #include "bootloader_iap.h" /*IAP¸üгÌÐòÁ÷³Ì£º9601 -> 9604 -> 9602 -> 9603 -> 9600*/ ErrorStatus_STM32 UC_IapResetHandler(u16 data_category_ID,uint8_t *DataPtr,UC_RECV_DATA_UNION_T *uc_respond_data_p) { /*¹Ø±ÕÈ«²¿ÍâÉè*/ __disable_irq();//¹Ø±ÕÈ«¾ÖÖжÏʹÄÜ delay_ms(100); RMU->SOFTRST = 0x5C5CAABB; //?Èí¼þ¸´Î» return SUCCESS_0; } /****************************************** * func: UC_IapConfigSetHander * desc: IAPÏà¹ØµÄһЩÅäÖòÎÊýÉèÖà * input: pInputData£º²ÎÊýÊý¾Ý£¬Ïê¼ûBOOTLOAD_PARA_STRUCT½á¹¹Ìå * output: none * return: SUCCESS_0£º³É¹¦ ERROR_1/ÆäËû£ºÊ§°Ü *****************************************/ ErrorStatus_STM32 UC_IapConfigSetHandler(u16 data_category_ID,uint8_t *DataPtr,UC_RECV_DATA_UNION_T *uc_respond_data_p) { uint8_t return_flag = SUCCESS_0; uint32_t data_len = uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.data_field_length - UC_PROTOCOL_TABLE_ID_LENGTH;//¼õÈ¥±íºÅ return_flag = BootLoader_IapConfigSetHander(DataPtr,data_len); if(return_flag == SUCCESS_0){ uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = 0; }else{ uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = return_flag; } uc_respond_data_p->uc_protocol_head_s.data_field_length = UC_PROTOCOL_TABLE_ID_LENGTH + 1; return (ErrorStatus_STM32)return_flag; } ErrorStatus_STM32 UC_IapConfigLzmaSetHandler(u16 data_category_ID,uint8_t *DataPtr,UC_RECV_DATA_UNION_T *uc_respond_data_p) { uint8_t return_flag = SUCCESS_0; uint32_t data_len = uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.data_field_length - UC_PROTOCOL_TABLE_ID_LENGTH;//¼õÈ¥±íºÅ return_flag = BootLoader_IapConfigLzmaSetHander(DataPtr,data_len); if(return_flag == SUCCESS_0){ uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = 0; }else{ uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = return_flag; } uc_respond_data_p->uc_protocol_head_s.data_field_length = UC_PROTOCOL_TABLE_ID_LENGTH + 1; return (ErrorStatus_STM32)return_flag; } /****************************************** * func: UC_IapDiffDataHander * desc: ÕýʽдÈë²îÒìÊý¾Ý£¨´æ´¢ÔÚÆ¬ÍâFlash£© * input: pInputData£º²îÒìÊý¾Ý£¬ÓÉÉÏλ»ú´ÓHexÎļþÌáÈ¡ * output: none * return: SUCCESS_0£º³É¹¦ ERROR_1/ÆäËû£ºÊ§°Ü *****************************************/ ErrorStatus_STM32 UC_IapDiffDataHandler(u16 data_category_ID,uint8_t *DataPtr,UC_RECV_DATA_UNION_T *uc_respond_data_p) { uint8_t return_flag = SUCCESS_0; uint32_t offset_addr = (DataPtr[3] << 24) | (DataPtr[2] << 16) | (DataPtr[1] << 8) | DataPtr[0]; uint32_t data_len = uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.data_field_length - 4 //¼õÈ¥µØÖ· - UC_PROTOCOL_TABLE_ID_LENGTH;//¼õÈ¥±íºÅ //Êý¾Ý´Ó[4]¿ªÊ¼ return_flag = BootLoader_IapDiffDataHandler(&DataPtr[4],offset_addr,data_len); if(return_flag == SUCCESS_0){ uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = 0; }else{ uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = return_flag; } uc_respond_data_p->uc_protocol_head_s.data_field_length = UC_PROTOCOL_TABLE_ID_LENGTH + 1; return (ErrorStatus_STM32)return_flag; } /****************************************** * func: UC_IapConfigCheckHander * desc: IAPÍê³ÉºóºË²éÊý¾ÝºÍ²ÎÊý * input: none * output: none * return: SUCCESS_0£º³É¹¦ ERROR_1/ÆäËû£ºÊ§°Ü *****************************************/ ErrorStatus_STM32 UC_IapConfigCheckHandler(u16 data_category_ID,uint8_t *DataPtr,UC_RECV_DATA_UNION_T *uc_respond_data_p) { uint8_t return_flag = SUCCESS_0; return_flag = BootLoader_IapConfigCheckHandler(); if(return_flag == SUCCESS_0){ uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = 0; }else{ uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = return_flag; } uc_respond_data_p->uc_protocol_head_s.data_field_length = UC_PROTOCOL_TABLE_ID_LENGTH + 1; return (ErrorStatus_STM32)return_flag; } /****************************************** * func: UC_IapDiffMapSetHander * desc: IAPÏà¹ØµÄ²îÒì±í²ÎÊýÉèÖà * input: pInputData£º²ÎÊýÊý¾Ý£¬Ïê¼ûÉÏλ»úЭÒé * output: none * return: SUCCESS_0£º³É¹¦ ERROR_1/ÆäËû£ºÊ§°Ü *****************************************/ ErrorStatus_STM32 UC_IapDiffMapSetHandler(u16 data_category_ID,uint8_t *DataPtr,UC_RECV_DATA_UNION_T *uc_respond_data_p) { uint8_t return_flag = SUCCESS_0; uint32_t offset_addr = (DataPtr[3] << 24) | (DataPtr[2] << 16) | (DataPtr[1] << 8) | DataPtr[0]; uint32_t data_len = uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.data_field_length - 4 //¼õÈ¥µØÖ· - UC_PROTOCOL_TABLE_ID_LENGTH;//¼õÈ¥±íºÅ //Êý¾Ý´ÓpInputData[4]¿ªÊ¼ return_flag = BootLoader_IapDiffMapSetHandler(&DataPtr[4],offset_addr,data_len); if(return_flag == SUCCESS_0){ uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = 0; }else{ uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = return_flag; } uc_respond_data_p->uc_protocol_head_s.data_field_length = UC_PROTOCOL_TABLE_ID_LENGTH + 1; return (ErrorStatus_STM32)return_flag; } /*ÉÏλ»úдÊý¾Ý´¦Àíº¯Êý*/ void Upper_ComputerIapHandler(UC_RECV_DATA_UNION_T *uc_recv_data_union_p,UC_RECV_DATA_UNION_T *uc_respond_data_p) { uint16_t data_category_ID; uint8_t *data_p; uc_respond_data_p->uc_protocol_head_s.data_table_id = uc_recv_data_union_p->uc_protocol_head_s.data_table_id; data_category_ID= BSWAP_16(uc_recv_data_union_p->uc_protocol_head_s.data_table_id); data_p = uc_recv_data_union_p->uc_recv_buf + UC_PROTOCOL_HEAD_LENGTH +sizeof (uc_recv_data_union_p->uc_protocol_head_s.data_table_id); switch(data_category_ID) { case UIC_APP_RESET : UC_IapResetHandler(data_category_ID,data_p,uc_respond_data_p) ;break; case UIC_APP_CONFIG : UC_IapConfigSetHandler(data_category_ID,data_p,uc_respond_data_p) ;break; case UIC_APP_DIFF_DATA : UC_IapDiffDataHandler(data_category_ID,data_p,uc_respond_data_p) ;break; case UIC_APP_CONFIG_CHECK : UC_IapConfigCheckHandler(data_category_ID,data_p,uc_respond_data_p) ;break; case UIC_APP_DIFF_MAP : UC_IapDiffMapSetHandler(data_category_ID,data_p,uc_respond_data_p) ;break; case UIC_APP_CONFIG_LZMA : UC_IapConfigLzmaSetHandler(data_category_ID,data_p,uc_respond_data_p) ;break; default : break; } }