AppTaskUart.h 5.2 KB

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