fsl_flexcan.h 56 KB

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