hal_adapter.h 10 KB

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