FlexCAN_Ip_HwAccess.h 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral : FLEXCAN
  5. * Dependencies :
  6. *
  7. * Autosar Version : 4.4.0
  8. * Autosar Revision : ASR_REL_4_4_REV_0000
  9. * Autosar Conf.Variant :
  10. * SW Version : 1.0.0
  11. * Build Version : S32K1_RTD_1_0_0_HF01_D2109_ASR_REL_4_4_REV_0000_20210907
  12. *
  13. * (c) Copyright 2020-2021 NXP Semiconductors
  14. * All Rights Reserved.
  15. *
  16. * NXP Confidential. This software is owned or controlled by NXP and may only be
  17. * used strictly in accordance with the applicable license terms. By expressly
  18. * accepting such terms or by downloading, installing, activating and/or otherwise
  19. * using the software, you are agreeing that you have read, and that you agree to
  20. * comply with and are bound by, such license terms. If you do not agree to be
  21. * bound by the applicable license terms, then you may not retain, install,
  22. * activate or otherwise use the software.
  23. ==================================================================================================*/
  24. #ifndef FLEXCAN_FLEXCAN_IP_HWACCESS_H_
  25. #define FLEXCAN_FLEXCAN_IP_HWACCESS_H_
  26. /**
  27. * @file FlexCAN_Ip_HwAccess.h
  28. *
  29. * @brief FlexCAN HardWare Access Header File
  30. *
  31. * @addtogroup FlexCAN
  32. * @{
  33. */
  34. #ifdef __cplusplus
  35. extern "C"{
  36. #endif
  37. /*==================================================================================================
  38. * INCLUDE FILES
  39. * 1) system and project includes
  40. * 2) needed interfaces from external units
  41. * 3) internal and external interfaces from this unit
  42. ==================================================================================================*/
  43. #include "FlexCAN_Ip.h"
  44. #if (FLEXCAN_IP_DEV_ERROR_DETECT == STD_ON)
  45. #include "Devassert.h"
  46. #endif
  47. #include "OsIf.h"
  48. /*==================================================================================================
  49. * SOURCE FILE VERSION INFORMATION
  50. ==================================================================================================*/
  51. #define FLEXCAN_IP_HWACCESS_VENDOR_ID_H 43
  52. #define FLEXCAN_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION_H 4
  53. #define FLEXCAN_IP_HWACCESS_AR_RELEASE_MINOR_VERSION_H 4
  54. #define FLEXCAN_IP_HWACCESS_AR_RELEASE_REVISION_VERSION_H 0
  55. #define FLEXCAN_IP_HWACCESS_SW_MAJOR_VERSION_H 1
  56. #define FLEXCAN_IP_HWACCESS_SW_MINOR_VERSION_H 0
  57. #define FLEXCAN_IP_HWACCESS_SW_PATCH_VERSION_H 0
  58. /*==================================================================================================
  59. * FILE VERSION CHECKS
  60. ==================================================================================================*/
  61. /* Check if current file and FlexCAN_Ip header file are of the same vendor */
  62. #if (FLEXCAN_IP_HWACCESS_VENDOR_ID_H != FLEXCAN_IP_VENDOR_ID_H)
  63. #error "FlexCAN_Ip_HwAccess.h and FlexCAN_Ip.h have different vendor ids"
  64. #endif
  65. /* Check if current file and FlexCAN_Ip header file are of the same Autosar version */
  66. #if ((FLEXCAN_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION_H != FLEXCAN_IP_AR_RELEASE_MAJOR_VERSION_H) || \
  67. (FLEXCAN_IP_HWACCESS_AR_RELEASE_MINOR_VERSION_H != FLEXCAN_IP_AR_RELEASE_MINOR_VERSION_H) || \
  68. (FLEXCAN_IP_HWACCESS_AR_RELEASE_REVISION_VERSION_H != FLEXCAN_IP_AR_RELEASE_REVISION_VERSION_H) \
  69. )
  70. #error "AutoSar Version Numbers of FlexCAN_Ip_HwAccess.h and FlexCAN_Ip.h are different"
  71. #endif
  72. /* Check if current file and FlexCAN_Ip header file are of the same Software version */
  73. #if ((FLEXCAN_IP_HWACCESS_SW_MAJOR_VERSION_H != FLEXCAN_IP_SW_MAJOR_VERSION_H) || \
  74. (FLEXCAN_IP_HWACCESS_SW_MINOR_VERSION_H != FLEXCAN_IP_SW_MINOR_VERSION_H) || \
  75. (FLEXCAN_IP_HWACCESS_SW_PATCH_VERSION_H != FLEXCAN_IP_SW_PATCH_VERSION_H) \
  76. )
  77. #error "Software Version Numbers of FlexCAN_Ip_HwAccess.h and FlexCAN_Ip.h are different"
  78. #endif
  79. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  80. /* Check if current file and Devassert header file are of the same version */
  81. #if (FLEXCAN_IP_DEV_ERROR_DETECT == STD_ON)
  82. #if ((FLEXCAN_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION_H != DEVASSERT_AR_RELEASE_MAJOR_VERSION) || \
  83. (FLEXCAN_IP_HWACCESS_AR_RELEASE_MINOR_VERSION_H != DEVASSERT_AR_RELEASE_MINOR_VERSION) \
  84. )
  85. #error "AUTOSAR Version Numbers of FlexCAN_Ip_HwAccess.h and Devassert.h are different"
  86. #endif
  87. #endif
  88. /* Check if current file and osif header file are of the same version */
  89. #if ((FLEXCAN_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION_H != OSIF_AR_RELEASE_MAJOR_VERSION) || \
  90. (FLEXCAN_IP_HWACCESS_AR_RELEASE_MINOR_VERSION_H != OSIF_AR_RELEASE_MINOR_VERSION) \
  91. )
  92. #error "AUTOSAR Version Numbers of FlexCAN_Ip_HwAccess.h and OsIf.h are different"
  93. #endif
  94. #endif
  95. /*==================================================================================================
  96. * CONSTANTS
  97. ==================================================================================================*/
  98. /*==================================================================================================
  99. * DEFINES AND MACROS
  100. ==================================================================================================*/
  101. /* @brief Frames available in Rx FIFO flag shift */
  102. #define FLEXCAN_IP_LEGACY_RXFIFO_FRAME_AVAILABLE (5U)
  103. /* @brief Rx FIFO warning flag shift */
  104. #define FLEXCAN_IP_LEGACY_RXFIFO_WARNING (6U)
  105. /* @brief Rx FIFO overflow flag shift */
  106. #define FLEXCAN_IP_LEGACY_RXFIFO_OVERFLOW (7U)
  107. #if (FLEXCAN_IP_FEATURE_HAS_ENHANCED_RX_FIFO == STD_ON)
  108. /* @brief Frames available in Enhanced Rx FIFO flag shift */
  109. #define FLEXCAN_IP_ENHANCED_RXFIFO_FRAME_AVAILABLE (28U)
  110. /* @brief Enhanced Rx FIFO Watermark Indication flag shift */
  111. #define FLEXCAN_IP_ENHANCED_RXFIFO_WATERMARK (29U)
  112. /* @brief Enhanced Rx FIFO Overflow flag shift */
  113. #define FLEXCAN_IP_ENHANCED_RXFIFO_OVERFLOW (30U)
  114. /* @brief Enhanced Rx FIFO Underflow flag shift */
  115. #define FLEXCAN_IP_ENHANCED_RXFIFO_UNDERFLOW (31U)
  116. /*! @brief FlexCAN Enhanced Fifo Embedded RAM address offset */
  117. #define FLEXCAN_IP_FEATURE_ENHANCED_FIFO_RAM_OFFSET (0x00002000u)
  118. #endif /* (FLEXCAN_IP_FEATURE_HAS_ENHANCED_RX_FIFO == STD_ON) */
  119. /*! @brief FlexCAN Embedded RAM address offset */
  120. #define FLEXCAN_IP_FEATURE_RAM_OFFSET (0x00000080u)
  121. #if (STD_ON == FLEXCAN_IP_FEATURE_HAS_EXPANDABLE_MEMORY)
  122. /*! @brief FlexCAN Expandable Embedded RAM address offset */
  123. #define FLEXCAN_IP_FEATURE_EXP_RAM_OFFSET (0x00001000u)
  124. #endif /* (STD_ON == FLEXCAN_IP_FEATURE_HAS_EXPANDABLE_MEMORY) */
  125. #define FLEXCAN_IP_ALL_INT (0x3B0006U) /*!< Masks for wakeup, error, bus off*/
  126. #if (FLEXCAN_IP_FEATURE_BUSOFF_ERROR_INTERRUPT_UNIFIED == STD_OFF)
  127. #define FLEXCAN_IP_BUS_OFF_INT (0xB0004U) /*!< Masks for busOff, Tx/Rx Warning */
  128. #define FLEXCAN_IP_ERROR_INT (0x300002U) /*!< Masks for ErrorOvr, ErrorFast, Error */
  129. #endif
  130. #define FLEXCAN_IP_ESR1_FLTCONF_BUS_OFF (0x00000020U)
  131. #define FLEXCAN_IP_ID_EXT_MASK 0x3FFFFu
  132. #define FLEXCAN_IP_ID_EXT_SHIFT 0
  133. #define FLEXCAN_IP_ID_EXT_WIDTH 18
  134. #define FLEXCAN_IP_ID_STD_MASK 0x1FFC0000u
  135. #define FLEXCAN_IP_ID_STD_SHIFT 18
  136. #define FLEXCAN_IP_ID_STD_WIDTH 11
  137. #define FLEXCAN_IP_ID_PRIO_MASK 0xE0000000u
  138. #define FLEXCAN_IP_ID_PRIO_SHIFT 29
  139. #define FLEXCAN_IP_ID_PRIO_WIDTH 3
  140. /* CS Bit Fields */
  141. #define FLEXCAN_IP_CS_TIME_STAMP_MASK 0xFFFFu
  142. #define FLEXCAN_IP_CS_TIME_STAMP_SHIFT 0
  143. #define FLEXCAN_IP_CS_TIME_STAMP_WIDTH 16
  144. #define FLEXCAN_IP_CS_DLC_MASK 0xF0000u
  145. #define FLEXCAN_IP_CS_DLC_SHIFT 16
  146. #define FLEXCAN_IP_CS_DLC_WIDTH 4
  147. #define FLEXCAN_IP_CS_RTR_MASK 0x100000u
  148. #define FLEXCAN_IP_CS_RTR_SHIFT 20
  149. #define FLEXCAN_IP_CS_RTR_WIDTH 1
  150. #define FLEXCAN_IP_CS_IDE_MASK 0x200000u
  151. #define FLEXCAN_IP_CS_IDE_SHIFT 21
  152. #define FLEXCAN_IP_CS_IDE_WIDTH 1
  153. #define FLEXCAN_IP_CS_SRR_MASK 0x400000u
  154. #define FLEXCAN_IP_CS_SRR_SHIFT 22
  155. #define FLEXCAN_IP_CS_SRR_WIDTH 1
  156. #define FLEXCAN_IP_CS_CODE_MASK 0xF000000u
  157. #define FLEXCAN_IP_CS_CODE_SHIFT 24
  158. #define FLEXCAN_IP_CS_CODE_WIDTH 4
  159. #define FLEXCAN_IP_CS_IDHIT_MASK 0xFF800000u
  160. #define FLEXCAN_IP_CS_IDHIT_SHIFT 23
  161. #define FLEXCAN_IP_CS_IDHIT_WIDTH 9
  162. #define FLEXCAN_IP_MB_EDL_MASK 0x80000000u
  163. #define FLEXCAN_IP_MB_BRS_MASK 0x40000000u
  164. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATAB_RTR_SHIFT (31U) /*!< FlexCAN RX FIFO ID filter*/
  165. /*! format A&B RTR mask.*/
  166. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATAB_IDE_SHIFT (30U) /*!< FlexCAN RX FIFO ID filter*/
  167. /*! format A&B IDE mask.*/
  168. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATB_RTR_SHIFT (15U) /*!< FlexCAN RX FIFO ID filter*/
  169. /*! format B RTR-2 mask.*/
  170. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATB_IDE_SHIFT (14U) /*!< FlexCAN RX FIFO ID filter*/
  171. /*! format B IDE-2 mask.*/
  172. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATA_EXT_MASK (0x3FFFFFFFU) /*!< FlexCAN RX FIFO ID filter*/
  173. /*! format A extended mask.*/
  174. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATA_EXT_SHIFT (1U) /*!< FlexCAN RX FIFO ID filter*/
  175. /*! format A extended shift.*/
  176. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATA_STD_MASK (0x3FF80000U) /*!< FlexCAN RX FIFO ID filter*/
  177. /*! format A standard mask.*/
  178. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATA_STD_SHIFT (19U) /*!< FlexCAN RX FIFO ID filter*/
  179. /*! format A standard shift.*/
  180. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATB_EXT_MASK (0x1FFF8000U) /*!< FlexCAN RX FIFO ID filter*/
  181. /*! format B extended mask1.*/
  182. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATB_EXT_SHIFT1 (16U) /*!< FlexCAN RX FIFO ID filter*/
  183. /*! format B extended shift 1.*/
  184. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATB_EXT_SHIFT2 (0U) /*!< FlexCAN RX FIFO ID filter*/
  185. /*! format B extended shift 2.*/
  186. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATB_STD_MASK (0x7FFU) /*!< FlexCAN RX FIFO ID filter*/
  187. /*! format B standard mask.*/
  188. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATB_STD_SHIFT1 (19U) /*!< FlexCAN RX FIFO ID filter*/
  189. /*! format B standard shift1.*/
  190. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATB_STD_SHIFT2 (3U) /*!< FlexCAN RX FIFO ID filter*/
  191. /*! format B standard shift2.*/
  192. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATB_EXT_CMP_SHIFT (15U) /*!< FlexCAN RX FIFO ID filter*/
  193. /*! format B extended compare shift.*/
  194. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATC_EXT_MASK (0x1FE00000U) /*!< FlexCAN RX FIFO ID filter*/
  195. /*! format C mask.*/
  196. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATC_STD_MASK (0x7F8U) /*!< FlexCAN RX FIFO ID filter*/
  197. /*! format C mask.*/
  198. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATC_SHIFT1 (24U) /*!< FlexCAN RX FIFO ID filter*/
  199. /*! format C shift1.*/
  200. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATC_SHIFT2 (16U) /*!< FlexCAN RX FIFO ID filter*/
  201. /*! format C shift2.*/
  202. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATC_SHIFT3 (8U) /*!< FlexCAN RX FIFO ID filter*/
  203. /*! format C shift3.*/
  204. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATC_SHIFT4 (0U) /*!< FlexCAN RX FIFO ID filter*/
  205. /*! format C shift4.*/
  206. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATC_EXT_CMP_SHIFT (21U) /*!< FlexCAN RX FIFO ID filter*/
  207. /*! format C extended compare shift.*/
  208. #define FLEXCAN_IP_RX_FIFO_ID_FILTER_FORMATC_STD_CMP_SHIFT (3U) /*!< FlexCAN RX FIFO ID filter*/
  209. #if (FLEXCAN_IP_FEATURE_HAS_ENHANCED_RX_FIFO == STD_ON)
  210. #define FLEXCAN_IP_ENHANCED_IDHIT_MASK 0x7Fu
  211. #define FLEXCAN_IP_ENHANCED_IDHIT_SHIFT 0
  212. #define FLEXCAN_IP_ENHANCED_IDHIT_WIDTH 7
  213. #define FLEXCAN_IP_ENHANCED_RX_FIFO_ID_FILTER_FSCH_SHIFT (30U) /*!< FlexCAN Enhanced RX FIFO ID filter*/
  214. /*! Standard & Extended FSCH shift.*/
  215. #define FLEXCAN_IP_ENHANCED_RX_FIFO_ID_FILTER_STD_RTR2_SHIFT (27U) /*!< FlexCAN Enhanced RX FIFO ID filter*/
  216. /*! Standard RTR-2 shift.*/
  217. #define FLEXCAN_IP_ENHANCED_RX_FIFO_ID_FILTER_STD_RTR1_SHIFT (11U) /*!< FlexCAN Enhanced RX FIFO ID filter*/
  218. /*! Standard RTR-1 shift.*/
  219. #define FLEXCAN_IP_ENHANCED_RX_FIFO_ID_FILTER_EXT_RTR_SHIFT (29U) /*!< FlexCAN Enhanced RX FIFO ID filter*/
  220. /*! Extended RTR shift.*/
  221. #define FLEXCAN_IP_ENHANCED_RX_FIFO_ID_FILTER_STD_SHIFT2 (16U) /*!< FlexCAN Enhanced RX FIFO ID filter*/
  222. /*! Standard ID-2 shift.*/
  223. #define FLEXCAN_IP_ENHANCED_RX_FIFO_ID_FILTER_STD_SHIFT1 (0U) /*!< FlexCAN Enhanced RX FIFO ID filter*/
  224. /*! Standard ID-1 shift.*/
  225. #define FLEXCAN_IP_ENHANCED_RX_FIFO_ID_FILTER_STD_MASK (0x7FFU) /*!< FlexCAN Enhanced RX FIFO ID filter*/
  226. /*! Standard ID mask.*/
  227. #define FLEXCAN_IP_ENHANCED_RX_FIFO_ID_FILTER_EXT_SHIFT (0U) /*!< FlexCAN Enhanced RX FIFO ID filter*/
  228. /*! Extended ID shift.*/
  229. #define FLEXCAN_IP_ENHANCED_RX_FIFO_ID_FILTER_EXT_MASK (0x1FFFFFFFU) /*!< FlexCAN Enhanced RX FIFO ID filter*/
  230. /*! Mask for enable all enhanced interrupts */
  231. #define FLEXCAN_IP_ENHACED_RX_FIFO_ALL_INTERRUPT_MASK (FLEXCAN_ERFIER_ERFUFWIE_MASK | FLEXCAN_ERFIER_ERFOVFIE_MASK | \
  232. FLEXCAN_ERFIER_ERFWMIIE_MASK | FLEXCAN_ERFIER_ERFDAIE_MASK \
  233. )
  234. /*! Mask for disable all enhanced interrupts */
  235. #define FLEXCAN_IP_ENHACED_RX_FIFO_NO_INTERRUPT_MASK (0U)
  236. #endif /* (FLEXCAN_IP_FEATURE_HAS_ENHANCED_RX_FIFO == STD_On) */
  237. /* This are for little endians cores and supporting rev32 asm instuction */
  238. #define FLEXCAN_IP_SWAP_BYTES_IN_WORD_INDEX(index) (((index) & ~3U) + (3U - ((index) & 3U)))
  239. #define FLEXCAN_IP_SWAP_BYTES_IN_WORD(a, b) FLEXCAN_IP_REV_BYTES_32(a, b)
  240. #define FLEXCAN_IP_REV_BYTES_32(a, b) ((b) = (((a) & 0xFF000000U) >> 24U) | (((a) & 0xFF0000U) >> 8U) \
  241. | (((a) & 0xFF00U) << 8U) | (((a) & 0xFFU) << 24U))
  242. /*==================================================================================================
  243. * ENUMS
  244. ==================================================================================================*/
  245. /*! @brief FlexCAN message buffer CODE for Rx buffers*/
  246. enum
  247. {
  248. FLEXCAN_RX_INACTIVE = 0x0, /*!< MB is not active.*/
  249. FLEXCAN_RX_FULL = 0x2, /*!< MB is full.*/
  250. FLEXCAN_RX_EMPTY = 0x4, /*!< MB is active and empty.*/
  251. FLEXCAN_RX_OVERRUN = 0x6, /*!< MB is overwritten into a full buffer.*/
  252. FLEXCAN_RX_BUSY = 0x8, /*!< FlexCAN is updating the contents of the MB.*/
  253. /*! The CPU must not access the MB.*/
  254. FLEXCAN_RX_RANSWER = 0xA, /*!< A frame was configured to recognize a Remote Request Frame*/
  255. /*! and transmit a Response Frame in return.*/
  256. FLEXCAN_RX_NOT_USED = 0xF /*!< Not used*/
  257. };
  258. /*! @brief FlexCAN message buffer CODE FOR Tx buffers*/
  259. enum
  260. {
  261. FLEXCAN_TX_INACTIVE = 0x08, /*!< MB is not active.*/
  262. FLEXCAN_TX_ABORT = 0x09, /*!< MB is aborted.*/
  263. FLEXCAN_TX_DATA = 0x0C, /*!< MB is a TX Data Frame(MB RTR must be 0).*/
  264. FLEXCAN_TX_REMOTE = 0x1C, /*!< MB is a TX Remote Request Frame (MB RTR must be 1).*/
  265. FLEXCAN_TX_TANSWER = 0x0E, /*!< MB is a TX Response Request Frame from.*/
  266. /*! an incoming Remote Request Frame.*/
  267. FLEXCAN_TX_NOT_USED = 0xF /*!< Not used*/
  268. };
  269. /*! @brief FlexCAN error interrupt types
  270. */
  271. typedef enum
  272. {
  273. FLEXCAN_INT_RX_WARNING = FLEXCAN_CTRL1_RWRNMSK_MASK, /*!< RX warning interrupt*/
  274. FLEXCAN_INT_TX_WARNING = FLEXCAN_CTRL1_TWRNMSK_MASK, /*!< TX warning interrupt*/
  275. FLEXCAN_INT_ERR = FLEXCAN_CTRL1_ERRMSK_MASK, /*!< Error interrupt*/
  276. FLEXCAN_INT_ERR_FAST, /*!< Error Fast interrupt*/
  277. FLEXCAN_INT_BUSOFF = FLEXCAN_CTRL1_BOFFMSK_MASK, /*!< Bus off interrupt*/
  278. } flexcan_int_type_t;
  279. /*==================================================================================================
  280. * STRUCTURES AND OTHER TYPEDEFS
  281. ==================================================================================================*/
  282. /*! @brief FlexCAN Message Buffer code and status for transmit and receive
  283. */
  284. typedef struct
  285. {
  286. uint32 code; /*!< MB code for TX or RX buffers.*/
  287. /*! Defined by flexcan_mb_code_rx_t and flexcan_mb_code_tx_t */
  288. Flexcan_Ip_MsgBuffIdType msgIdType; /*!< Type of message ID (standard or extended)*/
  289. uint32 dataLen; /*!< Length of Data in Bytes*/
  290. boolean fd_enable;
  291. uint8 fd_padding;
  292. boolean enable_brs; /* Enable bit rate switch*/
  293. } Flexcan_Ip_MsbuffCodeStatusType;
  294. /*==================================================================================================
  295. * GLOBAL VARIABLE DECLARATIONS
  296. ==================================================================================================*/
  297. /*==================================================================================================
  298. * FUNCTION PROTOTYPES
  299. ==================================================================================================*/
  300. #define CAN_START_SEC_CODE
  301. #include "Can_MemMap.h"
  302. void FLEXCAN_ClearMsgBuffIntCmd(FLEXCAN_Type * pBase,
  303. uint8 u8Instance,
  304. uint32 mb_idx,
  305. boolean bIsIntActive
  306. );
  307. void FlexCAN_SetErrIntCmd(FLEXCAN_Type * base,
  308. flexcan_int_type_t errType,
  309. boolean enable
  310. );
  311. Flexcan_Ip_StatusType FlexCAN_EnterFreezeMode(FLEXCAN_Type * base);
  312. /*!
  313. * @brief Sets the FlexCAN Rx FIFO fields.
  314. *
  315. * @param base The FlexCAN base address
  316. * @param idFormat The format of the Rx FIFO ID Filter Table Elements
  317. * @param idFilterTable The ID filter table elements which contain RTR bit,
  318. * IDE bit, and RX message ID.
  319. */
  320. void FlexCAN_SetRxFifoFilter(FLEXCAN_Type * base,
  321. Flexcan_Ip_RxFifoIdElementFormatType idFormat,
  322. const Flexcan_Ip_IdTableType * idFilterTable
  323. );
  324. /*!
  325. * @brief Gets the FlexCAN Rx FIFO data.
  326. *
  327. * @param base The FlexCAN base address
  328. * @param rxFifo The FlexCAN receive FIFO data
  329. */
  330. void FlexCAN_ReadRxFifo(const FLEXCAN_Type * base,
  331. Flexcan_Ip_MsgBuffType * rxFifo
  332. );
  333. /*!
  334. * @brief Un freezes the FlexCAN module.
  335. *
  336. * @param base The FlexCAN base address
  337. * @return FLEXCAN_STATUS_SUCCESS successfully exit from freeze
  338. * FLEXCAN_STATUS_TIMEOUT fail to exit from freeze
  339. */
  340. Flexcan_Ip_StatusType FlexCAN_ExitFreezeMode(FLEXCAN_Type * base);
  341. Flexcan_Ip_StatusType FlexCAN_Disable(FLEXCAN_Type * base);
  342. Flexcan_Ip_StatusType FlexCAN_Enable(FLEXCAN_Type * base);
  343. /*!
  344. * @brief Locks the FlexCAN Rx message buffer.
  345. *
  346. * @param base The FlexCAN base address
  347. * @param msgBuffIdx Index of the message buffer
  348. *
  349. */
  350. void FlexCAN_LockRxMsgBuff(const FLEXCAN_Type * base,
  351. uint32 msgBuffIdx
  352. );
  353. /*!
  354. * @brief Enables/Disables the FlexCAN Message Buffer interrupt.
  355. *
  356. * @param base The FlexCAN base address
  357. * @param msgBuffIdx Index of the message buffer
  358. * @param enable choose enable or disable
  359. * @return FLEXCAN_STATUS_SUCCESS if successful;
  360. * FLEXCAN_STATUS_CAN_BUFF_OUT_OF_RANGE if the index of the
  361. * message buffer is invalid
  362. */
  363. Flexcan_Ip_StatusType FlexCAN_SetMsgBuffIntCmd(FLEXCAN_Type * base,
  364. uint8 u8Instance,
  365. uint32 msgBuffIdx,
  366. boolean enable,
  367. boolean bIsIntActive
  368. );
  369. /*!
  370. * @brief Disable all interrupts.
  371. *
  372. * @param pBase The FlexCAN base address
  373. */
  374. void FlexCAN_DisableInterrupts(FLEXCAN_Type * pBase);
  375. /*!
  376. * @brief Enable all interrupts configured.
  377. *
  378. * @param pBase The FlexCAN base address
  379. * @param u8Instance A FlexCAN instance number
  380. */
  381. void FlexCAN_EnableInterrupts(FLEXCAN_Type * pBase, uint8 u8Instance);
  382. /*!
  383. * @brief Sets the FlexCAN message buffer fields for transmitting.
  384. *
  385. * @param pMbAddr The Message buffer address
  386. * @param cs CODE/status values (TX)
  387. * @param msgId ID of the message to transmit
  388. * @param msgData Bytes of the FlexCAN message
  389. * @param isRemote Will set RTR remote Flag
  390. * @return FLEXCAN_STATUS_SUCCESS if successful;
  391. * FLEXCAN_STATUS_CAN_BUFF_OUT_OF_RANGE if the index of the
  392. * message buffer is invalid
  393. */
  394. void FlexCAN_SetTxMsgBuff(volatile uint32 * const pMbAddr,
  395. const Flexcan_Ip_MsbuffCodeStatusType * cs,
  396. uint32 msgId,
  397. const uint8 * msgData,
  398. const boolean isRemote
  399. );
  400. /*!
  401. * @brief Enables the Rx FIFO.
  402. *
  403. * @param base The FlexCAN base address
  404. * @param numOfFilters The number of Rx FIFO filters
  405. * @return The status of the operation
  406. * @retval FLEXCAN_STATUS_SUCCESS RxFIFO was successfully enabled
  407. * @retval FLEXCAN_STATUS_ERROR RxFIFO could not be enabled (e.g. the FD feature
  408. * was enabled, and these two features are not compatible)
  409. */
  410. Flexcan_Ip_StatusType FlexCAN_EnableRxFifo(FLEXCAN_Type * base, uint32 numOfFilters);
  411. /*!
  412. * @brief Sets the maximum number of Message Buffers.
  413. *
  414. * @param base The FlexCAN base address
  415. * @param maxMsgBuffNum Maximum number of message buffers
  416. * @return FLEXCAN_STATUS_SUCCESS if successful;
  417. * FLEXCAN_STATUS_BUFF_OUT_OF_RANGE if the index of the
  418. * message buffer is invalid
  419. */
  420. Flexcan_Ip_StatusType FlexCAN_SetMaxMsgBuffNum(FLEXCAN_Type * base, uint32 maxMsgBuffNum);
  421. /*!
  422. * @brief Sets the FlexCAN message buffer fields for receiving.
  423. *
  424. * @param base The FlexCAN base address
  425. * @param msgBuffIdx Index of the message buffer
  426. * @param cs CODE/status values (RX)
  427. * @param msgId ID of the message to receive
  428. * @return FLEXCAN_STATUS_SUCCESS if successful;
  429. * FLEXCAN_STATUS_BUFF_OUT_OF_RANGE if the index of the
  430. * message buffer is invalid
  431. */
  432. void FlexCAN_SetRxMsgBuff(const FLEXCAN_Type * base,
  433. uint32 msgBuffIdx,
  434. const Flexcan_Ip_MsbuffCodeStatusType * cs,
  435. uint32 msgId
  436. );
  437. /*!
  438. * @brief Gets the message buffer timestamp value.
  439. *
  440. * @param base The FlexCAN base address
  441. * @param msgBuffIdx Index of the message buffer
  442. * @return value of timestamp for selected message buffer.
  443. */
  444. uint32 FlexCAN_GetMsgBuffTimestamp(const FLEXCAN_Type * base, uint32 msgBuffIdx);
  445. /*!
  446. * @brief Gets the FlexCAN message buffer fields.
  447. *
  448. * @param base The FlexCAN base address
  449. * @param msgBuffIdx Index of the message buffer
  450. * @param msgBuff The fields of the message buffer
  451. */
  452. void FlexCAN_GetMsgBuff(const FLEXCAN_Type * base,
  453. uint32 msgBuffIdx,
  454. Flexcan_Ip_MsgBuffType * msgBuff
  455. );
  456. #if (FLEXCAN_IP_FEATURE_HAS_FD == STD_ON)
  457. #if defined(CAN_FEATURE_S32K1XX)
  458. /*!
  459. * @brief Check if instance support FD.
  460. *
  461. * @param[in] base The FlexCAN base address
  462. * @return TRUE\FALSE if support FD.
  463. */
  464. boolean FlexCAN_IsFDAvailable(const FLEXCAN_Type * base);
  465. #endif
  466. /*!
  467. * @brief Sets the payload size of the MBs.
  468. *
  469. * @param base The FlexCAN base address
  470. * @param payloadSize The payload size
  471. */
  472. void FlexCAN_SetPayloadSize(FLEXCAN_Type * base, const Flexcan_Ip_PayloadSizeType * payloadSize);
  473. /*!
  474. * @brief Check If mb index is out of range or not.
  475. *
  476. * @param pBase The FlexCAN base address
  477. * @param u8MbIndex MB index
  478. * @param bIsLegacyFifoEn Legacy fifo enabled or not
  479. * @param u32MaxMbNum Max mb number
  480. */
  481. boolean FlexCAN_IsMbOutOfRange
  482. (
  483. const FLEXCAN_Type * pBase,
  484. uint8 u8MbIndex,
  485. boolean bIsLegacyFifoEn,
  486. uint32 u32MaxMbNum
  487. );
  488. /*!
  489. * @brief Sets the FlexCAN RX FIFO global mask.
  490. *
  491. * @param[in] base The FlexCAN base address
  492. * @param[in] Mask Sets mask
  493. */
  494. static inline void FlexCAN_SetRxFifoGlobalMask(FLEXCAN_Type * base, uint32 Mask)
  495. {
  496. (base->RXFGMASK) = Mask;
  497. }
  498. /*!
  499. * @brief Enables/Disables the Transceiver Delay Compensation feature and sets
  500. * the Transceiver Delay Compensation Offset (offset value to be added to the
  501. * measured transceiver's loop delay in order to define the position of the
  502. * delayed comparison point when bit rate switching is active).
  503. *
  504. * @param base The FlexCAN base address
  505. * @param enable Enable/Disable Transceiver Delay Compensation
  506. * @param offset Transceiver Delay Compensation Offset
  507. */
  508. static inline void FlexCAN_SetTDCOffset(FLEXCAN_Type * base,
  509. boolean enable,
  510. uint8 offset
  511. )
  512. {
  513. uint32 tmp;
  514. tmp = base->FDCTRL;
  515. tmp &= ~(FLEXCAN_FDCTRL_TDCEN_MASK | FLEXCAN_FDCTRL_TDCOFF_MASK);
  516. if (enable)
  517. {
  518. tmp = tmp | FLEXCAN_FDCTRL_TDCEN_MASK;
  519. tmp = tmp | FLEXCAN_FDCTRL_TDCOFF(offset);
  520. }
  521. base->FDCTRL = tmp;
  522. }
  523. #if (FLEXCAN_IP_FEATURE_HAS_ENHANCE_CBT == STD_ON)
  524. /*!
  525. * @brief Enables/Disables the Transceiver Delay Compensation feature and sets
  526. * the Transceiver Delay Compensation Offset (offset value to be added to the
  527. * measured transceiver's loop delay in order to define the position of the
  528. * delayed comparison point when bit rate switching is active).
  529. *
  530. * @param base The FlexCAN base address
  531. * @param enable Enable/Disable Transceiver Delay Compensation
  532. * @param offset Transceiver Delay Compensation Offset
  533. */
  534. static inline void FlexCAN_SetEnhancedTDCOffset(FLEXCAN_Type * base,
  535. boolean enable,
  536. uint8 offset
  537. )
  538. {
  539. uint32 tmp;
  540. tmp = base->ETDC;
  541. tmp &= ~(FLEXCAN_ETDC_ETDCEN_MASK | FLEXCAN_ETDC_ETDCOFF_MASK);
  542. if (enable)
  543. {
  544. tmp = tmp | FLEXCAN_ETDC_ETDCEN_MASK;
  545. tmp = tmp | FLEXCAN_ETDC_ETDCOFF(offset);
  546. }
  547. base->ETDC = tmp;
  548. }
  549. #endif
  550. #endif /* FLEXCAN_IP_FEATURE_HAS_FD */
  551. /*!
  552. * @brief Gets the payload size of the MBs.
  553. *
  554. * @param base The FlexCAN base address
  555. * @return The payload size in bytes
  556. */
  557. uint8 FlexCAN_GetMbPayloadSize(const FLEXCAN_Type * base, uint32 maxMsgBuffNum);
  558. /*!
  559. * @brief Initializes the FlexCAN controller.
  560. *
  561. * @param base The FlexCAN base address
  562. */
  563. Flexcan_Ip_StatusType FlexCAN_Init(FLEXCAN_Type * base);
  564. /*!
  565. * @brief Checks if the FlexCAN is enabled.
  566. *
  567. * @param base The FlexCAN base address
  568. * @return TRUE if enabled; FALSE if disabled
  569. */
  570. static inline boolean FlexCAN_IsEnabled(const FLEXCAN_Type * pBase)
  571. {
  572. return (((pBase->MCR & FLEXCAN_MCR_MDIS_MASK) >> FLEXCAN_MCR_MDIS_SHIFT) != 0U) ? FALSE : TRUE;
  573. }
  574. #if (FLEXCAN_IP_FEATURE_HAS_MEM_ERR_DET == STD_ON)
  575. /*!
  576. * @brief Disable Error Detection and Correction of Memory Errors.
  577. *
  578. * @param base The FlexCAN base address
  579. */
  580. static inline void FlexCAN_DisableMemErrorDetection(FLEXCAN_Type * base)
  581. {
  582. /* Enable write of MECR register */
  583. base->CTRL2 |= FLEXCAN_CTRL2_ECRWRE(1);
  584. /* Enable write of MECR */
  585. base->MECR = FLEXCAN_MECR_ECRWRDIS(0);
  586. /* Disable Error Detection and Correction mechanism,
  587. * that will set CAN in Freez Mode in case of trigger */
  588. base->MECR = FLEXCAN_MECR_NCEFAFRZ(0);
  589. /* Disable memory error correction */
  590. base->MECR |= FLEXCAN_MECR_ECCDIS(1);
  591. /* Disable write of MECR */
  592. base->CTRL2 &= ~FLEXCAN_CTRL2_ECRWRE(1);
  593. }
  594. #endif /* FLEXCAN_IP_FEATURE_HAS_MEM_ERR_DET */
  595. /*!
  596. * @brief Enables/Disables Flexible Data rate (if supported).
  597. *
  598. * @param base The FlexCAN base address
  599. * @param enable TRUE to enable; FALSE to disable
  600. */
  601. static inline void FlexCAN_SetFDEnabled(FLEXCAN_Type * base,
  602. boolean enableFD,
  603. boolean enableBRS
  604. )
  605. {
  606. base->MCR = (base->MCR & ~FLEXCAN_MCR_FDEN_MASK) | FLEXCAN_MCR_FDEN(enableFD ? 1UL : 0UL);
  607. /* Enable BitRate Switch support from BRS_TX_MB field or ignore it */
  608. base->FDCTRL = (base->FDCTRL & ~FLEXCAN_FDCTRL_FDRATE_MASK) | FLEXCAN_FDCTRL_FDRATE(enableBRS ? 1UL : 0UL);
  609. /* Disable Transmission Delay Compensation by default */
  610. base->FDCTRL &= ~(FLEXCAN_FDCTRL_TDCEN_MASK | FLEXCAN_FDCTRL_TDCOFF_MASK);
  611. }
  612. /*!
  613. * @brief Enables/Disables Listen Only Mode.
  614. *
  615. * @param base The FlexCAN base address
  616. * @param enable TRUE to enable; FALSE to disable
  617. */
  618. static inline void FlexCAN_SetListenOnlyMode(FLEXCAN_Type * base, boolean enableListenOnly)
  619. {
  620. base->CTRL1 = (base->CTRL1 & ~FLEXCAN_CTRL1_LOM_MASK) | FLEXCAN_CTRL1_LOM(enableListenOnly ? 1UL : 0UL);
  621. }
  622. #if (FLEXCAN_IP_FEATURE_HAS_DMA_ENABLE == STD_ON)
  623. /*!
  624. * @brief Clears the FIFO
  625. *
  626. * @param base The FlexCAN base address
  627. */
  628. static inline void FlexCAN_ClearFIFO(FLEXCAN_Type * base)
  629. {
  630. base->IFLAG1 = FLEXCAN_IFLAG1_BUF0I_MASK;
  631. }
  632. /*!
  633. * @brief Enables/Disables the DMA support for RxFIFO.
  634. *
  635. * @param base The FlexCAN base address
  636. * @param enable Enable/Disable DMA support
  637. */
  638. static inline void FlexCAN_SetRxFifoDMA(FLEXCAN_Type * base, boolean enable)
  639. {
  640. base->MCR = (base->MCR & ~FLEXCAN_MCR_DMA_MASK) | FLEXCAN_MCR_DMA(enable ? 1UL : 0UL);
  641. }
  642. #if (FLEXCAN_IP_FEATURE_HAS_ENHANCED_RX_FIFO == STD_ON)
  643. /*!
  644. * @brief Resets Enhanced Rx FIFO engine and state.
  645. *
  646. * @param base The FlexCAN base address
  647. */
  648. static inline void FlexCAN_ClearEnhancedRxFifoEngine(FLEXCAN_Type * base)
  649. {
  650. base->ERFSR = base->ERFSR | FLEXCAN_ERFSR_ERFCLR_MASK;
  651. }
  652. /*!
  653. * @brief Clears the Enhanced Rx FIFO
  654. *
  655. * @param base The FlexCAN base address
  656. */
  657. static inline void FlexCAN_ClearEnhancedFIFO(FLEXCAN_Type * base)
  658. {
  659. base->ERFSR = FLEXCAN_ERFSR_ERFCLR_MASK;
  660. }
  661. /*!
  662. * @brief Configure the number of words to transfer for each Enhanced Rx FIFO data element in DMA mode.
  663. *
  664. * @param base The FlexCAN base address
  665. * @param numOfWords The number of words to transfer
  666. */
  667. static inline void FlexCAN_ConfigEnhancedRxFifoDMA(FLEXCAN_Type * base, uint32 numOfWords)
  668. {
  669. base->ERFCR = (base->ERFCR & (~FLEXCAN_ERFCR_DMALW_MASK)) | (((numOfWords - 1u) << FLEXCAN_ERFCR_DMALW_SHIFT) & FLEXCAN_ERFCR_DMALW_MASK);
  670. }
  671. #endif /* FLEXCAN_IP_FEATURE_HAS_ENHANCED_RX_FIFO */
  672. #endif /* if FLEXCAN_IP_FEATURE_HAS_DMA_ENABLE */
  673. /*!
  674. * @brief Get The Max no of MBs allowed on CAN instance.
  675. *
  676. * @param base The FlexCAN base address
  677. * @return The Max No of MBs on the CAN instance;
  678. */
  679. uint32 FlexCAN_GetMaxMbNum(const FLEXCAN_Type * base);
  680. /*!
  681. * @brief Unlocks the FlexCAN Rx message buffer.
  682. *
  683. * @param base The FlexCAN base address
  684. */
  685. static inline void FlexCAN_UnlockRxMsgBuff(const FLEXCAN_Type * base)
  686. {
  687. /* Unlock the mailbox by reading the free running timer */
  688. (void)base->TIMER;
  689. }
  690. /*!
  691. * @brief Clears the interrupt flag of the message buffers.
  692. *
  693. * @param base The FlexCAN base address
  694. * @param msgBuffIdx Index of the message buffer
  695. */
  696. static inline void FlexCAN_ClearMsgBuffIntStatusFlag(FLEXCAN_Type * base, uint32 msgBuffIdx)
  697. {
  698. uint32 flag = ((uint32)1U << (msgBuffIdx % 32U));
  699. /* Clear the corresponding message buffer interrupt flag*/
  700. if (msgBuffIdx < 32U)
  701. {
  702. (base->IFLAG1) = (flag);
  703. }
  704. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM > 32U
  705. else if (msgBuffIdx < 64U)
  706. {
  707. (base->IFLAG2) = (flag);
  708. }
  709. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM <= 64U
  710. else
  711. {
  712. /* Required Rule 15.7, no 'else' at end of 'if ... else if' chain */
  713. }
  714. #endif
  715. #endif /* if FLEXCAN_IP_FEATURE_MAX_MB_NUM > 32U */
  716. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM > 64U
  717. else if (msgBuffIdx < 96U)
  718. {
  719. (base->IFLAG3) = (flag);
  720. }
  721. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM <= 96U
  722. else
  723. {
  724. /* Required Rule 15.7, no 'else' at end of 'if ... else if' chain */
  725. }
  726. #endif
  727. #endif /* if FLEXCAN_IP_FEATURE_MAX_MB_NUM > 64U */
  728. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM > 96U
  729. else
  730. {
  731. (base->IFLAG4) = (flag);
  732. }
  733. #endif
  734. }
  735. /*!
  736. * @brief Get the interrupt flag of the message buffers.
  737. *
  738. * @param base The FlexCAN base address
  739. * @param msgBuffIdx Index of the message buffer
  740. * @return flag The value of interrupt flag of the message buffer.
  741. */
  742. static inline uint8 FlexCAN_GetBuffStatusFlag(const FLEXCAN_Type * base, uint32 msgBuffIdx)
  743. {
  744. uint32 flag = 0U;
  745. if (msgBuffIdx < 32U)
  746. {
  747. flag = ((base->IFLAG1 & ((uint32)1U << (msgBuffIdx % 32U))) >> (msgBuffIdx % 32U));
  748. }
  749. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM > 32U
  750. else if (msgBuffIdx < 64U)
  751. {
  752. flag = ((base->IFLAG2 & ((uint32)1U << (msgBuffIdx % 32U))) >> (msgBuffIdx % 32U));
  753. }
  754. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM <= 64U
  755. else
  756. {
  757. /* Required Rule 15.7, no 'else' at end of 'if ... else if' chain */
  758. }
  759. #endif /* FLEXCAN_IP_FEATURE_MAX_MB_NUM <= 64U */
  760. #endif /* FLEXCAN_IP_FEATURE_MAX_MB_NUM > 32U */
  761. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM > 64U
  762. else if (msgBuffIdx < 96U)
  763. {
  764. flag = ((base->IFLAG3 & ((uint32)1U << (msgBuffIdx % 32U))) >> (msgBuffIdx % 32U));
  765. }
  766. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM <= 96U
  767. else
  768. {
  769. /* Required Rule 15.7, no 'else' at end of 'if ... else if' chain */
  770. }
  771. #endif /* FLEXCAN_IP_FEATURE_MAX_MB_NUM <= 96U */
  772. #endif /* FLEXCAN_IP_FEATURE_MAX_MB_NUM > 64U */
  773. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM > 96U
  774. else
  775. {
  776. flag = ((base->IFLAG4 & ((uint32)1U << (msgBuffIdx % 32U))) >> (msgBuffIdx % 32U));
  777. }
  778. #endif
  779. return (uint8)flag;
  780. }
  781. /*!
  782. * @brief Get the interrupt Imask of the message buffers.
  783. *
  784. * @param base The FlexCAN base address
  785. * @param msgBuffIdx Index of the message buffer
  786. * @return Imask The value of interrupt Imask of the message buffer.
  787. */
  788. static inline uint8 FlexCAN_GetBuffStatusImask(const FLEXCAN_Type * base, uint32 msgBuffIdx)
  789. {
  790. uint32 u32Imask = 0U;
  791. if (msgBuffIdx < 32U)
  792. {
  793. u32Imask = ((base->IMASK1 & ((uint32)1U << (msgBuffIdx % 32U))) >> (msgBuffIdx % 32U));
  794. }
  795. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM > 32U
  796. else if (msgBuffIdx < 64U)
  797. {
  798. u32Imask = ((base->IMASK2 & ((uint32)1U << (msgBuffIdx % 32U))) >> (msgBuffIdx % 32U));
  799. }
  800. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM <= 64U
  801. else
  802. {
  803. /* Required Rule 15.7, no 'else' at end of 'if ... else if' chain */
  804. }
  805. #endif /* FLEXCAN_IP_FEATURE_MAX_MB_NUM <= 64U */
  806. #endif /* FLEXCAN_IP_FEATURE_MAX_MB_NUM > 32U */
  807. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM > 64U
  808. else if (msgBuffIdx < 96U)
  809. {
  810. u32Imask = ((base->IMASK3 & ((uint32)1U << (msgBuffIdx % 32U))) >> (msgBuffIdx % 32U));
  811. }
  812. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM <= 96U
  813. else
  814. {
  815. /* Required Rule 15.7, no 'else' at end of 'if ... else if' chain */
  816. }
  817. #endif /* FLEXCAN_IP_FEATURE_MAX_MB_NUM <= 96U */
  818. #endif /* FLEXCAN_IP_FEATURE_MAX_MB_NUM > 64U */
  819. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM > 96U
  820. else
  821. {
  822. u32Imask = ((base->IMASK4 & ((uint32)1U << (msgBuffIdx % 32U))) >> (msgBuffIdx % 32U));
  823. }
  824. #endif
  825. return (uint8)u32Imask;
  826. }
  827. #if (FLEXCAN_IP_FEATURE_HAS_FD == STD_ON)
  828. /*!
  829. * @brief Sets the FlexCAN time segments for setting up bit rate for FD BRS.
  830. *
  831. * @param base The FlexCAN base address
  832. * @param timeSeg FlexCAN time segments, which need to be set for the bit rate.
  833. */
  834. static inline void FlexCAN_SetFDTimeSegments(FLEXCAN_Type * base, const Flexcan_Ip_TimeSegmentType * timeSeg)
  835. {
  836. #if (FLEXCAN_IP_DEV_ERROR_DETECT == STD_ON)
  837. DevAssert(timeSeg != NULL_PTR);
  838. #endif
  839. /* Set FlexCAN time segments*/
  840. (base->FDCBT) = ((base->FDCBT) & ~((FLEXCAN_FDCBT_FPROPSEG_MASK | FLEXCAN_FDCBT_FPSEG2_MASK |
  841. FLEXCAN_FDCBT_FPSEG1_MASK | FLEXCAN_FDCBT_FPRESDIV_MASK
  842. ) | FLEXCAN_FDCBT_FRJW_MASK
  843. )
  844. );
  845. (base->FDCBT) = ((base->FDCBT) | (FLEXCAN_FDCBT_FPROPSEG(timeSeg->propSeg) |
  846. FLEXCAN_FDCBT_FPSEG2(timeSeg->phaseSeg2) |
  847. FLEXCAN_FDCBT_FPSEG1(timeSeg->phaseSeg1) |
  848. FLEXCAN_FDCBT_FPRESDIV(timeSeg->preDivider) |
  849. FLEXCAN_FDCBT_FRJW(timeSeg->rJumpwidth)
  850. )
  851. );
  852. }
  853. #endif /* FLEXCAN_IP_FEATURE_HAS_FD */
  854. /*!
  855. * @brief Sets the FlexCAN time segments for setting up bit rate.
  856. *
  857. * @param base The FlexCAN base address
  858. * @param timeSeg FlexCAN time segments, which need to be set for the bit rate.
  859. */
  860. static inline void FlexCAN_SetTimeSegments(FLEXCAN_Type * base, const Flexcan_Ip_TimeSegmentType * timeSeg)
  861. {
  862. #if (FLEXCAN_IP_DEV_ERROR_DETECT == STD_ON)
  863. DevAssert(timeSeg != NULL_PTR);
  864. #endif
  865. (base->CTRL1) = ((base->CTRL1) & ~((FLEXCAN_CTRL1_PROPSEG_MASK | FLEXCAN_CTRL1_PSEG2_MASK |
  866. FLEXCAN_CTRL1_PSEG1_MASK | FLEXCAN_CTRL1_PRESDIV_MASK
  867. ) | FLEXCAN_CTRL1_RJW_MASK
  868. )
  869. );
  870. (base->CTRL1) = ((base->CTRL1) | (FLEXCAN_CTRL1_PROPSEG(timeSeg->propSeg) |
  871. FLEXCAN_CTRL1_PSEG2(timeSeg->phaseSeg2) |
  872. FLEXCAN_CTRL1_PSEG1(timeSeg->phaseSeg1) |
  873. FLEXCAN_CTRL1_PRESDIV(timeSeg->preDivider) |
  874. FLEXCAN_CTRL1_RJW(timeSeg->rJumpwidth)
  875. )
  876. );
  877. }
  878. /*!
  879. * @brief Sets the FlexCAN extended time segments for setting up bit rate.
  880. *
  881. * @param base The FlexCAN base address
  882. * @param timeSeg FlexCAN time segments, which need to be set for the bit rate.
  883. */
  884. static inline void FlexCAN_SetExtendedTimeSegments(FLEXCAN_Type * base, const Flexcan_Ip_TimeSegmentType * timeSeg)
  885. {
  886. #if (FLEXCAN_IP_DEV_ERROR_DETECT == STD_ON)
  887. DevAssert(timeSeg != NULL_PTR);
  888. #endif
  889. /* If extended bit time definitions are enabled, use CBT register */
  890. (base->CBT) = ((base->CBT) & ~((FLEXCAN_CBT_EPROPSEG_MASK | FLEXCAN_CBT_EPSEG2_MASK |
  891. FLEXCAN_CBT_EPSEG1_MASK | FLEXCAN_CBT_EPRESDIV_MASK
  892. ) | FLEXCAN_CBT_ERJW_MASK
  893. )
  894. );
  895. (base->CBT) = ((base->CBT) | (FLEXCAN_CBT_EPROPSEG(timeSeg->propSeg) |
  896. FLEXCAN_CBT_EPSEG2(timeSeg->phaseSeg2) |
  897. FLEXCAN_CBT_EPSEG1(timeSeg->phaseSeg1) |
  898. FLEXCAN_CBT_EPRESDIV(timeSeg->preDivider) |
  899. FLEXCAN_CBT_ERJW(timeSeg->rJumpwidth)
  900. )
  901. );
  902. }
  903. #if (FLEXCAN_IP_FEATURE_HAS_ENHANCE_CBT == STD_ON)
  904. /*!
  905. * @brief Sets the FlexCAN Enhanced time segments for setting up nominal bit rate.
  906. *
  907. * @param base The FlexCAN base address
  908. * @param timeSeg FlexCAN time segments, which need to be set for the bit rate.
  909. */
  910. static inline void FlexCAN_SetEnhancedNominalTimeSegments(FLEXCAN_Type * base, const Flexcan_Ip_TimeSegmentType * timeSeg)
  911. {
  912. #if (FLEXCAN_IP_DEV_ERROR_DETECT == STD_ON)
  913. DevAssert(timeSeg != NULL_PTR);
  914. #endif
  915. (base->ENCBT) = ((base->ENCBT) & ~(FLEXCAN_ENCBT_NTSEG1_MASK | FLEXCAN_ENCBT_NTSEG2_MASK | FLEXCAN_ENCBT_NRJW_MASK));
  916. (base->ENCBT) = ((base->ENCBT) |(FLEXCAN_ENCBT_NTSEG1(timeSeg->phaseSeg1 + timeSeg->propSeg + 1U) |
  917. FLEXCAN_ENCBT_NTSEG2(timeSeg->phaseSeg2) |
  918. FLEXCAN_ENCBT_NRJW(timeSeg->rJumpwidth)
  919. )
  920. );
  921. (base->EPRS) = (base->EPRS & ~FLEXCAN_EPRS_ENPRESDIV_MASK);
  922. (base->EPRS) |= FLEXCAN_EPRS_ENPRESDIV(timeSeg->preDivider);
  923. }
  924. /*!
  925. * @brief Get the FlexCAN Enhanced time segments for nominal bit rate.
  926. *
  927. * @param base The FlexCAN base address
  928. * @param timeSeg FlexCAN time segments, which need to be set for the bit rate.
  929. */
  930. static inline void FlexCAN_GetEnhancedNominalTimeSegments(const FLEXCAN_Type * base, Flexcan_Ip_TimeSegmentType * timeSeg)
  931. {
  932. timeSeg->propSeg = 0;
  933. timeSeg->preDivider = ((base->EPRS & FLEXCAN_EPRS_ENPRESDIV_MASK) >> FLEXCAN_EPRS_ENPRESDIV_SHIFT);
  934. timeSeg->phaseSeg1 = ((base->ENCBT & FLEXCAN_ENCBT_NTSEG1_MASK) >> FLEXCAN_ENCBT_NTSEG1_SHIFT);
  935. timeSeg->phaseSeg2 = ((base->ENCBT & FLEXCAN_ENCBT_NTSEG2_MASK) >> FLEXCAN_ENCBT_NTSEG2_SHIFT);
  936. timeSeg->rJumpwidth = ((base->ENCBT & FLEXCAN_ENCBT_NRJW_MASK) >> FLEXCAN_ENCBT_NRJW_SHIFT);
  937. }
  938. /*!
  939. * @brief Sets the FlexCAN Enhanced time segments for setting up data bit rate.
  940. *
  941. * @param base The FlexCAN base address
  942. * @param timeSeg FlexCAN time segments, which need to be set for the bit rate.
  943. */
  944. static inline void FlexCAN_SetEnhancedDataTimeSegments(FLEXCAN_Type * base, const Flexcan_Ip_TimeSegmentType * timeSeg)
  945. {
  946. #if (FLEXCAN_IP_DEV_ERROR_DETECT == STD_ON)
  947. DevAssert(timeSeg != NULL_PTR);
  948. #endif
  949. (base->EDCBT) = ((base->EDCBT) & ~(FLEXCAN_EDCBT_DTSEG1_MASK | FLEXCAN_EDCBT_DTSEG2_MASK | FLEXCAN_EDCBT_DRJW_MASK));
  950. (base->EDCBT) = ((base->EDCBT) | (FLEXCAN_EDCBT_DTSEG1(timeSeg->phaseSeg1 + timeSeg->propSeg) |
  951. FLEXCAN_EDCBT_DTSEG2(timeSeg->phaseSeg2) |
  952. FLEXCAN_EDCBT_DRJW(timeSeg->rJumpwidth)
  953. )
  954. );
  955. (base->EPRS) = (base->EPRS & ~FLEXCAN_EPRS_EDPRESDIV_MASK);
  956. (base->EPRS) |= FLEXCAN_EPRS_EDPRESDIV(timeSeg->preDivider);
  957. }
  958. static inline void FlexCAN_GetEnhancedDataTimeSegments(const FLEXCAN_Type * base, Flexcan_Ip_TimeSegmentType * timeSeg)
  959. {
  960. #if (FLEXCAN_IP_DEV_ERROR_DETECT == STD_ON)
  961. DevAssert(timeSeg != NULL_PTR);
  962. #endif
  963. timeSeg->propSeg = 0U;
  964. timeSeg->phaseSeg1 = ((base->EDCBT & FLEXCAN_EDCBT_DTSEG1_MASK) >> FLEXCAN_EDCBT_DTSEG1_SHIFT);
  965. timeSeg->phaseSeg2 = ((base->EDCBT & FLEXCAN_EDCBT_DTSEG2_MASK) >> FLEXCAN_EDCBT_DTSEG2_SHIFT);
  966. timeSeg->rJumpwidth = ((base->EDCBT & FLEXCAN_EDCBT_DRJW_MASK) >> FLEXCAN_EDCBT_DRJW_SHIFT);
  967. timeSeg->preDivider = ((base->EPRS & FLEXCAN_EPRS_EDPRESDIV_MASK) >> FLEXCAN_EPRS_EDPRESDIV_SHIFT);
  968. }
  969. #endif /* (FLEXCAN_IP_FEATURE_HAS_ENHANCE_CBT == STD_ON) */
  970. /*!
  971. * @brief Gets the FlexCAN extended time segments used for setting up bit rate.
  972. *
  973. * @param[in] base The FlexCAN base address
  974. * @param[out] timeSeg FlexCAN time segments read for bit rate
  975. */
  976. static inline void FlexCAN_GetExtendedTimeSegments(const FLEXCAN_Type * base, Flexcan_Ip_TimeSegmentType * timeSeg)
  977. {
  978. timeSeg->preDivider = ((base->CBT) & FLEXCAN_CBT_EPRESDIV_MASK) >> FLEXCAN_CBT_EPRESDIV_SHIFT;
  979. timeSeg->propSeg = ((base->CBT) & FLEXCAN_CBT_EPROPSEG_MASK) >> FLEXCAN_CBT_EPROPSEG_SHIFT;
  980. timeSeg->phaseSeg1 = ((base->CBT) & FLEXCAN_CBT_EPSEG1_MASK) >> FLEXCAN_CBT_EPSEG1_SHIFT;
  981. timeSeg->phaseSeg2 = ((base->CBT) & FLEXCAN_CBT_EPSEG2_MASK) >> FLEXCAN_CBT_EPSEG2_SHIFT;
  982. timeSeg->rJumpwidth = ((base->CBT) & FLEXCAN_CBT_ERJW_MASK) >> FLEXCAN_CBT_ERJW_SHIFT;
  983. }
  984. /*!
  985. * @brief Gets the FlexCAN time segments to calculate the bit rate.
  986. *
  987. * @param[in] base The FlexCAN base address
  988. * @param[out] timeSeg FlexCAN time segments read for bit rate
  989. */
  990. static inline void FlexCAN_GetTimeSegments(const FLEXCAN_Type * base, Flexcan_Ip_TimeSegmentType * timeSeg)
  991. {
  992. timeSeg->preDivider = ((base->CTRL1) & FLEXCAN_CTRL1_PRESDIV_MASK) >> FLEXCAN_CTRL1_PRESDIV_SHIFT;
  993. timeSeg->propSeg = ((base->CTRL1) & FLEXCAN_CTRL1_PROPSEG_MASK) >> FLEXCAN_CTRL1_PROPSEG_SHIFT;
  994. timeSeg->phaseSeg1 = ((base->CTRL1) & FLEXCAN_CTRL1_PSEG1_MASK) >> FLEXCAN_CTRL1_PSEG1_SHIFT;
  995. timeSeg->phaseSeg2 = ((base->CTRL1) & FLEXCAN_CTRL1_PSEG2_MASK) >> FLEXCAN_CTRL1_PSEG2_SHIFT;
  996. timeSeg->rJumpwidth = ((base->CTRL1) & FLEXCAN_CTRL1_RJW_MASK) >> FLEXCAN_CTRL1_RJW_SHIFT;
  997. }
  998. #if (FLEXCAN_IP_FEATURE_HAS_FD == STD_ON)
  999. /*!
  1000. * @brief Gets the FlexCAN time segments for FD BRS to calculate the bit rate.
  1001. *
  1002. * @param base The FlexCAN base address
  1003. * @param timeSeg FlexCAN time segments read for bit rate
  1004. */
  1005. static inline void FlexCAN_GetFDTimeSegments(const FLEXCAN_Type * base, Flexcan_Ip_TimeSegmentType * timeSeg)
  1006. {
  1007. timeSeg->preDivider = ((base->FDCBT) & FLEXCAN_FDCBT_FPRESDIV_MASK) >> FLEXCAN_FDCBT_FPRESDIV_SHIFT;
  1008. timeSeg->propSeg = ((base->FDCBT) & FLEXCAN_FDCBT_FPROPSEG_MASK) >> FLEXCAN_FDCBT_FPROPSEG_SHIFT;
  1009. timeSeg->phaseSeg1 = ((base->FDCBT) & FLEXCAN_FDCBT_FPSEG1_MASK) >> FLEXCAN_FDCBT_FPSEG1_SHIFT;
  1010. timeSeg->phaseSeg2 = ((base->FDCBT) & FLEXCAN_FDCBT_FPSEG2_MASK) >> FLEXCAN_FDCBT_FPSEG2_SHIFT;
  1011. timeSeg->rJumpwidth = ((base->FDCBT) & FLEXCAN_FDCBT_FRJW_MASK) >> FLEXCAN_FDCBT_FRJW_SHIFT;
  1012. }
  1013. #endif /* if FLEXCAN_IP_FEATURE_HAS_FD */
  1014. /*!
  1015. * @brief Checks if the Extended Time Segment are enabled.
  1016. *
  1017. * @param base The FlexCAN base address
  1018. * @return TRUE if enabled; FALSE if disabled
  1019. */
  1020. static inline boolean FlexCAN_IsExCbtEnabled(const FLEXCAN_Type * pBase)
  1021. {
  1022. return (0U == ((pBase->CBT & FLEXCAN_CBT_BTF_MASK) >> FLEXCAN_CBT_BTF_SHIFT)) ? FALSE : TRUE;
  1023. }
  1024. #if (FLEXCAN_IP_FEATURE_HAS_ENHANCE_CBT == STD_ON)
  1025. /*!
  1026. * @brief Checks if the Enhanced Time Segment are enabled.
  1027. *
  1028. * @param base The FlexCAN base address
  1029. * @return TRUE if enabled; FALSE if disabled
  1030. */
  1031. static inline boolean FlexCAN_IsEnhCbtEnabled(const FLEXCAN_Type * pBase)
  1032. {
  1033. return (0U == ((pBase->CTRL2 & FLEXCAN_CTRL2_BTE_MASK) >> FLEXCAN_CTRL2_BTE_SHIFT)) ? FALSE : TRUE;
  1034. }
  1035. /*!
  1036. * @brief Set the Enhanced Time Segment are enabled or disabled.
  1037. *
  1038. * @param base The FlexCAN base address
  1039. * @param enableCBT Enable/Disable use of Enhanced Time Segments
  1040. */
  1041. static inline void FlexCAN_EnhCbtEnable(FLEXCAN_Type * base, boolean enableCBT)
  1042. { /* Enable the use of extended bit time definitions */
  1043. base->CTRL2 = (base->CTRL2 & ~FLEXCAN_CTRL2_BTE_MASK) | FLEXCAN_CTRL2_BTE(enableCBT ? 1UL : 0UL);
  1044. }
  1045. #endif
  1046. /*!
  1047. * @brief Set the Extended Time Segment are enabled or disabled.
  1048. *
  1049. * @param base The FlexCAN base address
  1050. * @param enableCBT Enable/Disable use of Extent Time Segments
  1051. */
  1052. static inline void FlexCAN_EnableExtCbt(FLEXCAN_Type * base, boolean enableCBT)
  1053. { /* Enable the use of extended bit time definitions */
  1054. base->CBT = (base->CBT & ~FLEXCAN_CBT_BTF_MASK) | FLEXCAN_CBT_BTF(enableCBT ? 1UL : 0UL);
  1055. }
  1056. /*!
  1057. * @brief Set operation mode.
  1058. *
  1059. * @param base The FlexCAN base address
  1060. * @param mode Set an operation mode
  1061. */
  1062. void FlexCAN_SetOperationMode(FLEXCAN_Type * base, Flexcan_Ip_ModesType mode);
  1063. /*!
  1064. * @brief Enables/Disables the Self Reception feature.
  1065. *
  1066. * If enabled, FlexCAN is allowed to receive frames transmitted by itself.
  1067. *
  1068. * @param base The FlexCAN base address
  1069. * @param enable Enable/Disable Self Reception
  1070. */
  1071. static inline void FlexCAN_SetSelfReception(FLEXCAN_Type * base, boolean enable)
  1072. {
  1073. base->MCR = (base->MCR & ~FLEXCAN_MCR_SRXDIS_MASK) | FLEXCAN_MCR_SRXDIS(enable ? 0UL : 1UL);
  1074. }
  1075. /*!
  1076. * @brief Checks if the Flexible Data rate feature is enabled.
  1077. *
  1078. * @param base The FlexCAN base address
  1079. * @return TRUE if enabled; FALSE if disabled
  1080. */
  1081. static inline boolean FlexCAN_IsFDEnabled(const FLEXCAN_Type * base)
  1082. {
  1083. return ((base->MCR & FLEXCAN_MCR_FDEN_MASK) >> FLEXCAN_MCR_FDEN_SHIFT) != 0U;
  1084. }
  1085. /*!
  1086. * @brief Checks if the listen only mode is enabled.
  1087. *
  1088. * @param base The FlexCAN base address
  1089. * @return TRUE if enabled; FALSE if disabled
  1090. */
  1091. static inline boolean FlexCAN_IsListenOnlyModeEnabled(const FLEXCAN_Type * base)
  1092. {
  1093. return (((base->CTRL1 & (FLEXCAN_CTRL1_LOM_MASK)) != 0U) ? TRUE : FALSE);
  1094. }
  1095. /*!
  1096. * @brief Return last Message Buffer Occupied By RxFIFO
  1097. *
  1098. * @param x Number of Configured RxFIFO Filters
  1099. * @return number of last MB occupied by RxFIFO
  1100. */
  1101. static inline uint32 RxFifoOcuppiedLastMsgBuff(uint32 x)
  1102. {
  1103. return 5U + ((((x) + 1U) * 8U) / 4U);
  1104. }
  1105. #if (FLEXCAN_IP_FEATURE_HAS_ENHANCED_RX_FIFO == STD_ON)
  1106. /*!
  1107. * @brief Computes the maximum payload size (in bytes), given a DLC
  1108. *
  1109. * @param dlcValue DLC code from the MB memory.
  1110. * @return payload size (in bytes)
  1111. */
  1112. uint8 FlexCAN_ComputePayloadSize(uint8 dlcValue);
  1113. #endif /*(FLEXCAN_IP_FEATURE_HAS_ENHANCED_RX_FIFO == STD_ON) */
  1114. /*!
  1115. * @brief Sets the FlexCAN message buffer fields for transmitting.
  1116. *
  1117. * @param base The FlexCAN base address
  1118. * @param msgBuffIdx Index of the message buffer
  1119. * @return Pointer to the beginning of the MBs space address
  1120. */
  1121. volatile uint32 * FlexCAN_GetMsgBuffRegion(const FLEXCAN_Type * base, uint32 msgBuffIdx);
  1122. /*!
  1123. * @brief Enables/Disables FD frame compatible with ISO-FD Frame ISO 11898-1 (2003)
  1124. *
  1125. * The CAN FD protocol has been improved to increase the failure detection capability that was in the original CAN FD protocol,
  1126. * which is also called non-ISO CAN FD, by CAN in Automation (CiA). A three-bit stuff counter and a parity bit have been introduced
  1127. * in the improved CAN FD protocol, now called ISO CAN FD. The CRC calculation has also been modified. All these improvements
  1128. * make the ISO CAN FD protocol incompatible with the non-FD CAN FD protocol.
  1129. *
  1130. * @param base The FlexCAN base address
  1131. * @param enable Enable/Disable ISO FD Compatible mode.
  1132. */
  1133. #if (FLEXCAN_IP_FEATURE_SWITCHINGISOMODE == STD_ON)
  1134. static inline void FlexCAN_SetIsoCan(FLEXCAN_Type * base, boolean enable)
  1135. {
  1136. base->CTRL2 = (base->CTRL2 & ~FLEXCAN_CTRL2_ISOCANFDEN_MASK) | FLEXCAN_CTRL2_ISOCANFDEN(enable ? 1UL : 0UL);
  1137. }
  1138. #endif
  1139. static inline void FlexCAN_SetEntireFrameArbitrationFieldComparison(FLEXCAN_Type * base, boolean enable)
  1140. {
  1141. base->CTRL2 = (base->CTRL2 & ~FLEXCAN_CTRL2_EACEN_MASK) | FLEXCAN_CTRL2_EACEN(enable ? 1UL : 0UL);
  1142. }
  1143. #if (FLEXCAN_IP_FEATURE_PROTOCOLEXCEPTION == STD_ON)
  1144. static inline void FlexCAN_SetProtocolException(FLEXCAN_Type * base, boolean enable)
  1145. {
  1146. base->CTRL2 = (base->CTRL2 & ~FLEXCAN_CTRL2_PREXCEN_MASK) | FLEXCAN_CTRL2_PREXCEN(enable ? 1UL : 0UL);
  1147. }
  1148. #endif
  1149. static inline void FlexCAN_SetRemoteReqStore(FLEXCAN_Type * base, boolean enable)
  1150. {
  1151. base->CTRL2 = (base->CTRL2 & ~FLEXCAN_CTRL2_RRS_MASK) | FLEXCAN_CTRL2_RRS(enable ? 1UL : 0UL);
  1152. }
  1153. static inline void FlexCAN_SetBusOffAutorecovery(FLEXCAN_Type * base, boolean enable)
  1154. {
  1155. base->CTRL1 = (base->CTRL1 & ~FLEXCAN_CTRL1_BOFFREC_MASK) | FLEXCAN_CTRL1_BOFFREC(enable ? 0UL : 1UL);
  1156. }
  1157. #if (FLEXCAN_IP_FEATURE_EDGEFILTER == STD_ON)
  1158. static inline void FlexCAN_SetEdgeFilter(FLEXCAN_Type * base, boolean enable)
  1159. {
  1160. base->CTRL2 = (base->CTRL2 & ~FLEXCAN_CTRL2_EDFLTDIS_MASK) | FLEXCAN_CTRL2_EDFLTDIS(enable ? 0UL : 1UL);
  1161. }
  1162. #endif
  1163. static inline void FlexCAN_CanBitSampling(FLEXCAN_Type * base, boolean enable)
  1164. {
  1165. base->CTRL1 = (base->CTRL1 & ~FLEXCAN_CTRL1_SMP_MASK) | FLEXCAN_CTRL1_SMP(enable ? 1UL : 0UL);
  1166. }
  1167. #if (FLEXCAN_IP_FEATURE_HAS_PE_CLKSRC_SELECT == STD_ON)
  1168. static inline void FlexCAN_SetClkSrc(FLEXCAN_Type * base, boolean enable)
  1169. {
  1170. base->CTRL1 = (base->CTRL1 & ~FLEXCAN_CTRL1_CLKSRC_MASK) | FLEXCAN_CTRL1_CLKSRC(enable ? 1UL : 0UL);
  1171. }
  1172. #endif
  1173. /*!
  1174. * @brief Gets the individual FlexCAN MB interrupt flag.
  1175. *
  1176. * @param base The FlexCAN base address
  1177. * @param msgBuffIdx Index of the message buffer
  1178. * @return the individual Message Buffer interrupt flag (0 and 1 are the flag value)
  1179. */
  1180. static inline uint8 FlexCAN_GetMsgBuffIntStatusFlag(const FLEXCAN_Type * base, uint32 msgBuffIdx)
  1181. {
  1182. /* TODO: This need to be protected multithread access*/
  1183. uint8 flag = 0;
  1184. uint32 mask;
  1185. if (msgBuffIdx < 32U)
  1186. {
  1187. mask = base->IMASK1 & FLEXCAN_IMASK1_BUF31TO0M_MASK;
  1188. flag = (uint8)(((base->IFLAG1 & mask) >> (msgBuffIdx % 32U)) & 1U);
  1189. }
  1190. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM > 32U
  1191. else if (msgBuffIdx < 64U)
  1192. {
  1193. mask = base->IMASK2 & FLEXCAN_IMASK2_BUF63TO32M_MASK;
  1194. flag = (uint8)(((base->IFLAG2 & mask) >> (msgBuffIdx % 32U)) & 1U);
  1195. }
  1196. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM <= 64U
  1197. else
  1198. {
  1199. /* Required Rule 15.7, no 'else' at end of 'if ... else if' chain */
  1200. }
  1201. #endif
  1202. #endif /* if FLEXCAN_IP_FEATURE_MAX_MB_NUM > 32U */
  1203. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM > 64U
  1204. else if (msgBuffIdx < 96U)
  1205. {
  1206. mask = base->IMASK3 & FLEXCAN_IMASK3_BUF95TO64M_MASK;
  1207. flag = (uint8)(((base->IFLAG3 & mask) >> (msgBuffIdx % 32U)) & 1U);
  1208. }
  1209. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM <= 96U
  1210. else
  1211. {
  1212. /* Required Rule 15.7, no 'else' at end of 'if ... else if' chain */
  1213. }
  1214. #endif
  1215. #endif /* if FLEXCAN_IP_FEATURE_MAX_MB_NUM > 64U */
  1216. #if FLEXCAN_IP_FEATURE_MAX_MB_NUM > 96U
  1217. else
  1218. {
  1219. mask = base->IMASK4 & FLEXCAN_IMASK4_BUF127TO96M_MASK;
  1220. flag = (uint8)(((base->IFLAG4 & mask) >> (msgBuffIdx % 32U)) & 1U);
  1221. }
  1222. #endif
  1223. return flag;
  1224. }
  1225. /*!
  1226. * @brief Sets the FlexCAN Rx Message Buffer global mask.
  1227. *
  1228. * @param base The FlexCAN base address
  1229. * @param Mask Mask Value
  1230. */
  1231. static inline void FlexCAN_SetRxMsgBuffGlobalMask(FLEXCAN_Type * base, uint32 Mask)
  1232. {
  1233. (base->RXMGMASK) = Mask;
  1234. }
  1235. /*!
  1236. * @brief Sets the FlexCAN Rx individual mask for ID filtering in the Rx Message Buffers and the Rx FIFO.
  1237. *
  1238. * @param base The FlexCAN base address
  1239. * @param msgBuffIdx Index of the message buffer/filter
  1240. * @param mask Individual mask
  1241. */
  1242. static inline void FlexCAN_SetRxIndividualMask(FLEXCAN_Type * base,
  1243. uint32 msgBuffIdx,
  1244. uint32 mask
  1245. )
  1246. {
  1247. base->RXIMR[msgBuffIdx] = mask;
  1248. }
  1249. /*!
  1250. * @brief Check if controller is in freeze mode or not.
  1251. *
  1252. * @param base The FlexCAN base address
  1253. * @return TRUE if controller is in freeze mode
  1254. * FALSE if controller is not in freeze mode
  1255. */
  1256. static inline boolean FlexCAN_IsFreezeMode(const FLEXCAN_Type * base)
  1257. {
  1258. return (((base->MCR & (FLEXCAN_MCR_FRZACK_MASK)) != 0U)? TRUE : FALSE);
  1259. }
  1260. static inline void FlexCAN_SetTxArbitrationStartDelay(FLEXCAN_Type * base, uint8 tasd)
  1261. {
  1262. base->CTRL2 = (base->CTRL2 & ~FLEXCAN_CTRL2_TASD_MASK) | FLEXCAN_CTRL2_TASD(tasd);
  1263. }
  1264. /*!
  1265. * @brief Sets the Rx masking type.
  1266. *
  1267. * @param base The FlexCAN base address
  1268. * @param type The FlexCAN Rx mask type
  1269. */
  1270. static inline void FlexCAN_SetRxMaskType(FLEXCAN_Type * base, Flexcan_Ip_RxMaskType type)
  1271. {
  1272. /* Set RX masking type (RX global mask or RX individual mask)*/
  1273. if (FLEXCAN_RX_MASK_GLOBAL == type)
  1274. {
  1275. /* Enable Global RX masking */
  1276. base->MCR = (base->MCR & ~FLEXCAN_MCR_IRMQ_MASK) | FLEXCAN_MCR_IRMQ(0U);
  1277. }
  1278. else
  1279. {
  1280. /* Enable Individual Rx Masking and Queue */
  1281. base->MCR = (base->MCR & ~FLEXCAN_MCR_IRMQ_MASK) | FLEXCAN_MCR_IRMQ(1U);
  1282. }
  1283. }
  1284. #if (FLEXCAN_IP_FEATURE_HAS_ENHANCED_RX_FIFO == STD_ON)
  1285. /*!
  1286. * @brief Checks if Enhanced Rx FIFO is enabled.
  1287. *
  1288. * @param base The FlexCAN base address
  1289. * @return EnhancedRxFifo status (true = enabled / false = disabled)
  1290. */
  1291. static inline boolean FlexCAN_IsEnhancedRxFifoEnabled(const FLEXCAN_Type * base)
  1292. {
  1293. return ((((base->ERFCR & FLEXCAN_ERFCR_ERFEN_MASK) >> FLEXCAN_ERFCR_ERFEN_SHIFT) != 0U) ? (TRUE): (FALSE));
  1294. }
  1295. /*FUNCTION**********************************************************************
  1296. *
  1297. * Function Name : FLEXCAN_SetEnhancedRxFifoIntAll
  1298. * Description : Enable/Disable All(Underflow, Overflow, Watermark and frame available)
  1299. * interrupts for Enhanced Rx FIFO.
  1300. *
  1301. *END**************************************************************************/
  1302. static inline void FlexCAN_SetEnhancedRxFifoIntAll(FLEXCAN_Type * base, boolean enable)
  1303. {
  1304. if (TRUE == enable)
  1305. {
  1306. (base->ERFIER) = (uint32)(FLEXCAN_IP_ENHACED_RX_FIFO_ALL_INTERRUPT_MASK);
  1307. }
  1308. else
  1309. {
  1310. (base->ERFIER) = (uint32)(FLEXCAN_IP_ENHACED_RX_FIFO_NO_INTERRUPT_MASK);
  1311. }
  1312. }
  1313. /*!
  1314. * @brief Gets the individual FlexCAN Enhanced Rx FIFO flag.
  1315. *
  1316. * @param base The FlexCAN base address
  1317. * @param intFlag Index of the Enhanced Rx FIFO flag
  1318. * @return the individual Enhanced Rx FIFO flag (0 and 1 are the flag value)
  1319. */
  1320. static inline uint8 FlexCAN_GetEnhancedRxFIFOStatusFlag(const FLEXCAN_Type * base, uint32 intFlag)
  1321. {
  1322. return (uint8)((base->ERFSR & ((uint32)1U << ((uint8)intFlag & (uint8)0x1F))) >> ((uint8)intFlag & (uint8)0x1F));
  1323. }
  1324. /*!
  1325. * @brief Clears the interrupt flag of the Enhanced Rx FIFO.
  1326. *
  1327. * @param base The FlexCAN base address
  1328. * @param intFlag Index of the Enhanced Rx FIFO interrupt flag
  1329. */
  1330. static inline void FlexCAN_ClearEnhancedRxFifoIntStatusFlag(FLEXCAN_Type * base, uint32 intFlag)
  1331. {
  1332. (base->ERFSR) = (uint32)1U << intFlag;
  1333. }
  1334. /*!
  1335. * @brief Gets the individual FlexCAN Enhanced Rx FIFO interrupt flag.
  1336. *
  1337. * @param base The FlexCAN base address
  1338. * @param intFlag Index of the Enhanced Rx FIFO interrupt flag
  1339. * @return the individual Enhanced Rx FIFO interrupt flag (0 and 1 are the flag value)
  1340. */
  1341. static inline uint8 FlexCAN_GetEnhancedRxFIFOIntStatusFlag(const FLEXCAN_Type * base, uint32 intFlag)
  1342. {
  1343. return (uint8)((base->ERFIER & ((uint32)1U << ((uint8)intFlag & (uint8)0x1F))) >> ((uint8)intFlag & (uint8)0x1F));
  1344. }
  1345. /*!
  1346. * @brief Checks if FlexCAN has Enhanced Rx FIFO.
  1347. *
  1348. * @param base The FlexCAN base address
  1349. * @return EnhancedRxFifo status (TRUE = available / FALSE = unavailable)
  1350. */
  1351. boolean FlexCAN_IsEnhancedRxFifoAvailable(const FLEXCAN_Type * base);
  1352. Flexcan_Ip_StatusType FlexCAN_EnableEnhancedRxFifo(FLEXCAN_Type * base,
  1353. uint32 numOfStdIDFilters,
  1354. uint32 numOfExtIDFilters,
  1355. uint32 numOfWatermark
  1356. );
  1357. void FlexCAN_SetEnhancedRxFifoFilter(FLEXCAN_Type * base, const Flexcan_Ip_EnhancedIdTableType * idFilterTable);
  1358. #if (FLEXCAN_IP_FEATURE_HAS_DMA_ENABLE == STD_ON)
  1359. /*!
  1360. * @brief Clear Enhance fifo data.
  1361. *
  1362. * @param base The FlexCAN base address
  1363. * @return void
  1364. */
  1365. void FlexCAN_ClearOutputEnhanceFIFO(FLEXCAN_Type * base);
  1366. #endif /* (FLEXCAN_IP_FEATURE_HAS_DMA_ENABLE == STD_ON) */
  1367. void FlexCAN_ReadEnhancedRxFifo(const FLEXCAN_Type * base, Flexcan_Ip_MsgBuffType * rxFifo);
  1368. #endif /* (FLEXCAN_IP_FEATURE_HAS_ENHANCED_RX_FIFO == STD_ON) */
  1369. #if (FLEXCAN_IP_FEATURE_HAS_DMA_ENABLE == STD_ON)
  1370. /*!
  1371. * @brief Clear Legacy fifo data.
  1372. *
  1373. * @param base The FlexCAN base address
  1374. * @return void
  1375. */
  1376. void FlexCAN_ClearOutputLegacyFIFO(FLEXCAN_Type * base);
  1377. #endif /* FLEXCAN_IP_FEATURE_HAS_DMA_ENABLE */
  1378. #if (FLEXCAN_IP_FEATURE_HAS_TS_ENABLE == STD_ON)
  1379. void FlexCAN_ConfigTimestamp(FLEXCAN_Type * base, const Flexcan_Ip_TimeStampConfigType * config);
  1380. #if (FLEXCAN_IP_FEATURE_HAS_HR_TIMER == STD_ON)
  1381. /*!
  1382. * @brief Checks if High Resolution Time Stamp is enabled.
  1383. *
  1384. * @param base The FlexCAN base address
  1385. * @return HRTimeStamp status (true = enabled / false = disabled)
  1386. */
  1387. static inline boolean FLEXCAN_IsHRTimeStampEnabled(const FLEXCAN_Type * base)
  1388. {
  1389. return ((((base->CTRL2 & FLEXCAN_CTRL2_TSTAMPCAP_MASK) >> FLEXCAN_CTRL2_TSTAMPCAP_SHIFT) != 0U) ? TRUE : FALSE);
  1390. }
  1391. static inline void FlexCAN_ConfigTimestampModule(const Flexcan_Ip_TimeStampConfigType * config)
  1392. {
  1393. FLEXCAN_IP_TIMESTAMP_REG = FLEXCAN_IP_TIMESTAMP_SEL(config->hrSrc)|FLEXCAN_IP_TIMESTAMP_EN_MASK;
  1394. }
  1395. #endif /*(FLEXCAN_IP_FEATURE_HAS_HR_TIMER == STD_ON) */
  1396. #endif /* #if (FLEXCAN_IP_FEATURE_HAS_TS_ENABLE == STD_ON) */
  1397. /*!
  1398. * @brief configure controller depending on options.
  1399. *
  1400. * @param pBase The FlexCAN base address.
  1401. * @param u32Options Controller Options.
  1402. */
  1403. void FlexCAN_ConfigCtrlOptions(FLEXCAN_Type * pBase, uint32 u32Options);
  1404. /*!
  1405. * @brief Will set Flexcan Peripheral Register to default val.
  1406. *
  1407. * @param base The FlexCAN base address
  1408. */
  1409. static inline void FlexCAN_SetRegDefaultVal(FLEXCAN_Type * base)
  1410. {
  1411. #if (FLEXCAN_IP_FEATURE_HAS_ENHANCED_RX_FIFO == STD_ON)
  1412. if (TRUE == FlexCAN_IsEnhancedRxFifoAvailable(base))
  1413. {
  1414. base->ERFSR = FLEXCAN_IP_ERFSR_DEFAULT_VALUE_U32;
  1415. base->ERFIER = FLEXCAN_IP_ERFIER_DEFAULT_VALUE_U32;
  1416. base->ERFCR = FLEXCAN_IP_ERFCR_DEFAULT_VALUE_U32;
  1417. }
  1418. #endif /* (FLEXCAN_IP_FEATURE_HAS_ENHANCED_RX_FIFO == STD_ON) */
  1419. #if (FLEXCAN_IP_FEATURE_HAS_FD == STD_ON)
  1420. #if defined(CAN_FEATURE_S32K1XX)
  1421. if (TRUE == FlexCAN_IsFDAvailable(base))
  1422. {
  1423. #endif /* defined(CAN_FEATURE_S32K1XX) */
  1424. base->FDCBT = FLEXCAN_IP_FDCBT_DEFAULT_VALUE_U32;
  1425. base->FDCTRL = FLEXCAN_IP_FDCTRL_DEFAULT_VALUE_U32;
  1426. #if defined(CAN_FEATURE_S32K1XX)
  1427. }
  1428. #endif /* defined(CAN_FEATURE_S32K1XX) */
  1429. #endif /* (FLEXCAN_IP_FEATURE_HAS_FD == STD_ON) */
  1430. #if (FLEXCAN_IP_FEATURE_HAS_MEM_ERR_DET == STD_ON)
  1431. base->ERRSR = FLEXCAN_IP_ERRSR_DEFAULT_VALUE_U32;
  1432. base->ERRIPPR = FLEXCAN_IP_ERRIPPR_DEFAULT_VALUE_U32;
  1433. base->ERRIDPR = FLEXCAN_IP_ERRIDPR_DEFAULT_VALUE_U32;
  1434. base->ERRIAR = FLEXCAN_IP_ERRIAR_DEFAULT_VALUE_U32;
  1435. /* Enable write of MECR register */
  1436. base->CTRL2 = (base->CTRL2 & ~FLEXCAN_CTRL2_ECRWRE_MASK) | FLEXCAN_CTRL2_ECRWRE(1);
  1437. /* Enable write of MECR */
  1438. base->MECR = (base->MECR & ~FLEXCAN_MECR_ECRWRDIS_MASK) | FLEXCAN_MECR_ECRWRDIS(0);
  1439. /* set Default value */
  1440. base->MECR = FLEXCAN_IP_MECR_DEFAULT_VALUE_U32;
  1441. /* disable write of MECR */
  1442. base->MECR = (base->MECR & ~FLEXCAN_MECR_ECRWRDIS_MASK) | FLEXCAN_MECR_ECRWRDIS(1);
  1443. /* Disable write of MECR */
  1444. base->CTRL2 = (base->CTRL2 & ~FLEXCAN_CTRL2_ECRWRE_MASK) | FLEXCAN_CTRL2_ECRWRE(0);
  1445. #endif /* (FLEXCAN_IP_FEATURE_HAS_MEM_ERR_DET == STD_ON) */
  1446. #if (FLEXCAN_IP_FEATURE_MAX_MB_NUM > 96U)
  1447. if (FlexCAN_GetMaxMbNum(base) > 96U)
  1448. {
  1449. base->IFLAG4 = FLEXCAN_IP_IFLAG_DEFAULT_VALUE_U32;
  1450. base->IMASK4 = FLEXCAN_IP_IMASK_DEFAULT_VALUE_U32;
  1451. }
  1452. #endif /* (FLEXCAN_IP_FEATURE_MAX_MB_NUM > 96U) */
  1453. #if (FLEXCAN_IP_FEATURE_MAX_MB_NUM > 64U)
  1454. if (FlexCAN_GetMaxMbNum(base) > 64U)
  1455. {
  1456. base->IFLAG3 = FLEXCAN_IP_IFLAG_DEFAULT_VALUE_U32;
  1457. base->IMASK3 = FLEXCAN_IP_IMASK_DEFAULT_VALUE_U32;
  1458. }
  1459. #endif /* (FLEXCAN_IP_FEATURE_MAX_MB_NUM > 64U) */
  1460. #if (FLEXCAN_IP_FEATURE_MAX_MB_NUM > 32U)
  1461. if (FlexCAN_GetMaxMbNum(base) > 32U)
  1462. {
  1463. base->IFLAG2 = FLEXCAN_IP_IFLAG_DEFAULT_VALUE_U32;
  1464. base->IMASK2 = FLEXCAN_IP_IMASK_DEFAULT_VALUE_U32;
  1465. }
  1466. #endif /* (FLEXCAN_IP_FEATURE_MAX_MB_NUM > 32U) */
  1467. base->IFLAG1 = FLEXCAN_IP_IFLAG_DEFAULT_VALUE_U32;
  1468. base->IMASK1 = FLEXCAN_IP_IMASK_DEFAULT_VALUE_U32;
  1469. base->CBT = FLEXCAN_IP_CBT_DEFAULT_VALUE_U32;
  1470. base->CTRL2 = FLEXCAN_IP_CTRL2_DEFAULT_VALUE_U32;
  1471. base->ESR1 = FLEXCAN_IP_ESR1_DEFAULT_VALUE_U32;
  1472. base->ECR = FLEXCAN_IP_ECR_DEFAULT_VALUE_U32;
  1473. base->TIMER = FLEXCAN_IP_TIMER_DEFAULT_VALUE_U32;
  1474. base->CTRL1 = FLEXCAN_IP_CTRL1_DEFAULT_VALUE_U32;
  1475. #if (FLEXCAN_IP_FEATURE_HAS_ENHANCE_CBT == STD_ON)
  1476. base->EPRS = FLEXCAN_IP_EPRS_DEFAULT_VALUE_U32;
  1477. base->ENCBT = FLEXCAN_IP_ENCBT_DEFAULT_VALUE_U32;
  1478. base->EDCBT = FLEXCAN_IP_EDCBT_DEFAULT_VALUE_U32;
  1479. base->ETDC = FLEXCAN_IP_ETDC_DEFAULT_VALUE_U32;
  1480. #endif
  1481. base->MCR = FLEXCAN_IP_MCR_DEFAULT_VALUE_U32;
  1482. }
  1483. #if (FLEXCAN_IP_FEATURE_HAS_PRETENDED_NETWORKING == STD_ON)
  1484. /*!
  1485. * @brief Configures Pretended Networking mode filtering selection.
  1486. *
  1487. * @param pBase The FlexCAN base address
  1488. * @param pPnConfig The pretended networking configuration
  1489. *
  1490. */
  1491. static inline void FlexCAN_SetPNFilteringSelection(FLEXCAN_Type * pBase, const Flexcan_Ip_PnConfigType * pPnConfig)
  1492. {
  1493. uint32 u32Tmp;
  1494. u32Tmp = pBase->CTRL1_PN;
  1495. u32Tmp &= ~(FLEXCAN_CTRL1_PN_WTOF_MSK_MASK |
  1496. FLEXCAN_CTRL1_PN_WUMF_MSK_MASK |
  1497. FLEXCAN_CTRL1_PN_NMATCH_MASK |
  1498. FLEXCAN_CTRL1_PN_PLFS_MASK |
  1499. FLEXCAN_CTRL1_PN_IDFS_MASK |
  1500. FLEXCAN_CTRL1_PN_FCS_MASK);
  1501. u32Tmp |= FLEXCAN_CTRL1_PN_WTOF_MSK(pPnConfig->bWakeUpTimeout ? 1UL : 0UL);
  1502. u32Tmp |= FLEXCAN_CTRL1_PN_WUMF_MSK(pPnConfig->bWakeUpMatch ? 1UL : 0UL);
  1503. u32Tmp |= FLEXCAN_CTRL1_PN_NMATCH(pPnConfig->u16NumMatches);
  1504. u32Tmp |= FLEXCAN_CTRL1_PN_FCS(pPnConfig->eFilterComb);
  1505. u32Tmp |= FLEXCAN_CTRL1_PN_IDFS(pPnConfig->eIdFilterType);
  1506. u32Tmp |= FLEXCAN_CTRL1_PN_PLFS(pPnConfig->ePayloadFilterType);
  1507. pBase->CTRL1_PN = u32Tmp;
  1508. }
  1509. /*!
  1510. * @brief Set PN timeout value.
  1511. *
  1512. * @param pBase The FlexCAN base address
  1513. * @param u16TimeoutValue timeout for no message matching
  1514. */
  1515. static inline void FlexCAN_SetPNTimeoutValue(FLEXCAN_Type * pBase, uint16 u16TimeoutValue)
  1516. {
  1517. pBase->CTRL2_PN = (pBase->CTRL2_PN & ~FLEXCAN_CTRL2_PN_MATCHTO_MASK) | FLEXCAN_CTRL2_PN_MATCHTO(u16TimeoutValue);
  1518. }
  1519. /*!
  1520. * @brief Configures the Pretended Networking ID Filter 1.
  1521. *
  1522. * @param pBase The FlexCAN base address
  1523. * @param idFilter The ID Filter configuration
  1524. */
  1525. static inline void FlexCAN_SetPNIdFilter1(FLEXCAN_Type * pBase, Flexcan_Ip_PnIdFilterType idFilter)
  1526. {
  1527. uint32 u32Tmp;
  1528. u32Tmp = pBase->FLT_ID1;
  1529. u32Tmp &= ~(FLEXCAN_FLT_ID1_FLT_IDE_MASK | FLEXCAN_FLT_ID1_FLT_RTR_MASK | FLEXCAN_FLT_ID1_FLT_ID1_MASK);
  1530. u32Tmp |= FLEXCAN_FLT_ID1_FLT_IDE(idFilter.bExtendedId ? 1UL : 0UL);
  1531. u32Tmp |= FLEXCAN_FLT_ID1_FLT_RTR(idFilter.bRemoteFrame ? 1UL : 0UL);
  1532. if (idFilter.bExtendedId)
  1533. {
  1534. u32Tmp |= FLEXCAN_FLT_ID1_FLT_ID1(idFilter.u32Id);
  1535. }
  1536. else
  1537. {
  1538. u32Tmp |= FLEXCAN_FLT_ID1_FLT_ID1(idFilter.u32Id << FLEXCAN_IP_ID_STD_SHIFT);
  1539. }
  1540. pBase->FLT_ID1 = u32Tmp;
  1541. }
  1542. /*!
  1543. * @brief Configures the Pretended Networking ID Filter 2 Check IDE&RTR.
  1544. *
  1545. * @param pBase The FlexCAN base address
  1546. */
  1547. static inline void FlexCAN_SetPNIdFilter2Check(FLEXCAN_Type * pBase)
  1548. {
  1549. pBase->FLT_ID2_IDMASK |= FLEXCAN_FLT_ID2_IDMASK_IDE_MSK_MASK | FLEXCAN_FLT_ID2_IDMASK_RTR_MSK_MASK;
  1550. }
  1551. /*!
  1552. * @brief Configures the Pretended Networking ID Filter 2.
  1553. *
  1554. * @param pBase The FlexCAN base address
  1555. * @param pPnConfig The pretended networking configuration
  1556. */
  1557. static inline void FlexCAN_SetPNIdFilter2(FLEXCAN_Type * pBase, const Flexcan_Ip_PnConfigType * pPnConfig)
  1558. {
  1559. uint32 u32Tmp;
  1560. u32Tmp = pBase->FLT_ID2_IDMASK;
  1561. u32Tmp &= ~(FLEXCAN_FLT_ID2_IDMASK_IDE_MSK_MASK | FLEXCAN_FLT_ID2_IDMASK_RTR_MSK_MASK | FLEXCAN_FLT_ID2_IDMASK_FLT_ID2_IDMASK_MASK);
  1562. u32Tmp |= FLEXCAN_FLT_ID2_IDMASK_IDE_MSK(pPnConfig->idFilter2.bExtendedId ? 1UL : 0UL);
  1563. u32Tmp |= FLEXCAN_FLT_ID2_IDMASK_RTR_MSK(pPnConfig->idFilter2.bRemoteFrame ? 1UL : 0UL);
  1564. /* Check if idFilter1 is extended and apply accordingly mask */
  1565. if (pPnConfig->idFilter1.bExtendedId)
  1566. {
  1567. u32Tmp |= FLEXCAN_FLT_ID2_IDMASK_FLT_ID2_IDMASK(pPnConfig->idFilter2.u32Id);
  1568. }
  1569. else
  1570. {
  1571. u32Tmp |= FLEXCAN_FLT_ID2_IDMASK_FLT_ID2_IDMASK(pPnConfig->idFilter2.u32Id << FLEXCAN_IP_ID_STD_SHIFT);
  1572. }
  1573. pBase->FLT_ID2_IDMASK = u32Tmp;
  1574. }
  1575. /*!
  1576. * @brief Set PN DLC Filter.
  1577. *
  1578. * @param pBase The FlexCAN base address
  1579. * @param timeoutValue timeout for no message matching
  1580. */
  1581. static inline void FlexCAN_SetPNDlcFilter(FLEXCAN_Type * pBase,
  1582. uint8 u8DlcLow,
  1583. uint8 u8DlcHigh
  1584. )
  1585. {
  1586. uint32 tmp;
  1587. tmp = pBase->FLT_DLC;
  1588. tmp &= ~(FLEXCAN_FLT_DLC_FLT_DLC_LO_MASK | FLEXCAN_FLT_DLC_FLT_DLC_HI_MASK);
  1589. tmp |= FLEXCAN_FLT_DLC_FLT_DLC_HI(u8DlcHigh);
  1590. tmp |= FLEXCAN_FLT_DLC_FLT_DLC_LO(u8DlcLow);
  1591. pBase->FLT_DLC = tmp;
  1592. }
  1593. /*!
  1594. * @brief Set PN Payload High Filter 1.
  1595. *
  1596. * @param pBase The FlexCAN Base address
  1597. * @param pPayload message Payload filter
  1598. */
  1599. static inline void FlexCAN_SetPNPayloadHighFilter1(FLEXCAN_Type * pBase, const uint8 * pPayload)
  1600. {
  1601. pBase->PL1_HI = FLEXCAN_PL1_HI_Data_byte_4(pPayload[4]) |
  1602. FLEXCAN_PL1_HI_Data_byte_5(pPayload[5]) |
  1603. FLEXCAN_PL1_HI_Data_byte_6(pPayload[6]) |
  1604. FLEXCAN_PL1_HI_Data_byte_7(pPayload[7]);
  1605. }
  1606. /*!
  1607. * @brief Set PN Payload Low Filter 1.
  1608. *
  1609. * @param pBase The FlexCAN Base address
  1610. * @param pPayload message Payload filter
  1611. */
  1612. static inline void FlexCAN_SetPNPayloadLowFilter1(FLEXCAN_Type * pBase, const uint8 * pPayload)
  1613. {
  1614. pBase->PL1_LO = FLEXCAN_PL1_LO_Data_byte_0(pPayload[0]) |
  1615. FLEXCAN_PL1_LO_Data_byte_1(pPayload[1]) |
  1616. FLEXCAN_PL1_LO_Data_byte_2(pPayload[2]) |
  1617. FLEXCAN_PL1_LO_Data_byte_3(pPayload[3]);
  1618. }
  1619. /*!
  1620. * @brief Set PN Payload High Filter 2.
  1621. *
  1622. * @param pBase The FlexCAN Base address
  1623. * @param pPayload message Payload filter
  1624. */
  1625. static inline void FlexCAN_SetPNPayloadHighFilter2(FLEXCAN_Type * pBase, const uint8 * pPayload)
  1626. {
  1627. pBase->PL2_PLMASK_HI = FLEXCAN_PL2_PLMASK_HI_Data_byte_4(pPayload[4]) |
  1628. FLEXCAN_PL2_PLMASK_HI_Data_byte_5(pPayload[5]) |
  1629. FLEXCAN_PL2_PLMASK_HI_Data_byte_6(pPayload[6]) |
  1630. FLEXCAN_PL2_PLMASK_HI_Data_byte_7(pPayload[7]);
  1631. }
  1632. /*!
  1633. * @brief Set PN Payload Low Filter 2.
  1634. *
  1635. * @param pBase The FlexCAN Base address
  1636. * @param pPayload message Payload filter
  1637. */
  1638. static inline void FlexCAN_SetPNPayloadLowFilter2(FLEXCAN_Type * pBase, const uint8 * pPayload)
  1639. {
  1640. pBase->PL2_PLMASK_LO = FLEXCAN_PL2_PLMASK_LO_Data_byte_0(pPayload[0]) |
  1641. FLEXCAN_PL2_PLMASK_LO_Data_byte_1(pPayload[1]) |
  1642. FLEXCAN_PL2_PLMASK_LO_Data_byte_2(pPayload[2]) |
  1643. FLEXCAN_PL2_PLMASK_LO_Data_byte_3(pPayload[3]);
  1644. }
  1645. /*!
  1646. * @brief Configures the Pretended Networking mode.
  1647. *
  1648. * @param pBase The FlexCAN Base address
  1649. * @param pnConfig The pretended networking configuration
  1650. */
  1651. void FlexCAN_ConfigPN(FLEXCAN_Type * pBase, const Flexcan_Ip_PnConfigType * pPnConfig);
  1652. /*!
  1653. * @brief Enables/Disables the Pretended Networking mode.
  1654. *
  1655. * @param pBase The FlexCAN Base address
  1656. * @param enable Enable/Disable Pretending Networking
  1657. */
  1658. static inline void FlexCAN_SetPN(FLEXCAN_Type * pBase, boolean enable)
  1659. {
  1660. pBase->MCR = (pBase->MCR & ~FLEXCAN_MCR_PNET_EN_MASK) | FLEXCAN_MCR_PNET_EN(enable ? 1UL : 0UL);
  1661. }
  1662. /*!
  1663. * @brief Checks if the Pretended Networking mode is enabled/disabled.
  1664. *
  1665. * @param pBase The FlexCAN Base address
  1666. * @return false if Pretended Networking mode is disabled;
  1667. * true if Pretended Networking mode is enabled
  1668. */
  1669. static inline boolean FlexCAN_IsPNEnabled(const FLEXCAN_Type * pBase)
  1670. {
  1671. return ((pBase->MCR & FLEXCAN_MCR_PNET_EN_MASK) >> FLEXCAN_MCR_PNET_EN_SHIFT) != 0U;
  1672. }
  1673. /*!
  1674. * @brief Gets the Wake Up by Timeout Flag Bit.
  1675. *
  1676. * @param pBase The FlexCAN Base address
  1677. * @return the Wake Up by Timeout Flag Bit
  1678. */
  1679. static inline uint8 FlexCAN_GetWTOF(const FLEXCAN_Type * pBase)
  1680. {
  1681. return (uint8)((pBase->WU_MTC & FLEXCAN_WU_MTC_WTOF_MASK) >> FLEXCAN_WU_MTC_WTOF_SHIFT);
  1682. }
  1683. /*!
  1684. * @brief Gets the Wake Up Timeout interrupt enable Bit.
  1685. *
  1686. * @param pBase The FlexCAN Base address
  1687. * @return the Wake Up Timeout interrupt enable Bit
  1688. */
  1689. static inline uint8 FlexCAN_GetWTOIE(const FLEXCAN_Type * pBase)
  1690. {
  1691. return (uint8)((pBase->CTRL1_PN & FLEXCAN_CTRL1_PN_WTOF_MSK_MASK) >> FLEXCAN_CTRL1_PN_WTOF_MSK_SHIFT);
  1692. }
  1693. /*!
  1694. * @brief Clears the Wake Up by Timeout Flag Bit.
  1695. *
  1696. * @param pBase The FlexCAN Base address
  1697. */
  1698. static inline void FlexCAN_ClearWTOF(FLEXCAN_Type * pBase)
  1699. {
  1700. pBase->WU_MTC = FLEXCAN_WU_MTC_WTOF_MASK;
  1701. }
  1702. /*!
  1703. * @brief Gets the Wake Up by Match Flag Bit.
  1704. *
  1705. * @param pBase The FlexCAN Base address
  1706. * @return the Wake Up by Match Flag Bit
  1707. */
  1708. static inline uint8 FlexCAN_GetWUMF(const FLEXCAN_Type * pBase)
  1709. {
  1710. return (uint8)((pBase->WU_MTC & FLEXCAN_WU_MTC_WUMF_MASK) >> FLEXCAN_WU_MTC_WUMF_SHIFT);
  1711. }
  1712. /*!
  1713. * @brief Gets the Wake Up Match IE Bit.
  1714. *
  1715. * @param pBase The FlexCAN Base address
  1716. * @return the Wake Up Match IE Bit
  1717. */
  1718. static inline uint8 FlexCAN_GetWUMIE(const FLEXCAN_Type * pBase)
  1719. {
  1720. return (uint8)((pBase->CTRL1_PN & FLEXCAN_CTRL1_PN_WUMF_MSK_MASK) >> FLEXCAN_CTRL1_PN_WUMF_MSK_SHIFT);
  1721. }
  1722. /*!
  1723. * @brief Clears the Wake Up by Match Flag Bit.
  1724. *
  1725. * @param pBase The FlexCAN Base address
  1726. */
  1727. static inline void FlexCAN_ClearWUMF(FLEXCAN_Type * pBase)
  1728. {
  1729. pBase->WU_MTC = FLEXCAN_WU_MTC_WUMF_MASK;
  1730. }
  1731. #endif /* FLEXCAN_IP_FEATURE_HAS_PRETENDED_NETWORKING */
  1732. #define CAN_STOP_SEC_CODE
  1733. #include "Can_MemMap.h"
  1734. #ifdef __cplusplus
  1735. }
  1736. #endif
  1737. /** @} */
  1738. #endif /* FLEXCAN_FLEXCAN_IP_HWACCESS_H_ */