/**************************************************************************** * * Copy right: Qx. * File name: UartTask.h * Description: 串口任务 * History: 2021-03-05 * ****************************************************************************/ #include "commontypedef.h" extern UINT8 BattChrgEndFlag; typedef struct _UartRedMsg { volatile bool UartFlag; UINT8 Header[3]; UINT8 data[120]; UINT16 len; }UartReadMsgType; typedef struct Uart_Write_Data_Type { volatile uint8_t WriteCmd; uint8_t Data[2]; }Uart_Write_Data_Type; //全局变量输出区 extern UartReadMsgType UartReadMsg; extern osMutexId_t UartMutex; extern QueueHandle_t UartWriteCmdHandle; // #define UART_WRITE_FLAG 0x01 #define UART_READ_FLAG 0x00 #define PROC_UART_TASK_STACK_SIZE (1024) #define BMS_ADDRESS_CODE 0x01 #define UART_READ_CODE 0x03 #define UART_WRITE_CODE 0x10 #define UART_ENCRYPT_CODE 0x05 typedef struct Uart_Read_Msg_Type { uint8_t Bms_Address; uint8_t Bms_Funcode; uint8_t Reg_Begin_H; uint8_t Reg_Begin_L; uint8_t Reg_Num_H; uint8_t Reg_Num_L; uint8_t CRC_L; uint8_t CRC_H; }Uart_Read_Msg_Type; typedef struct Uart_Write_Msg_Type { uint8_t Bms_Address; uint8_t Bms_Funcode; uint8_t Reg_Begin_H; uint8_t Reg_Begin_L; uint8_t Reg_Num_H; uint8_t Reg_Num_L; uint8_t Data_Count; uint8_t Data[2]; uint8_t CRC_L; uint8_t CRC_H; }Uart_Write_Msg_Type; typedef struct Uart_Write_Answer_Msg_Type { uint8_t Bms_Address; uint8_t Bms_Funcode; }Uart_Write_Answer_Msg_Type; typedef enum { PROCESS_UART_STATE_ENCRYPT = 0, PROCESS_UART_STATE_IDLE, PROCESS_UART_STATE_READ, PROCESS_UART_STATE_WRITE, PROCESS_UART_STATE_UPDATE, PROCESS_UART_STATE_SLEEP }process_Uart; 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 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; void UartTaskInit(void* arg); void UartTaskDeInit(void* arg); UINT8 SP_BMS_Update_Query(UINT8* pSend,UINT32 sendLen, UINT8* pRead, UINT32 readLen, UINT32 timeout); UINT8 SP_BMS_Update_CheckSUM(UINT8* pSendData,UINT8 len);