123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- /****************************************************************************
- *
- * 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 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;
- 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 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 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);
|