#include "upper_computer_iap_api.h"
|
#include "flash.h"
|
#include "low_pwr_test.h"
|
#include "upper_computer.h"
|
#include "bootloader_iap.h"
|
|
|
|
static const UC_RECV_IAP_FUNC_TABLE_DRV_T uc_recv_iap_tab_func[] = {
|
{UIC_APP_RESET,UC_IapResetHandler},
|
{UIC_APP_CONFIG,UC_IapConfigSetHandler},
|
{UIC_APP_DIFF_DATA,UC_IapDiffDataHandler},
|
{UIC_APP_CONFIG_CHECK,UC_IapConfigCheckHandler},
|
{UIC_APP_DIFF_MAP,UC_IapDiffMapSetHandler},
|
};
|
|
|
/*IAP¸üгÌÐòÁ÷³Ì£º9601 -> 9604 -> 9602 -> 9603 -> 9600*/
|
|
ErrorStatus_STM32 UC_IapResetHandler(uint8_t *pInputData)
|
{
|
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(uint8_t *pInputData)
|
{
|
uint32_t data_len = uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.data_field_length - UC_DATA_TABLE_BYTES_LENGTH;//¼õÈ¥±íºÅ
|
return BootLoader_IapConfigSetHander(pInputData,data_len);
|
}
|
|
/******************************************
|
* func: UC_IapDiffDataHander
|
* desc: ÕýʽдÈë²îÒìÊý¾Ý£¨´æ´¢ÔÚÆ¬ÍâFlash£©
|
* input: pInputData£º²îÒìÊý¾Ý£¬ÓÉÉÏλ»ú´ÓHexÎļþÌáÈ¡
|
* output: none
|
* return: SUCCESS_0£º³É¹¦ ERROR_1/ÆäËû£ºÊ§°Ü
|
*****************************************/
|
ErrorStatus_STM32 UC_IapDiffDataHandler(uint8_t *pInputData)
|
{
|
uint32_t offset_addr = (pInputData[3] << 24) | (pInputData[2] << 16) | (pInputData[1] << 8) | pInputData[0];
|
uint32_t data_len = uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.data_field_length - 4 //¼õÈ¥µØÖ·
|
- UC_DATA_TABLE_BYTES_LENGTH;//¼õÈ¥±íºÅ
|
//Êý¾Ý´ÓpInputData[4]¿ªÊ¼
|
return BootLoader_IapDiffDataHandler(&pInputData[4],offset_addr,data_len);
|
}
|
/******************************************
|
* func: UC_IapConfigCheckHander
|
* desc: IAPÍê³ÉºóºË²éÊý¾ÝºÍ²ÎÊý
|
* input: none
|
* output: none
|
* return: SUCCESS_0£º³É¹¦ ERROR_1/ÆäËû£ºÊ§°Ü
|
*****************************************/
|
ErrorStatus_STM32 UC_IapConfigCheckHandler(uint8_t *pInputData)
|
{
|
return BootLoader_IapConfigCheckHandler();
|
}
|
/******************************************
|
* func: UC_IapDiffMapSetHander
|
* desc: IAPÏà¹ØµÄ²îÒì±í²ÎÊýÉèÖÃ
|
* input: pInputData£º²ÎÊýÊý¾Ý£¬Ïê¼ûÉÏλ»úÐÒé
|
* output: none
|
* return: SUCCESS_0£º³É¹¦ ERROR_1/ÆäËû£ºÊ§°Ü
|
*****************************************/
|
ErrorStatus_STM32 UC_IapDiffMapSetHandler(uint8_t *pInputData)
|
{
|
uint32_t offset_addr = (pInputData[3] << 24) | (pInputData[2] << 16) | (pInputData[1] << 8) | pInputData[0];
|
uint32_t data_len = uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.data_field_length - 4 //¼õÈ¥µØÖ·
|
- UC_DATA_TABLE_BYTES_LENGTH;//¼õÈ¥±íºÅ
|
//Êý¾Ý´ÓpInputData[4]¿ªÊ¼
|
return BootLoader_IapDiffMapSetHandler(&pInputData[4],offset_addr,data_len);
|
}
|
|
|
|
/*ÉÏλ»úдÊý¾Ý´¦Àíº¯Êý*/
|
ErrorStatus_STM32 Upper_ComputerIapProcess(uint16_t table_id, uint8_t *pIapData)
|
{
|
ErrorStatus_STM32 result_flag = ERROR_1;
|
// ²é±í
|
for (uint8_t i = 0; i < UC_RECV_IAP_TABLE_NUM; i++)
|
{
|
if (uc_recv_iap_tab_func[i].uc_data_table == table_id && uc_recv_iap_tab_func[i].UcIapFuncHandler != NULL)
|
{
|
E2p_GPIO_Clk_Init();
|
FlashInit();
|
result_flag = uc_recv_iap_tab_func[i].UcIapFuncHandler(pIapData);
|
break;
|
}
|
}
|
return result_flag;
|
}
|