AppTaskUart.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. #include "bsp.h"
  11. #include "bsp_custom.h"
  12. #include "osasys.h"
  13. #include "ostask.h"
  14. #include "queue.h"
  15. #include "ps_event_callback.h"
  16. #include "cmisim.h"
  17. #include "cmimm.h"
  18. #include "cmips.h"
  19. #include "sockets.h"
  20. #include "psifevent.h"
  21. #include "ps_lib_api.h"
  22. #include "lwip/netdb.h"
  23. #include "debug_log.h"
  24. #include "slpman_ec616.h"
  25. #include "plat_config.h"
  26. #include "ec_tcpip_api.h"
  27. #include "hal_module_adapter.h"
  28. #include <stdlib.h>
  29. #include "numeric.h"
  30. #include "AppSignal.h"
  31. #include "hal_uart.h"
  32. #define PROC_UART_TASK_STACK_SIZE (2048)
  33. #define BMS_ADDRESS_CODE 0x01
  34. #define UART_READ_CODE 0x03
  35. #define UART_WRITE_CODE 0x10
  36. #define UART_ENCRYPT_CODE 0x05
  37. #define UART_WRITE_FLAG 0x01
  38. #define UART_READ_FLAG 0x00
  39. typedef enum
  40. {
  41. PROCESS_UART_STATE_INTI = 0,
  42. PROCESS_UART_STATE_ENCRYPT,
  43. PROCESS_UART_STATE_IDLE,
  44. PROCESS_UART_STATE_READ,
  45. PROCESS_UART_STATE_WRITE,
  46. PROCESS_UART_STATE_UPDATE,
  47. PROCESS_UART_STATE_SLEEP
  48. } process_Uart;
  49. typedef struct _UartQueryType
  50. {
  51. UINT8 Bms_Address;
  52. UINT8 Bms_Funcode;
  53. UINT8 Reg_Begin_H;
  54. UINT8 Reg_Begin_L;
  55. UINT8 Reg_Num_H;
  56. UINT8 Reg_Num_L;
  57. UINT8 CRC_L;
  58. UINT8 CRC_H;
  59. } UartQueryType;
  60. typedef struct _UartWriteMsgType
  61. {
  62. UINT8 Bms_Address;
  63. UINT8 Bms_Funcode;
  64. UINT8 Reg_Begin_H;
  65. UINT8 Reg_Begin_L;
  66. UINT8 Reg_Num_H;
  67. UINT8 Reg_Num_L;
  68. UINT8 Data_Count;
  69. UINT8 Data[2];
  70. UINT8 CRC_L;
  71. UINT8 CRC_H;
  72. } UartWriteMsgType;
  73. typedef struct _UartWriteDataType
  74. {
  75. volatile UINT8 WriteCmd;
  76. UINT8 Data[2];
  77. } UartWriteData_S;
  78. typedef enum
  79. {
  80. UPDATE_STEP_CHECK_VERSION = 0,
  81. UPDATE_STEP_REQUEST_UPDATE,
  82. UPDATE_STEP_START_UPDATE,
  83. UPDATE_STEP_CHECK_VERSION_AGAIN,
  84. UPDATE_STEP_SET_BAUD_RATE,
  85. UPDATE_STEP_PREPARE_SEND_DATA_LEN,
  86. UPDATE_STEP_SEND_DATA_LEN,
  87. UPDATE_STEP_PREPARE_SEND_UPDATE_DATA,
  88. UPDATE_STEP_SEND_UPDATE_DATA,
  89. UPDATE_STEP_SEND_DATA_END,
  90. UPDATE_STEP_START_INSTALL,
  91. UPDATE_STEP_END,
  92. UPDATE_STEP_RESET, //exit download, and go to before UPDATE_STEP_PREPARE_SEND_UPDATE_DATA
  93. UPDATE_STEP_DOWNLOAD_BREAK_OFF, //exite download, and return boot mode(not app mode)
  94. UPDATE_STEP_ERROR
  95. } UpdateStep;
  96. typedef enum
  97. {
  98. MS_UPDATE_STEP_SEND_FIRMWARE_UPDATE_REQUEST_AND_JUMP_TO_BOOTLOADER = 1,
  99. MS_UPDATE_STEP_FIRMWARE_UPDATE_REQUEST_ANSWER,
  100. MS_UPDATE_STEP_SEND_FIRMWARE_INFO,
  101. MS_UPDATE_STEP_FIRMWARE_INFO_CHECK_AND_UPDATE_REQEST_ANSWER,
  102. MS_UPDATE_STEP_EREASE_APP_FLASH_REQUEST,
  103. MS_UPDATE_STEP_EREASE_FLASH_ANSWER,
  104. MS_UPDATE_STEP_SEND_UPDATE_DATA,
  105. MS_UPDATE_STEP_UPDATE_DATA_WRITE_ANSWER,
  106. MS_UPDATE_STEP_SEND_UPDATE_DATA_END_AND_JUMP_TO_APP,
  107. MS_UPDATE_STEP_JUMP_TO_APP_ANSWER,
  108. MS_UPDATE_STEP_READ_CURRENT_RUNNING_MODE,
  109. MS_UPDATE_STEP_CURRENT_RUNNING_MODE_ANSWER,
  110. MS_UPDATE_STEP_END,
  111. MS_UPDATE_STEP_ERROR
  112. } UpdateStep_MS_BMS;
  113. typedef struct BMS_Update_Recv_Msg_Type
  114. {
  115. UINT8 startFlag;
  116. UINT8 addrFlag;
  117. UINT8 cmdRW;
  118. UINT8 dataLen;
  119. UINT8 cmd;
  120. UINT8 data;
  121. UINT8 checkSum;
  122. UINT8 endFlag;
  123. } BMS_Update_Recv_Msg_Type;
  124. typedef enum
  125. {
  126. updateOK = 0, ///< update successfully.
  127. updateErrorTimeout = 1, ///< update failed after try 3 times, so time out
  128. updateErrorBMSPowerLow = 2, ///update failed, because of bmp power low
  129. updateErrorBMSWarningProtect = 3, ///update failed, because there are some warning in bms which not allowed to update
  130. updateErrorBMSNotSurport = 4, ///update failed, because of bms not surpport
  131. updateErrorBMSWorkState = 5, ///update failed, because bms is charging or discharging
  132. updateErrorFirmwareInfoError = 6, //update failed, the firmware info error
  133. updateErrorFirmwareSizeError = 7, ///update failed, the firmware size in firmware info is to large
  134. updateErrorAppErease = 8, ///update failed, erease app flash failed
  135. updateErrorPackageCRC = 9, ///the crc of some package is wrong
  136. updateErrorPackageWrite = 10, ///package write in failed
  137. updateErrorPackageNo = 11, ///package number is not right or not continues
  138. updateErrorCheckSumError, // checksum != checksumcal
  139. updateFailed = 0xFF ///
  140. } updateBMSStatus;
  141. void AppTaskUartInit(void *arg);
  142. void AppTaskUartDeInit(void *arg);
  143. //BMS升级函数声明
  144. UINT8 SP_BMS_Update_CheckSUM(UINT8 *pSendData, UINT8 len);
  145. void SP_BMS_Update_Service();
  146. updateBMSStatus MS_BMS_Update_Service();
  147. UINT16 MS_BMS_Update_CRC16(UINT8 *pSendData, UINT16 len);
  148. UINT8 UartAppTrasmit(UINT8 *pSend, UINT32 sendLen, UINT8 *pRead, UINT32 readLen, UINT32 timeout);