UartTask.h 4.7 KB

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