fsl_flexcan.h 55 KB

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