/**************************************************************************** * * Copy right: Qx. * File name: UartTask.h * Description: 串口任务 * History: 2021-03-05 * ****************************************************************************/ #include "commontypedef.h" #include "bsp.h" #include "bsp_custom.h" #include "osasys.h" #include "ostask.h" #include "queue.h" #include "ps_event_callback.h" #include "cmisim.h" #include "cmimm.h" #include "cmips.h" #include "sockets.h" #include "psifevent.h" #include "ps_lib_api.h" #include "lwip/netdb.h" #include "debug_log.h" #include "slpman_ec616.h" #include "plat_config.h" #include "ec_tcpip_api.h" #include "hal_module_adapter.h" #include #include "numeric.h" #include "AppSignal.h" #include "hal_uart.h" #define PROC_UART_TASK_STACK_SIZE (2048) #define BMS_ADDRESS_CODE 0x01 #define UART_READ_CODE 0x03 #define UART_WRITE_CODE 0x10 #define UART_ENCRYPT_CODE 0x05 #define UART_WRITE_FLAG 0x01 #define UART_READ_FLAG 0x00 typedef enum { PROCESS_UART_STATE_INTI = 0, PROCESS_UART_STATE_ENCRYPT, PROCESS_UART_STATE_IDLE, PROCESS_UART_STATE_READ, PROCESS_UART_STATE_WRITE, PROCESS_UART_STATE_UPDATE, PROCESS_UART_STATE_SLEEP }process_Uart; typedef struct _UartQueryType { UINT8 Bms_Address; UINT8 Bms_Funcode; UINT8 Reg_Begin_H; UINT8 Reg_Begin_L; UINT8 Reg_Num_H; UINT8 Reg_Num_L; UINT8 CRC_L; UINT8 CRC_H; }UartQueryType; typedef struct _UartWriteMsgType { UINT8 Bms_Address; UINT8 Bms_Funcode; UINT8 Reg_Begin_H; UINT8 Reg_Begin_L; UINT8 Reg_Num_H; UINT8 Reg_Num_L; UINT8 Data_Count; UINT8 Data[2]; UINT8 CRC_L; UINT8 CRC_H; }UartWriteMsgType; typedef struct _UartWriteDataType { volatile UINT8 WriteCmd; UINT8 Data[2]; }UartWriteData_S; typedef enum { UPDATE_STEP_CHECK_VERSION=0, UPDATE_STEP_REQUEST_UPDATE, UPDATE_STEP_START_UPDATE, UPDATE_STEP_CHECK_VERSION_AGAIN, UPDATE_STEP_SET_BAUD_RATE, UPDATE_STEP_PREPARE_SEND_DATA_LEN, UPDATE_STEP_SEND_DATA_LEN, UPDATE_STEP_PREPARE_SEND_UPDATE_DATA, UPDATE_STEP_SEND_UPDATE_DATA, UPDATE_STEP_SEND_DATA_END, UPDATE_STEP_START_INSTALL, UPDATE_STEP_END, UPDATE_STEP_RESET, //exit download, and go to before UPDATE_STEP_PREPARE_SEND_UPDATE_DATA UPDATE_STEP_DOWNLOAD_BREAK_OFF, //exite download, and return boot mode(not app mode) UPDATE_STEP_ERROR }UpdateStep; typedef enum { MS_UPDATE_STEP_SEND_FIRMWARE_UPDATE_REQUEST_AND_JUMP_TO_BOOTLOADER = 1, MS_UPDATE_STEP_FIRMWARE_UPDATE_REQUEST_ANSWER, MS_UPDATE_STEP_SEND_FIRMWARE_INFO, MS_UPDATE_STEP_FIRMWARE_INFO_CHECK_AND_UPDATE_REQEST_ANSWER, MS_UPDATE_STEP_EREASE_APP_FLASH_REQUEST, MS_UPDATE_STEP_EREASE_FLASH_ANSWER, MS_UPDATE_STEP_SEND_UPDATE_DATA, MS_UPDATE_STEP_UPDATE_DATA_WRITE_ANSWER, MS_UPDATE_STEP_SEND_UPDATE_DATA_END_AND_JUMP_TO_APP, MS_UPDATE_STEP_JUMP_TO_APP_ANSWER, MS_UPDATE_STEP_READ_CURRENT_RUNNING_MODE, MS_UPDATE_STEP_CURRENT_RUNNING_MODE_ANSWER, MS_UPDATE_STEP_END, MS_UPDATE_STEP_ERROR }UpdateStep_MS_BMS; typedef struct BMS_Update_Recv_Msg_Type { UINT8 startFlag; UINT8 addrFlag; UINT8 cmdRW; UINT8 dataLen; UINT8 cmd; UINT8 data; UINT8 checkSum; UINT8 endFlag; }BMS_Update_Recv_Msg_Type; typedef enum { updateOK = 0, ///< update successfully. updateErrorTimeout = 1, ///< update failed after try 3 times, so time out updateErrorBMSPowerLow = 2, ///update failed, because of bmp power low updateErrorBMSWarningProtect = 3, ///update failed, because there are some warning in bms which not allowed to update updateErrorBMSNotSurport = 4, ///update failed, because of bms not surpport updateErrorBMSWorkState = 5, ///update failed, because bms is charging or discharging updateErrorFirmwareInfoError = 6, //update failed, the firmware info error updateErrorFirmwareSizeError = 7, ///update failed, the firmware size in firmware info is to large updateErrorAppErease = 8, ///update failed, erease app flash failed updateErrorPackageCRC = 9, ///the crc of some package is wrong updateErrorPackageWrite = 10, ///package write in failed updateErrorPackageNo = 11, ///package number is not right or not continues updateErrorCheckSumError , // checksum != checksumcal updateFailed = 0xFF /// }updateBMSStatus; void AppTaskUartInit(void *arg); void AppTaskUartDeInit(void *arg); //BMS升级函数声明 UINT8 SP_BMS_Update_CheckSUM(UINT8* pSendData,UINT8 len); void SP_BMS_Update_Service(); updateBMSStatus MS_BMS_Update_Service(); UINT16 MS_BMS_Update_CRC16(UINT8* pSendData,UINT16 len); UINT8 UartAppTrasmit(UINT8* pSend,UINT32 sendLen, UINT8* pRead, UINT32 readLen, UINT32 timeout);