UartTask.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /****************************************************************************
  2. *
  3. * Copy right: Qx.
  4. * File name: UartTask.h
  5. * Description: 串口任务
  6. * History: 2021-03-05
  7. *
  8. ****************************************************************************/
  9. #include "commontypedef.h"
  10. extern UINT8 BattChrgEndFlag;
  11. typedef struct _UartRedMsg
  12. {
  13. volatile BOOL UartFlag;
  14. UINT8 Header[3];
  15. UINT8 data[120];
  16. UINT16 len;
  17. }UartReadMsgType;
  18. typedef struct Uart_Write_Data_Type
  19. {
  20. volatile uint8_t WriteCmd;
  21. uint8_t Data[2];
  22. }Uart_Write_Data_Type;
  23. //全局变量输出区
  24. extern QueueHandle_t UartWriteCmdHandle;
  25. //
  26. #define UART_WRITE_FLAG 0x01
  27. #define UART_READ_FLAG 0x00
  28. #define PROC_UART_TASK_STACK_SIZE (1024)
  29. #define BMS_ADDRESS_CODE 0x01
  30. #define UART_READ_CODE 0x03
  31. #define UART_WRITE_CODE 0x10
  32. #define UART_ENCRYPT_CODE 0x05
  33. typedef struct Uart_Read_Msg_Type
  34. {
  35. uint8_t Bms_Address;
  36. uint8_t Bms_Funcode;
  37. uint8_t Reg_Begin_H;
  38. uint8_t Reg_Begin_L;
  39. uint8_t Reg_Num_H;
  40. uint8_t Reg_Num_L;
  41. uint8_t CRC_L;
  42. uint8_t CRC_H;
  43. }Uart_Read_Msg_Type;
  44. typedef struct Uart_Write_Msg_Type
  45. {
  46. uint8_t Bms_Address;
  47. uint8_t Bms_Funcode;
  48. uint8_t Reg_Begin_H;
  49. uint8_t Reg_Begin_L;
  50. uint8_t Reg_Num_H;
  51. uint8_t Reg_Num_L;
  52. uint8_t Data_Count;
  53. uint8_t Data[2];
  54. uint8_t CRC_L;
  55. uint8_t CRC_H;
  56. }Uart_Write_Msg_Type;
  57. typedef struct Uart_Write_Answer_Msg_Type
  58. {
  59. uint8_t Bms_Address;
  60. uint8_t Bms_Funcode;
  61. }Uart_Write_Answer_Msg_Type;
  62. typedef enum
  63. {
  64. PROCESS_UART_STATE_ENCRYPT = 0,
  65. PROCESS_UART_STATE_IDLE,
  66. PROCESS_UART_STATE_READ,
  67. PROCESS_UART_STATE_WRITE,
  68. PROCESS_UART_STATE_UPDATE,
  69. PROCESS_UART_STATE_SLEEP
  70. }process_Uart;
  71. typedef enum
  72. {
  73. UPDATE_STEP_CHECK_VERSION=0,
  74. UPDATE_STEP_REQUEST_UPDATE,
  75. UPDATE_STEP_START_UPDATE,
  76. UPDATE_STEP_CHECK_VERSION_AGAIN,
  77. UPDATE_STEP_SET_BAUD_RATE,
  78. UPDATE_STEP_PREPARE_SEND_DATA_LEN,
  79. UPDATE_STEP_SEND_DATA_LEN,
  80. UPDATE_STEP_PREPARE_SEND_UPDATE_DATA,
  81. UPDATE_STEP_SEND_UPDATE_DATA,
  82. UPDATE_STEP_SEND_DATA_END,
  83. UPDATE_STEP_START_INSTALL,
  84. UPDATE_STEP_END,
  85. UPDATE_STEP_RESET, //exit download, and go to before UPDATE_STEP_PREPARE_SEND_UPDATE_DATA
  86. UPDATE_STEP_DOWNLOAD_BREAK_OFF, //exite download, and return boot mode(not app mode)
  87. UPDATE_STEP_ERROR
  88. }UpdateStep;
  89. typedef struct BMS_Update_Recv_Msg_Type
  90. {
  91. UINT8 startFlag;
  92. UINT8 addrFlag;
  93. UINT8 cmdRW;
  94. UINT8 dataLen;
  95. UINT8 cmd;
  96. UINT8 data;
  97. UINT8 checkSum;
  98. UINT8 endFlag;
  99. }BMS_Update_Recv_Msg_Type;
  100. typedef enum
  101. {
  102. MS_UPDATE_STEP_SEND_FIRMWARE_UPDATE_REQUEST_AND_JUMP_TO_BOOTLOADER = 1,
  103. MS_UPDATE_STEP_FIRMWARE_UPDATE_REQUEST_ANSWER,
  104. MS_UPDATE_STEP_SEND_FIRMWARE_INFO,
  105. MS_UPDATE_STEP_FIRMWARE_INFO_CHECK_AND_UPDATE_REQEST_ANSWER,
  106. MS_UPDATE_STEP_EREASE_APP_FLASH_REQUEST,
  107. MS_UPDATE_STEP_EREASE_FLASH_ANSWER,
  108. MS_UPDATE_STEP_SEND_UPDATE_DATA,
  109. MS_UPDATE_STEP_UPDATE_DATA_WRITE_ANSWER,
  110. MS_UPDATE_STEP_SEND_UPDATE_DATA_END_AND_JUMP_TO_APP,
  111. MS_UPDATE_STEP_JUMP_TO_APP_ANSWER,
  112. MS_UPDATE_STEP_READ_CURRENT_RUNNING_MODE,
  113. MS_UPDATE_STEP_CURRENT_RUNNING_MODE_ANSWER,
  114. MS_UPDATE_STEP_END,
  115. MS_UPDATE_STEP_ERROR
  116. }UpdateStep_MS_BMS;
  117. typedef enum
  118. {
  119. updateOK = 0, ///< update successfully.
  120. updateErrorTimeout = 1, ///< update failed after try 3 times, so time out
  121. updateErrorBMSPowerLow = 2, ///update failed, because of bmp power low
  122. updateErrorBMSWarningProtect = 3, ///update failed, because there are some warning in bms which not allowed to update
  123. updateErrorBMSNotSurport = 4, ///update failed, because of bms not surpport
  124. updateErrorBMSWorkState = 5, ///update failed, because bms is charging or discharging
  125. updateErrorFirmwareInfoError = 6, //update failed, the firmware info error
  126. updateErrorFirmwareSizeError = 7, ///update failed, the firmware size in firmware info is to large
  127. updateErrorAppErease = 8, ///update failed, erease app flash failed
  128. updateErrorPackageCRC = 9, ///the crc of some package is wrong
  129. updateErrorPackageWrite = 10, ///package write in failed
  130. updateErrorPackageNo = 11, ///package number is not right or not continues
  131. updateErrorCheckSumError, // checksum != checksumcal
  132. updateFailed = 0xFF ///
  133. }updateBMSStatus;
  134. void UartTaskInit(void* arg);
  135. void UartTaskDeInit(void* arg);
  136. UINT8 SP_BMS_Update_Query(UINT8* pSend,UINT32 sendLen, UINT8* pRead, UINT32 readLen, UINT32 timeout);
  137. UINT8 SP_BMS_Update_CheckSUM(UINT8* pSendData,UINT8 len);