選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

1423 行
60 KiB

  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2020 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_FLEXCAN_H_
  9. #define _FSL_FLEXCAN_H_
  10. #include "fsl_common.h"
  11. /*!
  12. * @addtogroup flexcan_driver
  13. * @{
  14. */
  15. /******************************************************************************
  16. * Definitions
  17. *****************************************************************************/
  18. /*! @name Driver version */
  19. /*@{*/
  20. /*! @brief FlexCAN driver version. */
  21. #define FSL_FLEXCAN_DRIVER_VERSION (MAKE_VERSION(2, 5, 2))
  22. /*@}*/
  23. #if !(defined(FLEXCAN_WAIT_TIMEOUT) && FLEXCAN_WAIT_TIMEOUT)
  24. /* Define to 1000 means keep waiting 1000 times until the flag is assert/deassert. */
  25. #define FLEXCAN_WAIT_TIMEOUT (1000U)
  26. #endif
  27. /*! @brief FlexCAN Frame ID helper macro. */
  28. #define FLEXCAN_ID_STD(id) \
  29. (((uint32_t)(((uint32_t)(id)) << CAN_ID_STD_SHIFT)) & CAN_ID_STD_MASK) /*!< Standard Frame ID helper macro. */
  30. #define FLEXCAN_ID_EXT(id) \
  31. (((uint32_t)(((uint32_t)(id)) << CAN_ID_EXT_SHIFT)) & \
  32. (CAN_ID_EXT_MASK | CAN_ID_STD_MASK)) /*!< Extend Frame ID helper macro. */
  33. /*! @brief FlexCAN Rx Message Buffer Mask helper macro. */
  34. #define FLEXCAN_RX_MB_STD_MASK(id, rtr, ide) \
  35. (((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
  36. FLEXCAN_ID_STD(id)) /*!< Standard Rx Message Buffer Mask helper macro. */
  37. #define FLEXCAN_RX_MB_EXT_MASK(id, rtr, ide) \
  38. (((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
  39. FLEXCAN_ID_EXT(id)) /*!< Extend Rx Message Buffer Mask helper macro. */
  40. /*! @brief FlexCAN Rx FIFO Mask helper macro. */
  41. #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_A(id, rtr, ide) \
  42. (((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
  43. (FLEXCAN_ID_STD(id) << 1)) /*!< Standard Rx FIFO Mask helper macro Type A helper macro. */
  44. #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_HIGH(id, rtr, ide) \
  45. (((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
  46. (((uint32_t)(id)&0x7FF) << 19)) /*!< Standard Rx FIFO Mask helper macro Type B upper part helper macro. */
  47. #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_LOW(id, rtr, ide) \
  48. (((uint32_t)((uint32_t)(rtr) << 15) | (uint32_t)((uint32_t)(ide) << 14)) | \
  49. (((uint32_t)(id)&0x7FF) << 3)) /*!< Standard Rx FIFO Mask helper macro Type B lower part helper macro. */
  50. #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_HIGH(id) \
  51. (((uint32_t)(id)&0x7F8) << 21) /*!< Standard Rx FIFO Mask helper macro Type C upper part helper macro. */
  52. #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_HIGH(id) \
  53. (((uint32_t)(id)&0x7F8) << 13) /*!< Standard Rx FIFO Mask helper macro Type C mid-upper part helper macro. */
  54. #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_LOW(id) \
  55. (((uint32_t)(id)&0x7F8) << 5) /*!< Standard Rx FIFO Mask helper macro Type C mid-lower part helper macro. */
  56. #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_LOW(id) \
  57. (((uint32_t)(id)&0x7F8) >> 3) /*!< Standard Rx FIFO Mask helper macro Type C lower part helper macro. */
  58. #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_A(id, rtr, ide) \
  59. (((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
  60. (FLEXCAN_ID_EXT(id) << 1)) /*!< Extend Rx FIFO Mask helper macro Type A helper macro. */
  61. #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_HIGH(id, rtr, ide) \
  62. ( \
  63. ((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
  64. ((FLEXCAN_ID_EXT(id) & 0x1FFF8000) \
  65. << 1)) /*!< Extend Rx FIFO Mask helper macro Type B upper part helper macro. */
  66. #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_LOW(id, rtr, ide) \
  67. (((uint32_t)((uint32_t)(rtr) << 15) | (uint32_t)((uint32_t)(ide) << 14)) | \
  68. ((FLEXCAN_ID_EXT(id) & 0x1FFF8000) >> \
  69. 15)) /*!< Extend Rx FIFO Mask helper macro Type B lower part helper macro. */
  70. #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_HIGH(id) \
  71. ((FLEXCAN_ID_EXT(id) & 0x1FE00000) << 3) /*!< Extend Rx FIFO Mask helper macro Type C upper part helper macro. */
  72. #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_HIGH(id) \
  73. ((FLEXCAN_ID_EXT(id) & 0x1FE00000) >> \
  74. 5) /*!< Extend Rx FIFO Mask helper macro Type C mid-upper part helper macro. */
  75. #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_LOW(id) \
  76. ((FLEXCAN_ID_EXT(id) & 0x1FE00000) >> \
  77. 13) /*!< Extend Rx FIFO Mask helper macro Type C mid-lower part helper macro. */
  78. #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_LOW(id) \
  79. ((FLEXCAN_ID_EXT(id) & 0x1FE00000) >> 21) /*!< Extend Rx FIFO Mask helper macro Type C lower part helper macro. */
  80. /*! @brief FlexCAN Rx FIFO Filter helper macro. */
  81. #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_A(id, rtr, ide) \
  82. FLEXCAN_RX_FIFO_STD_MASK_TYPE_A(id, rtr, ide) /*!< Standard Rx FIFO Filter helper macro Type A helper macro. */
  83. #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_B_HIGH(id, rtr, ide) \
  84. FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_HIGH( \
  85. id, rtr, ide) /*!< Standard Rx FIFO Filter helper macro Type B upper part helper macro. */
  86. #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_B_LOW(id, rtr, ide) \
  87. FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_LOW( \
  88. id, rtr, ide) /*!< Standard Rx FIFO Filter helper macro Type B lower part helper macro. */
  89. #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_HIGH(id) \
  90. FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_HIGH( \
  91. id) /*!< Standard Rx FIFO Filter helper macro Type C upper part helper macro. */
  92. #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_MID_HIGH(id) \
  93. FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_HIGH( \
  94. id) /*!< Standard Rx FIFO Filter helper macro Type C mid-upper part helper macro. */
  95. #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_MID_LOW(id) \
  96. FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_LOW( \
  97. id) /*!< Standard Rx FIFO Filter helper macro Type C mid-lower part helper macro. */
  98. #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_LOW(id) \
  99. FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_LOW( \
  100. id) /*!< Standard Rx FIFO Filter helper macro Type C lower part helper macro. */
  101. #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_A(id, rtr, ide) \
  102. FLEXCAN_RX_FIFO_EXT_MASK_TYPE_A(id, rtr, ide) /*!< Extend Rx FIFO Filter helper macro Type A helper macro. */
  103. #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_B_HIGH(id, rtr, ide) \
  104. FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_HIGH( \
  105. id, rtr, ide) /*!< Extend Rx FIFO Filter helper macro Type B upper part helper macro. */
  106. #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_B_LOW(id, rtr, ide) \
  107. FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_LOW( \
  108. id, rtr, ide) /*!< Extend Rx FIFO Filter helper macro Type B lower part helper macro. */
  109. #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_HIGH(id) \
  110. FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_HIGH( \
  111. id) /*!< Extend Rx FIFO Filter helper macro Type C upper part helper macro. */
  112. #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_MID_HIGH(id) \
  113. FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_HIGH( \
  114. id) /*!< Extend Rx FIFO Filter helper macro Type C mid-upper part helper macro. */
  115. #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_MID_LOW(id) \
  116. FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_LOW( \
  117. id) /*!< Extend Rx FIFO Filter helper macro Type C mid-lower part helper macro. */
  118. #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_LOW(id) \
  119. FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_LOW(id) /*!< Extend Rx FIFO Filter helper macro Type C lower part helper macro. */
  120. /*! @brief FlexCAN transfer status. */
  121. enum
  122. {
  123. kStatus_FLEXCAN_TxBusy = MAKE_STATUS(kStatusGroup_FLEXCAN, 0), /*!< Tx Message Buffer is Busy. */
  124. kStatus_FLEXCAN_TxIdle = MAKE_STATUS(kStatusGroup_FLEXCAN, 1), /*!< Tx Message Buffer is Idle. */
  125. kStatus_FLEXCAN_TxSwitchToRx = MAKE_STATUS(
  126. kStatusGroup_FLEXCAN, 2), /*!< Remote Message is send out and Message buffer changed to Receive one. */
  127. kStatus_FLEXCAN_RxBusy = MAKE_STATUS(kStatusGroup_FLEXCAN, 3), /*!< Rx Message Buffer is Busy. */
  128. kStatus_FLEXCAN_RxIdle = MAKE_STATUS(kStatusGroup_FLEXCAN, 4), /*!< Rx Message Buffer is Idle. */
  129. kStatus_FLEXCAN_RxOverflow = MAKE_STATUS(kStatusGroup_FLEXCAN, 5), /*!< Rx Message Buffer is Overflowed. */
  130. kStatus_FLEXCAN_RxFifoBusy = MAKE_STATUS(kStatusGroup_FLEXCAN, 6), /*!< Rx Message FIFO is Busy. */
  131. kStatus_FLEXCAN_RxFifoIdle = MAKE_STATUS(kStatusGroup_FLEXCAN, 7), /*!< Rx Message FIFO is Idle. */
  132. kStatus_FLEXCAN_RxFifoOverflow = MAKE_STATUS(kStatusGroup_FLEXCAN, 8), /*!< Rx Message FIFO is overflowed. */
  133. kStatus_FLEXCAN_RxFifoWarning = MAKE_STATUS(kStatusGroup_FLEXCAN, 9), /*!< Rx Message FIFO is almost overflowed. */
  134. kStatus_FLEXCAN_ErrorStatus = MAKE_STATUS(kStatusGroup_FLEXCAN, 10), /*!< FlexCAN Module Error and Status. */
  135. kStatus_FLEXCAN_WakeUp = MAKE_STATUS(kStatusGroup_FLEXCAN, 11), /*!< FlexCAN is waken up from STOP mode. */
  136. kStatus_FLEXCAN_UnHandled = MAKE_STATUS(kStatusGroup_FLEXCAN, 12), /*!< UnHadled Interrupt asserted. */
  137. kStatus_FLEXCAN_RxRemote = MAKE_STATUS(kStatusGroup_FLEXCAN, 13), /*!< Rx Remote Message Received in Mail box. */
  138. };
  139. /*! @brief FlexCAN frame format. */
  140. typedef enum _flexcan_frame_format
  141. {
  142. kFLEXCAN_FrameFormatStandard = 0x0U, /*!< Standard frame format attribute. */
  143. kFLEXCAN_FrameFormatExtend = 0x1U, /*!< Extend frame format attribute. */
  144. } flexcan_frame_format_t;
  145. /*! @brief FlexCAN frame type. */
  146. typedef enum _flexcan_frame_type
  147. {
  148. kFLEXCAN_FrameTypeData = 0x0U, /*!< Data frame type attribute. */
  149. kFLEXCAN_FrameTypeRemote = 0x1U, /*!< Remote frame type attribute. */
  150. } flexcan_frame_type_t;
  151. /*! @brief FlexCAN clock source.
  152. * @deprecated Do not use the kFLEXCAN_ClkSrcOs. It has been superceded kFLEXCAN_ClkSrc0
  153. * @deprecated Do not use the kFLEXCAN_ClkSrcPeri. It has been superceded kFLEXCAN_ClkSrc1
  154. */
  155. typedef enum _flexcan_clock_source
  156. {
  157. kFLEXCAN_ClkSrcOsc = 0x0U, /*!< FlexCAN Protocol Engine clock from Oscillator. */
  158. kFLEXCAN_ClkSrcPeri = 0x1U, /*!< FlexCAN Protocol Engine clock from Peripheral Clock. */
  159. kFLEXCAN_ClkSrc0 = 0x0U, /*!< FlexCAN Protocol Engine clock selected by user as SRC == 0. */
  160. kFLEXCAN_ClkSrc1 = 0x1U, /*!< FlexCAN Protocol Engine clock selected by user as SRC == 1. */
  161. } flexcan_clock_source_t;
  162. /*! @brief FlexCAN wake up source. */
  163. typedef enum _flexcan_wake_up_source
  164. {
  165. kFLEXCAN_WakeupSrcUnfiltered = 0x0U, /*!< FlexCAN uses unfiltered Rx input to detect edge. */
  166. kFLEXCAN_WakeupSrcFiltered = 0x1U, /*!< FlexCAN uses filtered Rx input to detect edge. */
  167. } flexcan_wake_up_source_t;
  168. /*! @brief FlexCAN Rx Fifo Filter type. */
  169. typedef enum _flexcan_rx_fifo_filter_type
  170. {
  171. kFLEXCAN_RxFifoFilterTypeA = 0x0U, /*!< One full ID (standard and extended) per ID Filter element. */
  172. kFLEXCAN_RxFifoFilterTypeB =
  173. 0x1U, /*!< Two full standard IDs or two partial 14-bit ID slices per ID Filter Table element. */
  174. kFLEXCAN_RxFifoFilterTypeC =
  175. 0x2U, /*!< Four partial 8-bit Standard or extended ID slices per ID Filter Table element. */
  176. kFLEXCAN_RxFifoFilterTypeD = 0x3U, /*!< All frames rejected. */
  177. } flexcan_rx_fifo_filter_type_t;
  178. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  179. /*!
  180. * @brief FlexCAN Message Buffer Data Size.
  181. */
  182. typedef enum _flexcan_mb_size
  183. {
  184. kFLEXCAN_8BperMB = 0x0U, /*!< Selects 8 bytes per Message Buffer. */
  185. kFLEXCAN_16BperMB = 0x1U, /*!< Selects 16 bytes per Message Buffer. */
  186. kFLEXCAN_32BperMB = 0x2U, /*!< Selects 32 bytes per Message Buffer. */
  187. kFLEXCAN_64BperMB = 0x3U, /*!< Selects 64 bytes per Message Buffer. */
  188. } flexcan_mb_size_t;
  189. #endif
  190. /*!
  191. * @brief FlexCAN Rx FIFO priority.
  192. *
  193. * The matching process starts from the Rx MB(or Rx FIFO) with higher priority.
  194. * If no MB(or Rx FIFO filter) is satisfied, the matching process goes on with
  195. * the Rx FIFO(or Rx MB) with lower priority.
  196. */
  197. typedef enum _flexcan_rx_fifo_priority
  198. {
  199. kFLEXCAN_RxFifoPrioLow = 0x0U, /*!< Matching process start from Rx Message Buffer first*/
  200. kFLEXCAN_RxFifoPrioHigh = 0x1U, /*!< Matching process start from Rx FIFO first*/
  201. } flexcan_rx_fifo_priority_t;
  202. /*!
  203. * @brief FlexCAN interrupt configuration structure, default settings all disabled.
  204. *
  205. * This structure contains the settings for all of the FlexCAN Module interrupt configurations.
  206. * Note: FlexCAN Message Buffers and Rx FIFO have their own interrupts.
  207. */
  208. enum _flexcan_interrupt_enable
  209. {
  210. kFLEXCAN_BusOffInterruptEnable = CAN_CTRL1_BOFFMSK_MASK, /*!< Bus Off interrupt. */
  211. kFLEXCAN_ErrorInterruptEnable = CAN_CTRL1_ERRMSK_MASK, /*!< Error interrupt. */
  212. kFLEXCAN_RxWarningInterruptEnable = CAN_CTRL1_RWRNMSK_MASK, /*!< Rx Warning interrupt. */
  213. kFLEXCAN_TxWarningInterruptEnable = CAN_CTRL1_TWRNMSK_MASK, /*!< Tx Warning interrupt. */
  214. kFLEXCAN_WakeUpInterruptEnable = CAN_MCR_WAKMSK_MASK, /*!< Wake Up interrupt. */
  215. };
  216. /*!
  217. * @brief FlexCAN status flags.
  218. *
  219. * This provides constants for the FlexCAN status flags for use in the FlexCAN functions.
  220. * Note: The CPU read action clears FlEXCAN_ErrorFlag, therefore user need to
  221. * read FlEXCAN_ErrorFlag and distinguish which error is occur using
  222. * @ref _flexcan_error_flags enumerations.
  223. */
  224. enum _flexcan_flags
  225. {
  226. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  227. kFLEXCAN_FDErrorIntFlag = CAN_ESR1_ERRINT_FAST_MASK, /*!< Error Overrun Status. */
  228. kFLEXCAN_BusoffDoneIntFlag = CAN_ESR1_BOFFDONEINT_MASK, /*!< Error Overrun Status. */
  229. #endif
  230. kFLEXCAN_SynchFlag = CAN_ESR1_SYNCH_MASK, /*!< CAN Synchronization Status. */
  231. kFLEXCAN_TxWarningIntFlag = CAN_ESR1_TWRNINT_MASK, /*!< Tx Warning Interrupt Flag. */
  232. kFLEXCAN_RxWarningIntFlag = CAN_ESR1_RWRNINT_MASK, /*!< Rx Warning Interrupt Flag. */
  233. kFLEXCAN_TxErrorWarningFlag = CAN_ESR1_TXWRN_MASK, /*!< Tx Error Warning Status. */
  234. kFLEXCAN_RxErrorWarningFlag = CAN_ESR1_RXWRN_MASK, /*!< Rx Error Warning Status. */
  235. kFLEXCAN_IdleFlag = CAN_ESR1_IDLE_MASK, /*!< CAN IDLE Status Flag. */
  236. kFLEXCAN_FaultConfinementFlag = CAN_ESR1_FLTCONF_MASK, /*!< Fault Confinement State Flag. */
  237. kFLEXCAN_TransmittingFlag = CAN_ESR1_TX_MASK, /*!< FlexCAN In Transmission Status. */
  238. kFLEXCAN_ReceivingFlag = CAN_ESR1_RX_MASK, /*!< FlexCAN In Reception Status. */
  239. kFLEXCAN_BusOffIntFlag = CAN_ESR1_BOFFINT_MASK, /*!< Bus Off Interrupt Flag. */
  240. kFLEXCAN_ErrorIntFlag = CAN_ESR1_ERRINT_MASK, /*!< Error Interrupt Flag. */
  241. kFLEXCAN_WakeUpIntFlag = CAN_ESR1_WAKINT_MASK, /*!< Wake-Up Interrupt Flag. */
  242. kFLEXCAN_ErrorFlag = (int)( /*!< All FlexCAN Error Status. */
  243. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  244. CAN_ESR1_STFERR_FAST_MASK | CAN_ESR1_FRMERR_FAST_MASK | CAN_ESR1_CRCERR_FAST_MASK |
  245. CAN_ESR1_BIT0ERR_FAST_MASK | CAN_ESR1_BIT1ERR_FAST_MASK | CAN_ESR1_ERROVR_MASK |
  246. #endif
  247. CAN_ESR1_BIT1ERR_MASK | CAN_ESR1_BIT0ERR_MASK | CAN_ESR1_ACKERR_MASK |
  248. CAN_ESR1_CRCERR_MASK | CAN_ESR1_FRMERR_MASK | CAN_ESR1_STFERR_MASK),
  249. };
  250. /*!
  251. * @brief FlexCAN error status flags.
  252. *
  253. * The FlexCAN Error Status enumerations is used to report current error of the FlexCAN bus.
  254. * This enumerations should be used with KFLEXCAN_ErrorFlag in @ref _flexcan_flags enumerations
  255. * to ditermine which error is generated.
  256. */
  257. enum _flexcan_error_flags
  258. {
  259. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  260. kFLEXCAN_FDStuffingError = CAN_ESR1_STFERR_FAST_MASK, /*!< Stuffing Error. */
  261. kFLEXCAN_FDFormError = CAN_ESR1_FRMERR_FAST_MASK, /*!< Form Error. */
  262. kFLEXCAN_FDCrcError = CAN_ESR1_CRCERR_FAST_MASK, /*!< Cyclic Redundancy Check Error. */
  263. kFLEXCAN_FDBit0Error = CAN_ESR1_BIT0ERR_FAST_MASK, /*!< Unable to send dominant bit. */
  264. kFLEXCAN_FDBit1Error = (int)CAN_ESR1_BIT1ERR_FAST_MASK, /*!< Unable to send recessive bit. */
  265. kFLEXCAN_OverrunError = CAN_ESR1_ERROVR_MASK, /*!< Error Overrun Status. */
  266. #endif
  267. kFLEXCAN_StuffingError = CAN_ESR1_STFERR_MASK, /*!< Stuffing Error. */
  268. kFLEXCAN_FormError = CAN_ESR1_FRMERR_MASK, /*!< Form Error. */
  269. kFLEXCAN_CrcError = CAN_ESR1_CRCERR_MASK, /*!< Cyclic Redundancy Check Error. */
  270. kFLEXCAN_AckError = CAN_ESR1_ACKERR_MASK, /*!< Received no ACK on transmission. */
  271. kFLEXCAN_Bit0Error = CAN_ESR1_BIT0ERR_MASK, /*!< Unable to send dominant bit. */
  272. kFLEXCAN_Bit1Error = CAN_ESR1_BIT1ERR_MASK, /*!< Unable to send recessive bit. */
  273. };
  274. /*!
  275. * @brief FlexCAN Rx FIFO status flags.
  276. *
  277. * The FlexCAN Rx FIFO Status enumerations are used to determine the status of the
  278. * Rx FIFO. Because Rx FIFO occupy the MB0 ~ MB7 (Rx Fifo filter also occupies
  279. * more Message Buffer space), Rx FIFO status flags are mapped to the corresponding
  280. * Message Buffer status flags.
  281. */
  282. enum
  283. {
  284. kFLEXCAN_RxFifoOverflowFlag = CAN_IFLAG1_BUF7I_MASK, /*!< Rx FIFO overflow flag. */
  285. kFLEXCAN_RxFifoWarningFlag = CAN_IFLAG1_BUF6I_MASK, /*!< Rx FIFO almost full flag. */
  286. kFLEXCAN_RxFifoFrameAvlFlag = CAN_IFLAG1_BUF5I_MASK, /*!< Frames available in Rx FIFO flag. */
  287. };
  288. #if defined(__CC_ARM)
  289. #pragma anon_unions
  290. #endif
  291. /*! @brief FlexCAN message frame structure. */
  292. typedef struct _flexcan_frame
  293. {
  294. struct
  295. {
  296. uint32_t timestamp : 16; /*!< FlexCAN internal Free-Running Counter Time Stamp. */
  297. uint32_t length : 4; /*!< CAN frame payload length in bytes(Range: 0~8). */
  298. uint32_t type : 1; /*!< CAN Frame Type(DATA or REMOTE). */
  299. uint32_t format : 1; /*!< CAN Frame Identifier(STD or EXT format). */
  300. uint32_t : 1; /*!< Reserved. */
  301. uint32_t idhit : 9; /*!< CAN Rx FIFO filter hit id(This value is only used in Rx FIFO receive mode). */
  302. };
  303. struct
  304. {
  305. uint32_t id : 29; /*!< CAN Frame Identifier, should be set using FLEXCAN_ID_EXT() or FLEXCAN_ID_STD() macro. */
  306. uint32_t : 3; /*!< Reserved. */
  307. };
  308. union
  309. {
  310. struct
  311. {
  312. uint32_t dataWord0; /*!< CAN Frame payload word0. */
  313. uint32_t dataWord1; /*!< CAN Frame payload word1. */
  314. };
  315. struct
  316. {
  317. uint8_t dataByte3; /*!< CAN Frame payload byte3. */
  318. uint8_t dataByte2; /*!< CAN Frame payload byte2. */
  319. uint8_t dataByte1; /*!< CAN Frame payload byte1. */
  320. uint8_t dataByte0; /*!< CAN Frame payload byte0. */
  321. uint8_t dataByte7; /*!< CAN Frame payload byte7. */
  322. uint8_t dataByte6; /*!< CAN Frame payload byte6. */
  323. uint8_t dataByte5; /*!< CAN Frame payload byte5. */
  324. uint8_t dataByte4; /*!< CAN Frame payload byte4. */
  325. };
  326. };
  327. } flexcan_frame_t;
  328. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  329. /*! @brief CAN FDmessage frame structure. */
  330. typedef struct _flexcan_fd_frame
  331. {
  332. struct
  333. {
  334. uint32_t timestamp : 16; /*!< FlexCAN internal Free-Running Counter Time Stamp. */
  335. uint32_t length : 4; /*!< CAN frame payload length in bytes(Range: 0~8). */
  336. uint32_t type : 1; /*!< CAN Frame Type(DATA or REMOTE). */
  337. uint32_t format : 1; /*!< CAN Frame Identifier(STD or EXT format). */
  338. uint32_t srr : 1; /*!< Substitute Remote request. */
  339. uint32_t : 1;
  340. uint32_t code : 4; /*!< Message Buffer Code. */
  341. uint32_t : 1;
  342. uint32_t esi : 1; /*!< Error State Indicator. */
  343. uint32_t brs : 1; /*!< Bit Rate Switch. */
  344. uint32_t edl : 1; /*!< Extended Data Length. */
  345. };
  346. struct
  347. {
  348. uint32_t id : 29; /*!< CAN Frame Identifier, should be set using FLEXCAN_ID_EXT() or FLEXCAN_ID_STD() macro. */
  349. uint32_t : 3; /*!< Reserved. */
  350. };
  351. union
  352. {
  353. struct
  354. {
  355. uint32_t dataWord[16]; /*!< CAN FD Frame payload, 16 double word maximum. */
  356. };
  357. /* Note: the maximum databyte* below is actually 64, user can add them if needed,
  358. or just use dataWord[*] instead. */
  359. struct
  360. {
  361. uint8_t dataByte3; /*!< CAN Frame payload byte3. */
  362. uint8_t dataByte2; /*!< CAN Frame payload byte2. */
  363. uint8_t dataByte1; /*!< CAN Frame payload byte1. */
  364. uint8_t dataByte0; /*!< CAN Frame payload byte0. */
  365. uint8_t dataByte7; /*!< CAN Frame payload byte7. */
  366. uint8_t dataByte6; /*!< CAN Frame payload byte6. */
  367. uint8_t dataByte5; /*!< CAN Frame payload byte5. */
  368. uint8_t dataByte4; /*!< CAN Frame payload byte4. */
  369. };
  370. };
  371. } flexcan_fd_frame_t;
  372. #endif
  373. /*! @brief FlexCAN protocol timing characteristic configuration structure. */
  374. typedef struct _flexcan_timing_config
  375. {
  376. uint16_t preDivider; /*!< Clock Pre-scaler Division Factor. */
  377. uint8_t rJumpwidth; /*!< Re-sync Jump Width. */
  378. uint8_t phaseSeg1; /*!< Phase Segment 1. */
  379. uint8_t phaseSeg2; /*!< Phase Segment 2. */
  380. uint8_t propSeg; /*!< Propagation Segment. */
  381. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  382. uint16_t fpreDivider; /*!< Fast Clock Pre-scaler Division Factor. */
  383. uint8_t frJumpwidth; /*!< Fast Re-sync Jump Width. */
  384. uint8_t fphaseSeg1; /*!< Fast Phase Segment 1. */
  385. uint8_t fphaseSeg2; /*!< Fast Phase Segment 2. */
  386. uint8_t fpropSeg; /*!< Fast Propagation Segment. */
  387. #endif
  388. } flexcan_timing_config_t;
  389. /*! @brief FlexCAN module configuration structure. */
  390. typedef struct _flexcan_config
  391. {
  392. uint32_t baudRate; /*!< FlexCAN baud rate in bps. */
  393. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  394. uint32_t baudRateFD; /*!< FlexCAN FD baud rate in bps. */
  395. #endif
  396. flexcan_clock_source_t clkSrc; /*!< Clock source for FlexCAN Protocol Engine. */
  397. flexcan_wake_up_source_t wakeupSrc; /*!< Wake up source selection. */
  398. uint8_t maxMbNum; /*!< The maximum number of Message Buffers used by user. */
  399. bool enableLoopBack; /*!< Enable or Disable Loop Back Self Test Mode. */
  400. bool enableTimerSync; /*!< Enable or Disable Timer Synchronization. */
  401. bool enableSelfWakeup; /*!< Enable or Disable Self Wakeup Mode. */
  402. bool enableIndividMask; /*!< Enable or Disable Rx Individual Mask. */
  403. bool disableSelfReception; /*!< Enable or Disable Self Reflection. */
  404. bool enableListenOnlyMode; /*!< Enable or Disable Listen Only Mode. */
  405. #if (defined(FSL_FEATURE_FLEXCAN_HAS_DOZE_MODE_SUPPORT) && FSL_FEATURE_FLEXCAN_HAS_DOZE_MODE_SUPPORT)
  406. bool enableDoze; /*!< Enable or Disable Doze Mode. */
  407. #endif
  408. flexcan_timing_config_t timingConfig; /* Protocol timing . */
  409. } flexcan_config_t;
  410. /*!
  411. * @brief FlexCAN Receive Message Buffer configuration structure
  412. *
  413. * This structure is used as the parameter of FLEXCAN_SetRxMbConfig() function.
  414. * The FLEXCAN_SetRxMbConfig() function is used to configure FlexCAN Receive
  415. * Message Buffer. The function abort previous receiving process, clean the
  416. * Message Buffer and activate the Rx Message Buffer using given Message Buffer
  417. * setting.
  418. */
  419. typedef struct _flexcan_rx_mb_config
  420. {
  421. uint32_t id; /*!< CAN Message Buffer Frame Identifier, should be set using
  422. FLEXCAN_ID_EXT() or FLEXCAN_ID_STD() macro. */
  423. flexcan_frame_format_t format; /*!< CAN Frame Identifier format(Standard of Extend). */
  424. flexcan_frame_type_t type; /*!< CAN Frame Type(Data or Remote). */
  425. } flexcan_rx_mb_config_t;
  426. /*! @brief FlexCAN Rx FIFO configuration structure. */
  427. typedef struct _flexcan_rx_fifo_config
  428. {
  429. uint32_t *idFilterTable; /*!< Pointer to the FlexCAN Rx FIFO identifier filter table. */
  430. uint8_t idFilterNum; /*!< The quantity of filter elements. */
  431. flexcan_rx_fifo_filter_type_t idFilterType; /*!< The FlexCAN Rx FIFO Filter type. */
  432. flexcan_rx_fifo_priority_t priority; /*!< The FlexCAN Rx FIFO receive priority. */
  433. } flexcan_rx_fifo_config_t;
  434. /*! @brief FlexCAN Message Buffer transfer. */
  435. typedef struct _flexcan_mb_transfer
  436. {
  437. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  438. flexcan_fd_frame_t *framefd;
  439. #endif
  440. flexcan_frame_t *frame; /*!< The buffer of CAN Message to be transfer. */
  441. uint8_t mbIdx; /*!< The index of Message buffer used to transfer Message. */
  442. } flexcan_mb_transfer_t;
  443. /*! @brief FlexCAN Rx FIFO transfer. */
  444. typedef struct _flexcan_fifo_transfer
  445. {
  446. flexcan_frame_t *frame; /*!< The buffer of CAN Message to be received from Rx FIFO. */
  447. } flexcan_fifo_transfer_t;
  448. /*! @brief FlexCAN handle structure definition. */
  449. typedef struct _flexcan_handle flexcan_handle_t;
  450. /*! @brief FlexCAN transfer callback function.
  451. *
  452. * The FlexCAN transfer callback returns a value from the underlying layer.
  453. * If the status equals to kStatus_FLEXCAN_ErrorStatus, the result parameter is the Content of
  454. * FlexCAN status register which can be used to get the working status(or error status) of FlexCAN module.
  455. * If the status equals to other FlexCAN Message Buffer transfer status, the result is the index of
  456. * Message Buffer that generate transfer event.
  457. * If the status equals to other FlexCAN Message Buffer transfer status, the result is meaningless and should be
  458. * Ignored.
  459. */
  460. typedef void (*flexcan_transfer_callback_t)(
  461. CAN_Type *base, flexcan_handle_t *handle, status_t status, uint32_t result, void *userData);
  462. /*! @brief FlexCAN handle structure. */
  463. struct _flexcan_handle
  464. {
  465. flexcan_transfer_callback_t callback; /*!< Callback function. */
  466. void *userData; /*!< FlexCAN callback function parameter.*/
  467. flexcan_frame_t *volatile mbFrameBuf[CAN_WORD1_COUNT];
  468. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  469. flexcan_fd_frame_t *volatile mbFDFrameBuf[CAN_WORD1_COUNT];
  470. #endif
  471. /*!< The buffer for received data from Message Buffers. */
  472. flexcan_frame_t *volatile rxFifoFrameBuf; /*!< The buffer for received data from Rx FIFO. */
  473. volatile uint8_t mbState[CAN_WORD1_COUNT]; /*!< Message Buffer transfer state. */
  474. volatile uint8_t rxFifoState; /*!< Rx FIFO transfer state. */
  475. volatile uint32_t timestamp[CAN_WORD1_COUNT]; /*!< Mailbox transfer timestamp. */
  476. };
  477. /******************************************************************************
  478. * API
  479. *****************************************************************************/
  480. #if defined(__cplusplus)
  481. extern "C" {
  482. #endif
  483. /*!
  484. * @name Initialization and deinitialization
  485. * @{
  486. */
  487. /*!
  488. * @brief Enter FlexCAN Freeze Mode.
  489. *
  490. * This function makes the FlexCAN work under Freeze Mode.
  491. *
  492. * @param base FlexCAN peripheral base address.
  493. */
  494. void FLEXCAN_EnterFreezeMode(CAN_Type *base);
  495. /*!
  496. * @brief Exit FlexCAN Freeze Mode.
  497. *
  498. * This function makes the FlexCAN leave Freeze Mode.
  499. *
  500. * @param base FlexCAN peripheral base address.
  501. */
  502. void FLEXCAN_ExitFreezeMode(CAN_Type *base);
  503. /*!
  504. * @brief Get the FlexCAN instance from peripheral base address.
  505. *
  506. * @param base FlexCAN peripheral base address.
  507. * @return FlexCAN instance.
  508. */
  509. uint32_t FLEXCAN_GetInstance(CAN_Type *base);
  510. /*!
  511. * @brief Calculates the improved timing values by specific baudrates for classical CAN
  512. *
  513. * @param baudRate The classical CAN speed in bps defined by user
  514. * @param sourceClock_Hz The Source clock data speed in bps. Zero to disable baudrate switching
  515. * @param pTimingConfig Pointer to the FlexCAN timing configuration structure.
  516. *
  517. * @return TRUE if timing configuration found, FALSE if failed to find configuration
  518. */
  519. bool FLEXCAN_CalculateImprovedTimingValues(uint32_t baudRate,
  520. uint32_t sourceClock_Hz,
  521. flexcan_timing_config_t *pTimingConfig);
  522. /*!
  523. * @brief Initializes a FlexCAN instance.
  524. *
  525. * This function initializes the FlexCAN module with user-defined settings.
  526. * This example shows how to set up the flexcan_config_t parameters and how
  527. * to call the FLEXCAN_Init function by passing in these parameters.
  528. * @code
  529. * flexcan_config_t flexcanConfig;
  530. * flexcanConfig.clkSrc = kFLEXCAN_ClkSrc0;
  531. * flexcanConfig.baudRate = 1000000U;
  532. * flexcanConfig.maxMbNum = 16;
  533. * flexcanConfig.enableLoopBack = false;
  534. * flexcanConfig.enableSelfWakeup = false;
  535. * flexcanConfig.enableIndividMask = false;
  536. * flexcanConfig.enableDoze = false;
  537. * flexcanConfig.disableSelfReception = false;
  538. * flexcanConfig.enableListenOnlyMode = false;
  539. * flexcanConfig.timingConfig = timingConfig;
  540. * FLEXCAN_Init(CAN0, &flexcanConfig, 8000000UL);
  541. * @endcode
  542. *
  543. * @param base FlexCAN peripheral base address.
  544. * @param pConfig Pointer to the user-defined configuration structure.
  545. * @param sourceClock_Hz FlexCAN Protocol Engine clock source frequency in Hz.
  546. */
  547. void FLEXCAN_Init(CAN_Type *base, const flexcan_config_t *pConfig, uint32_t sourceClock_Hz);
  548. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  549. /*!
  550. * @brief Calculates the improved timing values by specific baudrates for CANFD
  551. *
  552. * @param baudRate The CANFD bus control speed in bps defined by user
  553. * @param baudRateFD The CANFD bus data speed in bps defined by user
  554. * @param sourceClock_Hz The Source clock data speed in bps. Zero to disable baudrate switching
  555. * @param pTimingConfig Pointer to the FlexCAN timing configuration structure.
  556. *
  557. * @return TRUE if timing configuration found, FALSE if failed to find configuration
  558. */
  559. bool FLEXCAN_FDCalculateImprovedTimingValues(uint32_t baudRate,
  560. uint32_t baudRateFD,
  561. uint32_t sourceClock_Hz,
  562. flexcan_timing_config_t *pTimingConfig);
  563. /*!
  564. * @brief Initializes a FlexCAN instance.
  565. *
  566. * This function initializes the FlexCAN module with user-defined settings.
  567. * This example shows how to set up the flexcan_config_t parameters and how
  568. * to call the FLEXCAN_FDInit function by passing in these parameters.
  569. * @code
  570. * flexcan_config_t flexcanConfig;
  571. * flexcanConfig.clkSrc = kFLEXCAN_ClkSrc0;
  572. * flexcanConfig.baudRate = 1000000U;
  573. * flexcanConfig.baudRateFD = 2000000U;
  574. * flexcanConfig.maxMbNum = 16;
  575. * flexcanConfig.enableLoopBack = false;
  576. * flexcanConfig.enableSelfWakeup = false;
  577. * flexcanConfig.enableIndividMask = false;
  578. * flexcanConfig.disableSelfReception = false;
  579. * flexcanConfig.enableListenOnlyMode = false;
  580. * flexcanConfig.enableDoze = false;
  581. * flexcanConfig.timingConfig = timingConfig;
  582. * FLEXCAN_FDInit(CAN0, &flexcanConfig, 8000000UL, kFLEXCAN_16BperMB, false);
  583. * @endcode
  584. *
  585. * @param base FlexCAN peripheral base address.
  586. * @param pConfig Pointer to the user-defined configuration structure.
  587. * @param sourceClock_Hz FlexCAN Protocol Engine clock source frequency in Hz.
  588. * @param dataSize FlexCAN FD frame payload size.
  589. * @param brs If bitrate switch is enabled in FD mode.
  590. */
  591. void FLEXCAN_FDInit(
  592. CAN_Type *base, const flexcan_config_t *pConfig, uint32_t sourceClock_Hz, flexcan_mb_size_t dataSize, bool brs);
  593. #endif
  594. /*!
  595. * @brief De-initializes a FlexCAN instance.
  596. *
  597. * This function disables the FlexCAN module clock and sets all register values
  598. * to the reset value.
  599. *
  600. * @param base FlexCAN peripheral base address.
  601. */
  602. void FLEXCAN_Deinit(CAN_Type *base);
  603. /*!
  604. * @brief Gets the default configuration structure.
  605. *
  606. * This function initializes the FlexCAN configuration structure to default values. The default
  607. * values are as follows.
  608. * flexcanConfig->clkSrc = kFLEXCAN_ClkSrc0;
  609. * flexcanConfig->baudRate = 1000000U;
  610. * flexcanConfig->baudRateFD = 2000000U;
  611. * flexcanConfig->maxMbNum = 16;
  612. * flexcanConfig->enableLoopBack = false;
  613. * flexcanConfig->enableSelfWakeup = false;
  614. * flexcanConfig->enableIndividMask = false;
  615. * flexcanConfig->disableSelfReception = false;
  616. * flexcanConfig->enableListenOnlyMode = false;
  617. * flexcanConfig->enableDoze = false;
  618. * flexcanConfig.timingConfig = timingConfig;
  619. *
  620. * @param pConfig Pointer to the FlexCAN configuration structure.
  621. */
  622. void FLEXCAN_GetDefaultConfig(flexcan_config_t *pConfig);
  623. /* @} */
  624. /*!
  625. * @name Configuration.
  626. * @{
  627. */
  628. /*!
  629. * @brief Sets the FlexCAN protocol timing characteristic.
  630. *
  631. * This function gives user settings to CAN bus timing characteristic.
  632. * The function is for an experienced user. For less experienced users, call
  633. * the FLEXCAN_Init() and fill the baud rate field with a desired value.
  634. * This provides the default timing characteristics to the module.
  635. *
  636. * Note that calling FLEXCAN_SetTimingConfig() overrides the baud rate set
  637. * in FLEXCAN_Init().
  638. *
  639. * @param base FlexCAN peripheral base address.
  640. * @param pConfig Pointer to the timing configuration structure.
  641. */
  642. void FLEXCAN_SetTimingConfig(CAN_Type *base, const flexcan_timing_config_t *pConfig);
  643. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  644. /*!
  645. * @brief Sets the FlexCAN FD protocol timing characteristic.
  646. *
  647. * This function gives user settings to CAN bus timing characteristic.
  648. * The function is for an experienced user. For less experienced users, call
  649. * the FLEXCAN_Init() and fill the baud rate field with a desired value.
  650. * This provides the default timing characteristics to the module.
  651. *
  652. * Note that calling FLEXCAN_SetFDTimingConfig() overrides the baud rate set
  653. * in FLEXCAN_Init().
  654. *
  655. * @param base FlexCAN peripheral base address.
  656. * @param pConfig Pointer to the timing configuration structure.
  657. */
  658. void FLEXCAN_SetFDTimingConfig(CAN_Type *base, const flexcan_timing_config_t *pConfig);
  659. #endif
  660. /*!
  661. * @brief Sets the FlexCAN receive message buffer global mask.
  662. *
  663. * This function sets the global mask for the FlexCAN message buffer in a matching process.
  664. * The configuration is only effective when the Rx individual mask is disabled in the FLEXCAN_Init().
  665. *
  666. * @param base FlexCAN peripheral base address.
  667. * @param mask Rx Message Buffer Global Mask value.
  668. */
  669. void FLEXCAN_SetRxMbGlobalMask(CAN_Type *base, uint32_t mask);
  670. /*!
  671. * @brief Sets the FlexCAN receive FIFO global mask.
  672. *
  673. * This function sets the global mask for FlexCAN FIFO in a matching process.
  674. *
  675. * @param base FlexCAN peripheral base address.
  676. * @param mask Rx Fifo Global Mask value.
  677. */
  678. void FLEXCAN_SetRxFifoGlobalMask(CAN_Type *base, uint32_t mask);
  679. /*!
  680. * @brief Sets the FlexCAN receive individual mask.
  681. *
  682. * This function sets the individual mask for the FlexCAN matching process.
  683. * The configuration is only effective when the Rx individual mask is enabled in the FLEXCAN_Init().
  684. * If the Rx FIFO is disabled, the individual mask is applied to the corresponding Message Buffer.
  685. * If the Rx FIFO is enabled, the individual mask for Rx FIFO occupied Message Buffer is applied to
  686. * the Rx Filter with the same index. Note that only the first 32
  687. * individual masks can be used as the Rx FIFO filter mask.
  688. *
  689. * @param base FlexCAN peripheral base address.
  690. * @param maskIdx The Index of individual Mask.
  691. * @param mask Rx Individual Mask value.
  692. */
  693. void FLEXCAN_SetRxIndividualMask(CAN_Type *base, uint8_t maskIdx, uint32_t mask);
  694. /*!
  695. * @brief Configures a FlexCAN transmit message buffer.
  696. *
  697. * This function aborts the previous transmission, cleans the Message Buffer, and
  698. * configures it as a Transmit Message Buffer.
  699. *
  700. * @param base FlexCAN peripheral base address.
  701. * @param mbIdx The Message Buffer index.
  702. * @param enable Enable/disable Tx Message Buffer.
  703. * - true: Enable Tx Message Buffer.
  704. * - false: Disable Tx Message Buffer.
  705. */
  706. void FLEXCAN_SetTxMbConfig(CAN_Type *base, uint8_t mbIdx, bool enable);
  707. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  708. /*!
  709. * @brief Configures a FlexCAN transmit message buffer.
  710. *
  711. * This function aborts the previous transmission, cleans the Message Buffer, and
  712. * configures it as a Transmit Message Buffer.
  713. *
  714. * @param base FlexCAN peripheral base address.
  715. * @param mbIdx The Message Buffer index.
  716. * @param enable Enable/disable Tx Message Buffer.
  717. * - true: Enable Tx Message Buffer.
  718. * - false: Disable Tx Message Buffer.
  719. */
  720. void FLEXCAN_SetFDTxMbConfig(CAN_Type *base, uint8_t mbIdx, bool enable);
  721. #endif
  722. /*!
  723. * @brief Configures a FlexCAN Receive Message Buffer.
  724. *
  725. * This function cleans a FlexCAN build-in Message Buffer and configures it
  726. * as a Receive Message Buffer.
  727. *
  728. * @param base FlexCAN peripheral base address.
  729. * @param mbIdx The Message Buffer index.
  730. * @param pRxMbConfig Pointer to the FlexCAN Message Buffer configuration structure.
  731. * @param enable Enable/disable Rx Message Buffer.
  732. * - true: Enable Rx Message Buffer.
  733. * - false: Disable Rx Message Buffer.
  734. */
  735. void FLEXCAN_SetRxMbConfig(CAN_Type *base, uint8_t mbIdx, const flexcan_rx_mb_config_t *pRxMbConfig, bool enable);
  736. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  737. /*!
  738. * @brief Configures a FlexCAN Receive Message Buffer.
  739. *
  740. * This function cleans a FlexCAN build-in Message Buffer and configures it
  741. * as a Receive Message Buffer.
  742. *
  743. * @param base FlexCAN peripheral base address.
  744. * @param mbIdx The Message Buffer index.
  745. * @param pRxMbConfig Pointer to the FlexCAN Message Buffer configuration structure.
  746. * @param enable Enable/disable Rx Message Buffer.
  747. * - true: Enable Rx Message Buffer.
  748. * - false: Disable Rx Message Buffer.
  749. */
  750. void FLEXCAN_SetFDRxMbConfig(CAN_Type *base, uint8_t mbIdx, const flexcan_rx_mb_config_t *pRxMbConfig, bool enable);
  751. #endif
  752. /*!
  753. * @brief Configures the FlexCAN Rx FIFO.
  754. *
  755. * This function configures the Rx FIFO with given Rx FIFO configuration.
  756. *
  757. * @param base FlexCAN peripheral base address.
  758. * @param pRxFifoConfig Pointer to the FlexCAN Rx FIFO configuration structure.
  759. * @param enable Enable/disable Rx FIFO.
  760. * - true: Enable Rx FIFO.
  761. * - false: Disable Rx FIFO.
  762. */
  763. void FLEXCAN_SetRxFifoConfig(CAN_Type *base, const flexcan_rx_fifo_config_t *pRxFifoConfig, bool enable);
  764. /* @} */
  765. /*!
  766. * @name Status
  767. * @{
  768. */
  769. /*!
  770. * @brief Gets the FlexCAN module interrupt flags.
  771. *
  772. * This function gets all FlexCAN status flags. The flags are returned as the logical
  773. * OR value of the enumerators @ref _flexcan_flags. To check the specific status,
  774. * compare the return value with enumerators in @ref _flexcan_flags.
  775. *
  776. * @param base FlexCAN peripheral base address.
  777. * @return FlexCAN status flags which are ORed by the enumerators in the _flexcan_flags.
  778. */
  779. static inline uint32_t FLEXCAN_GetStatusFlags(CAN_Type *base)
  780. {
  781. return base->ESR1;
  782. }
  783. /*!
  784. * @brief Clears status flags with the provided mask.
  785. *
  786. * This function clears the FlexCAN status flags with a provided mask. An automatically cleared flag
  787. * can't be cleared by this function.
  788. *
  789. * @param base FlexCAN peripheral base address.
  790. * @param mask The status flags to be cleared, it is logical OR value of @ref _flexcan_flags.
  791. */
  792. static inline void FLEXCAN_ClearStatusFlags(CAN_Type *base, uint32_t mask)
  793. {
  794. /* Write 1 to clear status flag. */
  795. base->ESR1 = mask;
  796. }
  797. /*!
  798. * @brief Gets the FlexCAN Bus Error Counter value.
  799. *
  800. * This function gets the FlexCAN Bus Error Counter value for both Tx and
  801. * Rx direction. These values may be needed in the upper layer error handling.
  802. *
  803. * @param base FlexCAN peripheral base address.
  804. * @param txErrBuf Buffer to store Tx Error Counter value.
  805. * @param rxErrBuf Buffer to store Rx Error Counter value.
  806. */
  807. static inline void FLEXCAN_GetBusErrCount(CAN_Type *base, uint8_t *txErrBuf, uint8_t *rxErrBuf)
  808. {
  809. if (NULL != txErrBuf)
  810. {
  811. *txErrBuf = (uint8_t)((base->ECR & CAN_ECR_TXERRCNT_MASK) >> CAN_ECR_TXERRCNT_SHIFT);
  812. }
  813. if (NULL != rxErrBuf)
  814. {
  815. *rxErrBuf = (uint8_t)((base->ECR & CAN_ECR_RXERRCNT_MASK) >> CAN_ECR_RXERRCNT_SHIFT);
  816. }
  817. }
  818. /*!
  819. * @brief Gets the FlexCAN Message Buffer interrupt flags.
  820. *
  821. * This function gets the interrupt flags of a given Message Buffers.
  822. *
  823. * @param base FlexCAN peripheral base address.
  824. * @param mask The ORed FlexCAN Message Buffer mask.
  825. * @return The status of given Message Buffers.
  826. */
  827. #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
  828. static inline uint64_t FLEXCAN_GetMbStatusFlags(CAN_Type *base, uint64_t mask)
  829. #else
  830. static inline uint32_t FLEXCAN_GetMbStatusFlags(CAN_Type *base, uint32_t mask)
  831. #endif
  832. {
  833. #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
  834. uint64_t tempflag = (uint64_t)base->IFLAG1;
  835. return (tempflag | (((uint64_t)base->IFLAG2) << 32)) & mask;
  836. #else
  837. return (base->IFLAG1 & mask);
  838. #endif
  839. }
  840. /*!
  841. * @brief Clears the FlexCAN Message Buffer interrupt flags.
  842. *
  843. * This function clears the interrupt flags of a given Message Buffers.
  844. *
  845. * @param base FlexCAN peripheral base address.
  846. * @param mask The ORed FlexCAN Message Buffer mask.
  847. */
  848. #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
  849. static inline void FLEXCAN_ClearMbStatusFlags(CAN_Type *base, uint64_t mask)
  850. #else
  851. static inline void FLEXCAN_ClearMbStatusFlags(CAN_Type *base, uint32_t mask)
  852. #endif
  853. {
  854. #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
  855. base->IFLAG1 = (uint32_t)(mask & 0xFFFFFFFFU);
  856. base->IFLAG2 = (uint32_t)(mask >> 32);
  857. #else
  858. base->IFLAG1 = mask;
  859. #endif
  860. }
  861. /* @} */
  862. /*!
  863. * @name Interrupts
  864. * @{
  865. */
  866. /*!
  867. * @brief Enables FlexCAN interrupts according to the provided mask.
  868. *
  869. * This function enables the FlexCAN interrupts according to the provided mask. The mask
  870. * is a logical OR of enumeration members, see @ref _flexcan_interrupt_enable.
  871. *
  872. * @param base FlexCAN peripheral base address.
  873. * @param mask The interrupts to enable. Logical OR of @ref _flexcan_interrupt_enable.
  874. */
  875. static inline void FLEXCAN_EnableInterrupts(CAN_Type *base, uint32_t mask)
  876. {
  877. /* Solve Wake Up Interrupt. */
  878. if ((uint32_t)kFLEXCAN_WakeUpInterruptEnable == (mask & (uint32_t)kFLEXCAN_WakeUpInterruptEnable))
  879. {
  880. base->MCR |= CAN_MCR_WAKMSK_MASK;
  881. }
  882. /* Solve others. */
  883. base->CTRL1 |= (mask & (~((uint32_t)kFLEXCAN_WakeUpInterruptEnable)));
  884. }
  885. /*!
  886. * @brief Disables FlexCAN interrupts according to the provided mask.
  887. *
  888. * This function disables the FlexCAN interrupts according to the provided mask. The mask
  889. * is a logical OR of enumeration members, see @ref _flexcan_interrupt_enable.
  890. *
  891. * @param base FlexCAN peripheral base address.
  892. * @param mask The interrupts to disable. Logical OR of @ref _flexcan_interrupt_enable.
  893. */
  894. static inline void FLEXCAN_DisableInterrupts(CAN_Type *base, uint32_t mask)
  895. {
  896. /* Solve Wake Up Interrupt. */
  897. if ((uint32_t)kFLEXCAN_WakeUpInterruptEnable == (mask & (uint32_t)kFLEXCAN_WakeUpInterruptEnable))
  898. {
  899. base->MCR &= ~CAN_MCR_WAKMSK_MASK;
  900. }
  901. /* Solve others. */
  902. base->CTRL1 &= ~(mask & (~((uint32_t)kFLEXCAN_WakeUpInterruptEnable)));
  903. }
  904. /*!
  905. * @brief Enables FlexCAN Message Buffer interrupts.
  906. *
  907. * This function enables the interrupts of given Message Buffers.
  908. *
  909. * @param base FlexCAN peripheral base address.
  910. * @param mask The ORed FlexCAN Message Buffer mask.
  911. */
  912. #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
  913. static inline void FLEXCAN_EnableMbInterrupts(CAN_Type *base, uint64_t mask)
  914. #else
  915. static inline void FLEXCAN_EnableMbInterrupts(CAN_Type *base, uint32_t mask)
  916. #endif
  917. {
  918. #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
  919. base->IMASK1 |= (uint32_t)(mask & 0xFFFFFFFFU);
  920. base->IMASK2 |= (uint32_t)(mask >> 32);
  921. #else
  922. base->IMASK1 |= mask;
  923. #endif
  924. }
  925. /*!
  926. * @brief Disables FlexCAN Message Buffer interrupts.
  927. *
  928. * This function disables the interrupts of given Message Buffers.
  929. *
  930. * @param base FlexCAN peripheral base address.
  931. * @param mask The ORed FlexCAN Message Buffer mask.
  932. */
  933. #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
  934. static inline void FLEXCAN_DisableMbInterrupts(CAN_Type *base, uint64_t mask)
  935. #else
  936. static inline void FLEXCAN_DisableMbInterrupts(CAN_Type *base, uint32_t mask)
  937. #endif
  938. {
  939. #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
  940. base->IMASK1 &= ~((uint32_t)(mask & 0xFFFFFFFFU));
  941. base->IMASK2 &= ~((uint32_t)(mask >> 32));
  942. #else
  943. base->IMASK1 &= ~mask;
  944. #endif
  945. }
  946. /* @} */
  947. #if (defined(FSL_FEATURE_FLEXCAN_HAS_RX_FIFO_DMA) && FSL_FEATURE_FLEXCAN_HAS_RX_FIFO_DMA)
  948. /*!
  949. * @name DMA Control
  950. * @{
  951. */
  952. /*!
  953. * @brief Enables or disables the FlexCAN Rx FIFO DMA request.
  954. *
  955. * This function enables or disables the DMA feature of FlexCAN build-in Rx FIFO.
  956. *
  957. * @param base FlexCAN peripheral base address.
  958. * @param enable true to enable, false to disable.
  959. */
  960. void FLEXCAN_EnableRxFifoDMA(CAN_Type *base, bool enable);
  961. /*!
  962. * @brief Gets the Rx FIFO Head address.
  963. *
  964. * This function returns the FlexCAN Rx FIFO Head address, which is mainly used for the DMA/eDMA use case.
  965. *
  966. * @param base FlexCAN peripheral base address.
  967. * @return FlexCAN Rx FIFO Head address.
  968. */
  969. static inline uint32_t FLEXCAN_GetRxFifoHeadAddr(CAN_Type *base)
  970. {
  971. return (uint32_t) & (base->MB[0].CS);
  972. }
  973. /* @} */
  974. #endif /* FSL_FEATURE_FLEXCAN_HAS_RX_FIFO_DMA */
  975. /*!
  976. * @name Bus Operations
  977. * @{
  978. */
  979. /*!
  980. * @brief Enables or disables the FlexCAN module operation.
  981. *
  982. * This function enables or disables the FlexCAN module.
  983. *
  984. * @param base FlexCAN base pointer.
  985. * @param enable true to enable, false to disable.
  986. */
  987. static inline void FLEXCAN_Enable(CAN_Type *base, bool enable)
  988. {
  989. if (enable)
  990. {
  991. base->MCR &= ~CAN_MCR_MDIS_MASK;
  992. /* Wait FlexCAN exit from low-power mode. */
  993. while (0U != (base->MCR & CAN_MCR_LPMACK_MASK))
  994. {
  995. }
  996. }
  997. else
  998. {
  999. base->MCR |= CAN_MCR_MDIS_MASK;
  1000. /* Wait FlexCAN enter low-power mode. */
  1001. while (0U == (base->MCR & CAN_MCR_LPMACK_MASK))
  1002. {
  1003. }
  1004. }
  1005. }
  1006. /*!
  1007. * @brief Writes a FlexCAN Message to the Transmit Message Buffer.
  1008. *
  1009. * This function writes a CAN Message to the specified Transmit Message Buffer
  1010. * and changes the Message Buffer state to start CAN Message transmit. After
  1011. * that the function returns immediately.
  1012. *
  1013. * @param base FlexCAN peripheral base address.
  1014. * @param mbIdx The FlexCAN Message Buffer index.
  1015. * @param pTxFrame Pointer to CAN message frame to be sent.
  1016. * @retval kStatus_Success - Write Tx Message Buffer Successfully.
  1017. * @retval kStatus_Fail - Tx Message Buffer is currently in use.
  1018. */
  1019. status_t FLEXCAN_WriteTxMb(CAN_Type *base, uint8_t mbIdx, const flexcan_frame_t *pTxFrame);
  1020. /*!
  1021. * @brief Reads a FlexCAN Message from Receive Message Buffer.
  1022. *
  1023. * This function reads a CAN message from a specified Receive Message Buffer.
  1024. * The function fills a receive CAN message frame structure with
  1025. * just received data and activates the Message Buffer again.
  1026. * The function returns immediately.
  1027. *
  1028. * @param base FlexCAN peripheral base address.
  1029. * @param mbIdx The FlexCAN Message Buffer index.
  1030. * @param pRxFrame Pointer to CAN message frame structure for reception.
  1031. * @retval kStatus_Success - Rx Message Buffer is full and has been read successfully.
  1032. * @retval kStatus_FLEXCAN_RxOverflow - Rx Message Buffer is already overflowed and has been read successfully.
  1033. * @retval kStatus_Fail - Rx Message Buffer is empty.
  1034. */
  1035. status_t FLEXCAN_ReadRxMb(CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *pRxFrame);
  1036. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  1037. /*!
  1038. * @brief Writes a FlexCAN FD Message to the Transmit Message Buffer.
  1039. *
  1040. * This function writes a CAN FD Message to the specified Transmit Message Buffer
  1041. * and changes the Message Buffer state to start CAN FD Message transmit. After
  1042. * that the function returns immediately.
  1043. *
  1044. * @param base FlexCAN peripheral base address.
  1045. * @param mbIdx The FlexCAN FD Message Buffer index.
  1046. * @param pTxFrame Pointer to CAN FD message frame to be sent.
  1047. * @retval kStatus_Success - Write Tx Message Buffer Successfully.
  1048. * @retval kStatus_Fail - Tx Message Buffer is currently in use.
  1049. */
  1050. status_t FLEXCAN_WriteFDTxMb(CAN_Type *base, uint8_t mbIdx, const flexcan_fd_frame_t *pTxFrame);
  1051. /*!
  1052. * @brief Reads a FlexCAN FD Message from Receive Message Buffer.
  1053. *
  1054. * This function reads a CAN FD message from a specified Receive Message Buffer.
  1055. * The function fills a receive CAN FD message frame structure with
  1056. * just received data and activates the Message Buffer again.
  1057. * The function returns immediately.
  1058. *
  1059. * @param base FlexCAN peripheral base address.
  1060. * @param mbIdx The FlexCAN FD Message Buffer index.
  1061. * @param pRxFrame Pointer to CAN FD message frame structure for reception.
  1062. * @retval kStatus_Success - Rx Message Buffer is full and has been read successfully.
  1063. * @retval kStatus_FLEXCAN_RxOverflow - Rx Message Buffer is already overflowed and has been read successfully.
  1064. * @retval kStatus_Fail - Rx Message Buffer is empty.
  1065. */
  1066. status_t FLEXCAN_ReadFDRxMb(CAN_Type *base, uint8_t mbIdx, flexcan_fd_frame_t *pRxFrame);
  1067. #endif
  1068. /*!
  1069. * @brief Reads a FlexCAN Message from Rx FIFO.
  1070. *
  1071. * This function reads a CAN message from the FlexCAN build-in Rx FIFO.
  1072. *
  1073. * @param base FlexCAN peripheral base address.
  1074. * @param pRxFrame Pointer to CAN message frame structure for reception.
  1075. * @retval kStatus_Success - Read Message from Rx FIFO successfully.
  1076. * @retval kStatus_Fail - Rx FIFO is not enabled.
  1077. */
  1078. status_t FLEXCAN_ReadRxFifo(CAN_Type *base, flexcan_frame_t *pRxFrame);
  1079. /* @} */
  1080. /*!
  1081. * @name Transactional
  1082. * @{
  1083. */
  1084. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  1085. /*!
  1086. * @brief Performs a polling send transaction on the CAN bus.
  1087. *
  1088. * Note that a transfer handle does not need to be created before calling this API.
  1089. *
  1090. * @param base FlexCAN peripheral base pointer.
  1091. * @param mbIdx The FlexCAN FD Message Buffer index.
  1092. * @param pTxFrame Pointer to CAN FD message frame to be sent.
  1093. * @retval kStatus_Success - Write Tx Message Buffer Successfully.
  1094. * @retval kStatus_Fail - Tx Message Buffer is currently in use.
  1095. */
  1096. status_t FLEXCAN_TransferFDSendBlocking(CAN_Type *base, uint8_t mbIdx, flexcan_fd_frame_t *pTxFrame);
  1097. /*!
  1098. * @brief Performs a polling receive transaction on the CAN bus.
  1099. *
  1100. * Note that a transfer handle does not need to be created before calling this API.
  1101. *
  1102. * @param base FlexCAN peripheral base pointer.
  1103. * @param mbIdx The FlexCAN FD Message Buffer index.
  1104. * @param pRxFrame Pointer to CAN FD message frame structure for reception.
  1105. * @retval kStatus_Success - Rx Message Buffer is full and has been read successfully.
  1106. * @retval kStatus_FLEXCAN_RxOverflow - Rx Message Buffer is already overflowed and has been read successfully.
  1107. * @retval kStatus_Fail - Rx Message Buffer is empty.
  1108. */
  1109. status_t FLEXCAN_TransferFDReceiveBlocking(CAN_Type *base, uint8_t mbIdx, flexcan_fd_frame_t *pRxFrame);
  1110. /*!
  1111. * @brief Sends a message using IRQ.
  1112. *
  1113. * This function sends a message using IRQ. This is a non-blocking function, which returns
  1114. * right away. When messages have been sent out, the send callback function is called.
  1115. *
  1116. * @param base FlexCAN peripheral base address.
  1117. * @param handle FlexCAN handle pointer.
  1118. * @param pMbXfer FlexCAN FD Message Buffer transfer structure. See the #flexcan_mb_transfer_t.
  1119. * @retval kStatus_Success Start Tx Message Buffer sending process successfully.
  1120. * @retval kStatus_Fail Write Tx Message Buffer failed.
  1121. * @retval kStatus_FLEXCAN_TxBusy Tx Message Buffer is in use.
  1122. */
  1123. status_t FLEXCAN_TransferFDSendNonBlocking(CAN_Type *base, flexcan_handle_t *handle, flexcan_mb_transfer_t *pMbXfer);
  1124. /*!
  1125. * @brief Receives a message using IRQ.
  1126. *
  1127. * This function receives a message using IRQ. This is non-blocking function, which returns
  1128. * right away. When the message has been received, the receive callback function is called.
  1129. *
  1130. * @param base FlexCAN peripheral base address.
  1131. * @param handle FlexCAN handle pointer.
  1132. * @param pMbXfer FlexCAN FD Message Buffer transfer structure. See the #flexcan_mb_transfer_t.
  1133. * @retval kStatus_Success - Start Rx Message Buffer receiving process successfully.
  1134. * @retval kStatus_FLEXCAN_RxBusy - Rx Message Buffer is in use.
  1135. */
  1136. status_t FLEXCAN_TransferFDReceiveNonBlocking(CAN_Type *base, flexcan_handle_t *handle, flexcan_mb_transfer_t *pMbXfer);
  1137. /*!
  1138. * @brief Aborts the interrupt driven message send process.
  1139. *
  1140. * This function aborts the interrupt driven message send process.
  1141. *
  1142. * @param base FlexCAN peripheral base address.
  1143. * @param handle FlexCAN handle pointer.
  1144. * @param mbIdx The FlexCAN FD Message Buffer index.
  1145. */
  1146. void FLEXCAN_TransferFDAbortSend(CAN_Type *base, flexcan_handle_t *handle, uint8_t mbIdx);
  1147. /*!
  1148. * @brief Aborts the interrupt driven message receive process.
  1149. *
  1150. * This function aborts the interrupt driven message receive process.
  1151. *
  1152. * @param base FlexCAN peripheral base address.
  1153. * @param handle FlexCAN handle pointer.
  1154. * @param mbIdx The FlexCAN FD Message Buffer index.
  1155. */
  1156. void FLEXCAN_TransferFDAbortReceive(CAN_Type *base, flexcan_handle_t *handle, uint8_t mbIdx);
  1157. #endif
  1158. /*!
  1159. * @brief Performs a polling send transaction on the CAN bus.
  1160. *
  1161. * Note that a transfer handle does not need to be created before calling this API.
  1162. *
  1163. * @param base FlexCAN peripheral base pointer.
  1164. * @param mbIdx The FlexCAN Message Buffer index.
  1165. * @param pTxFrame Pointer to CAN message frame to be sent.
  1166. * @retval kStatus_Success - Write Tx Message Buffer Successfully.
  1167. * @retval kStatus_Fail - Tx Message Buffer is currently in use.
  1168. */
  1169. status_t FLEXCAN_TransferSendBlocking(CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *pTxFrame);
  1170. /*!
  1171. * @brief Performs a polling receive transaction on the CAN bus.
  1172. *
  1173. * Note that a transfer handle does not need to be created before calling this API.
  1174. *
  1175. * @param base FlexCAN peripheral base pointer.
  1176. * @param mbIdx The FlexCAN Message Buffer index.
  1177. * @param pRxFrame Pointer to CAN message frame structure for reception.
  1178. * @retval kStatus_Success - Rx Message Buffer is full and has been read successfully.
  1179. * @retval kStatus_FLEXCAN_RxOverflow - Rx Message Buffer is already overflowed and has been read successfully.
  1180. * @retval kStatus_Fail - Rx Message Buffer is empty.
  1181. */
  1182. status_t FLEXCAN_TransferReceiveBlocking(CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *pRxFrame);
  1183. /*!
  1184. * @brief Performs a polling receive transaction from Rx FIFO on the CAN bus.
  1185. *
  1186. * Note that a transfer handle does not need to be created before calling this API.
  1187. *
  1188. * @param base FlexCAN peripheral base pointer.
  1189. * @param pRxFrame Pointer to CAN message frame structure for reception.
  1190. * @retval kStatus_Success - Read Message from Rx FIFO successfully.
  1191. * @retval kStatus_Fail - Rx FIFO is not enabled.
  1192. */
  1193. status_t FLEXCAN_TransferReceiveFifoBlocking(CAN_Type *base, flexcan_frame_t *pRxFrame);
  1194. /*!
  1195. * @brief Initializes the FlexCAN handle.
  1196. *
  1197. * This function initializes the FlexCAN handle, which can be used for other FlexCAN
  1198. * transactional APIs. Usually, for a specified FlexCAN instance,
  1199. * call this API once to get the initialized handle.
  1200. *
  1201. * @param base FlexCAN peripheral base address.
  1202. * @param handle FlexCAN handle pointer.
  1203. * @param callback The callback function.
  1204. * @param userData The parameter of the callback function.
  1205. */
  1206. void FLEXCAN_TransferCreateHandle(CAN_Type *base,
  1207. flexcan_handle_t *handle,
  1208. flexcan_transfer_callback_t callback,
  1209. void *userData);
  1210. /*!
  1211. * @brief Sends a message using IRQ.
  1212. *
  1213. * This function sends a message using IRQ. This is a non-blocking function, which returns
  1214. * right away. When messages have been sent out, the send callback function is called.
  1215. *
  1216. * @param base FlexCAN peripheral base address.
  1217. * @param handle FlexCAN handle pointer.
  1218. * @param pMbXfer FlexCAN Message Buffer transfer structure. See the #flexcan_mb_transfer_t.
  1219. * @retval kStatus_Success Start Tx Message Buffer sending process successfully.
  1220. * @retval kStatus_Fail Write Tx Message Buffer failed.
  1221. * @retval kStatus_FLEXCAN_TxBusy Tx Message Buffer is in use.
  1222. */
  1223. status_t FLEXCAN_TransferSendNonBlocking(CAN_Type *base, flexcan_handle_t *handle, flexcan_mb_transfer_t *pMbXfer);
  1224. /*!
  1225. * @brief Receives a message using IRQ.
  1226. *
  1227. * This function receives a message using IRQ. This is non-blocking function, which returns
  1228. * right away. When the message has been received, the receive callback function is called.
  1229. *
  1230. * @param base FlexCAN peripheral base address.
  1231. * @param handle FlexCAN handle pointer.
  1232. * @param pMbXfer FlexCAN Message Buffer transfer structure. See the #flexcan_mb_transfer_t.
  1233. * @retval kStatus_Success - Start Rx Message Buffer receiving process successfully.
  1234. * @retval kStatus_FLEXCAN_RxBusy - Rx Message Buffer is in use.
  1235. */
  1236. status_t FLEXCAN_TransferReceiveNonBlocking(CAN_Type *base, flexcan_handle_t *handle, flexcan_mb_transfer_t *pMbXfer);
  1237. /*!
  1238. * @brief Receives a message from Rx FIFO using IRQ.
  1239. *
  1240. * This function receives a message using IRQ. This is a non-blocking function, which returns
  1241. * right away. When all messages have been received, the receive callback function is called.
  1242. *
  1243. * @param base FlexCAN peripheral base address.
  1244. * @param handle FlexCAN handle pointer.
  1245. * @param pFifoXfer FlexCAN Rx FIFO transfer structure. See the @ref flexcan_fifo_transfer_t.
  1246. * @retval kStatus_Success - Start Rx FIFO receiving process successfully.
  1247. * @retval kStatus_FLEXCAN_RxFifoBusy - Rx FIFO is currently in use.
  1248. */
  1249. status_t FLEXCAN_TransferReceiveFifoNonBlocking(CAN_Type *base,
  1250. flexcan_handle_t *handle,
  1251. flexcan_fifo_transfer_t *pFifoXfer);
  1252. /*!
  1253. * @brief Gets the detail index of Mailbox's Timestamp by handle.
  1254. *
  1255. * Then function can only be used when calling non-blocking Data transfer (TX/RX) API,
  1256. * After TX/RX data transfer done (User can get the status by handler's callback function),
  1257. * we can get the detail index of Mailbox's timestamp by handle,
  1258. * Detail non-blocking data transfer API (TX/RX) contain.
  1259. * -FLEXCAN_TransferSendNonBlocking
  1260. * -FLEXCAN_TransferFDSendNonBlocking
  1261. * -FLEXCAN_TransferReceiveNonBlocking
  1262. * -FLEXCAN_TransferFDReceiveNonBlocking
  1263. * -FLEXCAN_TransferReceiveFifoNonBlocking
  1264. *
  1265. * @param handle FlexCAN handle pointer.
  1266. * @param mbIdx The FlexCAN FD Message Buffer index.
  1267. * @retval the index of mailbox 's timestamp stored in the handle.
  1268. *
  1269. */
  1270. uint32_t FLEXCAN_GetTimeStamp(flexcan_handle_t *handle, uint8_t mbIdx);
  1271. /*!
  1272. * @brief Aborts the interrupt driven message send process.
  1273. *
  1274. * This function aborts the interrupt driven message send process.
  1275. *
  1276. * @param base FlexCAN peripheral base address.
  1277. * @param handle FlexCAN handle pointer.
  1278. * @param mbIdx The FlexCAN Message Buffer index.
  1279. */
  1280. void FLEXCAN_TransferAbortSend(CAN_Type *base, flexcan_handle_t *handle, uint8_t mbIdx);
  1281. /*!
  1282. * @brief Aborts the interrupt driven message receive process.
  1283. *
  1284. * This function aborts the interrupt driven message receive process.
  1285. *
  1286. * @param base FlexCAN peripheral base address.
  1287. * @param handle FlexCAN handle pointer.
  1288. * @param mbIdx The FlexCAN Message Buffer index.
  1289. */
  1290. void FLEXCAN_TransferAbortReceive(CAN_Type *base, flexcan_handle_t *handle, uint8_t mbIdx);
  1291. /*!
  1292. * @brief Aborts the interrupt driven message receive from Rx FIFO process.
  1293. *
  1294. * This function aborts the interrupt driven message receive from Rx FIFO process.
  1295. *
  1296. * @param base FlexCAN peripheral base address.
  1297. * @param handle FlexCAN handle pointer.
  1298. */
  1299. void FLEXCAN_TransferAbortReceiveFifo(CAN_Type *base, flexcan_handle_t *handle);
  1300. /*!
  1301. * @brief FlexCAN IRQ handle function.
  1302. *
  1303. * This function handles the FlexCAN Error, the Message Buffer, and the Rx FIFO IRQ request.
  1304. *
  1305. * @param base FlexCAN peripheral base address.
  1306. * @param handle FlexCAN handle pointer.
  1307. */
  1308. void FLEXCAN_TransferHandleIRQ(CAN_Type *base, flexcan_handle_t *handle);
  1309. /* @} */
  1310. #if defined(__cplusplus)
  1311. }
  1312. #endif
  1313. /*! @}*/
  1314. #endif /* _FSL_FLEXCAN_H_ */