1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2022 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 #ifndef FSL_MCAN_H_
9 #define FSL_MCAN_H_
10 
11 #include "fsl_common.h"
12 
13 /*!
14  * @addtogroup mcan
15  * @{
16  */
17 
18 /******************************************************************************
19  * Definitions
20  *****************************************************************************/
21 
22 /*! @name Driver version */
23 /*! @{ */
24 /*! @brief MCAN driver version. */
25 #define FSL_MCAN_DRIVER_VERSION (MAKE_VERSION(2, 3, 2))
26 /*! @} */
27 
28 #ifndef MCAN_RETRY_TIMES
29 /* Define to 0 by default means to retry infinitely until the flag is assert/de-assert.
30  * User can change the macro with their requirement by defined the MACRO.
31  */
32 #define MCAN_RETRY_TIMES (0U)
33 #endif
34 
35 /*! @brief MCAN transfer status. */
36 enum
37 {
38     kStatus_MCAN_TxBusy           = MAKE_STATUS(kStatusGroup_MCAN, 0),  /*!< Tx Buffer is Busy. */
39     kStatus_MCAN_TxIdle           = MAKE_STATUS(kStatusGroup_MCAN, 1),  /*!< Tx Buffer is Idle. */
40     kStatus_MCAN_RxBusy           = MAKE_STATUS(kStatusGroup_MCAN, 2),  /*!< Rx Buffer is Busy. */
41     kStatus_MCAN_RxIdle           = MAKE_STATUS(kStatusGroup_MCAN, 3),  /*!< Rx Buffer is Idle. */
42     kStatus_MCAN_RxFifo0New       = MAKE_STATUS(kStatusGroup_MCAN, 4),  /*!< New message written to Rx FIFO 0. */
43     kStatus_MCAN_RxFifo0Idle      = MAKE_STATUS(kStatusGroup_MCAN, 5),  /*!< Rx FIFO 0 is Idle. */
44     kStatus_MCAN_RxFifo0Watermark = MAKE_STATUS(kStatusGroup_MCAN, 6),  /*!< Rx FIFO 0 fill level reached watermark. */
45     kStatus_MCAN_RxFifo0Full      = MAKE_STATUS(kStatusGroup_MCAN, 7),  /*!< Rx FIFO 0 full. */
46     kStatus_MCAN_RxFifo0Lost      = MAKE_STATUS(kStatusGroup_MCAN, 8),  /*!< Rx FIFO 0 message lost. */
47     kStatus_MCAN_RxFifo1New       = MAKE_STATUS(kStatusGroup_MCAN, 9),  /*!< New message written to Rx FIFO 1. */
48     kStatus_MCAN_RxFifo1Idle      = MAKE_STATUS(kStatusGroup_MCAN, 10), /*!< Rx FIFO 1 is Idle. */
49     kStatus_MCAN_RxFifo1Watermark = MAKE_STATUS(kStatusGroup_MCAN, 11), /*!< Rx FIFO 1 fill level reached watermark. */
50     kStatus_MCAN_RxFifo1Full      = MAKE_STATUS(kStatusGroup_MCAN, 12), /*!< Rx FIFO 1 full. */
51     kStatus_MCAN_RxFifo1Lost      = MAKE_STATUS(kStatusGroup_MCAN, 13), /*!< Rx FIFO 1 message lost. */
52     kStatus_MCAN_RxFifo0Busy      = MAKE_STATUS(kStatusGroup_MCAN, 14), /*!< Rx FIFO 0 is busy. */
53     kStatus_MCAN_RxFifo1Busy      = MAKE_STATUS(kStatusGroup_MCAN, 15), /*!< Rx FIFO 1 is busy. */
54     kStatus_MCAN_ErrorStatus      = MAKE_STATUS(kStatusGroup_MCAN, 16), /*!< MCAN Module Error and Status. */
55     kStatus_MCAN_UnHandled        = MAKE_STATUS(kStatusGroup_MCAN, 17), /*!< UnHadled Interrupt asserted. */
56 };
57 
58 /*!
59  * @brief MCAN status flags.
60  *
61  * This provides constants for the MCAN status flags for use in the MCAN functions.
62  * Note: The CPU read action clears MCAN_ErrorFlag, therefore user need to
63  * read MCAN_ErrorFlag and distinguish which error is occur using
64  * _mcan_error_flags enumerations.
65  */
66 enum _mcan_flags
67 {
68     kMCAN_AccesstoRsvdFlag    = CAN_IR_ARA_MASK, /*!< CAN Synchronization Status. */
69     kMCAN_ProtocolErrDIntFlag = CAN_IR_PED_MASK, /*!< Tx Warning Interrupt Flag. */
70     kMCAN_ProtocolErrAIntFlag = CAN_IR_PEA_MASK, /*!< Rx Warning Interrupt Flag. */
71     kMCAN_BusOffIntFlag       = CAN_IR_BO_MASK,  /*!< Tx Error Warning Status. */
72     kMCAN_ErrorWarningIntFlag = CAN_IR_EW_MASK,  /*!< Rx Error Warning Status. */
73     kMCAN_ErrorPassiveIntFlag = CAN_IR_EP_MASK,  /*!< Rx Error Warning Status. */
74 };
75 
76 /*!
77  * @brief MCAN Rx FIFO status flags.
78  *
79  * The MCAN Rx FIFO Status enumerations are used to determine the status of the
80  * Rx FIFO.
81  */
82 enum _mcan_rx_fifo_flags
83 {
84     kMCAN_RxFifo0NewFlag       = CAN_IR_RF0N_MASK, /*!< Rx FIFO 0 new message flag. */
85     kMCAN_RxFifo0WatermarkFlag = CAN_IR_RF0W_MASK, /*!< Rx FIFO 0 watermark reached flag. */
86     kMCAN_RxFifo0FullFlag      = CAN_IR_RF0F_MASK, /*!< Rx FIFO 0 full flag. */
87     kMCAN_RxFifo0LostFlag      = CAN_IR_RF0L_MASK, /*!< Rx FIFO 0 message lost flag. */
88     kMCAN_RxFifo1NewFlag       = CAN_IR_RF1N_MASK, /*!< Rx FIFO 0 new message flag. */
89     kMCAN_RxFifo1WatermarkFlag = CAN_IR_RF1W_MASK, /*!< Rx FIFO 0 watermark reached flag. */
90     kMCAN_RxFifo1FullFlag      = CAN_IR_RF1F_MASK, /*!< Rx FIFO 0 full flag. */
91     kMCAN_RxFifo1LostFlag      = CAN_IR_RF1L_MASK, /*!< Rx FIFO 0 message lost flag. */
92 };
93 
94 /*!
95  * @brief MCAN Tx status flags.
96  *
97  * The MCAN Tx Status enumerations are used to determine the status of the
98  * Tx Buffer/Event FIFO.
99  */
100 enum _mcan_tx_flags
101 {
102     kMCAN_TxTransmitCompleteFlag     = CAN_IR_TC_MASK,   /*!< Transmission completed flag. */
103     kMCAN_TxTransmitCancelFinishFlag = CAN_IR_TCF_MASK,  /*!< Transmission cancellation finished flag. */
104     kMCAN_TxEventFifoLostFlag        = CAN_IR_TEFL_MASK, /*!< Tx Event FIFO element lost. */
105     kMCAN_TxEventFifoFullFlag        = CAN_IR_TEFF_MASK, /*!< Tx Event FIFO full. */
106     kMCAN_TxEventFifoWatermarkFlag   = CAN_IR_TEFW_MASK, /*!< Tx Event FIFO fill level reached watermark. */
107     kMCAN_TxEventFifoNewFlag         = CAN_IR_TEFN_MASK, /*!< Tx Handler wrote Tx Event FIFO element flag. */
108     kMCAN_TxEventFifoEmptyFlag       = CAN_IR_TFE_MASK,  /*!< Tx FIFO empty flag. */
109 };
110 
111 /*!
112  * @brief MCAN interrupt configuration structure, default settings all disabled.
113  *
114  * This structure contains the settings for all of the MCAN Module interrupt configurations.
115  */
116 enum _mcan_interrupt_enable
117 {
118     kMCAN_BusOffInterruptEnable  = CAN_IE_BOE_MASK, /*!< Bus Off interrupt. */
119     kMCAN_ErrorInterruptEnable   = CAN_IE_EPE_MASK, /*!< Error interrupt. */
120     kMCAN_WarningInterruptEnable = CAN_IE_EWE_MASK, /*!< Rx Warning interrupt. */
121 };
122 
123 /*! @brief MCAN frame format. */
124 typedef enum _mcan_frame_idformat
125 {
126     kMCAN_FrameIDStandard = 0x0U, /*!< Standard frame format attribute. */
127     kMCAN_FrameIDExtend   = 0x1U, /*!< Extend frame format attribute. */
128 } mcan_frame_idformat_t;
129 
130 /*! @brief MCAN frame type. */
131 typedef enum _mcan_frame_type
132 {
133     kMCAN_FrameTypeData   = 0x0U, /*!< Data frame type attribute. */
134     kMCAN_FrameTypeRemote = 0x1U, /*!< Remote frame type attribute. */
135 } mcan_frame_type_t;
136 
137 /*! @brief MCAN frame datafield size. */
138 typedef enum _mcan_bytes_in_datafield
139 {
140     kMCAN_8ByteDatafield  = 0x0U, /*!< 8 byte data field. */
141     kMCAN_12ByteDatafield = 0x1U, /*!< 12 byte data field. */
142     kMCAN_16ByteDatafield = 0x2U, /*!< 16 byte data field. */
143     kMCAN_20ByteDatafield = 0x3U, /*!< 20 byte data field. */
144     kMCAN_24ByteDatafield = 0x4U, /*!< 24 byte data field. */
145     kMCAN_32ByteDatafield = 0x5U, /*!< 32 byte data field. */
146     kMCAN_48ByteDatafield = 0x6U, /*!< 48 byte data field. */
147     kMCAN_64ByteDatafield = 0x7U, /*!< 64 byte data field. */
148 } mcan_bytes_in_datafield_t;
149 
150 #if defined(__CC_ARM)
151 #pragma anon_unions
152 #endif
153 /*! @brief MCAN Tx Buffer structure. */
154 typedef struct _mcan_tx_buffer_frame
155 {
156     struct
157     {
158         uint32_t id : 29; /*!< CAN Frame Identifier. */
159         uint32_t rtr : 1; /*!< CAN Frame Type(DATA or REMOTE). */
160         uint32_t xtd : 1; /*!< CAN Frame Type(STD or EXT). */
161         uint32_t esi : 1; /*!< CAN Frame Error State Indicator. */
162     };
163     struct
164     {
165         uint32_t : 16;
166         uint32_t dlc : 4; /*!< Data Length Code      9 10 11 12 13 14 15
167                                Number of data bytes 12 16 20 24 32 48 64 */
168         uint32_t brs : 1; /*!< Bit Rate Switch. */
169         uint32_t fdf : 1; /*!< CAN FD format. */
170         uint32_t : 1;     /*!< Reserved. */
171         uint32_t efc : 1; /*!< Event FIFO control. */
172         uint32_t mm : 8;  /*!< Message Marker. */
173     };
174     uint8_t *data;
175     uint8_t size; /*!< classical CAN is 8(bytes), FD is 12/64 such. */
176 } mcan_tx_buffer_frame_t;
177 
178 /*! @brief MCAN Rx FIFO/Buffer structure. */
179 typedef struct _mcan_rx_buffer_frame
180 {
181     struct
182     {
183         uint32_t id : 29; /*!< CAN Frame Identifier. */
184         uint32_t rtr : 1; /*!< CAN Frame Type(DATA or REMOTE). */
185         uint32_t xtd : 1; /*!< CAN Frame Type(STD or EXT). */
186         uint32_t esi : 1; /*!< CAN Frame Error State Indicator. */
187     };
188     struct
189     {
190         uint32_t rxts : 16; /*!< Rx Timestamp. */
191         uint32_t dlc : 4;   /*!< Data Length Code      9 10 11 12 13 14 15
192                                  Number of data bytes 12 16 20 24 32 48 64 */
193         uint32_t brs : 1;   /*!< Bit Rate Switch. */
194         uint32_t fdf : 1;   /*!< CAN FD format. */
195         uint32_t : 2;       /*!< Reserved. */
196         uint32_t fidx : 7;  /*!< Filter Index. */
197         uint32_t anmf : 1;  /*!< Accepted Non-matching Frame. */
198     };
199     uint8_t *data;
200     uint8_t size; /*!< classical CAN is 8(bytes), FD is 12/64 such. */
201 } mcan_rx_buffer_frame_t;
202 
203 /*! @brief MCAN Rx FIFO block number. */
204 typedef enum _mcan_fifo_type
205 {
206     kMCAN_Fifo0 = 0x0U, /*!< CAN Rx FIFO 0. */
207     kMCAN_Fifo1 = 0x1U, /*!< CAN Rx FIFO 1. */
208 } mcan_fifo_type_t;
209 
210 /*! @brief MCAN FIFO Operation Mode. */
211 typedef enum _mcan_fifo_opmode_config
212 {
213     kMCAN_FifoBlocking  = 0x0U, /*!< FIFO blocking mode. */
214     kMCAN_FifoOverwrite = 0x1U, /*!< FIFO overwrite mode. */
215 } mcan_fifo_opmode_config_t;
216 
217 /*! @brief MCAN Tx FIFO/Queue Mode. */
218 typedef enum _mcan_txmode_config
219 {
220     kMCAN_txFifo  = 0x0U, /*!< Tx FIFO operation. */
221     kMCAN_txQueue = 0x1U, /*!< Tx Queue operation. */
222 } mcan_txmode_config_t;
223 
224 /*! @brief MCAN remote frames treatment. */
225 typedef enum _mcan_remote_frame_config
226 {
227     kMCAN_filterFrame = 0x0U, /*!< Filter remote frames. */
228     kMCAN_rejectFrame = 0x1U, /*!< Reject all remote frames. */
229 } mcan_remote_frame_config_t;
230 
231 /*! @brief MCAN non-masking frames treatment. */
232 typedef enum _mcan_nonmasking_frame_config
233 {
234     kMCAN_acceptinFifo0 = 0x0U, /*!< Accept non-masking frames in Rx FIFO 0. */
235     kMCAN_acceptinFifo1 = 0x1U, /*!< Accept non-masking frames in Rx FIFO 1. */
236     kMCAN_reject0       = 0x2U, /*!< Reject non-masking frames. */
237     kMCAN_reject1       = 0x3U, /*!< Reject non-masking frames. */
238 } mcan_nonmasking_frame_config_t;
239 
240 /*! @brief MCAN Filter Element Configuration. */
241 typedef enum _mcan_fec_config
242 {
243     kMCAN_disable       = 0x0U, /*!< Disable filter element. */
244     kMCAN_storeinFifo0  = 0x1U, /*!< Store in Rx FIFO 0 if filter matches. */
245     kMCAN_storeinFifo1  = 0x2U, /*!< Store in Rx FIFO 1 if filter matches. */
246     kMCAN_reject        = 0x3U, /*!< Reject ID if filter matches. */
247     kMCAN_setprio       = 0x4U, /*!< Set priority if filter matches. */
248     kMCAN_setpriofifo0  = 0x5U, /*!< Set priority and store in FIFO 0 if filter matches. */
249     kMCAN_setpriofifo1  = 0x6U, /*!< Set priority and store in FIFO 1 if filter matches. */
250     kMCAN_storeinbuffer = 0x7U, /*!< Store into Rx Buffer or as debug message. */
251 } mcan_fec_config_t;
252 
253 /*! @brief MCAN Rx FIFO configuration. */
254 typedef struct _mcan_rx_fifo_config
255 {
256     uint32_t address;                        /*!< FIFOn start address. */
257     uint32_t elementSize;                    /*!< FIFOn element number. */
258     uint32_t watermark;                      /*!< FIFOn watermark level. */
259     mcan_fifo_opmode_config_t opmode;        /*!< FIFOn blocking/overwrite mode. */
260     mcan_bytes_in_datafield_t datafieldSize; /*!< Data field size per frame, size>8 is for CANFD. */
261 } mcan_rx_fifo_config_t;
262 
263 /*! @brief MCAN Rx Buffer configuration. */
264 typedef struct _mcan_rx_buffer_config
265 {
266     uint32_t address;                        /*!< Rx Buffer start address. */
267     mcan_bytes_in_datafield_t datafieldSize; /*!< Data field size per frame, size>8 is for CANFD. */
268 } mcan_rx_buffer_config_t;
269 
270 /*! @brief MCAN Tx Event FIFO configuration. */
271 typedef struct _mcan_tx_fifo_config
272 {
273     uint32_t address;     /*!< Event fifo start address. */
274     uint32_t elementSize; /*!< FIFOn element number. */
275     uint32_t watermark;   /*!< FIFOn watermark level. */
276 } mcan_tx_fifo_config_t;
277 
278 /*! @brief MCAN Tx Buffer configuration. */
279 typedef struct _mcan_tx_buffer_config
280 {
281     uint32_t address;                        /*!< Tx Buffers Start Address. */
282     uint32_t dedicatedSize;                  /*!< Number of Dedicated Transmit Buffers. */
283     uint32_t fqSize;                         /*!< Transmit FIFO/Queue Size. */
284     mcan_txmode_config_t mode;               /*!< Tx FIFO/Queue Mode.*/
285     mcan_bytes_in_datafield_t datafieldSize; /*!< Data field size per frame, size>8 is for CANFD. */
286 } mcan_tx_buffer_config_t;
287 
288 /*! @brief MCAN Filter Type. */
289 typedef enum _mcan_std_filter_type
290 {
291     kMCAN_range           = 0x0U, /*!< Range filter from SFID1 to SFID2. */
292     kMCAN_dual            = 0x1U, /*!< Dual ID filter for SFID1 or SFID2. */
293     kMCAN_classic         = 0x2U, /*!< Classic filter: SFID1 = filter, SFID2 = mask. */
294     kMCAN_disableORrange2 = 0x3U, /*!< Filter element disabled for standard filter
295                                     or Range filter, XIDAM mask not applied for extended filter. */
296 } mcan_filter_type_t;
297 
298 /*! @brief MCAN Standard Message ID Filter Element. */
299 typedef struct _mcan_std_filter_element_config
300 {
301     uint32_t sfid2 : 11; /*!< Standard Filter ID 2. */
302     uint32_t : 5;        /*!< Reserved. */
303     uint32_t sfid1 : 11; /*!< Standard Filter ID 1. */
304     uint32_t sfec : 3;   /*!< Standard Filter Element Configuration. */
305     uint32_t sft : 2;    /*!< Standard Filter Type. */
306 } mcan_std_filter_element_config_t;
307 
308 /*! @brief MCAN Extended Message ID Filter Element. */
309 typedef struct _mcan_ext_filter_element_config
310 {
311     uint32_t efid1 : 29; /*!< Extended Filter ID 1. */
312     uint32_t efec : 3;   /*!< Extended Filter Element Configuration. */
313     uint32_t efid2 : 29; /*!< Extended Filter ID 2. */
314     uint32_t : 1;        /*!< Reserved. */
315     uint32_t eft : 2;    /*!< Extended Filter Type. */
316 } mcan_ext_filter_element_config_t;
317 
318 /*! @brief MCAN Rx filter configuration. */
319 typedef struct _mcan_frame_filter_config
320 {
321     uint32_t address;                       /*!< Filter start address. */
322     uint32_t listSize;                      /*!< Filter list size. */
323     mcan_frame_idformat_t idFormat;         /*!< Frame format. */
324     mcan_remote_frame_config_t remFrame;    /*!< Remote frame treatment. */
325     mcan_nonmasking_frame_config_t nmFrame; /*!< Non-masking frame treatment. */
326 } mcan_frame_filter_config_t;
327 
328 /*! @brief MCAN protocol timing characteristic configuration structure. */
329 typedef struct _mcan_timing_config
330 {
331     uint16_t preDivider; /*!< Nominal Clock Pre-scaler Division Factor. */
332     uint8_t rJumpwidth;  /*!< Nominal Re-sync Jump Width. */
333     uint8_t seg1;        /*!< Nominal Time Segment 1. */
334     uint8_t seg2;        /*!< Nominal Time Segment 2. */
335 #if (defined(FSL_FEATURE_CAN_SUPPORT_CANFD) && FSL_FEATURE_CAN_SUPPORT_CANFD)
336     uint16_t datapreDivider; /*!< Data Clock Pre-scaler Division Factor. */
337     uint8_t datarJumpwidth;  /*!< Data Re-sync Jump Width. */
338     uint8_t dataseg1;        /*!< Data Time Segment 1. */
339     uint8_t dataseg2;        /*!< Data Time Segment 2. */
340 #endif
341 } mcan_timing_config_t;
342 
343 /*! @brief MCAN Message RAM related configuration structure. */
344 typedef struct _mcan_memory_config
345 {
346     uint32_t baseAddr;                        /*!< Message RAM base address, should be 4k alignment. */
347     mcan_frame_filter_config_t *stdFilterCfg; /* Standard message ID filter configure */
348     mcan_frame_filter_config_t *extFilterCfg; /* Extended message ID filter configure */
349     mcan_rx_fifo_config_t *rxFifo0Cfg;        /* Rx FIFO 0 configuration */
350     mcan_rx_fifo_config_t *rxFifo1Cfg;        /* Rx FIFO 1 configuration */
351     mcan_rx_buffer_config_t *rxBufferCfg;     /* Rx buffer configuration */
352     mcan_tx_fifo_config_t *txFifoCfg;         /* Tx event FIFO configuration */
353     mcan_tx_buffer_config_t *txBufferCfg;     /* Tx buffer configuration */
354 } mcan_memory_config_t;
355 
356 /*! @brief MCAN module configuration structure. */
357 typedef struct _mcan_config
358 {
359     uint32_t baudRateA;                /*!< Baud rate of Arbitration phase in bps. */
360     uint32_t baudRateD;                /*!< Baud rate of Data phase in bps. */
361     bool enableCanfdNormal;            /*!< Enable or Disable CANFD normal. */
362     bool enableCanfdSwitch;            /*!< Enable or Disable CANFD with baudrate switch. */
363     bool enableLoopBackInt;            /*!< Enable or Disable Internal Back. */
364     bool enableLoopBackExt;            /*!< Enable or Disable External Loop Back. */
365     bool enableBusMon;                 /*!< Enable or Disable Bus Monitoring Mode. */
366     mcan_timing_config_t timingConfig; /*!< Protocol timing . */
367 } mcan_config_t;
368 
369 /*! @brief MCAN Buffer transfer. */
370 typedef struct _mcan_buffer_transfer
371 {
372     mcan_tx_buffer_frame_t *frame; /*!< The buffer of CAN Message to be transfer. */
373     uint8_t bufferIdx;             /*!< The index of Message buffer used to transfer Message. */
374 } mcan_buffer_transfer_t;
375 
376 /*! @brief MCAN Rx FIFO transfer. */
377 typedef struct _mcan_fifo_transfer
378 {
379     mcan_rx_buffer_frame_t *frame; /*!< The buffer of CAN Message to be received from Rx FIFO. */
380 } mcan_fifo_transfer_t;
381 
382 /*! @brief MCAN handle structure definition. */
383 typedef struct _mcan_handle mcan_handle_t;
384 
385 /*! @brief MCAN transfer callback function.
386  *
387  *  The MCAN transfer callback returns a value from the underlying layer.
388  *  If the status equals to kStatus_MCAN_ErrorStatus, the result parameter is the Content of
389  *  MCAN status register which can be used to get the working status(or error status) of MCAN module.
390  *  If the status equals to other MCAN Message Buffer transfer status, the result is the index of
391  *  Message Buffer that generate transfer event.
392  *  If the status equals to other MCAN Message Buffer transfer status, the result is meaningless and should be
393  *  Ignored.
394  */
395 typedef void (*mcan_transfer_callback_t)(
396     CAN_Type *base, mcan_handle_t *handle, status_t status, uint32_t result, void *userData);
397 
398 /*! @brief MCAN handle structure. */
399 struct _mcan_handle
400 {
401     mcan_transfer_callback_t callback;                   /*!< Callback function. */
402     void *userData;                                      /*!< MCAN callback function parameter.*/
403     mcan_tx_buffer_frame_t *volatile bufferFrameBuf[64]; /*!< The buffer for received data from Buffers. */
404     mcan_rx_buffer_frame_t *volatile rxFifoFrameBuf;     /*!< The buffer for received data from Rx FIFO. */
405     volatile uint8_t bufferState[64];                    /*!< Message Buffer transfer state. */
406     volatile uint8_t rxFifoState;                        /*!< Rx FIFO transfer state. */
407 };
408 
409 /******************************************************************************
410  * API
411  *****************************************************************************/
412 
413 #if defined(__cplusplus)
414 extern "C" {
415 #endif
416 
417 /*!
418  * @name Initialization and deinitialization
419  * @{
420  */
421 
422 /*!
423  * @brief Initializes an MCAN instance.
424  *
425  * This function initializes the MCAN module with user-defined settings.
426  * This example shows how to set up the mcan_config_t parameters and how
427  * to call the MCAN_Init function by passing in these parameters.
428  *  @code
429  *   mcan_config_t config;
430  *   config->baudRateA = 500000U;
431  *   config->baudRateD = 1000000U;
432  *   config->enableCanfdNormal = false;
433  *   config->enableCanfdSwitch = false;
434  *   config->enableLoopBackInt = false;
435  *   config->enableLoopBackExt = false;
436  *   config->enableBusMon = false;
437  *   MCAN_Init(CANFD0, &config, 8000000UL);
438  *   @endcode
439  *
440  * @param base MCAN peripheral base address.
441  * @param config Pointer to the user-defined configuration structure.
442  * @param sourceClock_Hz MCAN Protocol Engine clock source frequency in Hz.
443  */
444 void MCAN_Init(CAN_Type *base, const mcan_config_t *config, uint32_t sourceClock_Hz);
445 
446 /*!
447  * @brief Deinitializes an MCAN instance.
448  *
449  * This function deinitializes the MCAN module.
450  *
451  * @param base MCAN peripheral base address.
452  */
453 void MCAN_Deinit(CAN_Type *base);
454 
455 /*!
456  * @brief Gets the default configuration structure.
457  *
458  * This function initializes the MCAN configuration structure to default values. The default
459  * values are as follows.
460  *   config->baudRateA = 500000U;
461  *   config->baudRateD = 1000000U;
462  *   config->enableCanfdNormal = false;
463  *   config->enableCanfdSwitch = false;
464  *   config->enableLoopBackInt = false;
465  *   config->enableLoopBackExt = false;
466  *   config->enableBusMon = false;
467  *
468  * @param config Pointer to the MCAN configuration structure.
469  */
470 void MCAN_GetDefaultConfig(mcan_config_t *config);
471 
472 /*!
473  * @brief MCAN enters initialization mode.
474  *
475  * After enter initialization mode, users can write access to the protected configuration registers.
476  *
477  * @param base MCAN peripheral base address.
478  */
MCAN_EnterInitialMode(CAN_Type * base)479 static inline void MCAN_EnterInitialMode(CAN_Type *base)
480 {
481     /* Enable write access to the protected configuration registers */
482     base->CCCR |= CAN_CCCR_INIT_MASK;
483     while (0U == (base->CCCR & CAN_CCCR_INIT_MASK))
484     {
485     }
486     base->CCCR |= CAN_CCCR_CCE_MASK;
487 }
488 
489 /*!
490  * @brief MCAN enters normal mode.
491  *
492  * After initialization, INIT bit in CCCR register must be cleared to enter
493  * normal mode thus synchronizes to the CAN bus and ready for communication.
494  *
495  * @param base MCAN peripheral base address.
496  */
MCAN_EnterNormalMode(CAN_Type * base)497 static inline void MCAN_EnterNormalMode(CAN_Type *base)
498 {
499     /* Reset INIT bit to enter normal mode. */
500     base->CCCR &= ~CAN_CCCR_INIT_MASK;
501     while (0U != (base->CCCR & CAN_CCCR_INIT_MASK))
502     {
503     }
504 }
505 
506 /*!
507  * @name Configuration.
508  * @{
509  */
510 
511 /*!
512  * @brief Sets the MCAN Message RAM base address.
513  *
514  * This function sets the Message RAM base address.
515  *
516  * @param base MCAN peripheral base address.
517  * @param value Desired Message RAM base.
518  */
MCAN_SetMsgRAMBase(CAN_Type * base,uint32_t value)519 static inline void MCAN_SetMsgRAMBase(CAN_Type *base, uint32_t value)
520 {
521     assert(((value >= 0x20000000U) && (value <= 0x20027FFFU)) || ((value >= 0x04000000U) && (value <= 0x04007FFFU)));
522 
523     base->MRBA = CAN_MRBA_BA(value >> 16U);
524 }
525 
526 /*!
527  * @brief Gets the MCAN Message RAM base address.
528  *
529  * This function gets the Message RAM base address.
530  *
531  * @param base MCAN peripheral base address.
532  * @return Message RAM base address.
533  */
MCAN_GetMsgRAMBase(CAN_Type * base)534 static inline uint32_t MCAN_GetMsgRAMBase(CAN_Type *base)
535 {
536     return base->MRBA;
537 }
538 
539 /*!
540  * @brief Calculates the improved timing values by specific baudrates for classical CAN
541  *
542  * @param baudRate  The classical CAN speed in bps defined by user
543  * @param sourceClock_Hz The Source clock data speed in bps. Zero to disable baudrate switching
544  * @param pconfig Pointer to the MCAN timing configuration structure.
545  *
546  * @return TRUE if timing configuration found, FALSE if failed to find configuration
547  */
548 bool MCAN_CalculateImprovedTimingValues(uint32_t baudRate, uint32_t sourceClock_Hz, mcan_timing_config_t *pconfig);
549 
550 /*!
551  * @brief Sets the MCAN protocol arbitration phase timing characteristic.
552  *
553  * This function gives user settings to CAN bus timing characteristic.
554  * The function is for an experienced user. For less experienced users, call
555  * the MCAN_Init() and fill the baud rate field with a desired value.
556  * This provides the default arbitration phase timing characteristics.
557  *
558  * Note that calling MCAN_SetArbitrationTimingConfig() overrides the baud rate
559  * set in MCAN_Init().
560  *
561  * @param base MCAN peripheral base address.
562  * @param config Pointer to the timing configuration structure.
563  */
564 void MCAN_SetArbitrationTimingConfig(CAN_Type *base, const mcan_timing_config_t *config);
565 
566 /*!
567  * @brief Set Baud Rate of MCAN classic mode.
568  *
569  * This function set the baud rate of MCAN base on MCAN_CalculateImprovedTimingValues() API calculated timing values.
570  *
571  * @param base MCAN peripheral base address.
572  * @param sourceClock_Hz Source Clock in Hz.
573  * @param baudRate_Bps Baud Rate in Bps.
574  * @return kStatus_Success - Set CAN baud rate (only has Nominal phase) successfully.
575  */
576 status_t MCAN_SetBaudRate(CAN_Type *base, uint32_t sourceClock_Hz, uint32_t baudRate_Bps);
577 
578 #if (defined(FSL_FEATURE_CAN_SUPPORT_CANFD) && FSL_FEATURE_CAN_SUPPORT_CANFD)
579 /*!
580  * @brief Calculates the improved timing values by specific baudrates for CANFD
581  *
582  * @param baudRate  The CANFD bus control speed in bps defined by user
583  * @param baudRateFD  The CANFD bus data speed in bps defined by user
584  * @param sourceClock_Hz The Source clock data speed in bps.
585  * @param pconfig Pointer to the MCAN timing configuration structure.
586  *
587  * @return TRUE if timing configuration found, FALSE if failed to find configuration
588  */
589 bool MCAN_FDCalculateImprovedTimingValues(uint32_t baudRate,
590                                           uint32_t baudRateFD,
591                                           uint32_t sourceClock_Hz,
592                                           mcan_timing_config_t *pconfig);
593 
594 /*!
595  * @brief Set Baud Rate of MCAN FD mode.
596  *
597  * This function set the baud rate of MCAN FD base on MCAN_FDCalculateImprovedTimingValues API calculated timing values.
598  *
599  * @param base MCAN peripheral base address.
600  * @param sourceClock_Hz Source Clock in Hz.
601  * @param baudRateN_Bps Nominal Baud Rate in Bps.
602  * @param baudRateD_Bps Data Baud Rate in Bps.
603  * @return kStatus_Success - Set CAN FD baud rate (include Nominal and Data phase) successfully.
604  */
605 status_t MCAN_SetBaudRateFD(CAN_Type *base, uint32_t sourceClock_Hz, uint32_t baudRateN_Bps, uint32_t baudRateD_Bps);
606 /*!
607  * @brief Sets the MCAN protocol data phase timing characteristic.
608  *
609  * This function gives user settings to CAN bus timing characteristic.
610  * The function is for an experienced user. For less experienced users, call
611  * the MCAN_Init() and fill the baud rate field with a desired value.
612  * This provides the default data phase timing characteristics.
613  *
614  * Note that calling MCAN_SetArbitrationTimingConfig() overrides the baud rate
615  * set in MCAN_Init().
616  *
617  * @param base MCAN peripheral base address.
618  * @param config Pointer to the timing configuration structure.
619  */
620 void MCAN_SetDataTimingConfig(CAN_Type *base, const mcan_timing_config_t *config);
621 #endif /* FSL_FEATURE_CAN_SUPPORT_CANFD */
622 
623 /*!
624  * @brief Configures an MCAN receive fifo 0 buffer.
625  *
626  * This function sets start address, element size, watermark, operation mode
627  * and datafield size of the recieve fifo 0.
628  *
629  * @param base MCAN peripheral base address.
630  * @param config The receive fifo 0 configuration structure.
631  */
632 void MCAN_SetRxFifo0Config(CAN_Type *base, const mcan_rx_fifo_config_t *config);
633 
634 /*!
635  * @brief Configures an MCAN receive fifo 1 buffer.
636  *
637  * This function sets start address, element size, watermark, operation mode
638  * and datafield size of the recieve fifo 1.
639  *
640  * @param base MCAN peripheral base address.
641  * @param config The receive fifo 1 configuration structure.
642  */
643 void MCAN_SetRxFifo1Config(CAN_Type *base, const mcan_rx_fifo_config_t *config);
644 
645 /*!
646  * @brief Configures an MCAN receive buffer.
647  *
648  * This function sets start address and datafield size of the recieve buffer.
649  *
650  * @param base MCAN peripheral base address.
651  * @param config The receive buffer configuration structure.
652  */
653 void MCAN_SetRxBufferConfig(CAN_Type *base, const mcan_rx_buffer_config_t *config);
654 
655 /*!
656  * @brief Configures an MCAN transmit event fifo.
657  *
658  * This function sets start address, element size, watermark of the transmit event fifo.
659  *
660  * @param base MCAN peripheral base address.
661  * @param config The transmit event fifo configuration structure.
662  */
663 void MCAN_SetTxEventFifoConfig(CAN_Type *base, const mcan_tx_fifo_config_t *config);
664 
665 /*!
666  * @brief Configures an MCAN transmit buffer.
667  *
668  * This function sets start address, element size, fifo/queue mode and datafield
669  * size of the transmit buffer.
670  *
671  * @param base MCAN peripheral base address.
672  * @param config The transmit buffer configuration structure.
673  */
674 void MCAN_SetTxBufferConfig(CAN_Type *base, const mcan_tx_buffer_config_t *config);
675 
676 /*!
677  * @brief Set filter configuration.
678  *
679  * This function sets remote and non masking frames in global filter configuration,
680  * also the start address, list size in standard/extended ID filter configuration.
681  *
682  * @param base MCAN peripheral base address.
683  * @param config The MCAN filter configuration.
684  */
685 void MCAN_SetFilterConfig(CAN_Type *base, const mcan_frame_filter_config_t *config);
686 
687 /*!
688  * @brief Set Message RAM related configuration.
689  *
690  * @note This function include Standard/extended ID filter, Rx FIFO 0/1, Rx buffer, Tx event FIFO and Tx buffer
691  *      configurations
692  * @param base MCAN peripheral base address.
693  * @param config The MCAN filter configuration.
694  * @retval kStatus_Success - Message RAM related configuration Successfully.
695  * @retval kStatus_Fail    - Message RAM related configure fail due to wrong address parameter.
696  */
697 status_t MCAN_SetMessageRamConfig(CAN_Type *base, const mcan_memory_config_t *config);
698 
699 /*!
700  * @brief Set standard message ID filter element configuration.
701  *
702  * @param base MCAN peripheral base address.
703  * @param config The MCAN filter configuration.
704  * @param filter The MCAN standard message ID filter element configuration.
705  * @param idx The standard message ID filter element index.
706  */
707 void MCAN_SetSTDFilterElement(CAN_Type *base,
708                               const mcan_frame_filter_config_t *config,
709                               const mcan_std_filter_element_config_t *filter,
710                               uint8_t idx);
711 
712 /*!
713  * @brief Set extended message ID filter element configuration.
714  *
715  * @param base MCAN peripheral base address.
716  * @param config The MCAN filter configuration.
717  * @param filter The MCAN extended message ID filter element configuration.
718  * @param idx The extended message ID filter element index.
719  */
720 void MCAN_SetEXTFilterElement(CAN_Type *base,
721                               const mcan_frame_filter_config_t *config,
722                               const mcan_ext_filter_element_config_t *filter,
723                               uint8_t idx);
724 
725 /*!
726  * @name Status
727  * @{
728  */
729 
730 /*!
731  * @brief Gets the MCAN module interrupt flags.
732  *
733  * This function gets all MCAN interrupt status flags.
734  *
735  * @param base MCAN peripheral base address.
736  * @param mask The ORed MCAN interrupt mask.
737  * @return MCAN status flags which are ORed.
738  */
MCAN_GetStatusFlag(CAN_Type * base,uint32_t mask)739 static inline uint32_t MCAN_GetStatusFlag(CAN_Type *base, uint32_t mask)
740 {
741     return (base->IR & mask);
742 }
743 
744 /*!
745  * @brief Clears the MCAN module interrupt flags.
746  *
747  * This function clears MCAN interrupt status flags.
748  *
749  * @param base MCAN peripheral base address.
750  * @param mask The ORed MCAN interrupt mask.
751  */
MCAN_ClearStatusFlag(CAN_Type * base,uint32_t mask)752 static inline void MCAN_ClearStatusFlag(CAN_Type *base, uint32_t mask)
753 {
754     /* Write 1 to clear status flag, write 0 has no effect. */
755     base->IR = mask;
756 }
757 
758 /*!
759  * @brief Gets the new data flag of specific Rx Buffer.
760  *
761  * This function gets new data flag of specific Rx Buffer.
762  *
763  * @param base MCAN peripheral base address.
764  * @param idx Rx Buffer index.
765  * @return Rx Buffer new data status flag.
766  */
MCAN_GetRxBufferStatusFlag(CAN_Type * base,uint8_t idx)767 static inline bool MCAN_GetRxBufferStatusFlag(CAN_Type *base, uint8_t idx)
768 {
769     assert(idx <= 63U);
770 
771     bool fgRet;
772 
773     if (idx <= 31U)
774     {
775         fgRet = (0U != (base->NDAT1 & ((uint32_t)1U << idx)));
776     }
777     else
778     {
779         fgRet = (0U != (base->NDAT2 & ((uint32_t)1U << (idx - 32U))));
780     }
781 
782     return fgRet;
783 }
784 
785 /*!
786  * @brief Clears the new data flag of specific Rx Buffer.
787  *
788  * This function clears new data flag of specific Rx Buffer.
789  *
790  * @param base MCAN peripheral base address.
791  * @param idx Rx Buffer index.
792  */
MCAN_ClearRxBufferStatusFlag(CAN_Type * base,uint8_t idx)793 static inline void MCAN_ClearRxBufferStatusFlag(CAN_Type *base, uint8_t idx)
794 {
795     assert(idx <= 63U);
796 
797     if (idx <= 31U)
798     {
799         base->NDAT1 = ((uint32_t)1U << idx);
800     }
801     else
802     {
803         base->NDAT2 = ((uint32_t)1U << (idx - 32U));
804     }
805 }
806 
807 /*! @} */
808 
809 /*!
810  * @name Interrupts
811  * @{
812  */
813 
814 /*!
815  * @brief Enables MCAN interrupts according to the provided interrupt line and mask.
816  *
817  * This function enables the MCAN interrupts according to the provided interrupt line and mask.
818  * The mask is a logical OR of enumeration members.
819  *
820  * @param base MCAN peripheral base address.
821  * @param line Interrupt line number, 0 or 1.
822  * @param mask The interrupts to enable.
823  */
MCAN_EnableInterrupts(CAN_Type * base,uint32_t line,uint32_t mask)824 static inline void MCAN_EnableInterrupts(CAN_Type *base, uint32_t line, uint32_t mask)
825 {
826     base->ILE |= ((uint32_t)1U << line);
827     if (0U == line)
828     {
829         base->ILS &= ~mask;
830     }
831     else
832     {
833         base->ILS |= mask;
834     }
835     base->IE |= mask;
836 }
837 
838 /*!
839  * @brief Enables MCAN Tx Buffer interrupts according to the provided index.
840  *
841  * This function enables the MCAN Tx Buffer interrupts.
842  *
843  * @param base MCAN peripheral base address.
844  * @param idx Tx Buffer index.
845  */
MCAN_EnableTransmitBufferInterrupts(CAN_Type * base,uint8_t idx)846 static inline void MCAN_EnableTransmitBufferInterrupts(CAN_Type *base, uint8_t idx)
847 {
848     base->TXBTIE |= ((uint32_t)1U << idx);
849 }
850 
851 /*!
852  * @brief Disables MCAN Tx Buffer interrupts according to the provided index.
853  *
854  * This function disables the MCAN Tx Buffer interrupts.
855  *
856  * @param base MCAN peripheral base address.
857  * @param idx Tx Buffer index.
858  */
MCAN_DisableTransmitBufferInterrupts(CAN_Type * base,uint8_t idx)859 static inline void MCAN_DisableTransmitBufferInterrupts(CAN_Type *base, uint8_t idx)
860 {
861     base->TXBTIE &= (~((uint32_t)1U << idx));
862 }
863 
864 /*!
865  * @brief Disables MCAN interrupts according to the provided mask.
866  *
867  * This function disables the MCAN interrupts according to the provided mask.
868  * The mask is a logical OR of enumeration members.
869  *
870  * @param base MCAN peripheral base address.
871  * @param mask The interrupts to disable.
872  */
MCAN_DisableInterrupts(CAN_Type * base,uint32_t mask)873 static inline void MCAN_DisableInterrupts(CAN_Type *base, uint32_t mask)
874 {
875     base->IE &= ~mask;
876 }
877 
878 /*! @} */
879 
880 /*!
881  * @name Bus Operations
882  * @{
883  */
884 
885 /*!
886  * @brief Gets the Tx buffer request pending status.
887  *
888  * This function returns Tx Message Buffer transmission request pending status.
889  *
890  * @param base MCAN peripheral base address.
891  * @param idx The MCAN Tx Buffer index.
892  */
893 uint32_t MCAN_IsTransmitRequestPending(CAN_Type *base, uint8_t idx);
894 
895 /*!
896  * @brief Gets the Tx buffer transmission occurred status.
897  *
898  * This function returns Tx Message Buffer transmission occurred status.
899  *
900  * @param base MCAN peripheral base address.
901  * @param idx The MCAN Tx Buffer index.
902  */
903 uint32_t MCAN_IsTransmitOccurred(CAN_Type *base, uint8_t idx);
904 
905 /*!
906  * @brief Writes an MCAN Message to the Transmit Buffer.
907  *
908  * This function writes a CAN Message to the specified Transmit Message Buffer
909  * and changes the Message Buffer state to start CAN Message transmit. After
910  * that the function returns immediately.
911  *
912  * @param base MCAN peripheral base address.
913  * @param idx The MCAN Tx Buffer index.
914  * @param pTxFrame Pointer to CAN message frame to be sent.
915  */
916 status_t MCAN_WriteTxBuffer(CAN_Type *base, uint8_t idx, const mcan_tx_buffer_frame_t *pTxFrame);
917 
918 /*!
919  * @brief Reads an MCAN Message from Rx Buffer.
920  *
921  * This function reads a CAN message from the Rx Buffer in the Message RAM.
922  *
923  * @param base MCAN peripheral base address.
924  * @param idx The MCAN Rx Buffer index.
925  * @param pRxFrame Pointer to CAN message frame structure for reception.
926  * @retval kStatus_Success - Read Message from Rx Buffer successfully.
927  */
928 status_t MCAN_ReadRxBuffer(CAN_Type *base, uint8_t idx, mcan_rx_buffer_frame_t *pRxFrame);
929 
930 /*!
931  * @brief Reads an MCAN Message from Rx FIFO.
932  *
933  * This function reads a CAN message from the Rx FIFO in the Message RAM.
934  *
935  * @param base MCAN peripheral base address.
936  * @param fifoBlock Rx FIFO block 0 or 1.
937  * @param pRxFrame Pointer to CAN message frame structure for reception.
938  * @retval kStatus_Success - Read Message from Rx FIFO successfully.
939  */
940 status_t MCAN_ReadRxFifo(CAN_Type *base, uint8_t fifoBlock, mcan_rx_buffer_frame_t *pRxFrame);
941 
942 /*! @} */
943 
944 /*!
945  * @name Transactional
946  * @{
947  */
948 
949 /*!
950  * @brief Tx Buffer add request to send message out.
951  *
952  * This function add sending request to corresponding Tx Buffer.
953  *
954  * @param base MCAN peripheral base address.
955  * @param idx Tx Buffer index.
956  */
MCAN_TransmitAddRequest(CAN_Type * base,uint8_t idx)957 static inline void MCAN_TransmitAddRequest(CAN_Type *base, uint8_t idx)
958 {
959     base->TXBAR = ((uint32_t)1U << idx);
960 }
961 
962 /*!
963  * @brief Tx Buffer cancel sending request.
964  *
965  * This function clears Tx buffer request pending bit.
966  *
967  * @param base MCAN peripheral base address.
968  * @param idx Tx Buffer index.
969  */
MCAN_TransmitCancelRequest(CAN_Type * base,uint8_t idx)970 static inline void MCAN_TransmitCancelRequest(CAN_Type *base, uint8_t idx)
971 {
972     base->TXBCR = ((uint32_t)1U << idx);
973 }
974 
975 /*!
976  * @brief Performs a polling send transaction on the CAN bus.
977  *
978  * Note that a transfer handle does not need to be created  before calling this API.
979  *
980  * @param base MCAN peripheral base pointer.
981  * @param idx The MCAN buffer index.
982  * @param pTxFrame Pointer to CAN message frame to be sent.
983  * @retval kStatus_Success - Write Tx Message Buffer Successfully.
984  * @retval kStatus_Fail    - Tx Message Buffer is currently in use.
985  */
986 status_t MCAN_TransferSendBlocking(CAN_Type *base, uint8_t idx, mcan_tx_buffer_frame_t *pTxFrame);
987 
988 /*!
989  * @brief Performs a polling receive transaction on the CAN bus.
990  *
991  * Note that a transfer handle does not need to be created  before calling this API.
992  *
993  * @param base MCAN peripheral base pointer.
994  * @param idx The MCAN buffer index.
995  * @param pRxFrame Pointer to CAN message frame structure for reception.
996  * @retval kStatus_Success - Read Rx Message Buffer Successfully.
997  * @retval kStatus_Fail    - No new message.
998  */
999 status_t MCAN_TransferReceiveBlocking(CAN_Type *base, uint8_t idx, mcan_rx_buffer_frame_t *pRxFrame);
1000 
1001 /*!
1002  * @brief Performs a polling receive transaction from Rx FIFO on the CAN bus.
1003  *
1004  * Note that a transfer handle does not need to be created before calling this API.
1005  *
1006  * @param base MCAN peripheral base pointer.
1007  * @param fifoBlock Rx FIFO block, 0 or 1.
1008  * @param pRxFrame Pointer to CAN message frame structure for reception.
1009  * @retval kStatus_Success - Read Message from Rx FIFO successfully.
1010  * @retval kStatus_Fail    - No new message in Rx FIFO.
1011  */
1012 status_t MCAN_TransferReceiveFifoBlocking(CAN_Type *base, uint8_t fifoBlock, mcan_rx_buffer_frame_t *pRxFrame);
1013 
1014 /*!
1015  * @brief Initializes the MCAN handle.
1016  *
1017  * This function initializes the MCAN handle, which can be used for other MCAN
1018  * transactional APIs. Usually, for a specified MCAN instance,
1019  * call this API once to get the initialized handle.
1020  *
1021  * @param base MCAN peripheral base address.
1022  * @param handle MCAN handle pointer.
1023  * @param callback The callback function.
1024  * @param userData The parameter of the callback function.
1025  */
1026 void MCAN_TransferCreateHandle(CAN_Type *base,
1027                                mcan_handle_t *handle,
1028                                mcan_transfer_callback_t callback,
1029                                void *userData);
1030 
1031 /*!
1032  * @brief Sends a message using IRQ.
1033  *
1034  * This function sends a message using IRQ. This is a non-blocking function, which returns
1035  * right away. When messages have been sent out, the send callback function is called.
1036  *
1037  * @param base MCAN peripheral base address.
1038  * @param handle MCAN handle pointer.
1039  * @param xfer MCAN Buffer transfer structure. See the #mcan_buffer_transfer_t.
1040  * @retval kStatus_Success        Start Tx Buffer sending process successfully.
1041  * @retval kStatus_Fail           Write Tx Buffer failed.
1042  * @retval kStatus_MCAN_TxBusy Tx Buffer is in use.
1043  */
1044 status_t MCAN_TransferSendNonBlocking(CAN_Type *base, mcan_handle_t *handle, mcan_buffer_transfer_t *xfer);
1045 
1046 /*!
1047  * @brief Receives a message from Rx FIFO using IRQ.
1048  *
1049  * This function receives a message using IRQ. This is a non-blocking function, which returns
1050  * right away. When all messages have been received, the receive callback function is called.
1051  *
1052  * @param base MCAN peripheral base address.
1053  * @param handle MCAN handle pointer.
1054  * @param fifoBlock Rx FIFO block, 0 or 1.
1055  * @param xfer MCAN Rx FIFO transfer structure. See the @ref mcan_fifo_transfer_t.
1056  * @retval kStatus_Success            - Start Rx FIFO receiving process successfully.
1057  * @retval kStatus_MCAN_RxFifo0Busy - Rx FIFO 0 is currently in use.
1058  * @retval kStatus_MCAN_RxFifo1Busy - Rx FIFO 1 is currently in use.
1059  */
1060 status_t MCAN_TransferReceiveFifoNonBlocking(CAN_Type *base,
1061                                              uint8_t fifoBlock,
1062                                              mcan_handle_t *handle,
1063                                              mcan_fifo_transfer_t *xfer);
1064 
1065 /*!
1066  * @brief Aborts the interrupt driven message send process.
1067  *
1068  * This function aborts the interrupt driven message send process.
1069  *
1070  * @param base MCAN peripheral base address.
1071  * @param handle MCAN handle pointer.
1072  * @param bufferIdx The MCAN Buffer index.
1073  */
1074 void MCAN_TransferAbortSend(CAN_Type *base, mcan_handle_t *handle, uint8_t bufferIdx);
1075 
1076 /*!
1077  * @brief Aborts the interrupt driven message receive from Rx FIFO process.
1078  *
1079  * This function aborts the interrupt driven message receive from Rx FIFO process.
1080  *
1081  * @param base MCAN peripheral base address.
1082  * @param fifoBlock MCAN Fifo block, 0 or 1.
1083  * @param handle MCAN handle pointer.
1084  */
1085 void MCAN_TransferAbortReceiveFifo(CAN_Type *base, uint8_t fifoBlock, mcan_handle_t *handle);
1086 
1087 /*!
1088  * @brief MCAN IRQ handle function.
1089  *
1090  * This function handles the MCAN Error, the Buffer, and the Rx FIFO IRQ request.
1091  *
1092  * @param base MCAN peripheral base address.
1093  * @param handle MCAN handle pointer.
1094  */
1095 void MCAN_TransferHandleIRQ(CAN_Type *base, mcan_handle_t *handle);
1096 
1097 /*! @} */
1098 
1099 #if defined(__cplusplus)
1100 }
1101 #endif
1102 
1103 /*! @}*/
1104 
1105 #endif /* FSL_MCAN_H_ */
1106