diff --git a/code/application/source/sf_app/code/include/sf_mcu_upgrade.h b/code/application/source/sf_app/code/include/sf_mcu_upgrade.h index f0a86d7f5..70fea7492 100755 --- a/code/application/source/sf_app/code/include/sf_mcu_upgrade.h +++ b/code/application/source/sf_app/code/include/sf_mcu_upgrade.h @@ -44,6 +44,7 @@ typedef enum{ FWUPGRADE_TRANSFER_PACKET_STATE, FWUPGRADE_TRANSFER_FINISH_STATE, FWUPGRADE_ERROR_OCCUR_STATE, + FWUPGRADE_END, }FW_UPGRADE_STATE_e; extern unsigned char mcu_upgrade_buf[32]; diff --git a/code/application/source/sf_app/code/source/app/sf_system.c b/code/application/source/sf_app/code/source/app/sf_system.c index 88d9862c0..d3153d0a3 100755 --- a/code/application/source/sf_app/code/source/app/sf_system.c +++ b/code/application/source/sf_app/code/source/app/sf_system.c @@ -925,7 +925,7 @@ void sf_power_off(void) sf_power_off_check_sd(); sf_power_off_check_sd_fail(); - + sf_poweroff_check_lpa_excute_cmd(); sf_poweroff_check_lpa_enable_profile(); @@ -1641,13 +1641,21 @@ void* sf_app_mcu_updata_thread(void *arg) { SLOGI("thread run\n"); - McuUpDataTskCfg.IsRun = 1; MLOGI("MCU_UPGRADE\n"); UINT32 McuFsize = 0; SINT8 ret = 0; int sdflag = 0; int emmcflag = 0; char file_path[64] = {0}; + + if(SF_FAILURE == sf_check_sd()) + { + MLOGE("ERROR sf_check_sd\n"); + McuUpDataTskCfg.IsRun = 0; + SLOGI("thread end\n"); + return NULL; + } + if((access("/mnt/sd/Mupgrade.bin", F_OK) == 0)) { sdflag = 1; @@ -1682,7 +1690,6 @@ void* sf_app_mcu_updata_thread(void *arg) MLOGI(" sf_power_off_msg_to_cardv\n"); sf_power_off_msg_to_cardv(); } - McuUpDataTskCfg.IsRun = 0; SLOGI("thread end\n"); return NULL; @@ -1695,6 +1702,7 @@ SINT32 sf_app_mcu_updata_start(void) SLOGE("thread has already run !!!\n"); return SF_FAILURE; } + McuUpDataTskCfg.IsRun = 1; ret = pthread_create(&McuUpDataTskCfg.TskId, NULL, sf_app_mcu_updata_thread, NULL); if(ret != SF_SUCCESS) { @@ -1704,3 +1712,4 @@ SINT32 sf_app_mcu_updata_start(void) return SF_SUCCESS; } + diff --git a/code/application/source/sf_app/code/source/systemMng/sf_mcu_upgrade.c b/code/application/source/sf_app/code/source/systemMng/sf_mcu_upgrade.c index d99a3c4a0..cddb9d161 100755 --- a/code/application/source/sf_app/code/source/systemMng/sf_mcu_upgrade.c +++ b/code/application/source/sf_app/code/source/systemMng/sf_mcu_upgrade.c @@ -39,6 +39,7 @@ #include "sf_system.h" #include "sf_fileMng.h" #include "sf_storeMng.h" +#include "sf_commu_mcu.h" #ifdef __cplusplus #if __cplusplus extern "C" { @@ -228,12 +229,13 @@ SINT8 Fw_Read(UINT8* cmd, void * data, UINT32* size) } //len = read(fd, recvBuf, len); + ret = sf_commu_wait(MCU_FLAG_GET); + while(mcu_upgrade_buf_len == 0 && trytimes < 100) { trytimes++; usleep(10000); } - //ret = depack(recvBuf, len, cmd, data, size); ret = depack(mcu_upgrade_buf, mcu_upgrade_buf_len, cmd, (UINT8*)data, size); mcu_upgrade_buf_len = 0; @@ -352,11 +354,13 @@ static void * FwUpgradeTask(void * argv) { snprintf(file_path, sizeof(file_path), "/mnt/sd2/Mupgrade.bin"); } + printf("file_path:%s\r\n",file_path); if(file_path[0] == '\0') { MLOGE("no update file\n"); return NULL; } + FwUpgradeState = FWUPGRADE_INIT_STATE; while(FwUpgradeExit == 0) { @@ -476,7 +480,9 @@ static void * FwUpgradeTask(void * argv) ret = Fw_Send(0xee, &data, len + 4); ret = Fw_Read(&cmd, recvBuf, &recvl); - + // for(unsigned int i = 0; i < recvl; i++){ + // printf("srecv 0x%x\r\n", recvBuf[i]); + // } ack_id = ((UINT16)recvBuf[1]) << 8 | recvBuf[2]; printf("cmd %x, ack_id %d, pkt_id %d, recv3 %x\r\n", cmd, ack_id, pkt_id, recvBuf[3]); @@ -488,6 +494,10 @@ static void * FwUpgradeTask(void * argv) if(fw_packet.fw_total_size == fw_packet.fw_complete_size) { ret = Fw_Read(&cmd, recvBuf, &recvl); + // printf("cmd %x\r\n",cmd); + // for(unsigned int i = 0; i < recvl; i++){ + // printf("recv 0x%x\r\n", recvBuf[i]); + // } if(recvBuf[1] == 0) { FwUpgradeState = FWUPGRADE_TRANSFER_FINISH_STATE; @@ -512,25 +522,35 @@ static void * FwUpgradeTask(void * argv) case FWUPGRADE_TRANSFER_FINISH_STATE: printf("FWUPGRADE_TRANSFER_FINISH_STATE\r\n"); //sf_sys_status_led_set(SF_LED_SYS_STATE_UPGRADE_SUCCESS); - free(fw_packet.fw_content); + if(fw_packet.fw_content != NULL) + { + free(fw_packet.fw_content); + fw_packet.fw_content = NULL; + } /*exit upgrade thread*/ - FwUpgradeExit = 1; + FwUpgradeExit = 1; + FwUpgradeState = FWUPGRADE_END; break; case FWUPGRADE_ERROR_OCCUR_STATE: printf("FWUPGRADE_ERROR_OCCUR_STATE\r\n"); if(fw_packet.fw_content != NULL) { - free(fw_packet.fw_content); + free(fw_packet.fw_content); + fw_packet.fw_content = NULL; } data[0] = 0; ret = Fw_Send(0xec, data, 1); /*notify mcu to exit upgrade mode*/ + recvl = 0; Fw_Read(&cmd, recvBuf, &recvl); - + printf("cmd %x\r\n",cmd); + for(unsigned int i = 0; i < recvl; i++) + printf("recv 0x%x\r\n", recvBuf[i]); sf_power_off_msg_to_cardv(); /*exit upgrade thread*/ FwUpgradeExit = 1; + FwUpgradeState = FWUPGRADE_END; break; default: @@ -539,9 +559,9 @@ static void * FwUpgradeTask(void * argv) usleep(200000); } - free(file_path); printf("ret is %d\r\n", ret); - pthread_exit(NULL); + return NULL; +//pthread_exit(NULL); }