fsl_flexcan.h 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198
  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2021 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_FLEXCAN_H_
  9. #define _FSL_FLEXCAN_H_
  10. #include "fsl_common.h"
  11. /*!
  12. * @addtogroup flexcan_driver
  13. * @{
  14. */
  15. /******************************************************************************
  16. * Definitions
  17. *****************************************************************************/
  18. /*! @name Driver version */
  19. /*@{*/
  20. /*! @brief FlexCAN driver version. */
  21. #define FSL_FLEXCAN_DRIVER_VERSION (MAKE_VERSION(2, 8, 2))
  22. /*@}*/
  23. #if !(defined(FLEXCAN_WAIT_TIMEOUT) && FLEXCAN_WAIT_TIMEOUT)
  24. /* Define to 1000 means keep waiting 1000 times until the flag is assert/deassert. */
  25. #define FLEXCAN_WAIT_TIMEOUT (1000U)
  26. #endif
  27. /*! @brief FlexCAN frame length helper macro. */
  28. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  29. #define DLC_LENGTH_DECODE(dlc) (((dlc) <= 8U) ? (dlc) : (((dlc) <= 12U) ? (((dlc)-6U) * 4U) : (((dlc)-11U) * 16U)))
  30. #endif
  31. /*! @brief FlexCAN Frame ID helper macro. */
  32. #define FLEXCAN_ID_STD(id) \
  33. (((uint32_t)(((uint32_t)(id)) << CAN_ID_STD_SHIFT)) & CAN_ID_STD_MASK) /*!< Standard Frame ID helper macro. */
  34. #define FLEXCAN_ID_EXT(id) \
  35. (((uint32_t)(((uint32_t)(id)) << CAN_ID_EXT_SHIFT)) & \
  36. (CAN_ID_EXT_MASK | CAN_ID_STD_MASK)) /*!< Extend Frame ID helper macro. */
  37. /*! @brief FlexCAN Rx Message Buffer Mask helper macro. */
  38. #define FLEXCAN_RX_MB_STD_MASK(id, rtr, ide) \
  39. (((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
  40. FLEXCAN_ID_STD(id)) /*!< Standard Rx Message Buffer Mask helper macro. */
  41. #define FLEXCAN_RX_MB_EXT_MASK(id, rtr, ide) \
  42. (((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
  43. FLEXCAN_ID_EXT(id)) /*!< Extend Rx Message Buffer Mask helper macro. */
  44. /*! @brief FlexCAN Legacy Rx FIFO Mask helper macro. */
  45. #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_A(id, rtr, ide) \
  46. (((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
  47. (FLEXCAN_ID_STD(id) << 1)) /*!< Standard Rx FIFO Mask helper macro Type A helper macro. */
  48. #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_HIGH(id, rtr, ide) \
  49. (((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
  50. (((uint32_t)(id)&0x7FF) << 19)) /*!< Standard Rx FIFO Mask helper macro Type B upper part helper macro. */
  51. #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_LOW(id, rtr, ide) \
  52. (((uint32_t)((uint32_t)(rtr) << 15) | (uint32_t)((uint32_t)(ide) << 14)) | \
  53. (((uint32_t)(id)&0x7FF) << 3)) /*!< Standard Rx FIFO Mask helper macro Type B lower part helper macro. */
  54. #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_HIGH(id) \
  55. (((uint32_t)(id)&0x7F8) << 21) /*!< Standard Rx FIFO Mask helper macro Type C upper part helper macro. */
  56. #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_HIGH(id) \
  57. (((uint32_t)(id)&0x7F8) << 13) /*!< Standard Rx FIFO Mask helper macro Type C mid-upper part helper macro. */
  58. #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_LOW(id) \
  59. (((uint32_t)(id)&0x7F8) << 5) /*!< Standard Rx FIFO Mask helper macro Type C mid-lower part helper macro. */
  60. #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_LOW(id) \
  61. (((uint32_t)(id)&0x7F8) >> 3) /*!< Standard Rx FIFO Mask helper macro Type C lower part helper macro. */
  62. #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_A(id, rtr, ide) \
  63. (((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
  64. (FLEXCAN_ID_EXT(id) << 1)) /*!< Extend Rx FIFO Mask helper macro Type A helper macro. */
  65. #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_HIGH(id, rtr, ide) \
  66. ( \
  67. ((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
  68. ((FLEXCAN_ID_EXT(id) & 0x1FFF8000) \
  69. << 1)) /*!< Extend Rx FIFO Mask helper macro Type B upper part helper macro. */
  70. #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_LOW(id, rtr, ide) \
  71. (((uint32_t)((uint32_t)(rtr) << 15) | (uint32_t)((uint32_t)(ide) << 14)) | \
  72. ((FLEXCAN_ID_EXT(id) & 0x1FFF8000) >> \
  73. 15)) /*!< Extend Rx FIFO Mask helper macro Type B lower part helper macro. */
  74. #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_HIGH(id) \
  75. ((FLEXCAN_ID_EXT(id) & 0x1FE00000) << 3) /*!< Extend Rx FIFO Mask helper macro Type C upper part helper macro. */
  76. #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_HIGH(id) \
  77. ((FLEXCAN_ID_EXT(id) & 0x1FE00000) >> \
  78. 5) /*!< Extend Rx FIFO Mask helper macro Type C mid-upper part helper macro. */
  79. #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_LOW(id) \
  80. ((FLEXCAN_ID_EXT(id) & 0x1FE00000) >> \
  81. 13) /*!< Extend Rx FIFO Mask helper macro Type C mid-lower part helper macro. */
  82. #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_LOW(id) \
  83. ((FLEXCAN_ID_EXT(id) & 0x1FE00000) >> 21) /*!< Extend Rx FIFO Mask helper macro Type C lower part helper macro. */
  84. /*! @brief FlexCAN Rx FIFO Filter helper macro. */
  85. #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_A(id, rtr, ide) \
  86. FLEXCAN_RX_FIFO_STD_MASK_TYPE_A(id, rtr, ide) /*!< Standard Rx FIFO Filter helper macro Type A helper macro. */
  87. #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_B_HIGH(id, rtr, ide) \
  88. FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_HIGH( \
  89. id, rtr, ide) /*!< Standard Rx FIFO Filter helper macro Type B upper part helper macro. */
  90. #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_B_LOW(id, rtr, ide) \
  91. FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_LOW( \
  92. id, rtr, ide) /*!< Standard Rx FIFO Filter helper macro Type B lower part helper macro. */
  93. #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_HIGH(id) \
  94. FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_HIGH( \
  95. id) /*!< Standard Rx FIFO Filter helper macro Type C upper part helper macro. */
  96. #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_MID_HIGH(id) \
  97. FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_HIGH( \
  98. id) /*!< Standard Rx FIFO Filter helper macro Type C mid-upper part helper macro. */
  99. #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_MID_LOW(id) \
  100. FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_LOW( \
  101. id) /*!< Standard Rx FIFO Filter helper macro Type C mid-lower part helper macro. */
  102. #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_LOW(id) \
  103. FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_LOW( \
  104. id) /*!< Standard Rx FIFO Filter helper macro Type C lower part helper macro. */
  105. #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_A(id, rtr, ide) \
  106. FLEXCAN_RX_FIFO_EXT_MASK_TYPE_A(id, rtr, ide) /*!< Extend Rx FIFO Filter helper macro Type A helper macro. */
  107. #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_B_HIGH(id, rtr, ide) \
  108. FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_HIGH( \
  109. id, rtr, ide) /*!< Extend Rx FIFO Filter helper macro Type B upper part helper macro. */
  110. #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_B_LOW(id, rtr, ide) \
  111. FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_LOW( \
  112. id, rtr, ide) /*!< Extend Rx FIFO Filter helper macro Type B lower part helper macro. */
  113. #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_HIGH(id) \
  114. FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_HIGH( \
  115. id) /*!< Extend Rx FIFO Filter helper macro Type C upper part helper macro. */
  116. #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_MID_HIGH(id) \
  117. FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_HIGH( \
  118. id) /*!< Extend Rx FIFO Filter helper macro Type C mid-upper part helper macro. */
  119. #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_MID_LOW(id) \
  120. FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_LOW( \
  121. id) /*!< Extend Rx FIFO Filter helper macro Type C mid-lower part helper macro. */
  122. #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_LOW(id) \
  123. FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_LOW(id) /*!< Extend Rx FIFO Filter helper macro Type C lower part helper macro. */
  124. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  125. /*! @brief FlexCAN Enhanced Rx FIFO Filter and Mask helper macro. */
  126. #define ENHANCED_RX_FIFO_FSCH(x) (((uint32_t)(((uint32_t)(x)) << 30)) & 0xC0000000U)
  127. #define RTR_STD_HIGH(x) (((uint32_t)(((uint32_t)(x)) << 27)) & 0x08000000U)
  128. #define RTR_STD_LOW(x) (((uint32_t)(((uint32_t)(x)) << 11)) & 0x00000800U)
  129. #define RTR_EXT(x) (((uint32_t)(((uint32_t)(x)) << 29)) & 0x40000000U)
  130. #define ID_STD_LOW(id) (((uint32_t)id) & 0x7FFU)
  131. #define ID_STD_HIGH(id) (((uint32_t)(((uint32_t)(id)) << 16)) & 0x07FF0000U)
  132. #define ID_EXT(id) (((uint32_t)id) & 0x1FFFFFFFU)
  133. /*! Standard ID filter element with filter + mask scheme. */
  134. #define FLEXCAN_ENHANCED_RX_FIFO_STD_MASK_AND_FILTER(id, rtr, id_mask, rtr_mask) \
  135. (ENHANCED_RX_FIFO_FSCH(0x0) | RTR_STD_HIGH(rtr) | ID_STD_HIGH(id) | RTR_STD_LOW(rtr_mask) | ID_STD_LOW(id_mask))
  136. /*! Standard ID filter element with filter range. */
  137. #define FLEXCAN_ENHANCED_RX_FIFO_STD_FILTER_WITH_RANGE(id_upper, rtr, id_lower, rtr_mask) \
  138. (ENHANCED_RX_FIFO_FSCH(0x1) | RTR_STD_HIGH(rtr) | ID_STD_HIGH(id_upper) | RTR_STD_LOW(rtr_mask) | \
  139. ID_STD_LOW(id_lower))
  140. /*! Standard ID filter element with two filters without masks. */
  141. #define FLEXCAN_ENHANCED_RX_FIFO_STD_TWO_FILTERS(id1, rtr1, id2, rtr2) \
  142. (ENHANCED_RX_FIFO_FSCH(0x2) | RTR_STD_HIGH(rtr1) | ID_STD_HIGH(id1) | RTR_STD_LOW(rtr2) | ID_STD_LOW(id2))
  143. /*! Extended ID filter element with filter + mask scheme low word. */
  144. #define FLEXCAN_ENHANCED_RX_FIFO_EXT_MASK_AND_FILTER_LOW(id, rtr) \
  145. (ENHANCED_RX_FIFO_FSCH(0x0) | RTR_EXT(rtr) | ID_EXT(id))
  146. /*! Extended ID filter element with filter + mask scheme high word. */
  147. #define FLEXCAN_ENHANCED_RX_FIFO_EXT_MASK_AND_FILTER_HIGH(id_mask, rtr_mask) \
  148. (ENHANCED_RX_FIFO_FSCH(0x0) | RTR_EXT(rtr_mask) | ID_EXT(id_mask))
  149. /*! Extended ID filter element with range scheme low word. */
  150. #define FLEXCAN_ENHANCED_RX_FIFO_EXT_FILTER_WITH_RANGE_LOW(id_upper, rtr) \
  151. (ENHANCED_RX_FIFO_FSCH(0x1) | RTR_EXT(rtr) | ID_EXT(id_upper))
  152. /*! Extended ID filter element with range scheme high word. */
  153. #define FLEXCAN_ENHANCED_RX_FIFO_EXT_FILTER_WITH_RANGE_HIGH(id_lower, rtr_mask) \
  154. (ENHANCED_RX_FIFO_FSCH(0x1) | RTR_EXT(rtr_mask) | ID_EXT(id_lower))
  155. /*! Extended ID filter element with two filters without masks low word. */
  156. #define FLEXCAN_ENHANCED_RX_FIFO_EXT_TWO_FILTERS_LOW(id2, rtr2) \
  157. (ENHANCED_RX_FIFO_FSCH(0x2) | RTR_EXT(rtr2) | ID_EXT(id2))
  158. /*! Extended ID filter element with two filters without masks high word. */
  159. #define FLEXCAN_ENHANCED_RX_FIFO_EXT_TWO_FILTERS_HIGH(id1, rtr1) \
  160. (ENHANCED_RX_FIFO_FSCH(0x2) | RTR_EXT(rtr1) | ID_EXT(id1))
  161. #endif
  162. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE)
  163. /*! @brief FlexCAN Pretended Networking ID Mask helper macro. */
  164. #define FLEXCAN_PN_STD_MASK(id, rtr) \
  165. ((uint32_t)((uint32_t)(rtr) << CAN_FLT_ID1_FLT_RTR_SHIFT) | \
  166. FLEXCAN_ID_STD(id)) /*!< Standard Rx Message Buffer Mask helper macro. */
  167. #define FLEXCAN_PN_EXT_MASK(id, rtr) \
  168. ((uint32_t)CAN_FLT_ID1_FLT_IDE_MASK | (uint32_t)((uint32_t)(rtr) << CAN_FLT_ID1_FLT_RTR_SHIFT) | \
  169. FLEXCAN_ID_EXT(id)) /*!< Extend Rx Message Buffer Mask helper macro. */
  170. #endif
  171. /*! @brief FlexCAN interrupt/status flag helper macro. */
  172. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE)
  173. #define FLEXCAN_PN_INT_MASK(x) (((uint64_t)(((uint64_t)(x)) << 32)) & 0x3000000000000U)
  174. #define FLEXCAN_PN_INT_UNMASK(x) (((uint32_t)(((uint64_t)(x)) >> 32)) & 0x00030000U)
  175. #define FLEXCAN_PN_STATUS_MASK(x) (((uint64_t)(((uint64_t)(x)) << 16)) & 0x300000000U)
  176. #define FLEXCAN_PN_STATUS_UNMASK(x) (((uint32_t)(((uint64_t)(x)) >> 16)) & 0x00030000U)
  177. #endif
  178. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  179. #define FLEXCAN_EFIFO_INT_MASK(x) (((uint64_t)(((uint64_t)(x)) << 32)) & 0xF000000000000000U)
  180. #define FLEXCAN_EFIFO_INT_UNMASK(x) (((uint32_t)(((uint64_t)(x)) >> 32)) & 0xF0000000U)
  181. #define FLEXCAN_EFIFO_STATUS_MASK(x) (((uint64_t)(((uint64_t)(x)) << 32)) & 0xF003000000000000U)
  182. #define FLEXCAN_EFIFO_STATUS_UNMASK(x) (((uint32_t)(((uint64_t)(x)) >> 32)) & 0xF0030000U)
  183. #endif
  184. #if (defined(FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL) && FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL)
  185. #define FLEXCAN_MECR_INT_MASK(x) (((uint64_t)(((uint64_t)(x)) << 16)) & 0xD00000000U)
  186. #define FLEXCAN_MECR_INT_UNMASK(x) (((uint32_t)(((uint64_t)(x)) >> 16)) & 0x000D0000U)
  187. #define FLEXCAN_MECR_STATUS_MASK(x) (((uint64_t)(((uint64_t)(x)) << 34)) & 0x34003400000000U)
  188. #define FLEXCAN_MECR_STATUS_UNMASK(x) (((uint32_t)(((uint64_t)(x)) >> 34)) & 0x000D000DU)
  189. #endif
  190. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  191. #define FLEXCAN_ERROR_AND_STATUS_INIT_FLAG \
  192. ((uint32_t)kFLEXCAN_ErrorOverrunFlag | (uint32_t)kFLEXCAN_FDErrorIntFlag | (uint32_t)kFLEXCAN_BusoffDoneIntFlag | \
  193. (uint32_t)kFLEXCAN_TxWarningIntFlag | (uint32_t)kFLEXCAN_RxWarningIntFlag | (uint32_t)kFLEXCAN_BusOffIntFlag | \
  194. (uint32_t)kFLEXCAN_ErrorIntFlag | FLEXCAN_MEMORY_ERROR_INIT_FLAG)
  195. #else
  196. #define FLEXCAN_ERROR_AND_STATUS_INIT_FLAG \
  197. ((uint32_t)kFLEXCAN_TxWarningIntFlag | (uint32_t)kFLEXCAN_RxWarningIntFlag | (uint32_t)kFLEXCAN_BusOffIntFlag | \
  198. (uint32_t)kFLEXCAN_ErrorIntFlag | FLEXCAN_MEMORY_ERROR_INIT_FLAG)
  199. #endif
  200. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE)
  201. #define FLEXCAN_WAKE_UP_FLAG \
  202. ((uint32_t)kFLEXCAN_WakeUpIntFlag | (uint64_t)kFLEXCAN_PNMatchIntFlag | (uint64_t)kFLEXCAN_PNTimeoutIntFlag)
  203. #else
  204. #define FLEXCAN_WAKE_UP_FLAG ((uint32_t)kFLEXCAN_WakeUpIntFlag)
  205. #endif
  206. #if (defined(FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL) && FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL)
  207. #define FLEXCAN_MEMORY_ERROR_INIT_FLAG ((uint64_t)kFLEXCAN_AllMemoryErrorFlag)
  208. #else
  209. #define FLEXCAN_MEMORY_ERROR_INIT_FLAG (0U)
  210. #endif
  211. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  212. #define FLEXCAN_MEMORY_ENHANCED_RX_FIFO_INIT_FLAG \
  213. ((uint64_t)kFLEXCAN_ERxFifoUnderflowIntFlag | (uint64_t)kFLEXCAN_ERxFifoOverflowIntFlag | \
  214. (uint64_t)kFLEXCAN_ERxFifoWatermarkIntFlag | (uint64_t)kFLEXCAN_ERxFifoDataAvlIntFlag)
  215. #define FLEXCAN_MEMORY_ENHANCED_RX_FIFO_INIT_MASK \
  216. (CAN_ERFIER_ERFUFWIE_MASK | CAN_ERFIER_ERFOVFIE_MASK | CAN_ERFIER_ERFWMIIE_MASK | CAN_ERFIER_ERFDAIE_MASK)
  217. #endif
  218. /*! @brief FlexCAN Enhanced Rx FIFO base address helper macro. */
  219. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  220. #define E_RX_FIFO(base) ((uint32_t)(base) + 0x2000U)
  221. #endif
  222. /*! @brief FlexCAN transfer status. */
  223. enum
  224. {
  225. kStatus_FLEXCAN_TxBusy = MAKE_STATUS(kStatusGroup_FLEXCAN, 0), /*!< Tx Message Buffer is Busy. */
  226. kStatus_FLEXCAN_TxIdle = MAKE_STATUS(kStatusGroup_FLEXCAN, 1), /*!< Tx Message Buffer is Idle. */
  227. kStatus_FLEXCAN_TxSwitchToRx = MAKE_STATUS(
  228. kStatusGroup_FLEXCAN, 2), /*!< Remote Message is send out and Message buffer changed to Receive one. */
  229. kStatus_FLEXCAN_RxBusy = MAKE_STATUS(kStatusGroup_FLEXCAN, 3), /*!< Rx Message Buffer is Busy. */
  230. kStatus_FLEXCAN_RxIdle = MAKE_STATUS(kStatusGroup_FLEXCAN, 4), /*!< Rx Message Buffer is Idle. */
  231. kStatus_FLEXCAN_RxOverflow = MAKE_STATUS(kStatusGroup_FLEXCAN, 5), /*!< Rx Message Buffer is Overflowed. */
  232. kStatus_FLEXCAN_RxFifoBusy = MAKE_STATUS(kStatusGroup_FLEXCAN, 6), /*!< Rx Message FIFO is Busy. */
  233. kStatus_FLEXCAN_RxFifoIdle = MAKE_STATUS(kStatusGroup_FLEXCAN, 7), /*!< Rx Message FIFO is Idle. */
  234. kStatus_FLEXCAN_RxFifoOverflow = MAKE_STATUS(kStatusGroup_FLEXCAN, 8), /*!< Rx Message FIFO is overflowed. */
  235. kStatus_FLEXCAN_RxFifoWarning = MAKE_STATUS(kStatusGroup_FLEXCAN, 9), /*!< Rx Message FIFO is almost overflowed. */
  236. kStatus_FLEXCAN_ErrorStatus = MAKE_STATUS(kStatusGroup_FLEXCAN, 10), /*!< FlexCAN Module Error and Status. */
  237. kStatus_FLEXCAN_WakeUp = MAKE_STATUS(kStatusGroup_FLEXCAN, 11), /*!< FlexCAN is waken up from STOP mode. */
  238. kStatus_FLEXCAN_UnHandled = MAKE_STATUS(kStatusGroup_FLEXCAN, 12), /*!< UnHadled Interrupt asserted. */
  239. kStatus_FLEXCAN_RxRemote = MAKE_STATUS(kStatusGroup_FLEXCAN, 13), /*!< Rx Remote Message Received in Mail box. */
  240. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  241. kStatus_FLEXCAN_RxFifoUnderflow =
  242. MAKE_STATUS(kStatusGroup_FLEXCAN, 14), /*!< Enhanced Rx Message FIFO is underflow. */
  243. #endif
  244. };
  245. /*! @brief FlexCAN frame format. */
  246. typedef enum _flexcan_frame_format
  247. {
  248. kFLEXCAN_FrameFormatStandard = 0x0U, /*!< Standard frame format attribute. */
  249. kFLEXCAN_FrameFormatExtend = 0x1U, /*!< Extend frame format attribute. */
  250. } flexcan_frame_format_t;
  251. /*! @brief FlexCAN frame type. */
  252. typedef enum _flexcan_frame_type
  253. {
  254. kFLEXCAN_FrameTypeData = 0x0U, /*!< Data frame type attribute. */
  255. kFLEXCAN_FrameTypeRemote = 0x1U, /*!< Remote frame type attribute. */
  256. } flexcan_frame_type_t;
  257. /*! @brief FlexCAN clock source.
  258. * @deprecated Do not use the kFLEXCAN_ClkSrcOs. It has been superceded kFLEXCAN_ClkSrc0
  259. * @deprecated Do not use the kFLEXCAN_ClkSrcPeri. It has been superceded kFLEXCAN_ClkSrc1
  260. */
  261. typedef enum _flexcan_clock_source
  262. {
  263. kFLEXCAN_ClkSrcOsc = 0x0U, /*!< FlexCAN Protocol Engine clock from Oscillator. */
  264. kFLEXCAN_ClkSrcPeri = 0x1U, /*!< FlexCAN Protocol Engine clock from Peripheral Clock. */
  265. kFLEXCAN_ClkSrc0 = 0x0U, /*!< FlexCAN Protocol Engine clock selected by user as SRC == 0. */
  266. kFLEXCAN_ClkSrc1 = 0x1U, /*!< FlexCAN Protocol Engine clock selected by user as SRC == 1. */
  267. } flexcan_clock_source_t;
  268. /*! @brief FlexCAN wake up source. */
  269. typedef enum _flexcan_wake_up_source
  270. {
  271. kFLEXCAN_WakeupSrcUnfiltered = 0x0U, /*!< FlexCAN uses unfiltered Rx input to detect edge. */
  272. kFLEXCAN_WakeupSrcFiltered = 0x1U, /*!< FlexCAN uses filtered Rx input to detect edge. */
  273. } flexcan_wake_up_source_t;
  274. /*! @brief FlexCAN Rx Fifo Filter type. */
  275. typedef enum _flexcan_rx_fifo_filter_type
  276. {
  277. kFLEXCAN_RxFifoFilterTypeA = 0x0U, /*!< One full ID (standard and extended) per ID Filter element. */
  278. kFLEXCAN_RxFifoFilterTypeB =
  279. 0x1U, /*!< Two full standard IDs or two partial 14-bit ID slices per ID Filter Table element. */
  280. kFLEXCAN_RxFifoFilterTypeC =
  281. 0x2U, /*!< Four partial 8-bit Standard or extended ID slices per ID Filter Table element. */
  282. kFLEXCAN_RxFifoFilterTypeD = 0x3U, /*!< All frames rejected. */
  283. } flexcan_rx_fifo_filter_type_t;
  284. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  285. /*!
  286. * @brief FlexCAN Message Buffer Payload size.
  287. */
  288. typedef enum _flexcan_mb_size
  289. {
  290. kFLEXCAN_8BperMB = 0x0U, /*!< Selects 8 bytes per Message Buffer. */
  291. kFLEXCAN_16BperMB = 0x1U, /*!< Selects 16 bytes per Message Buffer. */
  292. kFLEXCAN_32BperMB = 0x2U, /*!< Selects 32 bytes per Message Buffer. */
  293. kFLEXCAN_64BperMB = 0x3U, /*!< Selects 64 bytes per Message Buffer. */
  294. } flexcan_mb_size_t;
  295. /*!
  296. * @brief FlexCAN CAN FD frame supporting data length (available DLC values).
  297. *
  298. * For Tx, when the Data size corresponding to DLC value stored in the MB selected for transmission is larger than the
  299. * MB Payload size, FlexCAN adds the necessary number of bytes with constant 0xCC pattern to complete the expected DLC.
  300. * For Rx, when the Data size corresponding to DLC value received from the CAN bus is larger than the MB Payload size,
  301. * the high order bytes that do not fit the Payload size will lose.
  302. */
  303. enum _flexcan_fd_frame_length
  304. {
  305. kFLEXCAN_0BperFrame = 0x0U, /*!< Frame contains 0 valid data bytes. */
  306. kFLEXCAN_1BperFrame, /*!< Frame contains 1 valid data bytes. */
  307. kFLEXCAN_2BperFrame, /*!< Frame contains 2 valid data bytes. */
  308. kFLEXCAN_3BperFrame, /*!< Frame contains 3 valid data bytes. */
  309. kFLEXCAN_4BperFrame, /*!< Frame contains 4 valid data bytes. */
  310. kFLEXCAN_5BperFrame, /*!< Frame contains 5 valid data bytes. */
  311. kFLEXCAN_6BperFrame, /*!< Frame contains 6 valid data bytes. */
  312. kFLEXCAN_7BperFrame, /*!< Frame contains 7 valid data bytes. */
  313. kFLEXCAN_8BperFrame, /*!< Frame contains 8 valid data bytes. */
  314. kFLEXCAN_12BperFrame, /*!< Frame contains 12 valid data bytes. */
  315. kFLEXCAN_16BperFrame, /*!< Frame contains 16 valid data bytes. */
  316. kFLEXCAN_20BperFrame, /*!< Frame contains 20 valid data bytes. */
  317. kFLEXCAN_24Bperrame, /*!< Frame contains 24 valid data bytes. */
  318. kFLEXCAN_32BperFrame, /*!< Frame contains 32 valid data bytes. */
  319. kFLEXCAN_48BperFrame, /*!< Frame contains 48 valid data bytes. */
  320. kFLEXCAN_64BperFrame, /*!< Frame contains 64 valid data bytes. */
  321. };
  322. #endif
  323. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  324. /*! @brief FlexCAN Enhanced Rx Fifo DMA transfer per read length enumerations. */
  325. typedef enum _flexcan_efifo_dma_per_read_length
  326. {
  327. kFLEXCAN_1WordPerRead = 0x0U, /*!< Transfer 1 32-bit words (CS).*/
  328. kFLEXCAN_2WordPerRead, /*!< Transfer 2 32-bit words (CS + ID).*/
  329. kFLEXCAN_3WordPerRead, /*!< Transfer 3 32-bit words (CS + ID + 1~4 bytes data).*/
  330. kFLEXCAN_4WordPerRead, /*!< Transfer 4 32-bit words (CS + ID + 5~8 bytes data).*/
  331. kFLEXCAN_5WordPerRead, /*!< Transfer 5 32-bit words (CS + ID + 9~12 bytes data).*/
  332. kFLEXCAN_6WordPerRead, /*!< Transfer 6 32-bit words (CS + ID + 13~16 bytes data).*/
  333. kFLEXCAN_7WordPerRead, /*!< Transfer 7 32-bit words (CS + ID + 17~20 bytes data).*/
  334. kFLEXCAN_8WordPerRead, /*!< Transfer 8 32-bit words (CS + ID + 21~24 bytes data).*/
  335. kFLEXCAN_9WordPerRead, /*!< Transfer 9 32-bit words (CS + ID + 25~28 bytes data).*/
  336. kFLEXCAN_10WordPerRead, /*!< Transfer 10 32-bit words (CS + ID + 29~32 bytes data).*/
  337. kFLEXCAN_11WordPerRead, /*!< Transfer 11 32-bit words (CS + ID + 33~36 bytes data).*/
  338. kFLEXCAN_12WordPerRead, /*!< Transfer 12 32-bit words (CS + ID + 37~40 bytes data).*/
  339. kFLEXCAN_13WordPerRead, /*!< Transfer 13 32-bit words (CS + ID + 41~44 bytes data).*/
  340. kFLEXCAN_14WordPerRead, /*!< Transfer 14 32-bit words (CS + ID + 45~48 bytes data).*/
  341. kFLEXCAN_15WordPerRead, /*!< Transfer 15 32-bit words (CS + ID + 49~52 bytes data).*/
  342. kFLEXCAN_16WordPerRead, /*!< Transfer 16 32-bit words (CS + ID + 53~56 bytes data).*/
  343. kFLEXCAN_17WordPerRead, /*!< Transfer 17 32-bit words (CS + ID + 57~60 bytes data).*/
  344. kFLEXCAN_18WordPerRead, /*!< Transfer 18 32-bit words (CS + ID + 61~64 bytes data).*/
  345. kFLEXCAN_19WordPerRead /*!< Transfer 19 32-bit words (CS + ID + 64 bytes data + ID HIT).*/
  346. } flexcan_efifo_dma_per_read_length_t;
  347. #endif
  348. /*!
  349. * @brief FlexCAN Enhanced/Legacy Rx FIFO priority.
  350. *
  351. * The matching process starts from the Rx MB(or Enhanced/Legacy Rx FIFO) with higher priority.
  352. * If no MB(or Enhanced/Legacy Rx FIFO filter) is satisfied, the matching process goes on with
  353. * the Enhanced/Legacy Rx FIFO(or Rx MB) with lower priority.
  354. */
  355. typedef enum _flexcan_rx_fifo_priority
  356. {
  357. kFLEXCAN_RxFifoPrioLow = 0x0U, /*!< Matching process start from Rx Message Buffer first. */
  358. kFLEXCAN_RxFifoPrioHigh = 0x1U, /*!< Matching process start from Enhanced/Legacy Rx FIFO first. */
  359. } flexcan_rx_fifo_priority_t;
  360. /*!
  361. * @brief FlexCAN interrupt enable enumerations.
  362. *
  363. * This provides constants for the FlexCAN interrupt enable enumerations for use in the FlexCAN functions.
  364. * @note FlexCAN Message Buffers and Legacy Rx FIFO interrupts not included in.
  365. */
  366. enum _flexcan_interrupt_enable
  367. {
  368. kFLEXCAN_BusOffInterruptEnable = CAN_CTRL1_BOFFMSK_MASK, /*!< Bus Off interrupt, use bit 15. */
  369. kFLEXCAN_ErrorInterruptEnable = CAN_CTRL1_ERRMSK_MASK, /*!< CAN Error interrupt, use bit 14. */
  370. kFLEXCAN_TxWarningInterruptEnable = CAN_CTRL1_TWRNMSK_MASK, /*!< Tx Warning interrupt, use bit 11. */
  371. kFLEXCAN_RxWarningInterruptEnable = CAN_CTRL1_RWRNMSK_MASK, /*!< Rx Warning interrupt, use bit 10. */
  372. kFLEXCAN_WakeUpInterruptEnable = CAN_MCR_WAKMSK_MASK, /*!< Self Wake Up interrupt, use bit 22. */
  373. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  374. kFLEXCAN_FDErrorInterruptEnable = CAN_CTRL2_ERRMSK_FAST_MASK, /*!< CAN FD Error interrupt, use bit 31. */
  375. #endif
  376. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE)
  377. /*! PN Match Wake Up interrupt, use high word bit 17. */
  378. kFLEXCAN_PNMatchWakeUpInterruptEnable = FLEXCAN_PN_INT_MASK(CAN_CTRL1_PN_WTOF_MSK_MASK),
  379. /*! PN Timeout Wake Up interrupt, use high word bit 16. */
  380. kFLEXCAN_PNTimeoutWakeUpInterruptEnable = FLEXCAN_PN_INT_MASK(CAN_CTRL1_PN_WUMF_MSK_MASK),
  381. #endif
  382. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  383. /*!< Enhanced Rx FIFO Underflow interrupt, use high word bit 31. */
  384. kFLEXCAN_ERxFifoUnderflowInterruptEnable = FLEXCAN_EFIFO_INT_MASK(CAN_ERFIER_ERFUFWIE_MASK),
  385. /*!< Enhanced Rx FIFO Overflow interrupt, use high word bit 30. */
  386. kFLEXCAN_ERxFifoOverflowInterruptEnable = FLEXCAN_EFIFO_INT_MASK(CAN_ERFIER_ERFOVFIE_MASK),
  387. /*!< Enhanced Rx FIFO Watermark interrupt, use high word bit 29. */
  388. kFLEXCAN_ERxFifoWatermarkInterruptEnable = FLEXCAN_EFIFO_INT_MASK(CAN_ERFIER_ERFWMIIE_MASK),
  389. /*!< Enhanced Rx FIFO Data Avilable interrupt, use high word bit 28. */
  390. kFLEXCAN_ERxFifoDataAvlInterruptEnable = FLEXCAN_EFIFO_INT_MASK(CAN_ERFIER_ERFDAIE_MASK),
  391. #endif
  392. #if (defined(FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL) && FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL)
  393. /*! Host Access With Non-Correctable Errors interrupt, use high word bit 0. */
  394. kFLEXCAN_HostAccessNCErrorInterruptEnable = FLEXCAN_MECR_INT_MASK(CAN_MECR_HANCEI_MSK_MASK),
  395. /*! FlexCAN Access With Non-Correctable Errors interrupt, use high word bit 2. */
  396. kFLEXCAN_FlexCanAccessNCErrorInterruptEnable = FLEXCAN_MECR_INT_MASK(CAN_MECR_FANCEI_MSK_MASK),
  397. /*! Host or FlexCAN Access With Correctable Errors interrupt, use high word bit 3. */
  398. kFLEXCAN_HostOrFlexCanCErrorInterruptEnable = FLEXCAN_MECR_INT_MASK(CAN_MECR_CEI_MSK_MASK),
  399. #endif
  400. };
  401. /*!
  402. * @brief FlexCAN status flags.
  403. *
  404. * This provides constants for the FlexCAN status flags for use in the FlexCAN functions.
  405. * @note The CPU read action clears the bits corresponding to the FlEXCAN_ErrorFlag macro, therefore user need to
  406. * read status flags and distinguish which error is occur using @ref _flexcan_error_flags enumerations.
  407. */
  408. enum _flexcan_flags
  409. {
  410. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  411. kFLEXCAN_ErrorOverrunFlag = CAN_ESR1_ERROVR_MASK, /*!< Error Overrun Status. */
  412. kFLEXCAN_FDErrorIntFlag = CAN_ESR1_ERRINT_FAST_MASK, /*!< CAN FD Error Interrupt Flag. */
  413. kFLEXCAN_BusoffDoneIntFlag = CAN_ESR1_BOFFDONEINT_MASK, /*!< Bus Off process completed Interrupt Flag. */
  414. #endif
  415. kFLEXCAN_SynchFlag = CAN_ESR1_SYNCH_MASK, /*!< CAN Synchronization Status. */
  416. kFLEXCAN_TxWarningIntFlag = CAN_ESR1_TWRNINT_MASK, /*!< Tx Warning Interrupt Flag. */
  417. kFLEXCAN_RxWarningIntFlag = CAN_ESR1_RWRNINT_MASK, /*!< Rx Warning Interrupt Flag. */
  418. kFLEXCAN_IdleFlag = CAN_ESR1_IDLE_MASK, /*!< FlexCAN In IDLE Status. */
  419. kFLEXCAN_FaultConfinementFlag = CAN_ESR1_FLTCONF_MASK, /*!< FlexCAN Fault Confinement State. */
  420. kFLEXCAN_TransmittingFlag = CAN_ESR1_TX_MASK, /*!< FlexCAN In Transmission Status. */
  421. kFLEXCAN_ReceivingFlag = CAN_ESR1_RX_MASK, /*!< FlexCAN In Reception Status. */
  422. kFLEXCAN_BusOffIntFlag = CAN_ESR1_BOFFINT_MASK, /*!< Bus Off Interrupt Flag. */
  423. kFLEXCAN_ErrorIntFlag = CAN_ESR1_ERRINT_MASK, /*!< CAN Error Interrupt Flag. */
  424. kFLEXCAN_WakeUpIntFlag = CAN_ESR1_WAKINT_MASK, /*!< Self Wake-Up Interrupt Flag. */
  425. kFLEXCAN_ErrorFlag =
  426. (uint32_t)(/*!< All FlexCAN Read Clear Error Status. */
  427. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  428. CAN_ESR1_STFERR_FAST_MASK | CAN_ESR1_FRMERR_FAST_MASK | CAN_ESR1_CRCERR_FAST_MASK |
  429. CAN_ESR1_BIT0ERR_FAST_MASK | CAN_ESR1_BIT1ERR_FAST_MASK | CAN_ESR1_ERROVR_MASK |
  430. #endif
  431. CAN_ESR1_TXWRN_MASK | CAN_ESR1_RXWRN_MASK | CAN_ESR1_BIT1ERR_MASK | CAN_ESR1_BIT0ERR_MASK |
  432. CAN_ESR1_ACKERR_MASK | CAN_ESR1_CRCERR_MASK | CAN_ESR1_FRMERR_MASK | CAN_ESR1_STFERR_MASK),
  433. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE)
  434. kFLEXCAN_PNMatchIntFlag = FLEXCAN_PN_STATUS_MASK(CAN_WU_MTC_WUMF_MASK), /*!< PN Matching Event Interrupt Flag. */
  435. kFLEXCAN_PNTimeoutIntFlag = FLEXCAN_PN_STATUS_MASK(CAN_WU_MTC_WTOF_MASK), /*!< PN Timeout Event Interrupt Flag. */
  436. #endif
  437. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  438. kFLEXCAN_ERxFifoUnderflowIntFlag =
  439. FLEXCAN_EFIFO_STATUS_MASK(CAN_ERFSR_ERFUFW_MASK), /*!< Enhanced Rx FIFO underflow Interrupt Flag. */
  440. kFLEXCAN_ERxFifoOverflowIntFlag =
  441. FLEXCAN_EFIFO_STATUS_MASK(CAN_ERFSR_ERFOVF_MASK), /*!< Enhanced Rx FIFO overflow Interrupt Flag. */
  442. kFLEXCAN_ERxFifoWatermarkIntFlag =
  443. FLEXCAN_EFIFO_STATUS_MASK(CAN_ERFSR_ERFWMI_MASK), /*!< Enhanced Rx FIFO watermark Interrupt Flag. */
  444. kFLEXCAN_ERxFifoDataAvlIntFlag =
  445. FLEXCAN_EFIFO_STATUS_MASK(CAN_ERFSR_ERFDA_MASK), /*!< Enhanced Rx FIFO data available Interrupt Flag. */
  446. kFLEXCAN_ERxFifoEmptyFlag = FLEXCAN_EFIFO_STATUS_MASK(CAN_ERFSR_ERFE_MASK), /*!< Enhanced Rx FIFO empty status. */
  447. kFLEXCAN_ERxFifoFullFlag = FLEXCAN_EFIFO_STATUS_MASK(CAN_ERFSR_ERFF_MASK), /*!< Enhanced Rx FIFO full status. */
  448. #endif
  449. #if (defined(FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL) && FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL)
  450. /*! Host Access With Non-Correctable Error Interrupt Flag. */
  451. kFLEXCAN_HostAccessNonCorrectableErrorIntFlag = FLEXCAN_MECR_INT_MASK(CAN_ERRSR_HANCEIF_MASK),
  452. /*! FlexCAN Access With Non-Correctable Error Interrupt Flag. */
  453. kFLEXCAN_FlexCanAccessNonCorrectableErrorIntFlag = FLEXCAN_MECR_INT_MASK(CAN_ERRSR_FANCEIF_MASK),
  454. /*! Correctable Error Interrupt Flag. */
  455. kFLEXCAN_CorrectableErrorIntFlag = FLEXCAN_MECR_INT_MASK(CAN_ERRSR_CEIF_MASK),
  456. /*! Host Access With Non-Correctable Error Interrupt Overrun Flag. */
  457. kFLEXCAN_HostAccessNonCorrectableErrorOverrunFlag = FLEXCAN_MECR_INT_MASK(CAN_ERRSR_HANCEIOF_MASK),
  458. /*! FlexCAN Access With Non-Correctable Error Interrupt Overrun Flag. */
  459. kFLEXCAN_FlexCanAccessNonCorrectableErrorOverrunFlag = FLEXCAN_MECR_INT_MASK(CAN_ERRSR_FANCEIOF_MASK),
  460. /*! Correctable Error Interrupt Overrun Flag. */
  461. kFLEXCAN_CorrectableErrorOverrunFlag = FLEXCAN_MECR_INT_MASK(CAN_ERRSR_CEIOF_MASK),
  462. /*! All Memory Error Flags. */
  463. kFLEXCAN_AllMemoryErrorFlag =
  464. (kFLEXCAN_HostAccessNonCorrectableErrorIntFlag | kFLEXCAN_FlexCanAccessNonCorrectableErrorIntFlag |
  465. kFLEXCAN_CorrectableErrorIntFlag | kFLEXCAN_HostAccessNonCorrectableErrorOverrunFlag |
  466. kFLEXCAN_FlexCanAccessNonCorrectableErrorOverrunFlag | kFLEXCAN_CorrectableErrorOverrunFlag)
  467. #endif
  468. };
  469. /*!
  470. * @brief FlexCAN error status flags.
  471. *
  472. * The FlexCAN Error Status enumerations is used to report current error of the FlexCAN bus.
  473. * This enumerations should be used with KFLEXCAN_ErrorFlag in @ref _flexcan_flags enumerations
  474. * to ditermine which error is generated.
  475. */
  476. enum _flexcan_error_flags
  477. {
  478. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  479. kFLEXCAN_FDStuffingError = CAN_ESR1_STFERR_FAST_MASK, /*!< Stuffing Error. */
  480. kFLEXCAN_FDFormError = CAN_ESR1_FRMERR_FAST_MASK, /*!< Form Error. */
  481. kFLEXCAN_FDCrcError = CAN_ESR1_CRCERR_FAST_MASK, /*!< Cyclic Redundancy Check Error. */
  482. kFLEXCAN_FDBit0Error = CAN_ESR1_BIT0ERR_FAST_MASK, /*!< Unable to send dominant bit. */
  483. kFLEXCAN_FDBit1Error = (int)CAN_ESR1_BIT1ERR_FAST_MASK, /*!< Unable to send recessive bit. */
  484. #endif
  485. kFLEXCAN_TxErrorWarningFlag = CAN_ESR1_TXWRN_MASK, /*!< Tx Error Warning Status. */
  486. kFLEXCAN_RxErrorWarningFlag = CAN_ESR1_RXWRN_MASK, /*!< Rx Error Warning Status. */
  487. kFLEXCAN_StuffingError = CAN_ESR1_STFERR_MASK, /*!< Stuffing Error. */
  488. kFLEXCAN_FormError = CAN_ESR1_FRMERR_MASK, /*!< Form Error. */
  489. kFLEXCAN_CrcError = CAN_ESR1_CRCERR_MASK, /*!< Cyclic Redundancy Check Error. */
  490. kFLEXCAN_AckError = CAN_ESR1_ACKERR_MASK, /*!< Received no ACK on transmission. */
  491. kFLEXCAN_Bit0Error = CAN_ESR1_BIT0ERR_MASK, /*!< Unable to send dominant bit. */
  492. kFLEXCAN_Bit1Error = CAN_ESR1_BIT1ERR_MASK, /*!< Unable to send recessive bit. */
  493. };
  494. /*!
  495. * @brief FlexCAN Legacy Rx FIFO status flags.
  496. *
  497. * The FlexCAN Legacy Rx FIFO Status enumerations are used to determine the status of the
  498. * Rx FIFO. Because Rx FIFO occupy the MB0 ~ MB7 (Rx Fifo filter also occupies
  499. * more Message Buffer space), Rx FIFO status flags are mapped to the corresponding
  500. * Message Buffer status flags.
  501. */
  502. enum
  503. {
  504. kFLEXCAN_RxFifoOverflowFlag = CAN_IFLAG1_BUF7I_MASK, /*!< Rx FIFO overflow flag. */
  505. kFLEXCAN_RxFifoWarningFlag = CAN_IFLAG1_BUF6I_MASK, /*!< Rx FIFO almost full flag. */
  506. kFLEXCAN_RxFifoFrameAvlFlag = CAN_IFLAG1_BUF5I_MASK, /*!< Frames available in Rx FIFO flag. */
  507. };
  508. #if (defined(FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL) && FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL)
  509. /*!
  510. * @brief FlexCAN Memory Error Type.
  511. */
  512. typedef enum _flexcan_memory_error_type
  513. {
  514. kFLEXCAN_CorrectableError = 0U, /*!< The memory error is correctable which means on bit error. */
  515. kFLEXCAN_NonCorrectableError /*!< The memory error is non-correctable which means two bit errors. */
  516. } flexcan_memory_error_type_t;
  517. /*!
  518. * @brief FlexCAN Memory Access Type.
  519. */
  520. typedef enum _flexcan_memory_access_type
  521. {
  522. kFLEXCAN_MoveOutFlexCanAccess = 0U, /*!< The memory error was detected during move-out FlexCAN access. */
  523. kFLEXCAN_MoveInAccess, /*!< The memory error was detected during move-in FlexCAN access. */
  524. kFLEXCAN_TxArbitrationAccess, /*!< The memory error was detected during Tx Arbitration FlexCAN access. */
  525. kFLEXCAN_RxMatchingAccess, /*!< The memory error was detected during Rx Matching FlexCAN access. */
  526. kFLEXCAN_MoveOutHostAccess /*!< The memory error was detected during Rx Matching Host (CPU) access. */
  527. } flexcan_memory_access_type_t;
  528. /*!
  529. * @brief FlexCAN Memory Error Byte Syndrome.
  530. */
  531. typedef enum _flexcan_byte_error_syndrome
  532. {
  533. kFLEXCAN_NoError = 0U, /*!< No bit error in this byte. */
  534. kFLEXCAN_ParityBits0Error = 1U, /*!< Parity bit 0 error in this byte. */
  535. kFLEXCAN_ParityBits1Error = 2U, /*!< Parity bit 1 error in this byte. */
  536. kFLEXCAN_ParityBits2Error = 4U, /*!< Parity bit 2 error in this byte. */
  537. kFLEXCAN_ParityBits3Error = 8U, /*!< Parity bit 3 error in this byte. */
  538. kFLEXCAN_ParityBits4Error = 16U, /*!< Parity bit 4 error in this byte. */
  539. kFLEXCAN_DataBits0Error = 28U, /*!< Data bit 0 error in this byte. */
  540. kFLEXCAN_DataBits1Error = 22U, /*!< Data bit 1 error in this byte. */
  541. kFLEXCAN_DataBits2Error = 19U, /*!< Data bit 2 error in this byte. */
  542. kFLEXCAN_DataBits3Error = 25U, /*!< Data bit 3 error in this byte. */
  543. kFLEXCAN_DataBits4Error = 26U, /*!< Data bit 4 error in this byte. */
  544. kFLEXCAN_DataBits5Error = 7U, /*!< Data bit 5 error in this byte. */
  545. kFLEXCAN_DataBits6Error = 21U, /*!< Data bit 6 error in this byte. */
  546. kFLEXCAN_DataBits7Error = 14U, /*!< Data bit 7 error in this byte. */
  547. kFLEXCAN_AllZeroError = 6U, /*!< All-zeros non-correctable error in this byte. */
  548. kFLEXCAN_AllOneError = 31U, /*!< All-ones non-correctable error in this byte. */
  549. kFLEXCAN_NonCorrectableErrors /*!< Non-correctable error in this byte. */
  550. } flexcan_byte_error_syndrome_t;
  551. /*!
  552. * @brief FlexCAN memory error register status structure
  553. *
  554. * This structure contains the memory access properties that caused a memory error access.
  555. * It is used as the parameter of FLEXCAN_GetMemoryErrorReportStatus() function. And user can
  556. * use FLEXCAN_GetMemoryErrorReportStatus to get the status of the last memory error access.
  557. */
  558. typedef struct _flexcan_memory_error_report_status
  559. {
  560. flexcan_memory_error_type_t errorType; /*!< The type of memory error that giving rise to the report. */
  561. flexcan_memory_access_type_t accessType; /*!< The type of memory access that giving rise to the memory error. */
  562. uint16_t accessAddress; /*!< The address where memory error detected. */
  563. uint32_t errorData; /*!< The raw data word read from memory with error. */
  564. struct
  565. {
  566. bool byteIsRead; /*!< The byte n (0~3) was read or not. */
  567. /*!< The type of error and which bit in byte (n) is affected by the error. */
  568. flexcan_byte_error_syndrome_t bitAffected;
  569. } byteStatus[4];
  570. } flexcan_memory_error_report_status_t;
  571. #endif
  572. #if defined(__CC_ARM)
  573. #pragma anon_unions
  574. #endif
  575. /*! @brief FlexCAN message frame structure. */
  576. typedef struct _flexcan_frame
  577. {
  578. struct
  579. {
  580. uint32_t timestamp : 16; /*!< FlexCAN internal Free-Running Counter Time Stamp. */
  581. uint32_t length : 4; /*!< CAN frame data length in bytes (Range: 0~8). */
  582. uint32_t type : 1; /*!< CAN Frame Type(DATA or REMOTE). */
  583. uint32_t format : 1; /*!< CAN Frame Identifier(STD or EXT format). */
  584. uint32_t : 1; /*!< Reserved. */
  585. uint32_t idhit : 9; /*!< CAN Rx FIFO filter hit id(This value is only used in Rx FIFO receive mode). */
  586. };
  587. struct
  588. {
  589. uint32_t id : 29; /*!< CAN Frame Identifier, should be set using FLEXCAN_ID_EXT() or FLEXCAN_ID_STD() macro. */
  590. uint32_t : 3; /*!< Reserved. */
  591. };
  592. union
  593. {
  594. struct
  595. {
  596. uint32_t dataWord0; /*!< CAN Frame payload word0. */
  597. uint32_t dataWord1; /*!< CAN Frame payload word1. */
  598. };
  599. struct
  600. {
  601. uint8_t dataByte3; /*!< CAN Frame payload byte3. */
  602. uint8_t dataByte2; /*!< CAN Frame payload byte2. */
  603. uint8_t dataByte1; /*!< CAN Frame payload byte1. */
  604. uint8_t dataByte0; /*!< CAN Frame payload byte0. */
  605. uint8_t dataByte7; /*!< CAN Frame payload byte7. */
  606. uint8_t dataByte6; /*!< CAN Frame payload byte6. */
  607. uint8_t dataByte5; /*!< CAN Frame payload byte5. */
  608. uint8_t dataByte4; /*!< CAN Frame payload byte4. */
  609. };
  610. };
  611. } flexcan_frame_t;
  612. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  613. /*! @brief CAN FD message frame structure.
  614. *
  615. * The CAN FD message supporting up to sixty four bytes can be used for a data frame, depending on the length
  616. * selected for the message buffers. The length should be a enumeration member, see @ref _flexcan_fd_frame_length.
  617. */
  618. typedef struct _flexcan_fd_frame
  619. {
  620. struct
  621. {
  622. uint32_t timestamp : 16; /*!< FlexCAN internal Free-Running Counter Time Stamp. */
  623. uint32_t length : 4; /*!< CAN FD frame data length code (DLC), range see @ref _flexcan_fd_frame_length, When the
  624. length <= 8, it equal to the data length, otherwise the number of valid frame data is
  625. not equal to the length value. user can
  626. use DLC_LENGTH_DECODE(length) macro to get the number of valid data bytes. */
  627. uint32_t type : 1; /*!< CAN Frame Type(DATA or REMOTE). */
  628. uint32_t format : 1; /*!< CAN Frame Identifier(STD or EXT format). */
  629. uint32_t srr : 1; /*!< Substitute Remote request. */
  630. uint32_t : 6;
  631. uint32_t esi : 1; /*!< Error State Indicator. */
  632. uint32_t brs : 1; /*!< Bit Rate Switch. */
  633. uint32_t edl : 1; /*!< Extended Data Length. */
  634. };
  635. struct
  636. {
  637. uint32_t id : 29; /*!< CAN Frame Identifier, should be set using FLEXCAN_ID_EXT() or FLEXCAN_ID_STD() macro. */
  638. uint32_t : 3; /*!< Reserved. */
  639. };
  640. union
  641. {
  642. struct
  643. {
  644. uint32_t dataWord[16]; /*!< CAN FD Frame payload, 16 double word maximum. */
  645. };
  646. /* Note: the maximum databyte* below is actually 64, user can add them if needed,
  647. or just use dataWord[*] instead. */
  648. struct
  649. {
  650. uint8_t dataByte3; /*!< CAN Frame payload byte3. */
  651. uint8_t dataByte2; /*!< CAN Frame payload byte2. */
  652. uint8_t dataByte1; /*!< CAN Frame payload byte1. */
  653. uint8_t dataByte0; /*!< CAN Frame payload byte0. */
  654. uint8_t dataByte7; /*!< CAN Frame payload byte7. */
  655. uint8_t dataByte6; /*!< CAN Frame payload byte6. */
  656. uint8_t dataByte5; /*!< CAN Frame payload byte5. */
  657. uint8_t dataByte4; /*!< CAN Frame payload byte4. */
  658. };
  659. };
  660. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  661. /*! @note ID HIT offset is changed dynamically according to data length code (DLC), when DLC is 15, they will be
  662. * located below. Using FLEXCAN_FixEnhancedRxFifoFrameIdHit API is recommended to ensure this idhit value is
  663. * correct.*/
  664. uint32_t idhit; /*!< CAN Enhanced Rx FIFO filter hit id (This value is only used in Enhanced Rx FIFO receive
  665. mode). */
  666. #endif
  667. } flexcan_fd_frame_t;
  668. #endif
  669. /*! @brief FlexCAN protocol timing characteristic configuration structure. */
  670. typedef struct _flexcan_timing_config
  671. {
  672. uint16_t preDivider; /*!< Classic CAN or CAN FD nominal phase bit rate prescaler. */
  673. uint8_t rJumpwidth; /*!< Classic CAN or CAN FD nominal phase Re-sync Jump Width. */
  674. uint8_t phaseSeg1; /*!< Classic CAN or CAN FD nominal phase Segment 1. */
  675. uint8_t phaseSeg2; /*!< Classic CAN or CAN FD nominal phase Segment 2. */
  676. uint8_t propSeg; /*!< Classic CAN or CAN FD nominal phase Propagation Segment. */
  677. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  678. uint16_t fpreDivider; /*!< CAN FD data phase bit rate prescaler. */
  679. uint8_t frJumpwidth; /*!< CAN FD data phase Re-sync Jump Width. */
  680. uint8_t fphaseSeg1; /*!< CAN FD data phase Phase Segment 1. */
  681. uint8_t fphaseSeg2; /*!< CAN FD data phase Phase Segment 2. */
  682. uint8_t fpropSeg; /*!< CAN FD data phase Propagation Segment. */
  683. #endif
  684. } flexcan_timing_config_t;
  685. /*! @brief FlexCAN module configuration structure.
  686. * @deprecated Do not use the baudRate. It has been superceded bitRate
  687. * @deprecated Do not use the baudRateFD. It has been superceded bitRateFD
  688. */
  689. typedef struct _flexcan_config
  690. {
  691. union
  692. {
  693. struct
  694. {
  695. uint32_t baudRate; /*!< FlexCAN bit rate in bps, for classical CAN or CANFD nominal phase. */
  696. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  697. uint32_t baudRateFD; /*!< FlexCAN FD bit rate in bps, for CANFD data phase. */
  698. #endif
  699. };
  700. struct
  701. {
  702. uint32_t bitRate; /*!< FlexCAN bit rate in bps, for classical CAN or CANFD nominal phase. */
  703. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  704. uint32_t bitRateFD; /*!< FlexCAN FD bit rate in bps, for CANFD data phase. */
  705. #endif
  706. };
  707. };
  708. flexcan_clock_source_t clkSrc; /*!< Clock source for FlexCAN Protocol Engine. */
  709. flexcan_wake_up_source_t wakeupSrc; /*!< Wake up source selection. */
  710. uint8_t maxMbNum; /*!< The maximum number of Message Buffers used by user. */
  711. bool enableLoopBack; /*!< Enable or Disable Loop Back Self Test Mode. */
  712. bool enableTimerSync; /*!< Enable or Disable Timer Synchronization. */
  713. bool enableSelfWakeup; /*!< Enable or Disable Self Wakeup Mode. */
  714. bool enableIndividMask; /*!< Enable or Disable Rx Individual Mask and Queue feature. */
  715. bool disableSelfReception; /*!< Enable or Disable Self Reflection. */
  716. bool enableListenOnlyMode; /*!< Enable or Disable Listen Only Mode. */
  717. #if !(defined(FSL_FEATURE_FLEXCAN_HAS_NO_SUPV_SUPPORT) && FSL_FEATURE_FLEXCAN_HAS_NO_SUPV_SUPPORT)
  718. bool enableSupervisorMode; /*!< Enable or Disable Supervisor Mode, enable this mode will make registers allow only
  719. Supervisor access. */
  720. #endif
  721. #if (defined(FSL_FEATURE_FLEXCAN_HAS_DOZE_MODE_SUPPORT) && FSL_FEATURE_FLEXCAN_HAS_DOZE_MODE_SUPPORT)
  722. bool enableDoze; /*!< Enable or Disable Doze Mode. */
  723. #endif
  724. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE)
  725. bool enablePretendedeNetworking; /*!< Enable or Disable the Pretended Networking mode. */
  726. #endif
  727. #if (defined(FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL) && FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL)
  728. bool enableMemoryErrorControl; /*!< Enable or Disable the memory errors detection and correction mechanism. */
  729. bool enableNonCorrectableErrorEnterFreeze; /*!< Enable or Disable Non-Correctable Errors In FlexCAN Access Put
  730. Device In Freeze Mode. */
  731. #endif
  732. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_BIT_TIMING_REG) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_BIT_TIMING_REG)
  733. bool enableTransceiverDelayMeasure; /*!< Enable or Disable the transceiver delay measurement, when it is enabled,
  734. then the secondary sample point position is determined by the sum of the
  735. transceiver delay measurement plus the enhanced TDC offset. */
  736. #endif
  737. flexcan_timing_config_t timingConfig; /* Protocol timing . */
  738. } flexcan_config_t;
  739. /*!
  740. * @brief FlexCAN Receive Message Buffer configuration structure
  741. *
  742. * This structure is used as the parameter of FLEXCAN_SetRxMbConfig() function.
  743. * The FLEXCAN_SetRxMbConfig() function is used to configure FlexCAN Receive
  744. * Message Buffer. The function abort previous receiving process, clean the
  745. * Message Buffer and activate the Rx Message Buffer using given Message Buffer
  746. * setting.
  747. */
  748. typedef struct _flexcan_rx_mb_config
  749. {
  750. uint32_t id; /*!< CAN Message Buffer Frame Identifier, should be set using
  751. FLEXCAN_ID_EXT() or FLEXCAN_ID_STD() macro. */
  752. flexcan_frame_format_t format; /*!< CAN Frame Identifier format(Standard of Extend). */
  753. flexcan_frame_type_t type; /*!< CAN Frame Type(Data or Remote). */
  754. } flexcan_rx_mb_config_t;
  755. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE)
  756. /*! @brief FlexCAN Pretended Networking match source selection. */
  757. typedef enum _flexcan_pn_match_source
  758. {
  759. kFLEXCAN_PNMatSrcID = 0U, /*!< Message match with ID filtering. */
  760. kFLEXCAN_PNMatSrcIDAndData, /*!< Message match with ID filtering and payload filtering. */
  761. } flexcan_pn_match_source_t;
  762. /*! @brief FlexCAN Pretended Networking mode match type. */
  763. typedef enum _flexcan_pn_match_mode
  764. {
  765. kFLEXCAN_PNMatModeEqual = 0x0U, /*!< Match upon ID/Payload contents against an exact target value. */
  766. kFLEXCAN_PNMatModeGreater, /*!< Match upon an ID/Payload value greater than or equal to a specified target value.
  767. */
  768. kFLEXCAN_PNMatModeSmaller, /*!< Match upon an ID/Payload value smaller than or equal to a specified target value.
  769. */
  770. kFLEXCAN_PNMatModeRange, /*!< Match upon an ID/Payload value inside a range, greater than or equal to a specified
  771. lower limit, and smaller than or equal to a specified upper limit */
  772. } flexcan_pn_match_mode_t;
  773. /*!
  774. * @brief FlexCAN Pretended Networking configuration structure
  775. *
  776. * This structure is used as the parameter of FLEXCAN_SetPNConfig() function.
  777. * The FLEXCAN_SetPNConfig() function is used to configure FlexCAN Networking work mode.
  778. */
  779. typedef struct _flexcan_pn_config
  780. {
  781. bool enableTimeout; /*!< Enable or Disable timeout event trigger wakeup.*/
  782. uint16_t timeoutValue; /*!< The timeout value that generates a wakeup event, the counter timer is incremented based
  783. on 64 times the CAN Bit Time unit. */
  784. bool enableMatch; /*!< Enable or Disable match event trigger wakeup.*/
  785. flexcan_pn_match_source_t matchSrc; /*!< Selects the match source (ID and/or data match) to trigger wakeup. */
  786. uint8_t matchNum; /*!< The number of times a given message must match the predefined ID and/or data before
  787. generating a wakeup event, range in 0x1 ~ 0xFF. */
  788. flexcan_pn_match_mode_t idMatchMode; /*!< The ID match type. */
  789. flexcan_pn_match_mode_t dataMatchMode; /*!< The data match type. */
  790. uint32_t idLower; /*!< The ID target values 1 which used either for ID match "equal to", "smaller than",
  791. "greater than" comparisons, or as the lower limit value in ID match "range detection". */
  792. uint32_t idUpper; /*!< The ID target values 2 which used only as the upper limit value in ID match "range
  793. detection" or used to store the ID mask in "equal to". */
  794. uint8_t lengthLower; /*!< The lower limit for length of data bytes which used only in data match "range
  795. detection". Range in 0x0 ~ 0x8.*/
  796. uint8_t lengthUpper; /*!< The upper limit for length of data bytes which used only in data match "range
  797. detection". Range in 0x0 ~ 0x8.*/
  798. union
  799. {
  800. /*!< The data target values 1 which used either for data match "equal to", "smaller than",
  801. "greater than" comparisons, or as the lower limit value in data match "range
  802. detection". */
  803. struct
  804. {
  805. uint32_t lowerWord0; /*!< CAN Frame payload word0. */
  806. uint32_t lowerWord1; /*!< CAN Frame payload word1. */
  807. };
  808. struct
  809. {
  810. uint8_t lowerByte3; /*!< CAN Frame payload byte3. */
  811. uint8_t lowerByte2; /*!< CAN Frame payload byte2. */
  812. uint8_t lowerByte1; /*!< CAN Frame payload byte1. */
  813. uint8_t lowerByte0; /*!< CAN Frame payload byte0. */
  814. uint8_t lowerByte7; /*!< CAN Frame payload byte7. */
  815. uint8_t lowerByte6; /*!< CAN Frame payload byte6. */
  816. uint8_t lowerByte5; /*!< CAN Frame payload byte5. */
  817. uint8_t lowerByte4; /*!< CAN Frame payload byte4. */
  818. };
  819. };
  820. union
  821. {
  822. /*!< The data target values 2 which used only as the upper limit value in data match "range
  823. detection" or used to store the data mask in "equal to". */
  824. struct
  825. {
  826. uint32_t upperWord0; /*!< CAN Frame payload word0. */
  827. uint32_t upperWord1; /*!< CAN Frame payload word1. */
  828. };
  829. struct
  830. {
  831. uint8_t upperByte3; /*!< CAN Frame payload byte3. */
  832. uint8_t upperByte2; /*!< CAN Frame payload byte2. */
  833. uint8_t upperByte1; /*!< CAN Frame payload byte1. */
  834. uint8_t upperByte0; /*!< CAN Frame payload byte0. */
  835. uint8_t upperByte7; /*!< CAN Frame payload byte7. */
  836. uint8_t upperByte6; /*!< CAN Frame payload byte6. */
  837. uint8_t upperByte5; /*!< CAN Frame payload byte5. */
  838. uint8_t upperByte4; /*!< CAN Frame payload byte4. */
  839. };
  840. };
  841. } flexcan_pn_config_t;
  842. #endif
  843. /*! @brief FlexCAN Legacy Rx FIFO configuration structure. */
  844. typedef struct _flexcan_rx_fifo_config
  845. {
  846. uint32_t *idFilterTable; /*!< Pointer to the FlexCAN Legacy Rx FIFO identifier filter table. */
  847. uint8_t idFilterNum; /*!< The FlexCAN Legacy Rx FIFO Filter elements quantity. */
  848. flexcan_rx_fifo_filter_type_t idFilterType; /*!< The FlexCAN Legacy Rx FIFO Filter type. */
  849. flexcan_rx_fifo_priority_t priority; /*!< The FlexCAN Legacy Rx FIFO receive priority. */
  850. } flexcan_rx_fifo_config_t;
  851. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  852. /*! @brief FlexCAN Enhanced Rx FIFO Standard ID filter element structure. */
  853. typedef struct _flexcan_enhanced_rx_fifo_std_id_filter
  854. {
  855. uint32_t filterType : 2; /*!< FlexCAN internal Free-Running Counter Time Stamp. */
  856. uint32_t : 2;
  857. uint32_t rtr1 : 1; /*!< CAN FD frame data length code (DLC), range see @ref _flexcan_fd_frame_length, When the
  858. length <= 8, it equal to the data length, otherwise the number of valid frame data is
  859. not equal to the length value. user can
  860. use DLC_LENGTH_DECODE(length) macro to get the number of valid data bytes. */
  861. uint32_t std1 : 11; /*!< CAN Frame Type(DATA or REMOTE). */
  862. uint32_t : 4;
  863. uint32_t rtr2 : 1; /*!< CAN Frame Identifier(STD or EXT format). */
  864. uint32_t std2 : 11; /*!< Substitute Remote request. */
  865. } flexcan_enhanced_rx_fifo_std_id_filter_t;
  866. /*! @brief FlexCAN Enhanced Rx FIFO Extended ID filter element structure. */
  867. typedef struct _flexcan_enhanced_rx_fifo_ext_id_filter
  868. {
  869. uint32_t filterType : 2; /*!< FlexCAN internal Free-Running Counter Time Stamp. */
  870. uint32_t rtr1 : 1; /*!< CAN FD frame data length code (DLC), range see @ref _flexcan_fd_frame_length, When the
  871. length <= 8, it equal to the data length, otherwise the number of valid frame data is
  872. not equal to the length value. user can
  873. use DLC_LENGTH_DECODE(length) macro to get the number of valid data bytes. */
  874. uint32_t std1 : 29; /*!< CAN Frame Type(DATA or REMOTE). */
  875. uint32_t : 2;
  876. uint32_t rtr2 : 1; /*!< CAN Frame Identifier(STD or EXT format). */
  877. uint32_t std2 : 29; /*!< Substitute Remote request. */
  878. } flexcan_enhanced_rx_fifo_ext_id_filter_t;
  879. /*! @brief FlexCAN Enhanced Rx FIFO configuration structure. */
  880. typedef struct _flexcan_enhanced_rx_fifo_config
  881. {
  882. uint32_t *idFilterTable; /*!< Pointer to the FlexCAN Enhanced Rx FIFO identifier filter table, each table member
  883. occupies 32 bit word, table size should be equal to idFilterNum. There are two types of
  884. Enhanced Rx FIFO filter elements that can be stored in table : extended-ID filter element
  885. (1 word, occupie 1 table members) and standard-ID filter element (2 words, occupies 2 table
  886. members), the extended-ID filter element needs to be placed in front of the table. */
  887. uint8_t idFilterPairNum; /*!< (idFilterPairNum + 1) is the Enhanced Rx FIFO identifier filter element pair numbers,
  888. each pair of filter elements occupies 2 words and can consist of one extended ID filter
  889. element or two standard ID filter elements. */
  890. uint8_t extendIdFilterNum; /*!< The number of extended ID filter element items in the FlexCAN enhanced Rx FIFO
  891. identifier filter table, each extended-ID filter element occupies 2 words,
  892. extendIdFilterNum need less than or equal to (idFilterPairNum + 1). */
  893. uint8_t fifoWatermark; /*!< (fifoWatermark + 1) is the minimum number of CAN messages stored in the Enhanced RX FIFO
  894. which can trigger FIFO watermark interrupt or a DMA request. */
  895. flexcan_efifo_dma_per_read_length_t dmaPerReadLength; /*!< Define the length of each read of the Enhanced RX FIFO
  896. element by the DAM, see @ref _flexcan_fd_frame_length. */
  897. flexcan_rx_fifo_priority_t priority; /*!< The FlexCAN Enhanced Rx FIFO receive priority. */
  898. } flexcan_enhanced_rx_fifo_config_t;
  899. #endif
  900. /*! @brief FlexCAN Message Buffer transfer. */
  901. typedef struct _flexcan_mb_transfer
  902. {
  903. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  904. flexcan_fd_frame_t *framefd;
  905. #endif
  906. flexcan_frame_t *frame; /*!< The buffer of CAN Message to be transfer. */
  907. uint8_t mbIdx; /*!< The index of Message buffer used to transfer Message. */
  908. } flexcan_mb_transfer_t;
  909. /*! @brief FlexCAN Rx FIFO transfer. */
  910. typedef struct _flexcan_fifo_transfer
  911. {
  912. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  913. flexcan_fd_frame_t *framefd; /*!< The buffer of CAN Message to be received from Enhanced Rx FIFO. */
  914. size_t frameNum; /*!< Number of CAN Message need to be received from Ehanced Rx FIFO. */
  915. #endif
  916. flexcan_frame_t *frame; /*!< The buffer of CAN Message to be received from Rx FIFO. */
  917. } flexcan_fifo_transfer_t;
  918. /*! @brief FlexCAN handle structure definition. */
  919. typedef struct _flexcan_handle flexcan_handle_t;
  920. /*! @brief FlexCAN transfer callback function.
  921. *
  922. * The FlexCAN transfer callback returns a value from the underlying layer.
  923. * If the status equals to kStatus_FLEXCAN_ErrorStatus, the result parameter is the Content of
  924. * FlexCAN status register which can be used to get the working status(or error status) of FlexCAN module.
  925. * If the status equals to other FlexCAN Message Buffer transfer status, the result is the index of
  926. * Message Buffer that generate transfer event.
  927. * If the status equals to other FlexCAN Message Buffer transfer status, the result is meaningless and should be
  928. * Ignored.
  929. */
  930. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE) || \
  931. (defined(FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL) && FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL)
  932. #define FLEXCAN_CALLBACK(x) \
  933. void(x)(CAN_Type * base, flexcan_handle_t * handle, status_t status, uint64_t result, void *userData)
  934. typedef void (*flexcan_transfer_callback_t)(
  935. CAN_Type *base, flexcan_handle_t *handle, status_t status, uint64_t result, void *userData);
  936. #else
  937. #define FLEXCAN_CALLBACK(x) \
  938. void(x)(CAN_Type * base, flexcan_handle_t * handle, status_t status, uint32_t result, void *userData)
  939. typedef void (*flexcan_transfer_callback_t)(
  940. CAN_Type *base, flexcan_handle_t *handle, status_t status, uint32_t result, void *userData);
  941. #endif
  942. /*! @brief FlexCAN handle structure. */
  943. struct _flexcan_handle
  944. {
  945. flexcan_transfer_callback_t callback; /*!< Callback function. */
  946. void *userData; /*!< FlexCAN callback function parameter.*/
  947. flexcan_frame_t
  948. *volatile mbFrameBuf[CAN_WORD1_COUNT]; /*!< The buffer for received CAN data from Message Buffers. */
  949. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  950. flexcan_fd_frame_t
  951. *volatile mbFDFrameBuf[CAN_WORD1_COUNT]; /*!< The buffer for received CAN FD data from Message Buffers. */
  952. #endif
  953. flexcan_frame_t *volatile rxFifoFrameBuf; /*!< The buffer for received CAN data from Legacy Rx FIFO. */
  954. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  955. flexcan_fd_frame_t *volatile rxFifoFDFrameBuf; /*!< The buffer for received CAN FD data from Ehanced Rx FIFO. */
  956. size_t frameNum; /*!< The number of CAN messages remaining to be received. */
  957. size_t transferTotalNum; /*!< Total CAN Message number need to be received from Ehanced Rx FIFO. */
  958. #endif
  959. volatile uint8_t mbState[CAN_WORD1_COUNT]; /*!< Message Buffer transfer state. */
  960. volatile uint8_t rxFifoState; /*!< Rx FIFO transfer state. */
  961. volatile uint32_t timestamp[CAN_WORD1_COUNT]; /*!< Mailbox transfer timestamp. */
  962. };
  963. /******************************************************************************
  964. * API
  965. *****************************************************************************/
  966. #if defined(__cplusplus)
  967. extern "C" {
  968. #endif
  969. /*!
  970. * @name Initialization and deinitialization
  971. * @{
  972. */
  973. /*!
  974. * @brief Enter FlexCAN Freeze Mode.
  975. *
  976. * This function makes the FlexCAN work under Freeze Mode.
  977. *
  978. * @param base FlexCAN peripheral base address.
  979. */
  980. void FLEXCAN_EnterFreezeMode(CAN_Type *base);
  981. /*!
  982. * @brief Exit FlexCAN Freeze Mode.
  983. *
  984. * This function makes the FlexCAN leave Freeze Mode.
  985. *
  986. * @param base FlexCAN peripheral base address.
  987. */
  988. void FLEXCAN_ExitFreezeMode(CAN_Type *base);
  989. /*!
  990. * @brief Get the FlexCAN instance from peripheral base address.
  991. *
  992. * @param base FlexCAN peripheral base address.
  993. * @return FlexCAN instance.
  994. */
  995. uint32_t FLEXCAN_GetInstance(CAN_Type *base);
  996. /*!
  997. * @brief Calculates the improved timing values by specific bit Rates for classical CAN.
  998. *
  999. * This function use to calculates the Classical CAN timing values according to the given bit rate. The Calculated
  1000. * timing values will be set in CTRL1/CBT/ENCBT register. The calculation is based on the recommendation of the CiA 301
  1001. * v4.2.0 and previous version document.
  1002. *
  1003. * @param base FlexCAN peripheral base address.
  1004. * @param bitRate The classical CAN speed in bps defined by user, should be less than or equal to 1Mbps.
  1005. * @param sourceClock_Hz The Source clock frequency in Hz.
  1006. * @param pTimingConfig Pointer to the FlexCAN timing configuration structure.
  1007. *
  1008. * @return TRUE if timing configuration found, FALSE if failed to find configuration.
  1009. */
  1010. bool FLEXCAN_CalculateImprovedTimingValues(CAN_Type *base,
  1011. uint32_t bitRate,
  1012. uint32_t sourceClock_Hz,
  1013. flexcan_timing_config_t *pTimingConfig);
  1014. /*!
  1015. * @brief Initializes a FlexCAN instance.
  1016. *
  1017. * This function initializes the FlexCAN module with user-defined settings.
  1018. * This example shows how to set up the flexcan_config_t parameters and how
  1019. * to call the FLEXCAN_Init function by passing in these parameters.
  1020. * @code
  1021. * flexcan_config_t flexcanConfig;
  1022. * flexcanConfig.clkSrc = kFLEXCAN_ClkSrc0;
  1023. * flexcanConfig.bitRate = 1000000U;
  1024. * flexcanConfig.maxMbNum = 16;
  1025. * flexcanConfig.enableLoopBack = false;
  1026. * flexcanConfig.enableSelfWakeup = false;
  1027. * flexcanConfig.enableIndividMask = false;
  1028. * flexcanConfig.enableDoze = false;
  1029. * flexcanConfig.disableSelfReception = false;
  1030. * flexcanConfig.enableListenOnlyMode = false;
  1031. * flexcanConfig.timingConfig = timingConfig;
  1032. * FLEXCAN_Init(CAN0, &flexcanConfig, 40000000UL);
  1033. * @endcode
  1034. *
  1035. * @param base FlexCAN peripheral base address.
  1036. * @param pConfig Pointer to the user-defined configuration structure.
  1037. * @param sourceClock_Hz FlexCAN Protocol Engine clock source frequency in Hz.
  1038. */
  1039. void FLEXCAN_Init(CAN_Type *base, const flexcan_config_t *pConfig, uint32_t sourceClock_Hz);
  1040. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  1041. /*!
  1042. * @brief Calculates the improved timing values by specific bit rates for CANFD.
  1043. *
  1044. * This function use to calculates the CANFD timing values according to the given nominal phase bit rate and data phase
  1045. * bit rate. The Calculated timing values will be set in CBT/ENCBT and FDCBT/EDCBT registers. The calculation is based
  1046. * on the recommendation of the CiA 1301 v1.0.0 document.
  1047. *
  1048. * @param base FlexCAN peripheral base address.
  1049. * @param bitRate The CANFD bus control speed in bps defined by user.
  1050. * @param bitRateFD The CAN FD data phase speed in bps defined by user. Equal to bitRate means disable bit rate
  1051. * switching.
  1052. * @param sourceClock_Hz The Source clock frequency in Hz.
  1053. * @param pTimingConfig Pointer to the FlexCAN timing configuration structure.
  1054. *
  1055. * @return TRUE if timing configuration found, FALSE if failed to find configuration
  1056. */
  1057. bool FLEXCAN_FDCalculateImprovedTimingValues(CAN_Type *base,
  1058. uint32_t bitRate,
  1059. uint32_t bitRateFD,
  1060. uint32_t sourceClock_Hz,
  1061. flexcan_timing_config_t *pTimingConfig);
  1062. /*!
  1063. * @brief Initializes a FlexCAN instance.
  1064. *
  1065. * This function initializes the FlexCAN module with user-defined settings.
  1066. * This example shows how to set up the flexcan_config_t parameters and how
  1067. * to call the FLEXCAN_FDInit function by passing in these parameters.
  1068. * @code
  1069. * flexcan_config_t flexcanConfig;
  1070. * flexcanConfig.clkSrc = kFLEXCAN_ClkSrc0;
  1071. * flexcanConfig.bitRate = 1000000U;
  1072. * flexcanConfig.bitRateFD = 2000000U;
  1073. * flexcanConfig.maxMbNum = 16;
  1074. * flexcanConfig.enableLoopBack = false;
  1075. * flexcanConfig.enableSelfWakeup = false;
  1076. * flexcanConfig.enableIndividMask = false;
  1077. * flexcanConfig.disableSelfReception = false;
  1078. * flexcanConfig.enableListenOnlyMode = false;
  1079. * flexcanConfig.enableDoze = false;
  1080. * flexcanConfig.timingConfig = timingConfig;
  1081. * FLEXCAN_FDInit(CAN0, &flexcanConfig, 80000000UL, kFLEXCAN_16BperMB, true);
  1082. * @endcode
  1083. *
  1084. * @param base FlexCAN peripheral base address.
  1085. * @param pConfig Pointer to the user-defined configuration structure.
  1086. * @param sourceClock_Hz FlexCAN Protocol Engine clock source frequency in Hz.
  1087. * @param dataSize FlexCAN Message Buffer payload size. The actual transmitted or received CAN FD frame data size needs
  1088. * to be less than or equal to this value.
  1089. * @param brs True if bit rate switch is enabled in FD mode.
  1090. */
  1091. void FLEXCAN_FDInit(
  1092. CAN_Type *base, const flexcan_config_t *pConfig, uint32_t sourceClock_Hz, flexcan_mb_size_t dataSize, bool brs);
  1093. #endif
  1094. /*!
  1095. * @brief De-initializes a FlexCAN instance.
  1096. *
  1097. * This function disables the FlexCAN module clock and sets all register values
  1098. * to the reset value.
  1099. *
  1100. * @param base FlexCAN peripheral base address.
  1101. */
  1102. void FLEXCAN_Deinit(CAN_Type *base);
  1103. /*!
  1104. * @brief Gets the default configuration structure.
  1105. *
  1106. * This function initializes the FlexCAN configuration structure to default values. The default
  1107. * values are as follows.
  1108. * flexcanConfig->clkSrc = kFLEXCAN_ClkSrc0;
  1109. * flexcanConfig->bitRate = 1000000U;
  1110. * flexcanConfig->bitRateFD = 2000000U;
  1111. * flexcanConfig->maxMbNum = 16;
  1112. * flexcanConfig->enableLoopBack = false;
  1113. * flexcanConfig->enableSelfWakeup = false;
  1114. * flexcanConfig->enableIndividMask = false;
  1115. * flexcanConfig->disableSelfReception = false;
  1116. * flexcanConfig->enableListenOnlyMode = false;
  1117. * flexcanConfig->enableDoze = false;
  1118. * flexcanConfig->enableMemoryErrorControl = true;
  1119. * flexcanConfig->enableNonCorrectableErrorEnterFreeze = true;
  1120. * flexcanConfig.timingConfig = timingConfig;
  1121. *
  1122. * @param pConfig Pointer to the FlexCAN configuration structure.
  1123. */
  1124. void FLEXCAN_GetDefaultConfig(flexcan_config_t *pConfig);
  1125. /* @} */
  1126. /*!
  1127. * @name Configuration.
  1128. * @{
  1129. */
  1130. /*!
  1131. * @brief Sets the FlexCAN protocol timing characteristic.
  1132. *
  1133. * This function gives user settings to classical CAN or CANFD nominal phase timing characteristic.
  1134. * The function is for an experienced user. For less experienced users, call the FLEXCAN_GetDefaultConfig()
  1135. * and get the default timing characteristicsthe, then call FLEXCAN_Init() and fill the
  1136. * bit rate field.
  1137. *
  1138. * @note Calling FLEXCAN_SetTimingConfig() overrides the bit rate set in FLEXCAN_Init().
  1139. *
  1140. * @param base FlexCAN peripheral base address.
  1141. * @param pConfig Pointer to the timing configuration structure.
  1142. */
  1143. void FLEXCAN_SetTimingConfig(CAN_Type *base, const flexcan_timing_config_t *pConfig);
  1144. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  1145. /*!
  1146. * @brief Sets the FlexCAN CANFD data phase timing characteristic.
  1147. *
  1148. * This function gives user settings to CANFD data phase timing characteristic.
  1149. * The function is for an experienced user. For less experienced users, call the FLEXCAN_GetDefaultConfig()
  1150. * and get the default timing characteristicsthe, then call FLEXCAN_FDInit() and fill the
  1151. * data phase bit rate field.
  1152. *
  1153. * @note Calling FLEXCAN_SetFDTimingConfig() overrides the bit rate set in FLEXCAN_FDInit().
  1154. *
  1155. * @param base FlexCAN peripheral base address.
  1156. * @param pConfig Pointer to the timing configuration structure.
  1157. */
  1158. void FLEXCAN_SetFDTimingConfig(CAN_Type *base, const flexcan_timing_config_t *pConfig);
  1159. #endif
  1160. /*!
  1161. * @brief Sets the FlexCAN receive message buffer global mask.
  1162. *
  1163. * This function sets the global mask for the FlexCAN message buffer in a matching process.
  1164. * The configuration is only effective when the Rx individual mask is disabled in the FLEXCAN_Init().
  1165. *
  1166. * @param base FlexCAN peripheral base address.
  1167. * @param mask Rx Message Buffer Global Mask value.
  1168. */
  1169. void FLEXCAN_SetRxMbGlobalMask(CAN_Type *base, uint32_t mask);
  1170. /*!
  1171. * @brief Sets the FlexCAN receive FIFO global mask.
  1172. *
  1173. * This function sets the global mask for FlexCAN FIFO in a matching process.
  1174. *
  1175. * @param base FlexCAN peripheral base address.
  1176. * @param mask Rx Fifo Global Mask value.
  1177. */
  1178. void FLEXCAN_SetRxFifoGlobalMask(CAN_Type *base, uint32_t mask);
  1179. /*!
  1180. * @brief Sets the FlexCAN receive individual mask.
  1181. *
  1182. * This function sets the individual mask for the FlexCAN matching process.
  1183. * The configuration is only effective when the Rx individual mask is enabled in the FLEXCAN_Init().
  1184. * If the Rx FIFO is disabled, the individual mask is applied to the corresponding Message Buffer.
  1185. * If the Rx FIFO is enabled, the individual mask for Rx FIFO occupied Message Buffer is applied to
  1186. * the Rx Filter with the same index. Note that only the first 32
  1187. * individual masks can be used as the Rx FIFO filter mask.
  1188. *
  1189. * @param base FlexCAN peripheral base address.
  1190. * @param maskIdx The Index of individual Mask.
  1191. * @param mask Rx Individual Mask value.
  1192. */
  1193. void FLEXCAN_SetRxIndividualMask(CAN_Type *base, uint8_t maskIdx, uint32_t mask);
  1194. /*!
  1195. * @brief Configures a FlexCAN transmit message buffer.
  1196. *
  1197. * This function aborts the previous transmission, cleans the Message Buffer, and
  1198. * configures it as a Transmit Message Buffer.
  1199. *
  1200. * @param base FlexCAN peripheral base address.
  1201. * @param mbIdx The Message Buffer index.
  1202. * @param enable Enable/disable Tx Message Buffer.
  1203. * - true: Enable Tx Message Buffer.
  1204. * - false: Disable Tx Message Buffer.
  1205. */
  1206. void FLEXCAN_SetTxMbConfig(CAN_Type *base, uint8_t mbIdx, bool enable);
  1207. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  1208. /*!
  1209. * @brief Configures a FlexCAN transmit message buffer.
  1210. *
  1211. * This function aborts the previous transmission, cleans the Message Buffer, and
  1212. * configures it as a Transmit Message Buffer.
  1213. *
  1214. * @param base FlexCAN peripheral base address.
  1215. * @param mbIdx The Message Buffer index.
  1216. * @param enable Enable/disable Tx Message Buffer.
  1217. * - true: Enable Tx Message Buffer.
  1218. * - false: Disable Tx Message Buffer.
  1219. */
  1220. void FLEXCAN_SetFDTxMbConfig(CAN_Type *base, uint8_t mbIdx, bool enable);
  1221. #endif
  1222. /*!
  1223. * @brief Configures a FlexCAN Receive Message Buffer.
  1224. *
  1225. * This function cleans a FlexCAN build-in Message Buffer and configures it
  1226. * as a Receive Message Buffer.
  1227. *
  1228. * @param base FlexCAN peripheral base address.
  1229. * @param mbIdx The Message Buffer index.
  1230. * @param pRxMbConfig Pointer to the FlexCAN Message Buffer configuration structure.
  1231. * @param enable Enable/disable Rx Message Buffer.
  1232. * - true: Enable Rx Message Buffer.
  1233. * - false: Disable Rx Message Buffer.
  1234. */
  1235. void FLEXCAN_SetRxMbConfig(CAN_Type *base, uint8_t mbIdx, const flexcan_rx_mb_config_t *pRxMbConfig, bool enable);
  1236. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  1237. /*!
  1238. * @brief Configures a FlexCAN Receive Message Buffer.
  1239. *
  1240. * This function cleans a FlexCAN build-in Message Buffer and configures it
  1241. * as a Receive Message Buffer.
  1242. *
  1243. * @param base FlexCAN peripheral base address.
  1244. * @param mbIdx The Message Buffer index.
  1245. * @param pRxMbConfig Pointer to the FlexCAN Message Buffer configuration structure.
  1246. * @param enable Enable/disable Rx Message Buffer.
  1247. * - true: Enable Rx Message Buffer.
  1248. * - false: Disable Rx Message Buffer.
  1249. */
  1250. void FLEXCAN_SetFDRxMbConfig(CAN_Type *base, uint8_t mbIdx, const flexcan_rx_mb_config_t *pRxMbConfig, bool enable);
  1251. #endif
  1252. /*!
  1253. * @brief Configures the FlexCAN Legacy Rx FIFO.
  1254. *
  1255. * This function configures the FlexCAN Rx FIFO with given configuration.
  1256. * @note Legacy Rx FIFO only can receive classic CAN message.
  1257. *
  1258. * @param base FlexCAN peripheral base address.
  1259. * @param pRxFifoConfig Pointer to the FlexCAN Legacy Rx FIFO configuration structure. Can be NULL when enable parameter
  1260. * is false.
  1261. * @param enable Enable/disable Legacy Rx FIFO.
  1262. * - true: Enable Legacy Rx FIFO.
  1263. * - false: Disable Legacy Rx FIFO.
  1264. */
  1265. void FLEXCAN_SetRxFifoConfig(CAN_Type *base, const flexcan_rx_fifo_config_t *pRxFifoConfig, bool enable);
  1266. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  1267. /*!
  1268. * @brief Configures the FlexCAN Enhanced Rx FIFO.
  1269. *
  1270. * This function configures the Enhanced Rx FIFO with given configuration.
  1271. * @note Enhanced Rx FIFO support receive classic CAN or CAN FD messages, Legacy Rx FIFO and Enhanced Rx FIFO
  1272. * cannot be enabled at the same time.
  1273. *
  1274. * @param base FlexCAN peripheral base address.
  1275. * @param pConfig Pointer to the FlexCAN Enhanced Rx FIFO configuration structure. Can be NULL when enable parameter
  1276. * is false.
  1277. * @param enable Enable/disable Enhanced Rx FIFO.
  1278. * - true: Enable Enhanced Rx FIFO.
  1279. * - false: Disable Enhanced Rx FIFO.
  1280. */
  1281. void FLEXCAN_SetEnhancedRxFifoConfig(CAN_Type *base, const flexcan_enhanced_rx_fifo_config_t *pConfig, bool enable);
  1282. #endif
  1283. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE)
  1284. /*!
  1285. * @brief Configures the FlexCAN Pretended Networking mode.
  1286. *
  1287. * This function configures the FlexCAN Pretended Networking mode with given configuration.
  1288. *
  1289. * @param base FlexCAN peripheral base address.
  1290. * @param pConfig Pointer to the FlexCAN Rx FIFO configuration structure.
  1291. */
  1292. void FLEXCAN_SetPNConfig(CAN_Type *base, const flexcan_pn_config_t *pConfig);
  1293. #endif
  1294. /* @} */
  1295. /*!
  1296. * @name Status
  1297. * @{
  1298. */
  1299. /*!
  1300. * @brief Gets the FlexCAN module interrupt flags.
  1301. *
  1302. * This function gets all FlexCAN status flags. The flags are returned as the logical
  1303. * OR value of the enumerators @ref _flexcan_flags. To check the specific status,
  1304. * compare the return value with enumerators in @ref _flexcan_flags.
  1305. *
  1306. * @param base FlexCAN peripheral base address.
  1307. * @return FlexCAN status flags which are ORed by the enumerators in the _flexcan_flags.
  1308. */
  1309. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE) || \
  1310. (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) || \
  1311. (defined(FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL) && FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL)
  1312. static inline uint64_t FLEXCAN_GetStatusFlags(CAN_Type *base)
  1313. {
  1314. uint64_t tempflag = (uint64_t)base->ESR1;
  1315. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE)
  1316. /* Get PN Wake Up status. */
  1317. tempflag |= FLEXCAN_PN_STATUS_MASK(base->WU_MTC);
  1318. #endif
  1319. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  1320. /* Get Enhanced Rx FIFO status. */
  1321. tempflag |= FLEXCAN_EFIFO_STATUS_MASK(base->ERFSR);
  1322. #endif
  1323. #if (defined(FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL) && FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL)
  1324. /* Get Memory Error status. */
  1325. tempflag |= FLEXCAN_MECR_STATUS_MASK(base->ERRSR);
  1326. #endif
  1327. return tempflag;
  1328. }
  1329. #else
  1330. static inline uint32_t FLEXCAN_GetStatusFlags(CAN_Type *base)
  1331. {
  1332. return base->ESR1;
  1333. }
  1334. #endif
  1335. /*!
  1336. * @brief Clears status flags with the provided mask.
  1337. *
  1338. * This function clears the FlexCAN status flags with a provided mask. An automatically cleared flag
  1339. * can't be cleared by this function.
  1340. *
  1341. * @param base FlexCAN peripheral base address.
  1342. * @param mask The status flags to be cleared, it is logical OR value of @ref _flexcan_flags.
  1343. */
  1344. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE) || \
  1345. (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) || \
  1346. (defined(FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL) && FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL)
  1347. static inline void FLEXCAN_ClearStatusFlags(CAN_Type *base, uint64_t mask)
  1348. {
  1349. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE)
  1350. /* Clear PN Wake Up status. */
  1351. base->WU_MTC = FLEXCAN_PN_STATUS_UNMASK(mask);
  1352. #endif
  1353. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  1354. /* Clear Enhanced Rx FIFO status. */
  1355. base->ERFSR |= FLEXCAN_EFIFO_STATUS_UNMASK(mask);
  1356. #endif
  1357. #if (defined(FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL) && FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL)
  1358. /* Clear Memory Error status. */
  1359. base->ERRSR = FLEXCAN_MECR_STATUS_UNMASK(mask);
  1360. #endif
  1361. base->ESR1 = (uint32_t)(mask & 0xFFFFFFFFU);
  1362. }
  1363. #else
  1364. static inline void FLEXCAN_ClearStatusFlags(CAN_Type *base, uint32_t mask)
  1365. {
  1366. /* Write 1 to clear status flag. */
  1367. base->ESR1 = mask;
  1368. }
  1369. #endif
  1370. /*!
  1371. * @brief Gets the FlexCAN Bus Error Counter value.
  1372. *
  1373. * This function gets the FlexCAN Bus Error Counter value for both Tx and
  1374. * Rx direction. These values may be needed in the upper layer error handling.
  1375. *
  1376. * @param base FlexCAN peripheral base address.
  1377. * @param txErrBuf Buffer to store Tx Error Counter value.
  1378. * @param rxErrBuf Buffer to store Rx Error Counter value.
  1379. */
  1380. static inline void FLEXCAN_GetBusErrCount(CAN_Type *base, uint8_t *txErrBuf, uint8_t *rxErrBuf)
  1381. {
  1382. if (NULL != txErrBuf)
  1383. {
  1384. *txErrBuf = (uint8_t)((base->ECR & CAN_ECR_TXERRCNT_MASK) >> CAN_ECR_TXERRCNT_SHIFT);
  1385. }
  1386. if (NULL != rxErrBuf)
  1387. {
  1388. *rxErrBuf = (uint8_t)((base->ECR & CAN_ECR_RXERRCNT_MASK) >> CAN_ECR_RXERRCNT_SHIFT);
  1389. }
  1390. }
  1391. /*!
  1392. * @brief Gets the FlexCAN Message Buffer interrupt flags.
  1393. *
  1394. * This function gets the interrupt flags of a given Message Buffers.
  1395. *
  1396. * @param base FlexCAN peripheral base address.
  1397. * @param mask The ORed FlexCAN Message Buffer mask.
  1398. * @return The status of given Message Buffers.
  1399. */
  1400. #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
  1401. static inline uint64_t FLEXCAN_GetMbStatusFlags(CAN_Type *base, uint64_t mask)
  1402. #else
  1403. static inline uint32_t FLEXCAN_GetMbStatusFlags(CAN_Type *base, uint32_t mask)
  1404. #endif
  1405. {
  1406. #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
  1407. uint64_t tempflag = (uint64_t)base->IFLAG1;
  1408. return (tempflag | (((uint64_t)base->IFLAG2) << 32)) & mask;
  1409. #else
  1410. return (base->IFLAG1 & mask);
  1411. #endif
  1412. }
  1413. /*!
  1414. * @brief Clears the FlexCAN Message Buffer interrupt flags.
  1415. *
  1416. * This function clears the interrupt flags of a given Message Buffers.
  1417. *
  1418. * @param base FlexCAN peripheral base address.
  1419. * @param mask The ORed FlexCAN Message Buffer mask.
  1420. */
  1421. #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
  1422. static inline void FLEXCAN_ClearMbStatusFlags(CAN_Type *base, uint64_t mask)
  1423. #else
  1424. static inline void FLEXCAN_ClearMbStatusFlags(CAN_Type *base, uint32_t mask)
  1425. #endif
  1426. {
  1427. #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
  1428. base->IFLAG1 = (uint32_t)(mask & 0xFFFFFFFFU);
  1429. base->IFLAG2 = (uint32_t)(mask >> 32);
  1430. #else
  1431. base->IFLAG1 = mask;
  1432. #endif
  1433. }
  1434. #if (defined(FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL) && FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL)
  1435. /*!
  1436. * @brief Gets the FlexCAN Memory Error Report registers status.
  1437. *
  1438. * This function gets the FlexCAN Memory Error Report registers status.
  1439. *
  1440. * @param base FlexCAN peripheral base address.
  1441. * @param errorStatus Pointer to FlexCAN Memory Error Report registers status structure.
  1442. */
  1443. void FLEXCAN_GetMemoryErrorReportStatus(CAN_Type *base, flexcan_memory_error_report_status_t *errorStatus);
  1444. #endif
  1445. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE)
  1446. /*!
  1447. * @brief Gets the FlexCAN Number of Matches when in Pretended Networking.
  1448. *
  1449. * This function gets the number of times a given message has matched the predefined filtering criteria for ID and/or PL
  1450. * before a wakeup event.
  1451. *
  1452. * @param base FlexCAN peripheral base address.
  1453. * @return The number of received wake up msessages.
  1454. */
  1455. static inline uint8_t FLEXCAN_GetPNMatchCount(CAN_Type *base)
  1456. {
  1457. return (uint8_t)((base->WU_MTC & CAN_WU_MTC_MCOUNTER_MASK) >> CAN_WU_MTC_MCOUNTER_SHIFT);
  1458. }
  1459. #endif
  1460. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  1461. /*!
  1462. * @brief Gets the number of FlexCAN Enhanced Rx FIFO available frames.
  1463. *
  1464. * This function gets the number of CAN messages stored in the Enhanced Rx FIFO.
  1465. *
  1466. * @param base FlexCAN peripheral base address.
  1467. * @return The number of available CAN messages stored in the Enhanced Rx FIFO.
  1468. */
  1469. static inline uint32_t FLEXCAN_GetEnhancedFifoDataCount(CAN_Type *base)
  1470. {
  1471. return (base->ERFSR & CAN_ERFSR_ERFEL_MASK);
  1472. }
  1473. #endif
  1474. /* @} */
  1475. /*!
  1476. * @name Interrupts
  1477. * @{
  1478. */
  1479. /*!
  1480. * @brief Enables FlexCAN interrupts according to the provided mask.
  1481. *
  1482. * This function enables the FlexCAN interrupts according to the provided mask. The mask
  1483. * is a logical OR of enumeration members, see @ref _flexcan_interrupt_enable.
  1484. *
  1485. * @param base FlexCAN peripheral base address.
  1486. * @param mask The interrupts to enable. Logical OR of @ref _flexcan_interrupt_enable.
  1487. */
  1488. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE) || \
  1489. (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) || \
  1490. (defined(FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL) && FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL)
  1491. static inline void FLEXCAN_EnableInterrupts(CAN_Type *base, uint64_t mask)
  1492. #else
  1493. static inline void FLEXCAN_EnableInterrupts(CAN_Type *base, uint32_t mask)
  1494. #endif
  1495. {
  1496. /* Solve Self Wake Up interrupt. */
  1497. base->MCR |= (uint32_t)(mask & (uint32_t)kFLEXCAN_WakeUpInterruptEnable);
  1498. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  1499. if (0 != FSL_FEATURE_FLEXCAN_INSTANCE_HAS_FLEXIBLE_DATA_RATEn(base))
  1500. {
  1501. /* Solve CAN FD frames data phase error interrupt. */
  1502. base->CTRL2 |= (uint32_t)(mask & (uint32_t)kFLEXCAN_FDErrorInterruptEnable);
  1503. }
  1504. #endif
  1505. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE)
  1506. /* Solve PN Wake Up interrupt. */
  1507. base->CTRL1_PN |= FLEXCAN_PN_INT_UNMASK(mask);
  1508. #endif
  1509. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  1510. /* Solve Enhanced Rx FIFO interrupt. */
  1511. base->ERFIER |= FLEXCAN_EFIFO_INT_UNMASK(mask);
  1512. #endif
  1513. #if (defined(FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL) && FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL)
  1514. /* Solve Memory Error interrupt. */
  1515. base->MECR |= FLEXCAN_MECR_INT_UNMASK(mask);
  1516. #endif
  1517. /* Solve interrupt enable bits in CTRL1 register. */
  1518. base->CTRL1 |=
  1519. (uint32_t)(mask & ((uint32_t)kFLEXCAN_BusOffInterruptEnable | (uint32_t)kFLEXCAN_ErrorInterruptEnable |
  1520. (uint32_t)kFLEXCAN_RxWarningInterruptEnable | (uint32_t)kFLEXCAN_TxWarningInterruptEnable |
  1521. (uint32_t)kFLEXCAN_WakeUpInterruptEnable));
  1522. }
  1523. /*!
  1524. * @brief Disables FlexCAN interrupts according to the provided mask.
  1525. *
  1526. * This function disables the FlexCAN interrupts according to the provided mask. The mask
  1527. * is a logical OR of enumeration members, see @ref _flexcan_interrupt_enable.
  1528. *
  1529. * @param base FlexCAN peripheral base address.
  1530. * @param mask The interrupts to disable. Logical OR of @ref _flexcan_interrupt_enable.
  1531. */
  1532. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE) || \
  1533. (defined(FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL) && FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL)
  1534. static inline void FLEXCAN_DisableInterrupts(CAN_Type *base, uint64_t mask)
  1535. #else
  1536. static inline void FLEXCAN_DisableInterrupts(CAN_Type *base, uint32_t mask)
  1537. #endif
  1538. {
  1539. /* Solve Wake Up Interrupt. */
  1540. base->MCR &= ~(uint32_t)(mask & (uint32_t)kFLEXCAN_WakeUpInterruptEnable);
  1541. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  1542. if (0 != FSL_FEATURE_FLEXCAN_INSTANCE_HAS_FLEXIBLE_DATA_RATEn(base))
  1543. {
  1544. /* Solve CAN FD frames data phase error interrupt. */
  1545. base->CTRL2 &= ~(uint32_t)(mask & (uint32_t)kFLEXCAN_FDErrorInterruptEnable);
  1546. }
  1547. #endif
  1548. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE)
  1549. /* Solve PN Wake Up Interrupt. */
  1550. base->CTRL1_PN &= ~FLEXCAN_PN_STATUS_UNMASK(mask);
  1551. #endif
  1552. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  1553. /* Solve Enhanced Rx FIFO interrupt. */
  1554. base->ERFIER &= ~FLEXCAN_EFIFO_INT_UNMASK(mask);
  1555. #endif
  1556. #if (defined(FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL) && FSL_FEATURE_FLEXCAN_HAS_MEMORY_ERROR_CONTROL)
  1557. /* Solve Memory Error Interrupt. */
  1558. base->MECR &= ~FLEXCAN_MECR_STATUS_UNMASK(mask);
  1559. #endif
  1560. /* Solve interrupt enable bits in CTRL1 register. */
  1561. base->CTRL1 &=
  1562. ~(uint32_t)(mask & ((uint32_t)kFLEXCAN_BusOffInterruptEnable | (uint32_t)kFLEXCAN_ErrorInterruptEnable |
  1563. (uint32_t)kFLEXCAN_RxWarningInterruptEnable | (uint32_t)kFLEXCAN_TxWarningInterruptEnable |
  1564. (uint32_t)kFLEXCAN_WakeUpInterruptEnable));
  1565. }
  1566. /*!
  1567. * @brief Enables FlexCAN Message Buffer interrupts.
  1568. *
  1569. * This function enables the interrupts of given Message Buffers.
  1570. *
  1571. * @param base FlexCAN peripheral base address.
  1572. * @param mask The ORed FlexCAN Message Buffer mask.
  1573. */
  1574. #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
  1575. static inline void FLEXCAN_EnableMbInterrupts(CAN_Type *base, uint64_t mask)
  1576. #else
  1577. static inline void FLEXCAN_EnableMbInterrupts(CAN_Type *base, uint32_t mask)
  1578. #endif
  1579. {
  1580. #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
  1581. base->IMASK1 |= (uint32_t)(mask & 0xFFFFFFFFU);
  1582. base->IMASK2 |= (uint32_t)(mask >> 32);
  1583. #else
  1584. base->IMASK1 |= mask;
  1585. #endif
  1586. }
  1587. /*!
  1588. * @brief Disables FlexCAN Message Buffer interrupts.
  1589. *
  1590. * This function disables the interrupts of given Message Buffers.
  1591. *
  1592. * @param base FlexCAN peripheral base address.
  1593. * @param mask The ORed FlexCAN Message Buffer mask.
  1594. */
  1595. #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
  1596. static inline void FLEXCAN_DisableMbInterrupts(CAN_Type *base, uint64_t mask)
  1597. #else
  1598. static inline void FLEXCAN_DisableMbInterrupts(CAN_Type *base, uint32_t mask)
  1599. #endif
  1600. {
  1601. #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
  1602. base->IMASK1 &= ~((uint32_t)(mask & 0xFFFFFFFFU));
  1603. base->IMASK2 &= ~((uint32_t)(mask >> 32));
  1604. #else
  1605. base->IMASK1 &= ~mask;
  1606. #endif
  1607. }
  1608. /* @} */
  1609. #if (defined(FSL_FEATURE_FLEXCAN_HAS_RX_FIFO_DMA) && FSL_FEATURE_FLEXCAN_HAS_RX_FIFO_DMA)
  1610. /*!
  1611. * @name DMA Control
  1612. * @{
  1613. */
  1614. /*!
  1615. * @brief Enables or disables the FlexCAN Rx FIFO DMA request.
  1616. *
  1617. * This function enables or disables the DMA feature of FlexCAN build-in Rx FIFO.
  1618. *
  1619. * @param base FlexCAN peripheral base address.
  1620. * @param enable true to enable, false to disable.
  1621. */
  1622. void FLEXCAN_EnableRxFifoDMA(CAN_Type *base, bool enable);
  1623. /*!
  1624. * @brief Gets the Rx FIFO Head address.
  1625. *
  1626. * This function returns the FlexCAN Rx FIFO Head address, which is mainly used for the DMA/eDMA use case.
  1627. *
  1628. * @param base FlexCAN peripheral base address.
  1629. * @return FlexCAN Rx FIFO Head address.
  1630. */
  1631. static inline uint32_t FLEXCAN_GetRxFifoHeadAddr(CAN_Type *base)
  1632. {
  1633. return (uint32_t) & (base->MB[0].CS);
  1634. }
  1635. /* @} */
  1636. #endif /* FSL_FEATURE_FLEXCAN_HAS_RX_FIFO_DMA */
  1637. /*!
  1638. * @name Bus Operations
  1639. * @{
  1640. */
  1641. /*!
  1642. * @brief Enables or disables the FlexCAN module operation.
  1643. *
  1644. * This function enables or disables the FlexCAN module.
  1645. *
  1646. * @param base FlexCAN base pointer.
  1647. * @param enable true to enable, false to disable.
  1648. */
  1649. static inline void FLEXCAN_Enable(CAN_Type *base, bool enable)
  1650. {
  1651. if (enable)
  1652. {
  1653. base->MCR &= ~CAN_MCR_MDIS_MASK;
  1654. /* Wait FlexCAN exit from low-power mode. */
  1655. while (0U != (base->MCR & CAN_MCR_LPMACK_MASK))
  1656. {
  1657. }
  1658. }
  1659. else
  1660. {
  1661. base->MCR |= CAN_MCR_MDIS_MASK;
  1662. /* Wait FlexCAN enter low-power mode. */
  1663. while (0U == (base->MCR & CAN_MCR_LPMACK_MASK))
  1664. {
  1665. }
  1666. }
  1667. }
  1668. /*!
  1669. * @brief Writes a FlexCAN Message to the Transmit Message Buffer.
  1670. *
  1671. * This function writes a CAN Message to the specified Transmit Message Buffer
  1672. * and changes the Message Buffer state to start CAN Message transmit. After
  1673. * that the function returns immediately.
  1674. *
  1675. * @param base FlexCAN peripheral base address.
  1676. * @param mbIdx The FlexCAN Message Buffer index.
  1677. * @param pTxFrame Pointer to CAN message frame to be sent.
  1678. * @retval kStatus_Success - Write Tx Message Buffer Successfully.
  1679. * @retval kStatus_Fail - Tx Message Buffer is currently in use.
  1680. */
  1681. status_t FLEXCAN_WriteTxMb(CAN_Type *base, uint8_t mbIdx, const flexcan_frame_t *pTxFrame);
  1682. /*!
  1683. * @brief Reads a FlexCAN Message from Receive Message Buffer.
  1684. *
  1685. * This function reads a CAN message from a specified Receive Message Buffer.
  1686. * The function fills a receive CAN message frame structure with
  1687. * just received data and activates the Message Buffer again.
  1688. * The function returns immediately.
  1689. *
  1690. * @param base FlexCAN peripheral base address.
  1691. * @param mbIdx The FlexCAN Message Buffer index.
  1692. * @param pRxFrame Pointer to CAN message frame structure for reception.
  1693. * @retval kStatus_Success - Rx Message Buffer is full and has been read successfully.
  1694. * @retval kStatus_FLEXCAN_RxOverflow - Rx Message Buffer is already overflowed and has been read successfully.
  1695. * @retval kStatus_Fail - Rx Message Buffer is empty.
  1696. */
  1697. status_t FLEXCAN_ReadRxMb(CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *pRxFrame);
  1698. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  1699. /*!
  1700. * @brief Writes a FlexCAN FD Message to the Transmit Message Buffer.
  1701. *
  1702. * This function writes a CAN FD Message to the specified Transmit Message Buffer
  1703. * and changes the Message Buffer state to start CAN FD Message transmit. After
  1704. * that the function returns immediately.
  1705. *
  1706. * @param base FlexCAN peripheral base address.
  1707. * @param mbIdx The FlexCAN FD Message Buffer index.
  1708. * @param pTxFrame Pointer to CAN FD message frame to be sent.
  1709. * @retval kStatus_Success - Write Tx Message Buffer Successfully.
  1710. * @retval kStatus_Fail - Tx Message Buffer is currently in use.
  1711. */
  1712. status_t FLEXCAN_WriteFDTxMb(CAN_Type *base, uint8_t mbIdx, const flexcan_fd_frame_t *pTxFrame);
  1713. /*!
  1714. * @brief Reads a FlexCAN FD Message from Receive Message Buffer.
  1715. *
  1716. * This function reads a CAN FD message from a specified Receive Message Buffer.
  1717. * The function fills a receive CAN FD message frame structure with
  1718. * just received data and activates the Message Buffer again.
  1719. * The function returns immediately.
  1720. *
  1721. * @param base FlexCAN peripheral base address.
  1722. * @param mbIdx The FlexCAN FD Message Buffer index.
  1723. * @param pRxFrame Pointer to CAN FD message frame structure for reception.
  1724. * @retval kStatus_Success - Rx Message Buffer is full and has been read successfully.
  1725. * @retval kStatus_FLEXCAN_RxOverflow - Rx Message Buffer is already overflowed and has been read successfully.
  1726. * @retval kStatus_Fail - Rx Message Buffer is empty.
  1727. */
  1728. status_t FLEXCAN_ReadFDRxMb(CAN_Type *base, uint8_t mbIdx, flexcan_fd_frame_t *pRxFrame);
  1729. #endif
  1730. /*!
  1731. * @brief Reads a FlexCAN Message from Legacy Rx FIFO.
  1732. *
  1733. * This function reads a CAN message from the FlexCAN Legacy Rx FIFO.
  1734. *
  1735. * @param base FlexCAN peripheral base address.
  1736. * @param pRxFrame Pointer to CAN message frame structure for reception.
  1737. * @retval kStatus_Success - Read Message from Rx FIFO successfully.
  1738. * @retval kStatus_Fail - Rx FIFO is not enabled.
  1739. */
  1740. status_t FLEXCAN_ReadRxFifo(CAN_Type *base, flexcan_frame_t *pRxFrame);
  1741. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  1742. /*!
  1743. * @brief Reads a FlexCAN Message from Enhanced Rx FIFO.
  1744. *
  1745. * This function reads a CAN or CAN FD message from the FlexCAN Enhanced Rx FIFO.
  1746. *
  1747. * @param base FlexCAN peripheral base address.
  1748. * @param pRxFrame Pointer to CAN FD message frame structure for reception.
  1749. * @retval kStatus_Success - Read Message from Rx FIFO successfully.
  1750. * @retval kStatus_Fail - Rx FIFO is not enabled.
  1751. */
  1752. status_t FLEXCAN_ReadEnhancedRxFifo(CAN_Type *base, flexcan_fd_frame_t *pRxFrame);
  1753. #endif
  1754. #if (defined(FSL_FEATURE_FLEXCAN_HAS_PN_MODE) && FSL_FEATURE_FLEXCAN_HAS_PN_MODE)
  1755. /*!
  1756. * @brief Reads a FlexCAN Message from Wake Up MB.
  1757. *
  1758. * This function reads a CAN message from the FlexCAN Wake up Message Buffers. There are four Wake up Message Buffers
  1759. * (WMBs) used to store incoming messages in Pretended Networking mode. The WMB index indicates the arrival order. The
  1760. * last message is stored in WMB3.
  1761. *
  1762. * @param base FlexCAN peripheral base address.
  1763. * @param pRxFrame Pointer to CAN message frame structure for reception.
  1764. * @param mbIdx The FlexCAN Wake up Message Buffer index. Range in 0x0 ~ 0x3.
  1765. * @retval kStatus_Success - Read Message from Wake up Message Buffer successfully.
  1766. * @retval kStatus_Fail - Wake up Message Buffer has no valid content.
  1767. */
  1768. status_t FLEXCAN_ReadPNWakeUpMB(CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *pRxFrame);
  1769. #endif
  1770. /* @} */
  1771. /*!
  1772. * @name Transactional
  1773. * @{
  1774. */
  1775. #if (defined(FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE) && FSL_FEATURE_FLEXCAN_HAS_FLEXIBLE_DATA_RATE)
  1776. /*!
  1777. * @brief Performs a polling send transaction on the CAN bus.
  1778. *
  1779. * @note A transfer handle does not need to be created before calling this API.
  1780. *
  1781. * @param base FlexCAN peripheral base pointer.
  1782. * @param mbIdx The FlexCAN FD Message Buffer index.
  1783. * @param pTxFrame Pointer to CAN FD message frame to be sent.
  1784. * @retval kStatus_Success - Write Tx Message Buffer Successfully.
  1785. * @retval kStatus_Fail - Tx Message Buffer is currently in use.
  1786. */
  1787. status_t FLEXCAN_TransferFDSendBlocking(CAN_Type *base, uint8_t mbIdx, flexcan_fd_frame_t *pTxFrame);
  1788. /*!
  1789. * @brief Performs a polling receive transaction on the CAN bus.
  1790. *
  1791. * @note A transfer handle does not need to be created before calling this API.
  1792. *
  1793. * @param base FlexCAN peripheral base pointer.
  1794. * @param mbIdx The FlexCAN FD Message Buffer index.
  1795. * @param pRxFrame Pointer to CAN FD message frame structure for reception.
  1796. * @retval kStatus_Success - Rx Message Buffer is full and has been read successfully.
  1797. * @retval kStatus_FLEXCAN_RxOverflow - Rx Message Buffer is already overflowed and has been read successfully.
  1798. * @retval kStatus_Fail - Rx Message Buffer is empty.
  1799. */
  1800. status_t FLEXCAN_TransferFDReceiveBlocking(CAN_Type *base, uint8_t mbIdx, flexcan_fd_frame_t *pRxFrame);
  1801. /*!
  1802. * @brief Sends a message using IRQ.
  1803. *
  1804. * This function sends a message using IRQ. This is a non-blocking function, which returns
  1805. * right away. When messages have been sent out, the send callback function is called.
  1806. *
  1807. * @param base FlexCAN peripheral base address.
  1808. * @param handle FlexCAN handle pointer.
  1809. * @param pMbXfer FlexCAN FD Message Buffer transfer structure. See the #flexcan_mb_transfer_t.
  1810. * @retval kStatus_Success Start Tx Message Buffer sending process successfully.
  1811. * @retval kStatus_Fail Write Tx Message Buffer failed.
  1812. * @retval kStatus_FLEXCAN_TxBusy Tx Message Buffer is in use.
  1813. */
  1814. status_t FLEXCAN_TransferFDSendNonBlocking(CAN_Type *base, flexcan_handle_t *handle, flexcan_mb_transfer_t *pMbXfer);
  1815. /*!
  1816. * @brief Receives a message using IRQ.
  1817. *
  1818. * This function receives a message using IRQ. This is non-blocking function, which returns
  1819. * right away. When the message has been received, the receive callback function is called.
  1820. *
  1821. * @param base FlexCAN peripheral base address.
  1822. * @param handle FlexCAN handle pointer.
  1823. * @param pMbXfer FlexCAN FD Message Buffer transfer structure. See the #flexcan_mb_transfer_t.
  1824. * @retval kStatus_Success - Start Rx Message Buffer receiving process successfully.
  1825. * @retval kStatus_FLEXCAN_RxBusy - Rx Message Buffer is in use.
  1826. */
  1827. status_t FLEXCAN_TransferFDReceiveNonBlocking(CAN_Type *base, flexcan_handle_t *handle, flexcan_mb_transfer_t *pMbXfer);
  1828. /*!
  1829. * @brief Aborts the interrupt driven message send process.
  1830. *
  1831. * This function aborts the interrupt driven message send process.
  1832. *
  1833. * @param base FlexCAN peripheral base address.
  1834. * @param handle FlexCAN handle pointer.
  1835. * @param mbIdx The FlexCAN FD Message Buffer index.
  1836. */
  1837. void FLEXCAN_TransferFDAbortSend(CAN_Type *base, flexcan_handle_t *handle, uint8_t mbIdx);
  1838. /*!
  1839. * @brief Aborts the interrupt driven message receive process.
  1840. *
  1841. * This function aborts the interrupt driven message receive process.
  1842. *
  1843. * @param base FlexCAN peripheral base address.
  1844. * @param handle FlexCAN handle pointer.
  1845. * @param mbIdx The FlexCAN FD Message Buffer index.
  1846. */
  1847. void FLEXCAN_TransferFDAbortReceive(CAN_Type *base, flexcan_handle_t *handle, uint8_t mbIdx);
  1848. #endif
  1849. /*!
  1850. * @brief Performs a polling send transaction on the CAN bus.
  1851. *
  1852. * @note A transfer handle does not need to be created before calling this API.
  1853. *
  1854. * @param base FlexCAN peripheral base pointer.
  1855. * @param mbIdx The FlexCAN Message Buffer index.
  1856. * @param pTxFrame Pointer to CAN message frame to be sent.
  1857. * @retval kStatus_Success - Write Tx Message Buffer Successfully.
  1858. * @retval kStatus_Fail - Tx Message Buffer is currently in use.
  1859. */
  1860. status_t FLEXCAN_TransferSendBlocking(CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *pTxFrame);
  1861. /*!
  1862. * @brief Performs a polling receive transaction on the CAN bus.
  1863. *
  1864. * @note A transfer handle does not need to be created before calling this API.
  1865. *
  1866. * @param base FlexCAN peripheral base pointer.
  1867. * @param mbIdx The FlexCAN Message Buffer index.
  1868. * @param pRxFrame Pointer to CAN message frame structure for reception.
  1869. * @retval kStatus_Success - Rx Message Buffer is full and has been read successfully.
  1870. * @retval kStatus_FLEXCAN_RxOverflow - Rx Message Buffer is already overflowed and has been read successfully.
  1871. * @retval kStatus_Fail - Rx Message Buffer is empty.
  1872. */
  1873. status_t FLEXCAN_TransferReceiveBlocking(CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *pRxFrame);
  1874. /*!
  1875. * @brief Performs a polling receive transaction from Legacy Rx FIFO on the CAN bus.
  1876. *
  1877. * @note A transfer handle does not need to be created before calling this API.
  1878. *
  1879. * @param base FlexCAN peripheral base pointer.
  1880. * @param pRxFrame Pointer to CAN message frame structure for reception.
  1881. * @retval kStatus_Success - Read Message from Rx FIFO successfully.
  1882. * @retval kStatus_Fail - Rx FIFO is not enabled.
  1883. */
  1884. status_t FLEXCAN_TransferReceiveFifoBlocking(CAN_Type *base, flexcan_frame_t *pRxFrame);
  1885. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  1886. /*!
  1887. * @brief Performs a polling receive transaction from Enhanced Rx FIFO on the CAN bus.
  1888. *
  1889. * @note A transfer handle does not need to be created before calling this API.
  1890. *
  1891. * @param base FlexCAN peripheral base pointer.
  1892. * @param pRxFrame Pointer to CAN FD message frame structure for reception.
  1893. * @retval kStatus_Success - Read Message from Rx FIFO successfully.
  1894. * @retval kStatus_Fail - Rx FIFO is not enabled.
  1895. */
  1896. status_t FLEXCAN_TransferReceiveEnhancedFifoBlocking(CAN_Type *base, flexcan_fd_frame_t *pRxFrame);
  1897. #endif
  1898. /*!
  1899. * @brief Initializes the FlexCAN handle.
  1900. *
  1901. * This function initializes the FlexCAN handle, which can be used for other FlexCAN
  1902. * transactional APIs. Usually, for a specified FlexCAN instance,
  1903. * call this API once to get the initialized handle.
  1904. *
  1905. * @param base FlexCAN peripheral base address.
  1906. * @param handle FlexCAN handle pointer.
  1907. * @param callback The callback function.
  1908. * @param userData The parameter of the callback function.
  1909. */
  1910. void FLEXCAN_TransferCreateHandle(CAN_Type *base,
  1911. flexcan_handle_t *handle,
  1912. flexcan_transfer_callback_t callback,
  1913. void *userData);
  1914. /*!
  1915. * @brief Sends a message using IRQ.
  1916. *
  1917. * This function sends a message using IRQ. This is a non-blocking function, which returns
  1918. * right away. When messages have been sent out, the send callback function is called.
  1919. *
  1920. * @param base FlexCAN peripheral base address.
  1921. * @param handle FlexCAN handle pointer.
  1922. * @param pMbXfer FlexCAN Message Buffer transfer structure. See the #flexcan_mb_transfer_t.
  1923. * @retval kStatus_Success Start Tx Message Buffer sending process successfully.
  1924. * @retval kStatus_Fail Write Tx Message Buffer failed.
  1925. * @retval kStatus_FLEXCAN_TxBusy Tx Message Buffer is in use.
  1926. */
  1927. status_t FLEXCAN_TransferSendNonBlocking(CAN_Type *base, flexcan_handle_t *handle, flexcan_mb_transfer_t *pMbXfer);
  1928. /*!
  1929. * @brief Receives a message using IRQ.
  1930. *
  1931. * This function receives a message using IRQ. This is non-blocking function, which returns
  1932. * right away. When the message has been received, the receive callback function is called.
  1933. *
  1934. * @param base FlexCAN peripheral base address.
  1935. * @param handle FlexCAN handle pointer.
  1936. * @param pMbXfer FlexCAN Message Buffer transfer structure. See the #flexcan_mb_transfer_t.
  1937. * @retval kStatus_Success - Start Rx Message Buffer receiving process successfully.
  1938. * @retval kStatus_FLEXCAN_RxBusy - Rx Message Buffer is in use.
  1939. */
  1940. status_t FLEXCAN_TransferReceiveNonBlocking(CAN_Type *base, flexcan_handle_t *handle, flexcan_mb_transfer_t *pMbXfer);
  1941. /*!
  1942. * @brief Receives a message from Rx FIFO using IRQ.
  1943. *
  1944. * This function receives a message using IRQ. This is a non-blocking function, which returns
  1945. * right away. When all messages have been received, the receive callback function is called.
  1946. *
  1947. * @param base FlexCAN peripheral base address.
  1948. * @param handle FlexCAN handle pointer.
  1949. * @param pFifoXfer FlexCAN Rx FIFO transfer structure. See the @ref flexcan_fifo_transfer_t.
  1950. * @retval kStatus_Success - Start Rx FIFO receiving process successfully.
  1951. * @retval kStatus_FLEXCAN_RxFifoBusy - Rx FIFO is currently in use.
  1952. */
  1953. status_t FLEXCAN_TransferReceiveFifoNonBlocking(CAN_Type *base,
  1954. flexcan_handle_t *handle,
  1955. flexcan_fifo_transfer_t *pFifoXfer);
  1956. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  1957. /*!
  1958. * @brief Receives a message from Enhanced Rx FIFO using IRQ.
  1959. *
  1960. * This function receives a message using IRQ. This is a non-blocking function, which returns
  1961. * right away. When all messages have been received, the receive callback function is called.
  1962. *
  1963. * @param base FlexCAN peripheral base address.
  1964. * @param handle FlexCAN handle pointer.
  1965. * @param pFifoXfer FlexCAN Rx FIFO transfer structure. See the ref flexcan_fifo_transfer_t.@
  1966. * @retval kStatus_Success - Start Rx FIFO receiving process successfully.
  1967. * @retval kStatus_FLEXCAN_RxFifoBusy - Rx FIFO is currently in use.
  1968. */
  1969. status_t FLEXCAN_TransferReceiveEnhancedFifoNonBlocking(CAN_Type *base,
  1970. flexcan_handle_t *handle,
  1971. flexcan_fifo_transfer_t *pFifoXfer);
  1972. /*!
  1973. * @brief Gets the Enhanced Rx Fifo transfer status during a interrupt non-blocking receive.
  1974. *
  1975. * @param base FlexCAN peripheral base address.
  1976. * @param handle FlexCAN handle pointer.
  1977. * @param count Number of CAN messages receive so far by the non-blocking transaction.
  1978. * @retval kStatus_InvalidArgument count is Invalid.
  1979. * @retval kStatus_Success Successfully return the count.
  1980. */
  1981. status_t FLEXCAN_TransferGetReceiveEnhancedFifoCount(CAN_Type *base, flexcan_handle_t *handle, size_t *count);
  1982. #endif
  1983. /*!
  1984. * @brief Gets the detail index of Mailbox's Timestamp by handle.
  1985. *
  1986. * Then function can only be used when calling non-blocking Data transfer (TX/RX) API,
  1987. * After TX/RX data transfer done (User can get the status by handler's callback function),
  1988. * we can get the detail index of Mailbox's timestamp by handle,
  1989. * Detail non-blocking data transfer API (TX/RX) contain.
  1990. * -FLEXCAN_TransferSendNonBlocking
  1991. * -FLEXCAN_TransferFDSendNonBlocking
  1992. * -FLEXCAN_TransferReceiveNonBlocking
  1993. * -FLEXCAN_TransferFDReceiveNonBlocking
  1994. * -FLEXCAN_TransferReceiveFifoNonBlocking
  1995. *
  1996. * @param handle FlexCAN handle pointer.
  1997. * @param mbIdx The FlexCAN Message Buffer index.
  1998. * @retval the index of mailbox 's timestamp stored in the handle.
  1999. *
  2000. */
  2001. uint32_t FLEXCAN_GetTimeStamp(flexcan_handle_t *handle, uint8_t mbIdx);
  2002. /*!
  2003. * @brief Aborts the interrupt driven message send process.
  2004. *
  2005. * This function aborts the interrupt driven message send process.
  2006. *
  2007. * @param base FlexCAN peripheral base address.
  2008. * @param handle FlexCAN handle pointer.
  2009. * @param mbIdx The FlexCAN Message Buffer index.
  2010. */
  2011. void FLEXCAN_TransferAbortSend(CAN_Type *base, flexcan_handle_t *handle, uint8_t mbIdx);
  2012. /*!
  2013. * @brief Aborts the interrupt driven message receive process.
  2014. *
  2015. * This function aborts the interrupt driven message receive process.
  2016. *
  2017. * @param base FlexCAN peripheral base address.
  2018. * @param handle FlexCAN handle pointer.
  2019. * @param mbIdx The FlexCAN Message Buffer index.
  2020. */
  2021. void FLEXCAN_TransferAbortReceive(CAN_Type *base, flexcan_handle_t *handle, uint8_t mbIdx);
  2022. /*!
  2023. * @brief Aborts the interrupt driven message receive from Rx FIFO process.
  2024. *
  2025. * This function aborts the interrupt driven message receive from Rx FIFO process.
  2026. *
  2027. * @param base FlexCAN peripheral base address.
  2028. * @param handle FlexCAN handle pointer.
  2029. */
  2030. void FLEXCAN_TransferAbortReceiveFifo(CAN_Type *base, flexcan_handle_t *handle);
  2031. #if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
  2032. /*!
  2033. * @brief Aborts the interrupt driven message receive from Enhanced Rx FIFO process.
  2034. *
  2035. * This function aborts the interrupt driven message receive from Enhanced Rx FIFO process.
  2036. *
  2037. * @param base FlexCAN peripheral base address.
  2038. * @param handle FlexCAN handle pointer.
  2039. */
  2040. void FLEXCAN_TransferAbortReceiveEnhancedFifo(CAN_Type *base, flexcan_handle_t *handle);
  2041. #endif
  2042. /*!
  2043. * @brief FlexCAN IRQ handle function.
  2044. *
  2045. * This function handles the FlexCAN Error, the Message Buffer, and the Rx FIFO IRQ request.
  2046. *
  2047. * @param base FlexCAN peripheral base address.
  2048. * @param handle FlexCAN handle pointer.
  2049. */
  2050. void FLEXCAN_TransferHandleIRQ(CAN_Type *base, flexcan_handle_t *handle);
  2051. /* @} */
  2052. #if defined(__cplusplus)
  2053. }
  2054. #endif
  2055. /*! @}*/
  2056. #endif /* _FSL_FLEXCAN_H_ */