hal_adapter.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * @Author : ChenJie
  3. * @Date : 2022-01-23 13:52:10
  4. * @Version : V3.0
  5. * @LastEditors : ChenJie
  6. * @LastEditTime : 2022-05-17 16:22:16
  7. * @Description : file content
  8. * @FilePath : \S32K146_4G\src\hal_adapter.h
  9. */
  10. /*
  11. * hal_adapter.h
  12. *中间层函数调用库
  13. * Created on: 2022年1月18日
  14. * Author: QiXiang_CHENJIE
  15. */
  16. #ifndef HAL_ADAPTER_H_
  17. #define HAL_ADAPTER_H_
  18. #include "Mcal.h"
  19. #include "CAN.h"
  20. #include "SchM_Can.h"
  21. #include "Mcu.h"
  22. #include "Mcl.h"
  23. #include "Port.h"
  24. #include "Dio.h"
  25. #include "Uart.h"
  26. #include "Platform.h"
  27. #include "Lpuart_Uart_Ip_Irq.h"
  28. #include "Flexio_Uart_Ip_Irq.h"
  29. #include <string.h>
  30. #include <stdlib.h>
  31. #include "Dma_Ip.h"
  32. #include "Dma_Ip_Irq.h"
  33. #include "Lpuart_Uart_Ip.h"
  34. #include "FreeRTOS.h"
  35. #include "timers.h"
  36. #include "task.h"
  37. #include "semphr.h"
  38. #include "Adc.h"
  39. #include "Eep.h"
  40. #include "Fls.h"
  41. #include "SchM_Fls.h"
  42. #include "SL_Sc7a20_Driver.h"
  43. #include "SEGGER_RTT_Conf.h"
  44. #include "SEGGER_RTT.h"
  45. #include "hal_Wdg.h"
  46. #include "rtwtypes.h"
  47. #include "BCUDisp.h"
  48. #include "AppFuncLib.h"
  49. /*适应性定义*/
  50. typedef unsigned char UINT8;
  51. typedef unsigned short UINT16;
  52. typedef unsigned long UINT32;
  53. typedef unsigned char BOOL;
  54. typedef signed char INT8;
  55. typedef signed short INT16;
  56. typedef signed long INT32;
  57. #define CAN0 0
  58. #define CAN1 1
  59. #ifndef min
  60. #define min(A, B) ((A) <= (B) ? (A) : (B))
  61. #endif
  62. #ifndef max
  63. #define max(A, B) ((A) < (B) ? (B) : (A))
  64. #endif
  65. #define getbit(x, y) ((x) >> (y)&1) // 获取x的第y位的数值
  66. #define setbit(x, y) x |= (1 << y) // x的第y位置1
  67. #define clrbit(x, y) x &= ~(1 << y) // x的第y位置0
  68. #define UART_LPUART0 0
  69. #define UART_LPUART1 1
  70. #define UART_LPUART2 2
  71. #define FLEXIO_RX 3
  72. #define FLEXIO_TX 4
  73. #define main_TASK_PRIORITY (tskIDLE_PRIORITY + 7)
  74. /*LED*/
  75. #define LED_INDEX2 DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1
  76. #define LED_INDEX3 DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2
  77. #define LED_INDEX4 DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3
  78. #define MSG_LEN 50U
  79. #define TJA1153_START_ID (uint32_t)(0x555u)
  80. #define TJA1153_CONFIG_ID (uint32_t)(0x18DA00F1u)
  81. #define NUM_RESULTS ADC_CFGSET_VS_0_GROUP_0_CHANNELS
  82. #define BUFFER_SIZE 1024
  83. #define DMA_SIZE 128
  84. void Uart_Hal_RecvTask(void *pvParameters);
  85. void Uart_Hal_SendTask(void *pvParameters);
  86. typedef struct
  87. {
  88. uint8_t *source;
  89. uint32_t br;
  90. uint32_t bw;
  91. uint32_t btoRead;
  92. uint32_t length;
  93. } ringbuffer_t;
  94. typedef struct
  95. {
  96. uint16 DataLen;
  97. uint8 *dataPtr;
  98. uint32 dataAddr;
  99. } UartMsg_t;
  100. typedef struct
  101. {
  102. uint8 Channel;
  103. Lpuart_Uart_Ip_EventType event;
  104. uint16 value;
  105. } UartHalMsg_t;
  106. typedef enum
  107. {
  108. UartStartRecv = 0,
  109. UartAbortRecv,
  110. UartRecvOnGoing,
  111. UartRecvComplete,
  112. UartStartSend,
  113. UartAbortSend,
  114. UartSendOnGoing,
  115. UartSendComplete,
  116. UartNoDataSend,
  117. }UartState;
  118. typedef enum
  119. {
  120. SystemTPChannel = 0,
  121. SlowChargeTPChannel,
  122. QuickChargeTPChannel,
  123. CC1TPChannel,
  124. ChannelCounter = 4,
  125. } ADC_TP_Channel_Type;
  126. typedef uint32 TP_Value_Type;
  127. /*CAN*/
  128. typedef enum
  129. {
  130. CAN_STANDARD_ID_TYPE = 0x00, /**< * -00b CAN message with Standard CAN ID */
  131. CANFD_STANDARD_ID_TYPE = 0x01, /**< * -01b CAN FD frame with Standard CAN ID */
  132. CAN_EXTENDED_ID_TYPE = 0x02, /**< * -10b CAN message with Extended CAN ID */
  133. CANFD_EXTENDED_ID_TYPE = 0x03, /**< * -11b CAN FD frame with Extended CAN ID */
  134. } CAN_IdFrameType;
  135. typedef struct
  136. {
  137. Can_IdType id;
  138. CAN_IdFrameType idFrame;
  139. uint8 length; /**< @brief DLC = Data Length Code (part of L-PDU that describes
  140. the SDU length). */
  141. uint8 *sdu; /**< @brief CAN L-SDU = Link Layer Service Data
  142. Unit. Data that is transported inside
  143. the L-PDU. */
  144. } Can_Msg_Type;
  145. typedef struct
  146. {
  147. Can_IdType id;
  148. uint8 length;
  149. uint8 data[8];
  150. } Can_Msg_Type_Data;
  151. /*EEP*/
  152. typedef enum
  153. {
  154. EEP_FTFC_KEY_SIZE_0_BYTES = 0x0, /**< @brief control code for key size 0 bytes, used for the partitioning command */
  155. EEP_FTFC_KEY_SIZE_128_BYTES = 0x1, /**< @brief control code for key size 128 bytes, used for the partitioning command */
  156. EEP_FTFC_KEY_SIZE_256_BYTES = 0x2, /**< @brief control code for key size 256 bytes, used for the partitioning command */
  157. EEP_FTFC_KEY_SIZE_512_BYTES = 0x3 /**< @brief control code for key size 512 bytes, used for the partitioning command */
  158. } TestEep_CsecKeySize;
  159. /**
  160. @brief FlexRamPartition Type used for the partitioning command
  161. */
  162. typedef enum
  163. {
  164. EEP_FTFC_EERAM_SIZE_0K = 0xF, /**< @brief control code for flexram partitioned as sram, used for the partitioning command */
  165. EEP_FTFC_EERAM_SIZE_4K = 0x2, /**< @brief control code for flexram partitioned as eeram, used for the partitioning command */
  166. EEP_FTFC_EERAM_SIZE_2K = 0x3 /**< @brief control code for flexram partitioned as eeram, used for the partitioning command */
  167. } TestEep_Eeprom_FlexRamPartitionType;
  168. /**
  169. @brief FlexNvmPartition Type used for the partitioning command
  170. */
  171. typedef enum
  172. {
  173. EEP_FTFC_EEEPROM_SIZE_0K_V1 = 0x0, /**< @brief control code to partition EEPROM backup size as 0K, used for the partitioning command */
  174. EEP_FTFC_EEEPROM_SIZE_0K_V2 = 0xC, /**< @brief control code to partition EEPROM backup size as 0K, used for the partitioning command */
  175. EEP_FTFC_EEEPROM_SIZE_0K_V3 = 0x0F, /**< @brief control code to partition EEPROM backup size as 0K, used for the partitioning command */
  176. EEP_FTFC_EEEPROM_SIZE_32K_V1 = 0x3, /**< @brief control code to partition EEPROM backup size as 32K, used for the partitioning command */
  177. EEP_FTFC_EEEPROM_SIZE_32K_V2 = 0xB, /**< @brief control code to partition EEPROM backup size as 32K, used for the partitioning command */
  178. EEP_FTFC_EEEPROM_SIZE_48K_V1 = 0xA, /**< @brief control code to partition EEPROM backup size as 48K, used for the partitioning command */
  179. EEP_FTFC_EEEPROM_SIZE_64K_V1 = 0x8, /**< @brief control code to partition EEPROM backup size as 64K, used for the partitioning command */
  180. EEP_FTFC_EEEPROM_SIZE_64K_V2 = 0x4, /**< @brief control code to partition EEPROM backup size as 64K, used for the partitioning command */
  181. EEP_FTFC_EEEPROM_SIZE_24K_V2 = 0x9 /**< @brief control code to partition EEPROM backup size as 24K, used for the partitioning command */
  182. } TestEep_Eeprom_FlexNvmPartitionType;
  183. /**
  184. @brief Sfe Type used for the partitioning command
  185. */
  186. typedef enum
  187. {
  188. EEP_FTFC_VERIFY_ONLY_DISABLED = 0x0, /**< @brief control code for sfe verify only disabled, used for the partitioning command */
  189. EEP_FTFC_VERIFY_ONLY_ENABLED = 0x1 /**< @brief control code for sfe verify only enabled, used for the partitioning command */
  190. } TestEep_SfeType;
  191. /**
  192. @brief LoadFlexRam at reset Type used for the partitioning command
  193. */
  194. typedef enum
  195. {
  196. EEP_FTFC_LOAD_AT_RESET_ENABLED = 0x0, /**< @brief control code for loading flexram at reset, used for the partitioning command */
  197. EEP_FTFC_LOAD_AT_RESET_DISABLED = 0x1 /**< @brief control code for not loading flexram at reset, used for the partitioning command */
  198. } TestEep_LoadFlexRamType;
  199. #define EEP_ERASE_START_ADD (0U)
  200. #define EEP_WRTESTPATT_SIZE (33U)
  201. #define EEP_RDTESTPATT_SIZE (33U)
  202. #define REG_WRITE8(address, value) (*((volatile uint8 *)(address)) = (value))
  203. #define REG_BIT_GET8(address, mask) ((*(volatile uint8 *)(address)) & (mask))
  204. #define T_EEEPROM_SIZE EEP_FTFC_EEEPROM_SIZE_32K_V2
  205. #define TEST_EEP_EEPROM_FSTAT_ADDR32 ((uint32)(IP_FTFC_BASE + (uint32)0x00UL)) /**< @brief Eeprom Status Register (FTFE_FSTAT) */
  206. #define TEST_EEP_EEPROM_FCCOB3_ADDR32 ((uint32)(IP_FTFC_BASE + (uint32)0x04UL)) /**< @brief Eeprom Common Command Object Registers(FTFE_FCCOB3) */
  207. #define TEST_EEP_EEPROM_FCCOB2_ADDR32 ((uint32)(IP_FTFC_BASE + (uint32)0x05UL)) /**< @brief Eeprom Common Command Object Registers(FTFE_FCCOB2) */
  208. #define TEST_EEP_EEPROM_FCCOB1_ADDR32 ((uint32)(IP_FTFC_BASE + (uint32)0x06UL)) /**< @brief Eeprom Common Command Object Registers(FTFE_FCCOB1) */
  209. #define TEST_EEP_EEPROM_FCCOB0_ADDR32 ((uint32)(IP_FTFC_BASE + (uint32)0x07UL)) /**< @brief Eeprom Common Command Object Registers(FTFE_FCCOB0) */
  210. #define TEST_EEP_EEPROM_FCCOB7_ADDR32 ((uint32)(IP_FTFC_BASE + (uint32)0x08UL)) /**< @brief Eeprom Common Command Object Registers(FTFE_FCCOB7) */
  211. #define TEST_EEP_EEPROM_FCCOB6_ADDR32 ((uint32)(IP_FTFC_BASE + (uint32)0x09UL)) /**< @brief Eeprom Common Command Object Registers(FTFE_FCCOB6) */
  212. #define TEST_EEP_EEPROM_FCCOB5_ADDR32 ((uint32)(IP_FTFC_BASE + (uint32)0x0AUL)) /**< @brief Eeprom Common Command Object Registers(FTFE_FCCOB5) */
  213. #define TEST_EEP_EEPROM_FCCOB4_ADDR32 ((uint32)(IP_FTFC_BASE + (uint32)0x0BUL)) /**< @brief Eeprom Common Command Object Registers(FTFE_FCCOB4) */
  214. #define TEST_EEP_EEPROM_FSTAT_CCIF_U8 (0x0080U)
  215. #define TEST_EEP_EEPROM_FSTAT_ACCERR_U8 (0x0020U)
  216. #define TEST_EEP_EEPROM_FSTAT_FPVIOL_U8 (0x0010U)
  217. /* Start address for DFLASH sector 0 */
  218. #define TEST_EEP_DEEPROM_SECTOR_0_ADDR32 0x10000000
  219. #define D_EEPROM_BASE_ADDR (0x10000000UL)
  220. #define TEST_EEP_EEPROM_CMD_ERASE_SECTOR (0x09UL)
  221. #define EEPROM_CMD_PROGRAM_PARTITION (0x80UL)
  222. extern Std_ReturnType CanIf_SendMessage(uint8 ControllerId, Can_Msg_Type CanMsg);
  223. void Eep_DepartParitition(TestEep_Eeprom_FlexNvmPartitionType T_EEP_SIZE);
  224. Std_ReturnType HAL_EEP_Erase(uint32 eepEraseStartAddr, uint32 eepEraseSize);
  225. Std_ReturnType HAL_EEP_Read(uint32 eepReadStartAddr, uint8 *pDataBuffer, uint32 dataSize);
  226. Std_ReturnType HAL_EEP_Write(uint32 eepWriteStartAddr, uint8 *pDataNeedtoWrite, uint32 dataSize);
  227. Std_ReturnType HAL_EEP_Compare(uint32 eepCompareStartAddr, uint8 *pDataNeedtoCompare, uint32 dataSize);
  228. Std_ReturnType ADC_ReadValue(void);
  229. sint8 AtcmdDelayRecvFunc(uint8 recvChannel, char *ResultStrPtr, uint16 delayTime);
  230. Std_ReturnType UART_Query_Data(uint8 transChannel, uint8 recvChannel, uint8 *txBuffer, uint16 sendLength, uint8 *rxBuffer, uint16 *rxlen, uint32 T_timeout);
  231. Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32 sendLength, uint32 T_timeout);
  232. Std_ReturnType UART_Receive_Data(uint8 recvChannel, uint8 *rxBuffer, uint16 *rxlen, uint32 T_timeout);
  233. Std_ReturnType Tcp_Receive_Data(uint8 *rxBuffer, uint16 *rxlen, uint32 T_timeout);
  234. Std_ReturnType UART_Reset(uint8 recvChannel);
  235. void UART_Callback(uint32 hwInstance, Lpuart_Uart_Ip_EventType event);
  236. void UartInit(void);
  237. void SystemSoftwareReset(void);
  238. void create_ringBuffer(ringbuffer_t *ringBuf, uint8_t *buf, uint32_t buf_len);
  239. void clear_ringBuffer(ringbuffer_t *ringBuf);
  240. //uint32_t write_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf);
  241. //uint32_t read_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf);
  242. void coreInit(void);
  243. void SystemModulesInit(void);
  244. void Icu_DeInit(void);
  245. void SystemDeinit(void);
  246. void MCUSleep(void);
  247. void MCUEnterSleep(void);
  248. void displayResetReasonWithLED(void);
  249. void readConfigAndDataFromEEPROM(void);
  250. void IH_Data_Update(void);
  251. void OH_Data_Update(void);
  252. #endif /* HAL_ADAPTER_H_ */