hal_adapter.h 11 KB

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