fsl_flexcan.h 56 KB

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