hpm_mcan_drv.h 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577
  1. /*
  2. * Copyright (c) 2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_MCAN_DRV_H
  8. #define HPM_MCAN_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_mcan_regs.h"
  11. #include "hpm_mcan_soc.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. /**
  16. * @brief MCAN driver APIs
  17. * @defgroup mcan_interface MCAN driver APIs
  18. * @ingroup mcan_interfaces
  19. * @{
  20. *
  21. */
  22. enum {
  23. status_mcan_filter_index_out_of_range = MAKE_STATUS(status_group_mcan, 0),
  24. status_mcan_rxfifo_empty,
  25. status_mcan_rxfifo_full,
  26. status_mcan_txbuf_full,
  27. status_mcan_txfifo_full,
  28. status_mcan_rxfifo0_busy,
  29. status_mcan_rxfifo1_busy,
  30. status_mcan_txbuf_index_out_of_range,
  31. status_mcan_rxbuf_index_out_of_range,
  32. status_mcan_rxbuf_empty,
  33. status_mcan_tx_evt_fifo_empty,
  34. status_mcan_timestamp_not_exist,
  35. status_mcan_ram_out_of_range,
  36. };
  37. /**
  38. * @brief CAN Interrupt Mask
  39. */
  40. #define MCAN_INT_ACCESS_TO_RESERVED_ADDR MCAN_IR_ARA_MASK /*!< Access to Reserved Address */
  41. #define MCAN_INT_PROTOCOL_ERR_IN_DATA_PHASE MCAN_IR_PED_MASK /*!< Protocol Error Happened at Data Phase */
  42. #define MCAN_INT_PROTOCOL_ERR_IN_ARB_PHASE MCAN_IR_PEA_MASK /*!< Protocol Error Happened at Arbitration Phase */
  43. #define MCAN_INT_WATCHDOG_INT MCAN_IR_WDI_MASK /*!< Watchdog interrupt */
  44. #define MCAN_INT_BUS_OFF_STATUS MCAN_IR_BO_MASK /*!< Bus-off State Change */
  45. #define MCAN_INT_WARNING_STATUS MCAN_IR_EW_MASK /*!< Error Warning State Change */
  46. #define MCAN_INT_ERROR_PASSIVE MCAN_IR_EP_MASK /*!< Error Passive State Change */
  47. #define MCAN_INT_ERROR_LOGGING_OVERFLOW MCAN_IR_ELO_MASK /*!< Error Logging Overflow */
  48. #define MCAN_INT_BIT_ERROR_UNCORRECTED MCAN_IR_BEU_MASK /*!< Bit Error was not corrected */
  49. #define MCAN_INT_BIT_ERROR_CORRECTED MCAN_IR_BEC_MASK /*!< Bit Error was corrected */
  50. #define MCAN_INT_MSG_STORE_TO_RXBUF MCAN_IR_DRX_MASK /*!< Message was stored to RX Buffer */
  51. #define MCAN_INT_TIMEOUT_OCCURRED MCAN_IR_TOO_MASK /*!< Timeout Interrupt */
  52. #define MCAN_INT_MSG_RAM_ACCESS_FAILURE MCAN_IR_MRAF_MASK /*!< Message RAM Access Failure */
  53. #define MCAN_INT_TIMESTAMP_WRAPAROUND MCAN_IR_TSW_MASK /*!< Timestamp Counter Wrap Around */
  54. #define MCAN_INT_TX_EVT_FIFO_EVT_LOST MCAN_IR_TEFL_MASK /*!< TX Event FIFO Element Lost */
  55. #define MCAN_INT_TX_EVT_FIFO_FULL MCAN_IR_TEFF_MASK /*!< TX Event FIFO Full */
  56. #define MCAN_INT_TX_EVT_FIFO_WMK_REACHED MCAN_IR_TEFW_MASK /*!< TX Event FIFO Watermark Reached */
  57. #define MCAN_INT_TX_EVT_FIFO_NEW_ENTRY MCAN_IR_TEFN_MASK /*!< TX Event FIFO New Entry */
  58. #define MCAN_INT_TXFIFO_EMPTY MCAN_IR_TFE_MASK /*!< TX FIFO Empty */
  59. #define MCAN_INT_TX_CANCEL_FINISHED MCAN_IR_TCF_MASK /*!< Transmission Cancellation Finished */
  60. #define MCAN_INT_TX_COMPLETED MCAN_IR_TC_MASK /*!< Transmission Completed */
  61. #define MCAN_INT_HIGH_PRIORITY_MSG MCAN_IR_HPM_MASK /*!< High Priority Message */
  62. #define MCAN_INT_RXFIFO1_MSG_LOST MCAN_IR_RF1L_MASK /*!< RX FIFO0 Message Lost */
  63. #define MCAN_INT_RXFIFO1_FULL MCAN_IR_RF1F_MASK /*!< RX FIFO1 Full */
  64. #define MCAN_INT_RXFIFO1_WMK_REACHED MCAN_IR_RF1W_MASK /*!< RX FIFO1 Watermark Reached */
  65. #define MCAN_INT_RXFIFO1_NEW_MSG MCAN_IR_RF1N_MASK /*!< RX FIFO1 New Message */
  66. #define MCAN_INT_RXFIFO0_MSG_LOST MCAN_IR_RF0L_MASK /*!< RX FIFO0 Message Lost */
  67. #define MCAN_INT_RXFIFO0_FULL MCAN_IR_RF0F_MASK /*!< RX FIFO0 Full */
  68. #define MCAN_INT_RXFIFO0_WMK_REACHED MCAN_IR_RF0W_MASK /*!< RX FIFO0 Watermark Reached */
  69. #define MCAN_INT_RXFIFI0_NEW_MSG MCAN_IR_RF0N_MASK /*!< RX FIFO0 New Message */
  70. /**
  71. * @brief MCAN Receive Event Flags
  72. */
  73. #define MCAN_EVENT_RECEIVE (MCAN_INT_RXFIFI0_NEW_MSG | MCAN_INT_RXFIFO1_NEW_MSG | MCAN_INT_MSG_STORE_TO_RXBUF)
  74. /**
  75. * @brief MCAN Transmit Event Flags
  76. */
  77. #define MCAN_EVENT_TRANSMIT (MCAN_INT_TX_COMPLETED)
  78. /**
  79. * @brief MCAN Error Event Flags
  80. */
  81. #define MCAN_EVENT_ERROR (MCAN_INT_BUS_OFF_STATUS | MCAN_INT_WARNING_STATUS \
  82. | MCAN_INT_ERROR_PASSIVE | MCAN_INT_BIT_ERROR_UNCORRECTED)
  83. /**
  84. * @brief Maximum Transmission Retry Count
  85. */
  86. #define MCAN_TX_RETRY_COUNT_MAX (10000000UL)
  87. /**
  88. * @brief Maximum Receive Wait Retry Count
  89. */
  90. #define MCAN_RX_RETRY_COUNT_MAX (80000000UL)
  91. /***********************************************************************************************************************
  92. * @brief Default CAN RAM definitions
  93. **********************************************************************************************************************/
  94. #define MCAN_RAM_WORD_SIZE (640U) /*!< RAM WORD Size */
  95. /* CAN Filter Element Size Definitions */
  96. #define MCAN_FILTER_ELEM_STD_ID_SIZE (4U) /*!< Standard Filter Element Size in Bytes */
  97. #define MCAN_FILTER_ELEM_EXT_ID_SIZE (8U) /*!< Extended Filter Element SIze in Bytes */
  98. #define MCAN_STD_FILTER_ELEM_SIZE_MAX (128U) /*!< Maximum Standard Filter Element Count */
  99. #define MCAN_EXT_FILTER_ELEM_SIZE_MAX (64U) /*!< Maximum Extended Filter Element Count */
  100. /* MCAN Default Field Size Definitions for CAN2.0 */
  101. #define MCAN_TXRX_ELEM_SIZE_CAN_MAX (4U * sizeof(uint32_t))
  102. #define MCAN_FILTER_SIZE_CAN_DEFAULT (32U)
  103. #define MCAN_TXBUF_SIZE_CAN_DEFAULT (32U)
  104. #define MCAN_RXFIFO_SIZE_CAN_DEFAULT (32U)
  105. #define MCAN_RXBUF_SIZE_CAN_DEFAULT (16U)
  106. /* MCAN Default Field Size Definitions for CANFD */
  107. #define MCAN_TXRX_ELEM_SIZE_CANFD_MAX (18U * sizeof(uint32_t))
  108. #define MCAN_FILTER_SIZE_CANFD_DEFAULT (16U)
  109. #define MCAN_TXBUF_SIZE_CANFD_DEFAULT (8U)
  110. #define MCAN_RXFIFO_SIZE_CANFD_DEFAULT (8U)
  111. #define MCAN_RXBUF_SIZE_CANFD_DEFAULT (4U)
  112. #define MCAN_TXEVT_ELEM_SIZE (8U)
  113. /**
  114. * @brief CAN Bit Timing Parameters
  115. */
  116. typedef struct mcan_bit_timing_param_struct {
  117. uint16_t prescaler; /*!< Data Bit Rate Prescaler */
  118. uint16_t num_seg1; /*!< Time segment before sample point (including prop_seg and phase_sge1 */
  119. uint16_t num_seg2; /*!< Time segment after sample point */
  120. uint8_t num_sjw; /*!< Data (Re)Synchronization Jump Width */
  121. bool enable_tdc; /*!< Enable TDC flag, for CANFD data bit timing only */
  122. } mcan_bit_timing_param_t;
  123. /**
  124. * @brief CAN Bit Timing Options
  125. */
  126. typedef enum mcan_bit_timing_option {
  127. mcan_bit_timing_can2_0, /**< CAN 2.0 bit timing option */
  128. mcan_bit_timing_canfd_nominal, /**< CANFD nominal timing option */
  129. mcan_bit_timing_canfd_data, /**< CANFD data timing option */
  130. } mcan_bit_timing_option_t;
  131. /**
  132. * @brief CAN Message Header Size
  133. */
  134. #define MCAN_MESSAGE_HEADER_SIZE_IN_BYTES (8U)
  135. #define MCAN_MESSAGE_HEADER_SIZE_IN_WORDS (2U)
  136. /**
  137. * @brief CAN Transmit Message Frame
  138. *
  139. * @note Users need to pay attention to the CAN Identifier settings
  140. * For standard identifier, the use_ext_id should be set to 0 and the std_id should be used
  141. * For extended identifier, the use_ext_id should be set to 1 and the ext_id should be used
  142. */
  143. typedef struct mcan_tx_message_struct {
  144. union {
  145. struct {
  146. uint32_t ext_id: 29; /*!< Extended CAN Identifier */
  147. uint32_t rtr: 1; /*!< Remote Transmission Request */
  148. uint32_t use_ext_id: 1; /*!< Extended Identifier */
  149. uint32_t error_state_indicator: 1; /*!< Error State Indicator */
  150. };
  151. struct {
  152. uint32_t : 18;
  153. uint32_t std_id: 11; /*!< Standard CAN Identifier */
  154. uint32_t : 3;
  155. };
  156. };
  157. struct {
  158. uint32_t : 8;
  159. uint32_t message_marker_h: 8; /*!< Message Marker[15:8] */
  160. uint32_t dlc: 4; /*!< Data Length Code */
  161. uint32_t bitrate_switch: 1; /*!< Bit Rate Switch */
  162. uint32_t canfd_frame: 1; /*!< CANFD frame */
  163. uint32_t timestamp_capture_enable: 1; /*!< Timestamp Capture Enable for TSU */
  164. uint32_t event_fifo_control: 1; /*!< Event FIFO control */
  165. uint32_t message_marker_l: 8; /*!< Message Marker[7:0] */
  166. };
  167. union {
  168. uint8_t data_8[64]; /*!< Data buffer as byte array */
  169. uint32_t data_32[16]; /*!< Data buffer as word array */
  170. };
  171. } mcan_tx_frame_t;
  172. /**
  173. * @brief CAN Receive Message Frame
  174. *
  175. * @note Users need to pay attention to the CAN Identifier settings
  176. * For standard identifier, the use_ext_id should be set to 0 and the std_id should be used
  177. * For extended identifier, the use_ext_id should be set to 1 and the ext_id should be used
  178. */
  179. typedef struct mcan_rx_message_struct {
  180. union {
  181. struct {
  182. uint32_t ext_id: 29; /*!< Extended CAN Identifier */
  183. uint32_t rtr: 1; /*!< Remote Frame Flag */
  184. uint32_t use_ext_id: 1; /*!< Extended Identifier */
  185. uint32_t error_state_indicator: 1; /*!< Error State Indicator */
  186. };
  187. struct {
  188. uint32_t : 18;
  189. uint32_t std_id: 11; /*!< Standard CAN Identifier */
  190. uint32_t : 3;
  191. };
  192. };
  193. struct {
  194. union {
  195. uint16_t rx_timestamp; /*!< Received timestamp */
  196. struct {
  197. uint16_t rx_timestamp_pointer: 4; /*!< Timestamp Pointer */
  198. uint16_t rx_timestamp_captured: 1; /*!< Timestamp Captured flag */
  199. uint16_t : 11;
  200. };
  201. };
  202. };
  203. struct {
  204. uint16_t dlc: 4; /*!< Data Length Code */
  205. uint16_t bitrate_switch: 1; /*!< Bit rate switch flag */
  206. uint16_t canfd_frame: 1; /*!< CANFD Frame flag */
  207. uint16_t : 1;
  208. uint16_t filter_index: 7; /*!< CAN filter index */
  209. uint16_t accepted_non_matching_frame: 1; /*!< Accept non-matching Frame flag */
  210. };
  211. union {
  212. uint8_t data_8[64]; /*!< Data buffer as byte array */
  213. uint32_t data_32[16]; /*!< Data buffer as word array */
  214. };
  215. } mcan_rx_message_t;
  216. /**
  217. * @brief TX Event Fifo Element Structure
  218. */
  219. typedef union mcan_tx_event_fifo_elem_struct {
  220. struct {
  221. /* First word */
  222. union {
  223. struct {
  224. uint32_t ext_id: 29; /*!< CAN Identifier */
  225. uint32_t rtr: 1; /*!< Remote Transmission Request */
  226. uint32_t extend_id: 1; /*!< Extended Identifier */
  227. uint32_t error_state_indicator: 1; /*!< Error State Indicator */
  228. };
  229. struct {
  230. uint32_t : 18;
  231. uint32_t std_id: 11;
  232. uint32_t : 3;
  233. };
  234. };
  235. /* first 16-bit of the 2nd word */
  236. union {
  237. uint16_t tx_timestamp; /*!< Tx Timestamp */
  238. struct {
  239. uint16_t tx_timestamp_pointer: 4; /*!< TX timestamp pointer */
  240. uint16_t tx_timestamp_captured: 1; /*!< TX timestamp captured flag */
  241. uint16_t : 11;
  242. };
  243. };
  244. /* high-half 16-bit of the 2nd word */
  245. struct {
  246. uint16_t dlc: 4; /*!< Data length code */
  247. uint16_t bitrate_switch: 1; /*!< Bitrate Switch flag */
  248. uint16_t canfd_frame: 1; /*!< CANFD frame */
  249. uint16_t event_type: 2; /*!< Event type */
  250. uint16_t message_marker: 8; /*!< Message Marker */
  251. };
  252. };
  253. uint32_t words[2];
  254. } mcan_tx_event_fifo_elem_t;
  255. /**
  256. * @brief CAN Identifier Types
  257. */
  258. #define MCAN_CAN_ID_TYPE_STANDARD (0U) /*!< Standard Identifier */
  259. #define MCAN_CAN_ID_TYPE_EXTENDED (1U) /*!< Extended Identifier */
  260. /**
  261. * @brief MCAN Filter Configuration
  262. */
  263. typedef union mcan_filter_config_struct {
  264. struct {
  265. uint16_t list_start_addr; /*!< List Start address (CAN Message Buffer Offset) */
  266. uint16_t list_size; /*!< Element Count */
  267. };
  268. uint32_t reg_val; /*!< Register value */
  269. } mcan_filter_config_t;
  270. /**
  271. * @brief MCAN RXFIFO Configuration
  272. */
  273. typedef union mcan_rxfifo_config_struct {
  274. struct {
  275. uint32_t start_addr: 16; /*!< Start address (CAN Message Buffer Offset) */
  276. uint32_t fifo_size: 8; /*!< FIFO element count */
  277. uint32_t watermark: 7; /*!< FIFO watermark */
  278. uint32_t operation_mode: 1; /*!< Operation mode */
  279. };
  280. uint32_t reg_val; /*!< Register value */
  281. } mcan_rxfifo_config_t;
  282. /**
  283. * @brief MCAN RXBUF Configuration
  284. */
  285. typedef struct {
  286. uint32_t start_addr; /*!< Start address (CAN Message Buffer Offset) */
  287. } mcan_rxbuf_config_t;
  288. /**
  289. * @brief MCAN Data Field Size Definitions
  290. */
  291. #define MCAN_DATA_FIELD_SIZE_8BYTES (0U)
  292. #define MCAN_DATA_FIELD_SIZE_12BYTES (1U)
  293. #define MCAN_DATA_FIELD_SIZE_16BYTES (2U)
  294. #define MCAN_DATA_FIELD_SIZE_20BYTES (3U)
  295. #define MCAN_DATA_FIELD_SIZE_24BYTES (4U)
  296. #define MCAN_DATA_FIELD_SIZE_32BYTES (5U)
  297. #define MCAN_DATA_FIELD_SIZE_48BYTES (6U)
  298. #define MCAN_DATA_FIELD_SIZE_64BYTES (7U)
  299. /**
  300. * @brief MCAN FIFO Operation Mode types
  301. */
  302. #define MCAN_FIFO_OPERATION_MODE_BLOCKING (0U)
  303. #define MCAN_FIFO_OPERATION_MODE_OVERWRITE (1U)
  304. /**
  305. * @brief MCAN RXBUF or RXFIFO Element Configuration
  306. */
  307. typedef union mcan_rx_fifo_or_buf_elem_config_struct {
  308. struct {
  309. uint32_t fifo0_data_field_size: 4; /*!< FIFO0 data field size option */
  310. uint32_t fifo1_data_field_size: 4; /*!< FIFO1 data field size option */
  311. uint32_t buf_data_field_size: 4; /*!< Buffer Data field size option */
  312. uint32_t : 20;
  313. };
  314. uint32_t reg_val; /*!< Register value */
  315. } mcan_rx_fifo_or_buf_elem_config_t;
  316. /**
  317. * @brief MCAN TXBUF operation mode types
  318. */
  319. #define MCAN_TXBUF_OPERATION_MODE_FIFO (0U)
  320. #define MCAN_TXBUF_OPERATION_MODE_QUEUE (1U)
  321. typedef union mcan_txbuf_config_struct {
  322. struct {
  323. uint32_t start_addr: 16; /*!< Start address (CAN Message Buffer Offset) */
  324. uint32_t dedicated_tx_buf_size: 6; /*!< Dedicated TX buffer size */
  325. uint32_t : 2;
  326. uint32_t fifo_queue_size: 6; /*!< FIFO or Queue Size */
  327. uint32_t tx_fifo_queue_mode: 1; /*!< FIFO or Queue mode selection */
  328. uint32_t : 1;
  329. };
  330. uint32_t reg_val; /*!< register value */
  331. } mcan_txbuf_config_t;
  332. typedef struct mcan_txbuf_elem_config_struct {
  333. uint32_t data_field_size; /*!< Data Field size option */
  334. } mcan_txbuf_elem_config_t;
  335. /**
  336. * @brief MCAN TX Event FIFO Structure
  337. */
  338. typedef union {
  339. struct {
  340. uint16_t start_addr; /*!< Start Address(CAN Message Buffer Offset */
  341. uint8_t fifo_size; /*!< FIFO element count */
  342. uint8_t fifo_watermark; /*!< FIFO watermark */
  343. };
  344. uint32_t reg_val; /*!< register value */
  345. } mcan_tx_evt_fifo_config_t;
  346. /**
  347. * @brief MCAN RAM Flexible Configuration
  348. *
  349. * @Note This Configration provides the full MCAN RAM configuration, this configuration is recommended only for
  350. * experienced developers who is skilled at the MCAN IP
  351. */
  352. typedef struct mcan_ram_flexible_config_struct {
  353. bool enable_std_filter; /*!< Enable Standard Identifier Filter */
  354. bool enable_ext_filter; /*!< Enable Extended Identifier Filter */
  355. bool enable_rxfifo0; /*!< Enable RXFIFO */
  356. bool enable_rxfifo1; /*!< Enable RXFIF1 */
  357. bool enable_rxbuf; /*!< Enable RXBUF */
  358. bool enable_txbuf; /*!< Enable TXBUF */
  359. bool enable_tx_evt_fifo; /*!< Enable TX Event FIFO */
  360. mcan_filter_config_t std_filter_config; /*!< Standard Identifier Filter Configuration */
  361. mcan_filter_config_t ext_filter_config; /*!< Extended Identifier Filter Configuration */
  362. mcan_txbuf_config_t txbuf_config; /*!< TXBUF Configuration */
  363. mcan_txbuf_elem_config_t txbuf_elem_config; /*!< TXBUF Element Configuration */
  364. mcan_tx_evt_fifo_config_t tx_evt_fifo_config; /*!< TX Event FIFO Configuration */
  365. mcan_rxfifo_config_t rxfifo0_config; /*!< RXFIFO0 Configuration */
  366. mcan_rxfifo_config_t rxfifo1_config; /*!< RXFIFO1 Configuration */
  367. mcan_rxbuf_config_t rxbuf_config; /*!< RXBUF Configuration */
  368. mcan_rx_fifo_or_buf_elem_config_t rx_elem_config; /*!< RX Element Configuration */
  369. } mcan_ram_flexible_config_t;
  370. /**
  371. * @brief MCAN RAM configuration
  372. *
  373. * @Note: This Configuration focuses on the minimum required information for MCAN RAM configuration
  374. * The Start address of each BUF/FIFO will be automatically calculated by the MCAN Driver API
  375. * This RAM configuration is recommended for the most developers
  376. */
  377. typedef struct mcan_ram_config_struct {
  378. bool enable_std_filter; /*!< Enable Standard Identifier Filter */
  379. uint8_t std_filter_elem_count; /*!< Standard Identifier Filter Element Count */
  380. bool enable_ext_filter; /*!< Enable Extended Identifier Filter */
  381. uint8_t ext_filter_elem_count; /*!< Extended Identifier Filter Element Count */
  382. struct {
  383. uint32_t enable: 4; /*!< Enable Flag for RXFIFO */
  384. uint32_t elem_count: 8; /*!< Element Count for RXFIFO */
  385. uint32_t watermark: 8; /*!< Watermark for RXFIFO */
  386. uint32_t operation_mode: 4; /*!< Operation Mode for RXFIFO */
  387. uint32_t data_field_size: 8; /*!< Data field size option for RXFIFO */
  388. } rxfifos[2];
  389. bool enable_rxbuf; /*!< Enable RXBUF */
  390. uint8_t rxbuf_elem_count; /*!< RXBUF Element count */
  391. uint16_t rxbuf_data_field_size; /*!< RXBUF Data Field Size option */
  392. bool enable_txbuf; /*!< Enable TXBUF */
  393. uint8_t txbuf_data_field_size; /*!< TXBUF Data Field Size option */
  394. uint8_t txbuf_dedicated_txbuf_elem_count; /*!< Dedicated TXBUF element count */
  395. uint8_t txbuf_fifo_or_queue_elem_count; /*!< FIFO/Queue element count */
  396. uint8_t txfifo_or_txqueue_mode; /*!< TXFIFO/QUEUE mode */
  397. bool enable_tx_evt_fifo; /*!< Enable TX Event FIFO */
  398. uint8_t tx_evt_fifo_elem_count; /*!< TX Event FIFO Element count */
  399. uint8_t tx_evt_fifo_watermark; /*!< TX Event FIFO Watermark */
  400. } mcan_ram_config_t;
  401. /**
  402. * @brief MCAN Accept Non-Matching Frame options
  403. */
  404. #define MCAN_ACCEPT_NON_MATCHING_FRAME_OPTION_IN_RXFIFO0 (0U) /*!< Save non-matching frame to RXFIFO0 */
  405. #define MCAN_ACCEPT_NON_MATCHING_FRAME_OPTION_IN_RXFIFO1 (1U) /*!< Save non-matching frame to RXFIFO1 */
  406. #define MCAN_ACCEPT_NON_MATCHING_FRAME_OPTION_REJECT (2U) /*!< Reject non-matching frame */
  407. /**
  408. * @brief MCAN Global CAN configuration
  409. */
  410. typedef struct mcan_global_filter_config_struct {
  411. uint8_t accept_non_matching_std_frame_option; /*!< Accept non-matching standard frame option */
  412. uint8_t accept_non_matching_ext_frame_option; /*!< Accept non-matching extended frame option */
  413. bool reject_remote_std_frame; /*!< Reject Remote Standard Frame */
  414. bool reject_remote_ext_frame; /*!< Reject Remote Extended Frame */
  415. } mcan_global_filter_config_t;
  416. /**
  417. * @brief MCAN Filter type definitions
  418. */
  419. #define MCAN_FILTER_TYPE_RANGE_FILTER (0U) /*!< CAN Identifier Range filter */
  420. #define MCAN_FILTER_TYPE_SPECIFIED_ID_FILTER (1U) /*!< CAN Identifier ID filter */
  421. #define MCAN_FILTER_TYPE_CLASSIC_FILTER (2U) /*!< CAN classic filter */
  422. #define MCAN_FILTER_TYPE_FILTER_DISABLED (3U) /*!< CAN filter disabled */
  423. #define MCAN_FILTER_TYPE_DUAL_ID_EXT_FILTER_IGNORE_MASK /*!< CAN Identifier Range filter, ignoring extended ID mask */
  424. /**
  425. * @brief MCAN Filter Configuration Options
  426. */
  427. #define MCAN_FILTER_ELEM_CFG_DISABLED (0) /*!< Disable Filter Element */
  428. #define MCAN_FILTER_ELEM_CFG_STORE_IN_RX_FIFO0_IF_MATCH (1U) /*!< Store data into RXFIFO0 if matching */
  429. #define MCAN_FILTER_ELEM_CFG_STORE_IN_RX_FIFO1_IF_MATCH (2U) /*!< Store data into RXFIFO1 if matching */
  430. #define MCAN_FILTER_ELEM_CFG_REJECT_ID_IF_MATCH (3U) /*!< Reject ID if matching */
  431. #define MCAN_FILTER_ELEM_CFG_SET_PRIORITY_IF_MATCH (4U) /*!< Set Priority if matching */
  432. /*!< Set Priority and store into RXFIFO0 if matching */
  433. #define MCAN_FILTER_ELEM_CFG_SET_PRIORITY_AND_STORE_IN_FIFO0_IF_MATCH (5U)
  434. /*!< Set Priority and store into RXFIFO1 if matching */
  435. #define MCAN_FILTER_ELEM_CFG_SET_PRIORITY_AND_STORE_IN_FIFO1_IF_MATCH (6U)
  436. #define MCAN_FILTER_ELEM_CFG_STORE_INTO_RX_BUFFER_OR_AS_DBG_MSG (7U) /*!< Store into RXBUF if matching */
  437. /**
  438. * @brief MCAN Filter Element definitions
  439. */
  440. typedef struct mcan_std_id_filter_elem_struct {
  441. uint8_t filter_type; /*!< Filter type */
  442. uint8_t filter_config; /*!< Filter configuration */
  443. uint8_t can_id_type; /*!< CAN ID type */
  444. uint8_t sync_message; /*!< Sync Message */
  445. union {
  446. /* This definition takes effect if the filter type is range filter */
  447. struct {
  448. uint32_t start_id; /*!< Start of ID range */
  449. uint32_t end_id; /*!< End of ID range */
  450. };
  451. /* This definition takes effect if the filter type is dual id filter */
  452. struct {
  453. uint32_t id1; /*!< ID1 */
  454. uint32_t id2; /*!< ID2 */
  455. };
  456. /* This definition takes effect if the filter type is classic filter */
  457. struct {
  458. uint32_t filter_id; /*!< Filter ID */
  459. uint32_t filter_mask; /*!< Filter Mask */
  460. };
  461. /* This definition takes effect if the filter configuration is "store into RX Buffer or as debug message"
  462. *
  463. * In this definition, only the extact ID matching mode is activated
  464. */
  465. struct {
  466. uint32_t match_id; /*!< Matching ID */
  467. uint32_t offset: 6; /*!< RX Buffer Index */
  468. uint32_t filter_event: 3; /*!< Filter event, set to 0 */
  469. uint32_t store_location: 2; /*!< Store location, 0 - RX buffer */
  470. uint32_t : 21;
  471. };
  472. };
  473. } mcan_filter_elem_t;
  474. /**
  475. * @brief MCAN Filter Element List structure
  476. */
  477. typedef struct mcan_filter_elem_list_struct {
  478. uint32_t mcan_filter_elem_count; /*!< Number of Filter element */
  479. const mcan_filter_elem_t *filter_elem_list; /*!< Filter element list */
  480. } mcan_filter_elem_list_t;
  481. /**
  482. * @brief MCAN Configuration for all filters
  483. *
  484. * @Note The MCAN RAM related settings are excluded
  485. */
  486. typedef struct mcan_all_filters_config_struct {
  487. mcan_global_filter_config_t global_filter_config; /*!< Global Filter configuration */
  488. uint32_t ext_id_mask; /*!< Extended ID mask */
  489. mcan_filter_elem_list_t std_id_filter_list; /*!< Standard Identifier Configuration List */
  490. mcan_filter_elem_list_t ext_id_filter_list; /*!< Extended Identifier Configuration List */
  491. } mcan_all_filters_config_t;
  492. /**
  493. * @brief CAN Node Mode types
  494. */
  495. typedef enum mcan_node_mode_enum {
  496. mcan_mode_normal = 0, /*!< CAN works in normal mode */
  497. mcan_mode_loopback_internal = 1, /*!< CAN works in internal loopback mode */
  498. mcan_mode_loopback_external = 2, /*!< CAN works in external loopback mode */
  499. mcan_mode_listen_only = 3, /*!< CAN works in listen-only mode */
  500. } mcan_node_mode_t;
  501. /**
  502. * @brief MCAN Timestamp Value
  503. */
  504. typedef struct mcan_timestamp_value_struct {
  505. bool is_16bit; /*!< Timestamp is 16-bit */
  506. bool is_32bit; /*!< Timestamp is 32-bit */
  507. bool is_64bit; /*!< Timestamp is 64-bit */
  508. bool is_empty; /*!< Timestamp is empty */
  509. union {
  510. uint16_t ts_16bit; /*!< 16-bit timestamp value */
  511. uint32_t ts_32bit; /*!< 32-bit timestamp value */
  512. uint64_t ts_64bit; /*!< 64-bit timestamp value */
  513. uint32_t words[2]; /*!< timestamp words */
  514. };
  515. } mcan_timestamp_value_t;
  516. /**
  517. * @brief MCAN TSU Configuration
  518. */
  519. typedef struct mcan_tsu_config_struct {
  520. uint16_t prescaler; /*!< Prescaler for MCAN clock, Clock source: AHB clock */
  521. bool capture_on_sof; /*!< Capture On SOF, true - Capture on SOF, false - Capture on EOF */
  522. bool use_ext_timebase; /*!< Use External Timebase */
  523. uint16_t ext_timebase_src; /*!< External Timebase source, see the hpm_mcan_soc.h for more details */
  524. bool enable_tsu; /*!< Enable Timestamp Unit */
  525. bool enable_64bit_timestamp; /*!< Enable 64bit Timestamp */
  526. } mcan_tsu_config_t;
  527. /**
  528. * @brief MCAN Timestamp Select
  529. */
  530. #define MCAN_TIMESTAMP_SEL_MIN (0U)
  531. #define MCAN_TIMESTAMP_SEL_VALUE_ALWAYS_ZERO (0U) /*!< Timestamp value always equal to 0 */
  532. #define MCAN_TIMESTAMP_SEL_VALUE_INCREMENT (1U) /*!< Timestamp value increments according to prescaler */
  533. #define MCAN_TIMESTAMP_SEL_EXT_TS_VAL_USED (2U) /*!< External Timestamp value used */
  534. #define MCAN_TIMESTAMP_SEL_MAX (MCAN_TIMESTAMP_SEL_EXT_TS_VAL_USED)
  535. /**
  536. * @brief MCAN Internal timestamp configuration
  537. */
  538. typedef struct mcan_internal_timestamp_config_struct {
  539. uint8_t counter_prescaler; /*!< Timestamp Counter Prescaler, clock source: AHB clock */
  540. uint8_t timestamp_selection; /*!< Timestamp Select */
  541. } mcan_internal_timestamp_config_t;
  542. /**
  543. * @brief MCAN Configuration Structure
  544. */
  545. typedef struct mcan_config_struct {
  546. union {
  547. /* This struct takes effect if use_lowlevl_timing_setting = false */
  548. struct {
  549. uint32_t baudrate; /*!< CAN 2.0 baudrate/CAN-FD Nominal Baudrate, in terms of bps */
  550. uint32_t baudrate_fd; /*!< CANFD data baudrate, in terms of bps */
  551. uint16_t can20_samplepoint_min; /*!< Value = Minimum CAN2.0 sample point * 10 */
  552. uint16_t can20_samplepoint_max; /*!< Value = Maximum CAN2.0 sample point * 10 */
  553. uint16_t canfd_samplepoint_min; /*!< Value = Minimum CANFD sample point * 10 */
  554. uint16_t canfd_samplepoint_max; /*!< Value = Maximum CANFD sample point * 10 */
  555. };
  556. /* This struct takes effect if use_lowlevl_timing_setting = true */
  557. struct {
  558. mcan_bit_timing_param_t can_timing; /*!< CAN2.0/CANFD nominal timing setting */
  559. mcan_bit_timing_param_t canfd_timing; /*!< CANFD data timing setting */
  560. };
  561. };
  562. bool use_lowlevel_timing_setting; /*!< Use Low-level timing setting */
  563. mcan_node_mode_t mode; /*!< CAN node mode */
  564. bool enable_non_iso_mode; /*!< Enable Non-ISO FD mode */
  565. bool enable_transmit_pause; /*!< Enable Transmit Pause */
  566. bool enable_edge_filtering; /*!< Enable Edge Filtering */
  567. bool disable_protocol_exception_handling; /*!< Disable Protocol Exception Handling */
  568. bool enable_wide_message_marker; /*!< Enable Wide Message Marker */
  569. bool use_timestamping_unit; /*!< Use external Timestamp Unit */
  570. bool enable_canfd; /*!< Enable CANFD mode */
  571. bool enable_tdc; /*!< Enable transmitter delay compensation */
  572. mcan_internal_timestamp_config_t timestamp_cfg; /*!< Internal Timestamp Configuration */
  573. mcan_tsu_config_t tsu_config; /*!< TSU configuration */
  574. mcan_ram_config_t ram_config; /*!< MCAN RAM configuration */
  575. mcan_all_filters_config_t all_filters_config; /*!< All Filter configuration */
  576. } mcan_config_t;
  577. /**
  578. * @brief MCAN Timeout Selection Options
  579. */
  580. #define MCAN_TIMEOUT_SEL_TYPE_CONTINUOUS_OPERATION (0U)
  581. #define MCAN_TIMEOUT_SEL_TYPE_TIMEOUT_CTRL_BY_TX_EVT_FIFO (1U)
  582. #define MCAN_TIMEOUT_SEL_TYPE_TIMEOUT_CTRL_BY_RX_FIFO0 (2U)
  583. #define MCAN_TIMEOUT_SEL_TYPE_TIMEOUT_CTRL_BY_RX_FIFO1 (3U)
  584. /**
  585. * @brief MCAN Timeout Counter Configuration
  586. */
  587. typedef struct mcan_timeout_counter_config_struct {
  588. bool enable_timeout_counter; /*!< Enable Timeout counter */
  589. uint8_t timeout_selection; /*!< Timeout source selection */
  590. uint16_t timeout_period; /*!< Timeout period */
  591. } mcan_timeout_counter_config_t;
  592. /**
  593. * @brief MCAN Error Count Information
  594. */
  595. typedef struct mcan_error_count_struct {
  596. uint8_t transmit_error_count; /*!< Transmit Error Count */
  597. uint8_t receive_error_count; /*!< Receive Error Count */
  598. bool receive_error_passive; /*!< The Receive Error Counter has reached the error passive level */
  599. uint8_t can_error_logging_count; /*!< CAN Error Logging count */
  600. } mcan_error_count_t;
  601. /**
  602. * @brief MCAN Transmitter Delay Compensation Configuration
  603. */
  604. typedef struct mcan_tdc_config_t {
  605. uint8_t ssp_offset; /*!< SSP offset */
  606. uint8_t filter_window_length; /*!< Filter Window Length */
  607. } mcan_tdc_config_t;
  608. /**
  609. * @brief MCAN Message Storage Indicator Types
  610. */
  611. #define MCAN_MESSAGE_STORAGE_INDICATOR_NO_FIFO_SELECTED (0U)
  612. #define MCAN_MESSAGE_STORAGE_INDICATOR_FIFO_MESSAGE_LOST (1U)
  613. #define MCAN_MESSAGE_STORAGE_INDICATOR_RXFIFO0 (2U)
  614. #define MCAN_MESSAGE_STORAGE_INDICATOR_RXFIFO1 (3U)
  615. /**
  616. * @brief MCAN High Priority Message Status Information
  617. */
  618. typedef struct mcan_high_priority_message_status_struct {
  619. uint8_t filter_list_type; /*!< Filter List Type, 0 - STD filter, 1 - EXT filter */
  620. uint8_t filter_index; /*!< Filter Elem List */
  621. uint8_t message_storage_indicator; /*!< Message Storage Indicator */
  622. uint8_t buffer_index;
  623. } mcan_high_priority_message_status_t;
  624. /**
  625. * @brief Enable Transmit Pause
  626. * @param [in] ptr MCAN base
  627. */
  628. static inline void mcan_enable_transmit_pause(MCAN_Type *ptr)
  629. {
  630. ptr->CCCR |= MCAN_CCCR_TXP_MASK;
  631. }
  632. /**
  633. * @brief Disable Transmit Pause
  634. * @param [in] ptr MCAN base
  635. */
  636. static inline void mcan_disable_transmit_pause(MCAN_Type *ptr)
  637. {
  638. ptr->CCCR &= ~MCAN_CCCR_TXP_MASK;
  639. }
  640. /**
  641. * @brief Enable Edge Filtering
  642. * @param [in] ptr MCAN base
  643. */
  644. static inline void mcan_enable_edge_filtering(MCAN_Type *ptr)
  645. {
  646. ptr->CCCR |= MCAN_CCCR_EFBI_MASK;
  647. }
  648. /**
  649. * @brief Disable Edge Filtering
  650. * @param [in] ptr MCAN base
  651. */
  652. static inline void mcan_disable_edge_filtering(MCAN_Type *ptr)
  653. {
  654. ptr->CCCR &= ~MCAN_CCCR_EFBI_MASK;
  655. }
  656. /**
  657. * @brief Enable Protocol Exception Handling
  658. * @param [in] ptr MCAN base
  659. */
  660. static inline void mcan_enable_protocol_exception_handling(MCAN_Type *ptr)
  661. {
  662. ptr->CCCR &= ~MCAN_CCCR_PXHD_MASK;
  663. }
  664. /**
  665. * @brief Disable Protocol Exception Handling
  666. * @param [in] ptr MCAN base
  667. */
  668. static inline void mcan_disable_protocol_exception_handling(MCAN_Type *ptr)
  669. {
  670. ptr->CCCR |= MCAN_CCCR_PXHD_MASK;
  671. }
  672. /**
  673. * @brief Enable Wide Message Marker
  674. * @param [in] ptr MCAN base
  675. */
  676. static inline void mcan_enable_wide_message_marker(MCAN_Type *ptr)
  677. {
  678. ptr->CCCR |= MCAN_CCCR_WMM_MASK;
  679. }
  680. /**
  681. * @brief Disable Wide Message Marker
  682. * @param [in] ptr MCAN base
  683. */
  684. static inline void mcan_disable_wide_message_marker(MCAN_Type *ptr)
  685. {
  686. ptr->CCCR &= ~MCAN_CCCR_WMM_MASK;
  687. }
  688. /**
  689. * @brief Enable External Timestamp Unit
  690. * @param [in] ptr MCAN base
  691. */
  692. static inline void mcan_enable_tsu(MCAN_Type *ptr)
  693. {
  694. ptr->CCCR |= MCAN_CCCR_UTSU_MASK;
  695. }
  696. /**
  697. * @brief Disable External Timestamp Unit
  698. * @param [in] ptr MCAN base
  699. */
  700. static inline void mcan_disable_tsu(MCAN_Type *ptr)
  701. {
  702. ptr->CCCR &= ~MCAN_CCCR_UTSU_MASK;
  703. }
  704. /**
  705. * @brief Check whether TSU is used
  706. * @param [in] ptr MCAN base
  707. * @retval true if TSU is used
  708. * @retval false if TSU is not used
  709. */
  710. static inline bool mcan_is_tsu_used(MCAN_Type *ptr)
  711. {
  712. return ((ptr->CCCR & MCAN_CCCR_UTSU_MASK) != 0U);
  713. }
  714. /**
  715. * @brief Check whether 64-bit TSU timestamp is used
  716. * @param [in] ptr MCAN base
  717. * @retval true if 64-bit timestamp is used
  718. * @retval false if 32-bit timestamp is used
  719. */
  720. static inline bool mcan_is_64bit_tsu_timestamp_used(MCAN_Type *ptr)
  721. {
  722. return ((ptr->TSCFG & MCAN_TSCFG_EN64_MASK) != 0U);
  723. }
  724. /**
  725. * @brief Enable Bit Rate Switch
  726. * @param [in] ptr MCAN base
  727. */
  728. static inline void mcan_enable_bitrate_switch(MCAN_Type *ptr)
  729. {
  730. ptr->CCCR |= MCAN_CCCR_BRSE_MASK;
  731. }
  732. /**
  733. * @brief Disable Bit Rate Switch
  734. * @param [in] ptr MCAN base
  735. */
  736. static inline void mcan_disable_bitrate_switch(MCAN_Type *ptr)
  737. {
  738. ptr->CCCR &= ~MCAN_CCCR_BRSE_MASK;
  739. }
  740. /**
  741. * @brief Enable Auto Retransmission
  742. * @param [in] ptr MCAN base
  743. */
  744. static inline void mcan_enable_auto_retransmission(MCAN_Type *ptr)
  745. {
  746. ptr->CCCR &= ~MCAN_CCCR_DAR_MASK;
  747. }
  748. /**
  749. * @brief Disable Auto Transmission
  750. * @param [in] ptr MCAN base
  751. */
  752. static inline void mcan_disable_auto_retransmission(MCAN_Type *ptr)
  753. {
  754. ptr->CCCR |= MCAN_CCCR_DAR_MASK;
  755. }
  756. /**
  757. * @brief Disable Bus monitoring Mode
  758. * @param [in] ptr MCAN base
  759. */
  760. static inline void mcan_disable_bus_monitoring_mode(MCAN_Type *ptr)
  761. {
  762. ptr->CCCR &= ~MCAN_CCCR_MON_MASK;
  763. }
  764. /**
  765. * @brief Enable Clock Stop Request
  766. * @param [in] ptr MCAN base
  767. */
  768. static inline void mcan_enable_clock_stop_request(MCAN_Type *ptr)
  769. {
  770. ptr->CCCR |= MCAN_CCCR_CSR_MASK;
  771. }
  772. /**
  773. * @brief Disable Clock Stop Request
  774. * @param [in] ptr MCAN base
  775. */
  776. static inline void mcan_disable_clock_stop_request(MCAN_Type *ptr)
  777. {
  778. ptr->CCCR &= ~MCAN_CCCR_CSR_MASK;
  779. }
  780. /**
  781. * @brief Enable Clock Stop Acknowledge
  782. * @param [in] ptr MCAN base
  783. */
  784. static inline void mcan_enable_clock_stop_acknowledge(MCAN_Type *ptr)
  785. {
  786. ptr->CCCR |= MCAN_CCCR_CSA_MASK;
  787. }
  788. /**
  789. * @brief Disable Clock Stop Acknowledge
  790. * @param [in] ptr MCAN base
  791. */
  792. static inline void mcan_disable_clock_stop_acknowledge(MCAN_Type *ptr)
  793. {
  794. ptr->CCCR &= ~MCAN_CCCR_CSA_MASK;
  795. }
  796. /**
  797. * @brief Disable Restricted Operation Mode
  798. * @param [in] ptr MCAN base
  799. */
  800. static inline void mcan_disable_restricted_operation_mode(MCAN_Type *ptr)
  801. {
  802. ptr->CCCR &= ~MCAN_CCCR_ASM_MASK;
  803. }
  804. /**
  805. * @brief Get Timestamp Counter Value
  806. * @param [in] ptr MCAN base
  807. * @return timestamp value
  808. */
  809. static inline uint16_t mcan_get_timestamp_counter_value(MCAN_Type *ptr)
  810. {
  811. return ptr->TSCV;
  812. }
  813. /**
  814. * @brief Get Timeout value
  815. * @param [in] ptr MCAN base
  816. * @return timeout value
  817. */
  818. static inline uint16_t mcan_get_timeout_counter_value(MCAN_Type *ptr)
  819. {
  820. return ptr->TOCV;
  821. }
  822. /**
  823. * @brief Get Error Counter Information
  824. * @param [in] ptr MCAN base
  825. * @param [out] err_cnt Error Count buffer
  826. */
  827. static inline void mcan_get_error_counter(MCAN_Type *ptr, mcan_error_count_t *err_cnt)
  828. {
  829. uint32_t ecr = ptr->ECR;
  830. err_cnt->transmit_error_count = MCAN_ECR_TEC_GET(ecr);
  831. err_cnt->receive_error_count = MCAN_ECR_REC_GET(ecr);
  832. err_cnt->receive_error_passive = (MCAN_ECR_RP_GET(ecr) == 1U);
  833. err_cnt->can_error_logging_count = MCAN_ECR_CEL_GET(ecr);
  834. }
  835. /**
  836. * @brief Get Last Error Code
  837. * @param [in] ptr MCAN base
  838. * @return Last Error code
  839. */
  840. static inline uint8_t mcan_get_last_error_code(MCAN_Type *ptr)
  841. {
  842. return MCAN_PSR_LEC_GET(ptr->PSR);
  843. }
  844. /**
  845. * @brief Get Last Data Phase Error Code
  846. * @param [in] ptr MCAN base
  847. * @return Last Error Code in Data phase
  848. */
  849. static inline uint8_t mcan_get_last_data_error_code(MCAN_Type *ptr)
  850. {
  851. return MCAN_PSR_DLEC_GET(ptr->PSR);
  852. }
  853. /**
  854. * @brief Get CAN Activity
  855. * @param [in] ptr MCAN base
  856. * @return CAN IP activity
  857. */
  858. static inline uint8_t mcan_get_activity(MCAN_Type *ptr)
  859. {
  860. return MCAN_PSR_ACT_GET(ptr->PSR);
  861. }
  862. /**
  863. * @brief Check whether the CAN node is under error passive state
  864. * @param [in] ptr MCAN base
  865. * @return true is CAN is under error passive state
  866. */
  867. static inline bool mcan_is_in_err_passive_state(MCAN_Type *ptr)
  868. {
  869. return (MCAN_PSR_EP_GET(ptr->PSR) == 1U);
  870. }
  871. /**
  872. * @brief Check whether the CAN mode is under Warning State
  873. * @param [in] ptr MCAN base
  874. * @return true if the CAN node is under Error Warning State
  875. */
  876. static inline bool mcan_is_in_error_warning_state(MCAN_Type *ptr)
  877. {
  878. return (MCAN_PSR_EW_GET(ptr->PSR) == 1U);
  879. }
  880. /**
  881. * @brief Check whether the CAN node is under Bus-off state
  882. * @param [in] ptr MCAN base
  883. * @return true if the CAN node is under Bus-off state
  884. */
  885. static inline bool mcan_is_in_busoff_state(MCAN_Type *ptr)
  886. {
  887. return (MCAN_PSR_BO_GET(ptr->PSR) == 1U);
  888. }
  889. /**
  890. * @brief Get the Last Data Phase Error
  891. * @param [in] ptr MCAN base
  892. * @return The last Data Phase Error
  893. */
  894. static inline uint8_t mcan_get_data_phase_last_error_code(MCAN_Type *ptr)
  895. {
  896. return MCAN_PSR_DLEC_GET(ptr->PSR);
  897. }
  898. /**
  899. * @brief Check Whether the Error Status Indicator Flag is set in the last received CANFD message
  900. * @param [in] ptr MCAN base
  901. * @return true if the Error Status Indicator Flag is set in the last received CANFD Message
  902. */
  903. static inline bool mcan_is_error_state_indicator_flag_set_in_last_received_canfd_msg(MCAN_Type *ptr)
  904. {
  905. return (MCAN_PSR_RESI_GET(ptr->PSR) == 1U);
  906. }
  907. /**
  908. * @brief Check whether the Bitrate Switch Flag is set in the last received CANFD message
  909. * @param [in] ptr MCAN base
  910. * @return true if Bit rate switch flag is set in the last received CANFD message
  911. */
  912. static inline bool mcan_is_bitrate_switch_flag_set_in_last_received_canfd_msg(MCAN_Type *ptr)
  913. {
  914. return (MCAN_PSR_RBRS_GET(ptr->PSR) == 1U);
  915. }
  916. /**
  917. * @brief Check whether CANFD messages were received
  918. * @param [in] ptr MCAN base
  919. * @return true if a CANFD message was received
  920. */
  921. static inline bool mcan_is_canfd_message_received(MCAN_Type *ptr)
  922. {
  923. return (MCAN_PSR_RFDF_GET(ptr->PSR) == 1U);
  924. }
  925. /**
  926. * @brief Check whether Protocol Exception Events were occurred
  927. * @param [in] ptr MCAN base
  928. * @return true if Protocol Exception Events were occurred
  929. */
  930. static inline bool mcan_is_protocol_exception_event_occurred(MCAN_Type *ptr)
  931. {
  932. return (MCAN_PSR_PXE_GET(ptr->PSR) == 1U);
  933. }
  934. /**
  935. * @brief Get the Transmitter Delay Compensation Value
  936. * @param [in] ptr MCAN base
  937. * @return Transmitter Delay Compensation value
  938. */
  939. static inline uint8_t mcan_get_transmitter_delay_compensation_value(MCAN_Type *ptr)
  940. {
  941. return MCAN_PSR_TDCV_GET(ptr->PSR);
  942. }
  943. /**
  944. * @brief Get Interrupt Flags
  945. * @param [in] ptr MCAN base
  946. * @return Interrupt Flags
  947. */
  948. static inline uint32_t mcan_get_interrupt_flags(MCAN_Type *ptr)
  949. {
  950. return ptr->IR;
  951. }
  952. /**
  953. * @brief Clear Interrupt Flags
  954. * @param [in] ptr MCAN base
  955. * @param [in] mask Interrupt Mask
  956. */
  957. static inline void mcan_clear_interrupt_flags(MCAN_Type *ptr, uint32_t mask)
  958. {
  959. ptr->IR = mask;
  960. }
  961. /**
  962. * @brief Enable Interrupts
  963. * @param [in] ptr MCAN base
  964. * @param [in] mask Interrupt mask
  965. */
  966. static inline void mcan_enable_interrupts(MCAN_Type *ptr, uint32_t mask)
  967. {
  968. ptr->ILS &= ~mask;
  969. ptr->IE |= mask;
  970. ptr->ILE = 1U;
  971. }
  972. /**
  973. * @brief Enable TXBUF Interrupt
  974. * @param [in] ptr MCAN base
  975. * @param [in] mask Interrupt mask
  976. */
  977. static inline void mcan_enable_txbuf_interrupt(MCAN_Type *ptr, uint32_t mask)
  978. {
  979. ptr->TXBTIE |= mask;
  980. }
  981. /**
  982. * @brief Disable TXBUF Interrupt
  983. * @param [in] ptr MCAN base
  984. * @param [in] mask Interrupt mask
  985. */
  986. static inline void mcan_disable_txbuf_interrupt(MCAN_Type *ptr, uint32_t mask)
  987. {
  988. ptr->TXBTIE &= ~mask;
  989. }
  990. /**
  991. * @brief Disable Interrupts
  992. * @param [in] ptr MCAN base
  993. * @param [in] mask Interrupt mask
  994. */
  995. static inline void mcan_disable_interrupts(MCAN_Type *ptr, uint32_t mask)
  996. {
  997. ptr->IE &= ~mask;
  998. }
  999. /**
  1000. * @brief Enable TXBUF Transmission interrupt
  1001. * @param [in] ptr MCAN base
  1002. * @param [in] mask Interrupt mask
  1003. */
  1004. static inline void mcan_enable_txbuf_transmission_interrupt(MCAN_Type *ptr, uint32_t mask)
  1005. {
  1006. ptr->TXBTIE |= mask;
  1007. }
  1008. /**
  1009. * @brief Disable TXBUF Transmission interrupt
  1010. * @param [in] ptr MCAN base
  1011. * @param [in] mask Interrupt mask
  1012. */
  1013. static inline void mcan_disable_txbuf_transmission_interrupt(MCAN_Type *ptr, uint32_t mask)
  1014. {
  1015. ptr->TXBTIE &= ~mask;
  1016. }
  1017. /**
  1018. * @brief Enable TXBUF Cancellation Finish interrupt
  1019. * @param [in] ptr MCAN base
  1020. * @param [in] mask Interrupt mask
  1021. */
  1022. static inline void mcan_enable_txbuf_cancel_finish_interrupt(MCAN_Type *ptr, uint32_t mask)
  1023. {
  1024. ptr->TXBCIE |= mask;
  1025. }
  1026. /**
  1027. * @brief Disable TXBUF Cancellation Finish interrupt
  1028. * @param [in] ptr MCAN base
  1029. * @param [in] mask Interrupt mask
  1030. */
  1031. static inline void mcan_disable_txbuf_cancel_finish_interrupt(MCAN_Type *ptr, uint32_t mask)
  1032. {
  1033. ptr->TXBCIE &= ~mask;
  1034. }
  1035. /**
  1036. * @brief Select Interrupt Line
  1037. * @param [in] ptr MCAN base
  1038. * @param [in] mask Interrupt mask
  1039. * @param [in] line_index Interrupt Line Index
  1040. */
  1041. static inline void mcan_interrupt_line_select(MCAN_Type *ptr, uint32_t mask, uint8_t line_index)
  1042. {
  1043. if (line_index == 0) {
  1044. ptr->ILS &= ~mask;
  1045. } else {
  1046. ptr->ILS |= mask;
  1047. }
  1048. ptr->ILE = (1UL << line_index);
  1049. }
  1050. /**
  1051. * @brief Check whether a TXFIFO/TXBUF transmission request is pending
  1052. * @param [in] ptr CAN Base
  1053. * @param [in] index TXBUF/TXFIFO Index
  1054. * @return True is the specified TXFIFO/TXBUF Transmission request is pending
  1055. */
  1056. static inline bool mcan_is_transmit_request_pending(MCAN_Type *ptr, uint32_t index)
  1057. {
  1058. return ((ptr->TXBRP & ((1UL << index))) != 0U);
  1059. }
  1060. /**
  1061. * @brief Check whether TXFIFO is full
  1062. * @param [in] ptr MCAN base
  1063. * @return true if TXFIFO is full
  1064. */
  1065. static inline bool mcan_is_txfifo_full(MCAN_Type *ptr)
  1066. {
  1067. return ((ptr->TXFQS & MCAN_TXFQS_TFQF_MASK) != 0U);
  1068. }
  1069. /**
  1070. * @brief Get the TXFIFO Put Index
  1071. * @param [in] ptr MCAN base
  1072. * @return The TX FIFO Put Index
  1073. */
  1074. static inline uint32_t mcan_get_txfifo_put_index(MCAN_Type *ptr)
  1075. {
  1076. return MCAN_TXFQS_TFQPI_GET(ptr->TXFQS);
  1077. }
  1078. /**
  1079. * @brief Request A Transmission via specified TXBUF Index
  1080. * @param [in] ptr MCAN Base
  1081. * @param [in] index TXBUF index
  1082. */
  1083. static inline void mcan_send_add_request(MCAN_Type *ptr, uint32_t index)
  1084. {
  1085. ptr->TXBAR = (1UL << index);
  1086. }
  1087. /**
  1088. * @brief Check whether the Transmission completed via specified TXBUF/TXFIFO
  1089. * @param [in] ptr MCAN base
  1090. * @param [in] index TXBUF Index
  1091. * @return True is the Transmission completed via specified TXBUF
  1092. */
  1093. static inline bool mcan_is_transmit_occurred(MCAN_Type *ptr, uint32_t index)
  1094. {
  1095. return ((ptr->TXBTO & (1UL << index)) != 0U);
  1096. }
  1097. /**
  1098. * @brief Check Whether there are data available in specified RXBUF
  1099. * @param [in] ptr MCAN Base
  1100. * @param [in] index RXBUF index
  1101. * @return True if there are data available
  1102. */
  1103. static inline bool mcan_is_rxbuf_data_available(MCAN_Type *ptr, uint32_t index)
  1104. {
  1105. bool result;
  1106. if (index < 32U) {
  1107. result = (ptr->NDAT1 & (1UL << index)) != 0U;
  1108. } else if (index < 64U) {
  1109. result = (ptr->NDAT2 & (1UL << (index - 32U))) != 0U;
  1110. } else {
  1111. result = false;
  1112. }
  1113. return result;
  1114. }
  1115. /**
  1116. * @brief Clear RXBUF Data available Flag for specified RXBUF
  1117. * @param [in] ptr MCAN base
  1118. * @param [in] index RXBUF index
  1119. */
  1120. static inline void mcan_clear_rxbuf_data_available_flag(MCAN_Type *ptr, uint32_t index)
  1121. {
  1122. if (index < 32U) {
  1123. ptr->NDAT1 = (1UL << index);
  1124. } else if (index < 64U) {
  1125. ptr->NDAT2 = (1UL << (index - 32U));
  1126. } else {
  1127. /* Do nothing */
  1128. }
  1129. }
  1130. /**
  1131. * @brief Check whether specified Interrupt is set
  1132. * @param [in] ptr MCAN Base
  1133. * @param [in] mask Interrupt Flags
  1134. * @retval true if corresponding bits are set
  1135. */
  1136. static inline bool mcan_is_interrupt_flag_set(MCAN_Type *ptr, uint32_t mask)
  1137. {
  1138. return ((ptr->IR & mask) != 0U);
  1139. }
  1140. static inline bool mcan_is_tsu_timestamp_available(MCAN_Type *ptr, uint32_t index)
  1141. {
  1142. bool is_available = false;
  1143. if (index < ARRAY_SIZE(ptr->TS_SEL)) {
  1144. is_available = ((ptr->TSS1 & (1UL << index)) != 0U);
  1145. }
  1146. return is_available;
  1147. }
  1148. /**
  1149. * @brief Read 32bit Timestamp value from TSU
  1150. * @param [in] ptr MCAN Base
  1151. * @param [in] index Timestamp pointer
  1152. * @return Timestamp value
  1153. */
  1154. uint32_t mcan_read_32bit_tsu_timestamp(MCAN_Type *ptr, uint32_t index);
  1155. /**
  1156. * @brief Read 64bit Timestamp value from TSU
  1157. * @param [in] ptr MCAN Base
  1158. * @param [in] index Timestamp pointer
  1159. * @return Timestamp value
  1160. */
  1161. uint64_t mcan_read_64bit_tsu_timestamp(MCAN_Type *ptr, uint32_t index);
  1162. /**
  1163. * @brief Get High Priority Message Status
  1164. * @param [in] ptr MCAN base
  1165. * @param [out] status Pointer to High Priority Message Status Buffer
  1166. */
  1167. void mcan_get_high_priority_message_status(MCAN_Type *ptr, mcan_high_priority_message_status_t *status);
  1168. /**
  1169. * @brief Get Default CAN configuration
  1170. * @param [in] ptr MCAN base
  1171. * @param [out] config CAN configuration
  1172. */
  1173. void mcan_get_default_config(MCAN_Type *ptr, mcan_config_t *config);
  1174. /**
  1175. * @brief Get message Size from Data Length Code
  1176. * @param [in] dlc Data Length Code
  1177. * @return Message Size in Bytes
  1178. */
  1179. uint8_t mcan_get_message_size_from_dlc(uint8_t dlc);
  1180. uint8_t mcan_get_data_field_size(uint8_t data_field_size_option);
  1181. /**
  1182. * @brief Get Default Full MCAN RAM configuration
  1183. * If the device is configured as classic CAN node, the default CAN RAM settings are as below:
  1184. * - Standard Identifier Filter Elements: 32
  1185. * - Extended Identifier Filter Elements: 32
  1186. * - TXBUF Elements Info:
  1187. * - Element Count:32
  1188. * - Dedicated TXBUF element count: 16
  1189. * - TXFIFO/QQueue element count: 16
  1190. * - Data Field Size: 8
  1191. * - RXFIFO0 Elements Info:
  1192. * - Element Count :32
  1193. * - Data Field Size: 8
  1194. * - RXFIFO1 Elements Info:
  1195. * - Element Count : 32
  1196. * - Data Field Size: 8
  1197. * - RXBUF Element Info:
  1198. * - Element Count: 16
  1199. * - Data Field Size : 8
  1200. * - TX Event FIFO Element Count: 32
  1201. * If the device is configured as CANFD node, the default CAN RAM settings are as below:
  1202. * - Standard Identifier Filter Elements: 16
  1203. * - Extended Identifier Filter Elements: 16
  1204. * - TXBUF Elements Info:
  1205. * - Element Count:8
  1206. * - Dedicated TXBUF element count: 4
  1207. * - TXFIFO/QQueue element count: 4
  1208. * - Data Field Size: 64
  1209. * - RXFIFO0 Elements Info:
  1210. * - Element Count : 8
  1211. * - Data Field Size: 64
  1212. * - RXFIFO1 Elements Info:
  1213. * - Element Count : 8
  1214. * - Data Field Size: 64
  1215. * - RXBUF Element Info:
  1216. * - Element Count: 4
  1217. * - Data Field Size : 64
  1218. * - TX Event FIFO Element Count: 8
  1219. *
  1220. * @param [in] ptr MCAN base
  1221. * @param [out] ram_config CAN RAM Configuration
  1222. * @param [in] enable_canfd CANFD enable flag
  1223. */
  1224. void mcan_get_default_ram_flexible_config(MCAN_Type *ptr, mcan_ram_flexible_config_t *ram_config, bool enable_canfd);
  1225. /**
  1226. * @brief Get Default MCAN RAM configuration
  1227. * If the device is configured as classic CAN node, the default CAN RAM settings are as below:
  1228. * - Standard Identifier Filter Elements: 32
  1229. * - Extended Identifier Filter Elements: 32
  1230. * - TXBUF Elements Info:
  1231. * - Element Count:32
  1232. * - Dedicated TXBUF element count: 16
  1233. * - TXFIFO/QQueue element count: 16
  1234. * - Data Field Size: 8
  1235. * - RXFIFO0 Elements Info:
  1236. * - Element Count :32
  1237. * - Data Field Size: 8
  1238. * - RXFIFO1 Elements Info:
  1239. * - Element Count : 32
  1240. * - Data Field Size: 8
  1241. * - RXBUF Element Info:
  1242. * - Element Count: 16
  1243. * - Data Field Size : 8
  1244. * - TX Event FIFO Element Count: 32
  1245. * If the device is configured as CANFD node, the default CAN RAM settings are as below:
  1246. * - Standard Identifier Filter Elements: 16
  1247. * - Extended Identifier Filter Elements: 16
  1248. * - TXBUF Elements Info:
  1249. * - Element Count:8
  1250. * - Dedicated TXBUF element count: 4
  1251. * - TXFIFO/QQueue element count: 4
  1252. * - Data Field Size: 64
  1253. * - RXFIFO0 Elements Info:
  1254. * - Element Count : 8
  1255. * - Data Field Size: 64
  1256. * - RXFIFO1 Elements Info:
  1257. * - Element Count : 8
  1258. * - Data Field Size: 64
  1259. * - RXBUF Element Info:
  1260. * - Element Count: 4
  1261. * - Data Field Size : 64
  1262. * - TX Event FIFO Element Count: 8
  1263. *
  1264. * @param [in] ptr MCAN base
  1265. * @param [out] ram_config CAN RAM Configuration
  1266. * @param [in] enable_canfd CANFD enable flag
  1267. */
  1268. void mcan_get_default_ram_config(MCAN_Type *ptr, mcan_ram_config_t *simple_config, bool enable_canfd);
  1269. /**
  1270. * @brief Initialize CAN controller
  1271. * @param [in] ptr MCAN base
  1272. * @param [in] config CAN configuration
  1273. * @param [in] src_clk_freq CAN clock frequency
  1274. * @retval status_success if operation is successful
  1275. * @retval status_invalid_argument if any parameters are invalid
  1276. */
  1277. hpm_stat_t mcan_init(MCAN_Type *ptr, mcan_config_t *config, uint32_t src_clk_freq);
  1278. /**
  1279. * @brief Configure MCAN RAM will Full RAM configuration
  1280. * @param [in] ptr MCAN base
  1281. * @param [in] config MCAN RAM Full Configuration
  1282. * @return status_success if no errors reported
  1283. */
  1284. hpm_stat_t mcan_config_ram_with_flexible_config(MCAN_Type *ptr, mcan_ram_flexible_config_t *config);
  1285. /**
  1286. * @brief Configure MCAN RAM will Simplified RAM configuration
  1287. * @param [in] ptr MCAN base
  1288. * @param [in] config MCAN RAM configuration
  1289. * @return status_success if no errors reported
  1290. */
  1291. hpm_stat_t mcan_config_ram(MCAN_Type *ptr, mcan_ram_config_t *config);
  1292. /**
  1293. * @brief Configure All CAN filters
  1294. * @param [in] ptr MCAN base
  1295. * @param [in] config All CAN Filter configuration
  1296. * @return status_success if no errors reported
  1297. */
  1298. hpm_stat_t mcan_config_all_filters(MCAN_Type *ptr, mcan_all_filters_config_t *config);
  1299. /**
  1300. * @brief Configure Transmitter Delay Compensation
  1301. * @param [in] ptr MCAN base
  1302. * @param [in] config Transmitter Delay compensation configure
  1303. * @return status_success if no errors reported
  1304. */
  1305. hpm_stat_t mcan_config_transmitter_delay_compensation(MCAN_Type *ptr, mcan_tdc_config_t *config);
  1306. /**
  1307. * @brief Configure Global Filter
  1308. * @param [in] ptr MCAN base
  1309. * @param [in] filter_config Global Filter Configuration
  1310. * @return status_success if no errors reported
  1311. */
  1312. hpm_stat_t mcan_set_global_filter_config(MCAN_Type *ptr, mcan_global_filter_config_t *filter_config);
  1313. /**
  1314. * @brief Set CAN filter element
  1315. * @param [in] ptr MCAN base
  1316. * @param [in] filter_elem CAN filter element
  1317. * @param [in] index CAN Filter element index
  1318. * @return status_success if no errors reported
  1319. */
  1320. hpm_stat_t mcan_set_filter_element(MCAN_Type *ptr, const mcan_filter_elem_t *filter_elem, uint32_t index);
  1321. /**
  1322. * @brief Write Frame to CAN TX Buffer
  1323. * @param [in] ptr MCAN base
  1324. * @param [in] index TX Buffer Index
  1325. * @param [in] tx_frame TX frame
  1326. * @return status_success if no errors reported
  1327. */
  1328. hpm_stat_t mcan_write_txbuf(MCAN_Type *ptr, uint32_t index, mcan_tx_frame_t *tx_frame);
  1329. /**
  1330. * @brief Write Frame CAN to TXFIFO
  1331. * @param [in] ptr MCAN base
  1332. * @param [in] tx_frame TX frame
  1333. * @return status_success if no errors reported
  1334. */
  1335. hpm_stat_t mcan_write_txfifo(MCAN_Type *ptr, mcan_tx_frame_t *tx_frame);
  1336. /**
  1337. * @brief Read message from CAN RXBUF
  1338. * @param [in] ptr MCAN base
  1339. * @param [in] index Index of RXBUF
  1340. * @param [out] rx_frame Buffer to hold RX frame
  1341. * @return status_success if no errors reported
  1342. */
  1343. hpm_stat_t mcan_read_rxbuf(MCAN_Type *ptr, uint32_t index, mcan_rx_message_t *rx_frame);
  1344. /**
  1345. * @brief Read message from CAN RXBUF
  1346. * @param [in] ptr MCAN base
  1347. * @param [in] fifo_index RXFIFO index, 0 - RXFO0, 1 - RXFIFO1
  1348. * @param [out] rx_frame Buffer to hold RX frame
  1349. * @return status_success if no errors reported
  1350. */
  1351. hpm_stat_t mcan_read_rxfifo(MCAN_Type *ptr, uint32_t fifo_index, mcan_rx_message_t *rx_frame);
  1352. /**
  1353. * @brief Read TX Event from CAN TX EVENT FIFO
  1354. * @param [in] ptr MCAN base
  1355. * @param [out] tx_evt TX Event Buffer
  1356. * @retval status_success if no errors happened
  1357. * @retval status_mcan_tx_evt_fifo_empty if there are no TX events available
  1358. * @retval status_invalid_argument if any parameters are invalid
  1359. */
  1360. hpm_stat_t mcan_read_tx_evt_fifo(MCAN_Type *ptr, mcan_tx_event_fifo_elem_t *tx_evt);
  1361. /**
  1362. * @brief Transmit CAN message in blocking way
  1363. * @param [in] ptr MCAN base
  1364. * @param [in] tx_frame CAN Transmit Message buffer
  1365. * @return status_success if no errors reported
  1366. */
  1367. hpm_stat_t mcan_transmit_blocking(MCAN_Type *ptr, mcan_tx_frame_t *tx_frame);
  1368. /**
  1369. * @brief Transmit CAN message via TX in blocking way
  1370. * @param [in] ptr MCAN base
  1371. * @param [in] tx_frame CAN Transmit Message buffer
  1372. * @return status_success if no errors reported
  1373. */
  1374. hpm_stat_t mcan_transmit_via_txbuf_nonblocking(MCAN_Type *ptr, uint32_t index, mcan_tx_frame_t *tx_frame);
  1375. /**
  1376. * @brief Receive CAN Frame from RXBUF in blocking way
  1377. * @param [in] ptr MCAN base
  1378. * @param [in] index RXBUF index
  1379. * @param [out] rx_frame Buffer to hold Received Frame
  1380. * @return status_success if no errors reported
  1381. */
  1382. hpm_stat_t mcan_receive_from_buf_blocking(MCAN_Type *ptr, uint32_t index, mcan_rx_message_t *rx_frame);
  1383. /**
  1384. * @brief Receive CAN Frame from RXFIFO in blocking way
  1385. * @param [in] ptr MCAN base
  1386. * @param [in] fifo_index RXFIFO index, 0 - RXFIFO0, 1 - RXFIFO1
  1387. * @param [out] rx_frame Buffer to hold Received Frame
  1388. * @return status_success if no errors reported
  1389. */
  1390. hpm_stat_t mcan_receive_from_fifo_blocking(MCAN_Type *ptr, uint32_t fifo_index, mcan_rx_message_t *rx_frame);
  1391. /**
  1392. * @brief Get Timstamp from MCAN TX Event
  1393. * @param [in] ptr MCAN base
  1394. * @param [in] tx_evt TX Event Element
  1395. * @param [out] timestamp Timestamp value
  1396. * @retval status_success if no errors happened
  1397. * @retval status_invalid_argument if any parameters are invalid
  1398. * @retval status_mcan_timestamp_not_exist if no timestamp information is available
  1399. */
  1400. hpm_stat_t mcan_get_timestamp_from_tx_event(MCAN_Type *ptr,
  1401. const mcan_tx_event_fifo_elem_t *tx_evt,
  1402. mcan_timestamp_value_t *timestamp);
  1403. /**
  1404. * @brief Get Timstamp from MCAN RX frame
  1405. * @param [in] ptr MCAN base
  1406. * @param [in] rx_msg Received message
  1407. * @param [out] timestamp Timestamp value
  1408. * @retval status_success if no errors happened
  1409. * @retval status_invalid_argument if any parameters are invalid
  1410. * @retval status_mcan_timestamp_not_exist if no timestamp information is available
  1411. */
  1412. hpm_stat_t mcan_get_timestamp_from_received_message(MCAN_Type *ptr,
  1413. const mcan_rx_message_t *rx_msg,
  1414. mcan_timestamp_value_t *timestamp);
  1415. /**
  1416. * @}
  1417. *
  1418. */
  1419. #ifdef __cplusplus
  1420. }
  1421. #endif
  1422. #endif /* HPM_MCAN_DRV_H */