UartTask.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 UartReadMsgType UartReadMsg;
  25. extern osMutexId_t UartMutex;
  26. extern QueueHandle_t UartWriteCmdHandle;
  27. //
  28. #define UART_WRITE_FLAG 0x01
  29. #define UART_READ_FLAG 0x00
  30. #define PROC_UART_TASK_STACK_SIZE (1024)
  31. #define BMS_ADDRESS_CODE 0x01
  32. #define UART_READ_CODE 0x03
  33. #define UART_WRITE_CODE 0x10
  34. #define UART_ENCRYPT_CODE 0x05
  35. typedef struct Uart_Read_Msg_Type
  36. {
  37. uint8_t Bms_Address;
  38. uint8_t Bms_Funcode;
  39. uint8_t Reg_Begin_H;
  40. uint8_t Reg_Begin_L;
  41. uint8_t Reg_Num_H;
  42. uint8_t Reg_Num_L;
  43. uint8_t CRC_L;
  44. uint8_t CRC_H;
  45. }Uart_Read_Msg_Type;
  46. typedef struct Uart_Write_Msg_Type
  47. {
  48. uint8_t Bms_Address;
  49. uint8_t Bms_Funcode;
  50. uint8_t Reg_Begin_H;
  51. uint8_t Reg_Begin_L;
  52. uint8_t Reg_Num_H;
  53. uint8_t Reg_Num_L;
  54. uint8_t Data_Count;
  55. uint8_t Data[2];
  56. uint8_t CRC_L;
  57. uint8_t CRC_H;
  58. }Uart_Write_Msg_Type;
  59. typedef struct Uart_Write_Answer_Msg_Type
  60. {
  61. uint8_t Bms_Address;
  62. uint8_t Bms_Funcode;
  63. }Uart_Write_Answer_Msg_Type;
  64. typedef enum
  65. {
  66. PROCESS_UART_STATE_ENCRYPT = 0,
  67. PROCESS_UART_STATE_IDLE,
  68. PROCESS_UART_STATE_READ,
  69. PROCESS_UART_STATE_WRITE,
  70. PROCESS_UART_STATE_UPDATE,
  71. PROCESS_UART_STATE_SLEEP
  72. }process_Uart;
  73. typedef enum
  74. {
  75. UPDATE_STEP_CHECK_VERSION=0,
  76. UPDATE_STEP_REQUEST_UPDATE,
  77. UPDATE_STEP_START_UPDATE,
  78. UPDATE_STEP_CHECK_VERSION_AGAIN,
  79. UPDATE_STEP_SET_BAUD_RATE,
  80. UPDATE_STEP_PREPARE_SEND_DATA_LEN,
  81. UPDATE_STEP_SEND_DATA_LEN,
  82. UPDATE_STEP_PREPARE_SEND_UPDATE_DATA,
  83. UPDATE_STEP_SEND_UPDATE_DATA,
  84. UPDATE_STEP_SEND_DATA_END,
  85. UPDATE_STEP_START_INSTALL,
  86. UPDATE_STEP_END,
  87. UPDATE_STEP_RESET, //exit download, and go to before UPDATE_STEP_PREPARE_SEND_UPDATE_DATA
  88. UPDATE_STEP_DOWNLOAD_BREAK_OFF, //exite download, and return boot mode(not app mode)
  89. UPDATE_STEP_ERROR
  90. }UpdateStep;
  91. typedef struct BMS_Update_Recv_Msg_Type
  92. {
  93. UINT8 startFlag;
  94. UINT8 addrFlag;
  95. UINT8 cmdRW;
  96. UINT8 dataLen;
  97. UINT8 cmd;
  98. UINT8 data;
  99. UINT8 checkSum;
  100. UINT8 endFlag;
  101. }BMS_Update_Recv_Msg_Type;
  102. void UartTaskInit(void* arg);
  103. void UartTaskDeInit(void* arg);
  104. UINT8 SP_BMS_Update_Query(UINT8* pSend,UINT32 sendLen, UINT8* pRead, UINT32 readLen, UINT32 timeout);
  105. UINT8 SP_BMS_Update_CheckSUM(UINT8* pSendData,UINT8 len);