1 /*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * o Redistributions of source code must retain the above copyright notice, this list
9 * of conditions and the following disclaimer.
10 *
11 * o Redistributions in binary form must reproduce the above copyright notice, this
12 * list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
14 *
15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef __FLEXCAN_H__
32 #define __FLEXCAN_H__
33
34 #include <stdint.h>
35 #include <stdbool.h>
36 #include <assert.h>
37 #include "device_imx.h"
38
39 /* Start of section using anonymous unions. */
40 #if defined(__ARMCC_VERSION)
41 #pragma push
42 #pragma anon_unions
43 #elif defined(__GNUC__)
44 /* anonymous unions are enabled by default */
45 #elif defined(__IAR_SYSTEMS_ICC__)
46 #pragma language=extended
47 #else
48 #error Not supported compiler type
49 #endif
50
51 /*!
52 * @addtogroup flexcan_driver
53 * @{
54 */
55
56 /*******************************************************************************
57 * Definitions
58 ******************************************************************************/
59
60 /*! @brief FlexCAN message buffer CODE for Rx buffers. */
61 enum _flexcan_msgbuf_code_rx
62 {
63 flexcanRxInactive = 0x0, /*!< MB is not active. */
64 flexcanRxFull = 0x2, /*!< MB is full. */
65 flexcanRxEmpty = 0x4, /*!< MB is active and empty. */
66 flexcanRxOverrun = 0x6, /*!< MB is overwritten into a full buffer. */
67 flexcanRxBusy = 0x8, /*!< FlexCAN is updating the contents of the MB. */
68 /*! The CPU must not access the MB. */
69 flexcanRxRanswer = 0xA, /*!< A frame was configured to recognize a Remote Request Frame */
70 /*! and transmit a Response Frame in return. */
71 flexcanRxNotUsed = 0xF, /*!< Not used. */
72 };
73
74 /*! @brief FlexCAN message buffer CODE FOR Tx buffers. */
75 enum _flexcan_msgbuf_code_tx
76 {
77 flexcanTxInactive = 0x8, /*!< MB is not active. */
78 flexcanTxAbort = 0x9, /*!< MB is aborted. */
79 flexcanTxDataOrRemte = 0xC, /*!< MB is a TX Data Frame(when MB RTR = 0) or */
80 /*!< MB is a TX Remote Request Frame (when MB RTR = 1). */
81 flexcanTxTanswer = 0xE, /*!< MB is a TX Response Request Frame from. */
82 /*! an incoming Remote Request Frame. */
83 flexcanTxNotUsed = 0xF, /*!< Not used. */
84 };
85
86 /*! @brief FlexCAN operation modes. */
87 enum _flexcan_operatining_modes
88 {
89 flexcanNormalMode = 0x1, /*!< Normal mode or user mode @internal gui name="Normal". */
90 flexcanListenOnlyMode = 0x2, /*!< Listen-only mode @internal gui name="Listen-only". */
91 flexcanLoopBackMode = 0x4, /*!< Loop-back mode @internal gui name="Loop back". */
92 };
93
94 /*! @brief FlexCAN RX mask mode. */
95 enum _flexcan_rx_mask_mode
96 {
97 flexcanRxMaskGlobal = 0x0, /*!< Rx global mask. */
98 flexcanRxMaskIndividual = 0x1, /*!< Rx individual mask. */
99 };
100
101 /*! @brief The ID type used in rx matching process. */
102 enum _flexcan_rx_mask_id_type
103 {
104 flexcanRxMaskIdStd = 0x0, /*!< Standard ID. */
105 flexcanRxMaskIdExt = 0x1, /*!< Extended ID. */
106 };
107
108 /*! @brief FlexCAN error interrupt source enumeration. */
109 enum _flexcan_interrutpt
110 {
111 flexcanIntRxWarning = 0x01, /*!< Tx Warning interrupt source. */
112 flexcanIntTxWarning = 0x02, /*!< Tx Warning interrupt source. */
113 flexcanIntWakeUp = 0x04, /*!< Wake Up interrupt source. */
114 flexcanIntBusOff = 0x08, /*!< Bus Off interrupt source. */
115 flexcanIntError = 0x10, /*!< Error interrupt source. */
116 };
117
118 /*! @brief FlexCAN error interrupt flags. */
119 enum _flexcan_status_flag
120 {
121 flexcanStatusSynch = CAN_ESR1_SYNCH_MASK, /*!< Bus Synchronized flag. */
122 flexcanStatusTxWarningInt = CAN_ESR1_TWRN_INT_MASK, /*!< Tx Warning initerrupt flag. */
123 flexcanStatusRxWarningInt = CAN_ESR1_RWRN_INT_MASK, /*!< Tx Warning initerrupt flag. */
124 flexcanStatusBit1Err = CAN_ESR1_BIT1_ERR_MASK, /*!< Bit0 Error flag. */
125 flexcanStatusBit0Err = CAN_ESR1_BIT0_ERR_MASK, /*!< Bit1 Error flag. */
126 flexcanStatusAckErr = CAN_ESR1_ACK_ERR_MASK, /*!< Ack Error flag. */
127 flexcanStatusCrcErr = CAN_ESR1_CRC_ERR_MASK, /*!< CRC Error flag. */
128 flexcanStatusFrameErr = CAN_ESR1_FRM_ERR_MASK, /*!< Frame Error flag. */
129 flexcanStatusStuffingErr = CAN_ESR1_STF_ERR_MASK, /*!< Stuffing Error flag. */
130 flexcanStatusTxWarning = CAN_ESR1_TX_WRN_MASK, /*!< Tx Warning flag. */
131 flexcanStatusRxWarning = CAN_ESR1_RX_WRN_MASK, /*!< Rx Warning flag. */
132 flexcanStatusIdle = CAN_ESR1_IDLE_MASK, /*!< FlexCAN Idle flag. */
133 flexcanStatusTransmitting = CAN_ESR1_TX_MASK, /*!< Trasmitting flag. */
134 flexcanStatusFltConf = CAN_ESR1_FLT_CONF_MASK, /*!< Fault Config flag. */
135 flexcanStatusReceiving = CAN_ESR1_RX_MASK, /*!< Receiving flag. */
136 flexcanStatusBusOff = CAN_ESR1_BOFF_INT_MASK, /*!< Bus Off interrupt flag. */
137 flexcanStatusError = CAN_ESR1_ERR_INT_MASK, /*!< Error interrupt flag. */
138 flexcanStatusWake = CAN_ESR1_WAK_INT_MASK, /*!< Wake Up interrupt flag. */
139 };
140
141 /*! @brief The id filter element type selection. */
142 enum _flexcan_rx_fifo_id_element_format
143 {
144 flexcanRxFifoIdElementFormatA = 0x0, /*!< One full ID (standard and extended) per ID Filter Table element. */
145 flexcanRxFifoIdElementFormatB = 0x1, /*!< Two full standard IDs or two partial 14-bit (standard and extended) IDs per ID Filter Table element. */
146 flexcanRxFifoIdElementFormatC = 0x2, /*!< Four partial 8-bit Standard IDs per ID Filter Table element. */
147 flexcanRxFifoIdElementFormatD = 0x3, /*!< All frames rejected. */
148 };
149
150 /*! @brief FlexCAN Rx FIFO filters number. */
151 enum _flexcan_rx_fifo_filter_id_number
152 {
153 flexcanRxFifoIdFilterNum8 = 0x0, /*!< 8 Rx FIFO Filters. @internal gui name="8 Rx FIFO Filters" */
154 flexcanRxFifoIdFilterNum16 = 0x1, /*!< 16 Rx FIFO Filters. @internal gui name="16 Rx FIFO Filters" */
155 flexcanRxFifoIdFilterNum24 = 0x2, /*!< 24 Rx FIFO Filters. @internal gui name="24 Rx FIFO Filters" */
156 flexcanRxFifoIdFilterNum32 = 0x3, /*!< 32 Rx FIFO Filters. @internal gui name="32 Rx FIFO Filters" */
157 flexcanRxFifoIdFilterNum40 = 0x4, /*!< 40 Rx FIFO Filters. @internal gui name="40 Rx FIFO Filters" */
158 flexcanRxFifoIdFilterNum48 = 0x5, /*!< 48 Rx FIFO Filters. @internal gui name="48 Rx FIFO Filters" */
159 flexcanRxFifoIdFilterNum56 = 0x6, /*!< 56 Rx FIFO Filters. @internal gui name="56 Rx FIFO Filters" */
160 flexcanRxFifoIdFilterNum64 = 0x7, /*!< 64 Rx FIFO Filters. @internal gui name="64 Rx FIFO Filters" */
161 flexcanRxFifoIdFilterNum72 = 0x8, /*!< 72 Rx FIFO Filters. @internal gui name="72 Rx FIFO Filters" */
162 flexcanRxFifoIdFilterNum80 = 0x9, /*!< 80 Rx FIFO Filters. @internal gui name="80 Rx FIFO Filters" */
163 flexcanRxFifoIdFilterNum88 = 0xA, /*!< 88 Rx FIFO Filters. @internal gui name="88 Rx FIFO Filters" */
164 flexcanRxFifoIdFilterNum96 = 0xB, /*!< 96 Rx FIFO Filters. @internal gui name="96 Rx FIFO Filters" */
165 flexcanRxFifoIdFilterNum104 = 0xC, /*!< 104 Rx FIFO Filters. @internal gui name="104 Rx FIFO Filters" */
166 flexcanRxFifoIdFilterNum112 = 0xD, /*!< 112 Rx FIFO Filters. @internal gui name="112 Rx FIFO Filters" */
167 flexcanRxFifoIdFilterNum120 = 0xE, /*!< 120 Rx FIFO Filters. @internal gui name="120 Rx FIFO Filters" */
168 flexcanRxFifoIdFilterNum128 = 0xF, /*!< 128 Rx FIFO Filters. @internal gui name="128 Rx FIFO Filters" */
169 };
170
171 /*! @brief FlexCAN RX FIFO ID filter table structure. */
172 typedef struct _flexcan_id_table
173 {
174 uint32_t *idFilter; /*!< Rx FIFO ID filter elements. */
175 bool isRemoteFrame; /*!< Remote frame. */
176 bool isExtendedFrame; /*!< Extended frame. */
177 } flexcan_id_table_t;
178
179 /*! @brief FlexCAN message buffer structure. */
180 typedef struct _flexcan_msgbuf
181 {
182 union
183 {
184 uint32_t cs; /*!< Code and Status. */
185 struct
186 {
187 uint32_t timeStamp : 16;
188 uint32_t dlc : 4;
189 uint32_t rtr : 1;
190 uint32_t ide : 1;
191 uint32_t srr : 1;
192 uint32_t reserved1 : 1;
193 uint32_t code : 4;
194 uint32_t reserved2 : 4;
195 };
196 };
197
198 union
199 {
200 uint32_t id; /*!< Message Buffer ID. */
201 struct
202 {
203 uint32_t idExt : 18;
204 uint32_t idStd : 11;
205 uint32_t prio : 3;
206 };
207 };
208
209 union
210 {
211 uint32_t word0; /*!< Bytes of the FlexCAN message. */
212 struct
213 {
214 uint8_t data3;
215 uint8_t data2;
216 uint8_t data1;
217 uint8_t data0;
218 };
219 };
220
221 union
222 {
223 uint32_t word1; /*!< Bytes of the FlexCAN message. */
224 struct
225 {
226 uint8_t data7;
227 uint8_t data6;
228 uint8_t data5;
229 uint8_t data4;
230 };
231 };
232 } flexcan_msgbuf_t;
233
234 /*! @brief FlexCAN timing-related structures. */
235 typedef struct _flexcan_timing
236 {
237 uint32_t preDiv; /*!< Clock pre divider. */
238 uint32_t rJumpwidth; /*!< Resync jump width. */
239 uint32_t phaseSeg1; /*!< Phase segment 1. */
240 uint32_t phaseSeg2; /*!< Phase segment 2. */
241 uint32_t propSeg; /*!< Propagation segment. */
242 } flexcan_timing_t;
243
244 /*! @brief FlexCAN module initialization structure. */
245 typedef struct _flexcan_init_config
246 {
247 flexcan_timing_t timing; /*!< Desired FlexCAN module timing configuration. */
248 uint32_t operatingMode; /*!< Desired FlexCAN module operating mode. */
249 uint8_t maxMsgBufNum; /*!< The maximal number of available message buffer. */
250 } flexcan_init_config_t;
251
252 /*******************************************************************************
253 * API
254 ******************************************************************************/
255
256 #if defined(__cplusplus)
257 extern "C" {
258 #endif
259
260 /*!
261 * @name FlexCAN Initialization and Configuration functions
262 * @{
263 */
264
265 /*!
266 * @brief Initialize FlexCAN module with given initialization structure.
267 *
268 * @param base CAN base pointer.
269 * @param initConfig CAN initialization structure (see @ref flexcan_init_config_t structure).
270 */
271 void FLEXCAN_Init(CAN_Type* base, const flexcan_init_config_t* initConfig);
272
273 /*!
274 * @brief This function reset FlexCAN module register content to its default value.
275 *
276 * @param base FlexCAN base pointer.
277 */
278 void FLEXCAN_Deinit(CAN_Type* base);
279
280 /*!
281 * @brief This function is used to Enable the FlexCAN Module.
282 *
283 * @param base FlexCAN base pointer.
284 */
285 void FLEXCAN_Enable(CAN_Type* base);
286
287 /*!
288 * @brief This function is used to Disable the FlexCAN Module.
289 *
290 * @param base FlexCAN base pointer.
291 */
292 void FLEXCAN_Disable(CAN_Type* base);
293
294 /*!
295 * @brief Sets the FlexCAN time segments for setting up bit rate.
296 *
297 * @param base FlexCAN base pointer.
298 * @param timing FlexCAN time segments, which need to be set for the bit rate (See @ref flexcan_timing_t structure).
299 */
300 void FLEXCAN_SetTiming(CAN_Type* base, const flexcan_timing_t* timing);
301
302 /*!
303 * @brief Set operation mode.
304 *
305 * @param base FlexCAN base pointer.
306 * @param mode Set an operation mode.
307 */
308 void FLEXCAN_SetOperatingMode(CAN_Type* base, uint8_t mode);
309
310 /*!
311 * @brief Set the maximum number of Message Buffers.
312 *
313 * @param base FlexCAN base pointer.
314 * @param bufNum Maximum number of message buffers.
315 */
316 void FLEXCAN_SetMaxMsgBufNum(CAN_Type* base, uint32_t bufNum);
317
318 /*!
319 * @brief Get the working status of FlexCAN module.
320 *
321 * @param base FlexCAN base pointer.
322 * @return - true: FLEXCAN module is either in Normal Mode, Listen-Only Mode or Loop-Back Mode.
323 * - false: FLEXCAN module is either in Disable Mode, Stop Mode or Freeze Mode.
324 */
FLEXCAN_IsModuleReady(CAN_Type * base)325 static inline bool FLEXCAN_IsModuleReady(CAN_Type* base)
326 {
327 return !((CAN_MCR_REG(base) >> CAN_MCR_NOT_RDY_SHIFT) & 0x1);
328 }
329
330 /*!
331 * @brief Set the Transmit Abort feature enablement.
332 *
333 * @param base FlexCAN base pointer.
334 * @param enable Enable/Disable Transmit Abort feature.
335 * - true: Enable Transmit Abort feature.
336 * - false: Disable Transmit Abort feature.
337 */
338 void FLEXCAN_SetAbortCmd(CAN_Type* base, bool enable);
339
340 /*!
341 * @brief Set the local transmit priority enablement.
342 *
343 * @param base FlexCAN base pointer.
344 * @param enable Enable/Disable local transmit periority.
345 * - true: Transmit MB with highest local priority.
346 * - false: Transmit MB with lowest MB number.
347 */
348 void FLEXCAN_SetLocalPrioCmd(CAN_Type* base, bool enable);
349
350 /*!
351 * @brief Set the Rx matching process priority.
352 *
353 * @param base FlexCAN base pointer.
354 * @param priority Set Rx matching process priority.
355 * - true: Matching starts from Mailboxes and continues on Rx FIFO.
356 * - false: Matching starts from Rx FIFO and continues on Mailboxes.
357 */
358 void FLEXCAN_SetMatchPrioCmd(CAN_Type* base, bool priority);
359
360 /*@}*/
361
362 /*!
363 * @name FlexCAN Message buffer control functions
364 * @{
365 */
366
367 /*!
368 * @brief Get message buffer pointer for transition.
369 *
370 * @param base FlexCAN base pointer.
371 * @param msgBufIdx message buffer index.
372 * @return message buffer pointer.
373 */
374 flexcan_msgbuf_t* FLEXCAN_GetMsgBufPtr(CAN_Type* base, uint8_t msgBufIdx);
375
376 /*!
377 * @brief Locks the FlexCAN Rx message buffer.
378 *
379 * @param base FlexCAN base pointer.
380 * @param msgBufIdx Index of the message buffer
381 * @return - true: Lock Rx Message Buffer successful.
382 * - false: Lock Rx Message Buffer failed.
383 */
384 bool FLEXCAN_LockRxMsgBuf(CAN_Type* base, uint8_t msgBufIdx);
385
386 /*!
387 * @brief Unlocks the FlexCAN Rx message buffer.
388 *
389 * @param base FlexCAN base pointer.
390 * @return current free run timer counter value.
391 */
392 uint16_t FLEXCAN_UnlockAllRxMsgBuf(CAN_Type* base);
393
394 /*@}*/
395
396 /*!
397 * @name FlexCAN Interrupts and flags management functions
398 * @{
399 */
400
401 /*!
402 * @brief Enables/Disables the FlexCAN Message Buffer interrupt.
403 *
404 * @param base FlexCAN base pointer.
405 * @param msgBufIdx Index of the message buffer.
406 * @param enable Enables/Disables interrupt.
407 * - true: Enable Message Buffer interrupt.
408 * - disable: Disable Message Buffer interrupt.
409 */
410 void FLEXCAN_SetMsgBufIntCmd(CAN_Type* base, uint8_t msgBufIdx, bool enable);
411
412 /*!
413 * @brief Gets the individual FlexCAN MB interrupt flag.
414 *
415 * @param base FlexCAN base pointer.
416 * @param msgBufIdx Index of the message buffer.
417 * @retval true: Message Buffer Interrupt is pending.
418 * @retval false: There is no Message Buffer Interrupt.
419 */
420 bool FLEXCAN_GetMsgBufStatusFlag(CAN_Type* base, uint8_t msgBufIdx);
421
422 /*!
423 * @brief Clears the interrupt flag of the message buffers.
424 *
425 * @param base FlexCAN base pointer.
426 * @param msgBufIdx Index of the message buffer.
427 */
428 void FLEXCAN_ClearMsgBufStatusFlag(CAN_Type* base, uint32_t msgBufIdx);
429
430 /*!
431 * @brief Enables error interrupt of the FlexCAN module.
432 *
433 * @param base FlexCAN base pointer.
434 * @param errorSrc The interrupt source (see @ref _flexcan_interrutpt enumeration).
435 * @param enable Choose enable or disable.
436 */
437 void FLEXCAN_SetErrIntCmd(CAN_Type* base, uint32_t errorSrc, bool enable);
438
439 /*!
440 * @brief Gets the FlexCAN module interrupt flag.
441 *
442 * @param base FlexCAN base pointer.
443 * @param errFlags FlexCAN error flags (see @ref _flexcan_status_flag enumeration).
444 * @return The individual Message Buffer interrupt flag (0 and 1 are the flag value)
445 */
446 uint32_t FLEXCAN_GetErrStatusFlag(CAN_Type* base, uint32_t errFlags);
447
448 /*!
449 * @brief Clears the interrupt flag of the FlexCAN module.
450 *
451 * @param base FlexCAN base pointer.
452 * @param errFlags The value to be written to the interrupt flag1 register (see @ref _flexcan_status_flag enumeration).
453 */
454 void FLEXCAN_ClearErrStatusFlag(CAN_Type* base, uint32_t errFlags);
455
456 /*!
457 * @brief Get the error counter of FlexCAN module.
458 *
459 * @param base FlexCAN base pointer.
460 * @param txError Tx_Err_Counter pointer.
461 * @param rxError Rx_Err_Counter pointer.
462 */
463 void FLEXCAN_GetErrCounter(CAN_Type* base, uint8_t* txError, uint8_t* rxError);
464
465 /*@}*/
466
467 /*!
468 * @name Rx FIFO management functions
469 * @{
470 */
471
472 /*!
473 * @brief Enables the Rx FIFO.
474 *
475 * @param base FlexCAN base pointer.
476 * @param numOfFilters The number of Rx FIFO filters
477 */
478 void FLEXCAN_EnableRxFifo(CAN_Type* base, uint8_t numOfFilters);
479
480 /*!
481 * @brief Disables the Rx FIFO.
482 *
483 * @param base FlexCAN base pointer.
484 */
485 void FLEXCAN_DisableRxFifo(CAN_Type* base);
486
487 /*!
488 * @brief Set the number of the Rx FIFO filters.
489 *
490 * @param base FlexCAN base pointer.
491 * @param numOfFilters The number of Rx FIFO filters.
492 */
493 void FLEXCAN_SetRxFifoFilterNum(CAN_Type* base, uint32_t numOfFilters);
494
495 /*!
496 * @brief Set the FlexCAN Rx FIFO fields.
497 *
498 * @param base FlexCAN base pointer.
499 * @param idFormat The format of the Rx FIFO ID Filter Table Elements
500 * @param idFilterTable The ID filter table elements which contain RTR bit, IDE bit and RX message ID.
501 */
502 void FLEXCAN_SetRxFifoFilter(CAN_Type* base, uint32_t idFormat, flexcan_id_table_t *idFilterTable);
503
504 /*!
505 * @brief Gets the FlexCAN Rx FIFO data pointer.
506 *
507 * @param base FlexCAN base pointer.
508 * @return Rx FIFO data pointer.
509 */
510 flexcan_msgbuf_t* FLEXCAN_GetRxFifoPtr(CAN_Type* base);
511
512 /*!
513 * @brief Gets the FlexCAN Rx FIFO information.
514 * The return value indicates which Identifier Acceptance Filter
515 * (see Rx FIFO Structure) was hit by the received message.
516 * @param base FlexCAN base pointer.
517 * @return Rx FIFO filter number.
518 */
519 uint16_t FLEXCAN_GetRxFifoInfo(CAN_Type* base);
520
521 /*@}*/
522
523 /*!
524 * @name Rx Mask Setting functions
525 * @{
526 */
527
528 /*!
529 * @brief Set the Rx masking mode.
530 *
531 * @param base FlexCAN base pointer.
532 * @param mode The FlexCAN Rx mask mode (see @ref _flexcan_rx_mask_mode enumeration).
533 */
534 void FLEXCAN_SetRxMaskMode(CAN_Type* base, uint32_t mode);
535
536 /*!
537 * @brief Set the remote trasmit request mask enablement.
538 *
539 * @param base FlexCAN base pointer.
540 * @param enable Enable/Disable remote trasmit request mask.
541 * - true: Enable RTR matching judgement.
542 * - false: Disable RTR matching judgement.
543 */
544 void FLEXCAN_SetRxMaskRtrCmd(CAN_Type* base, bool enable);
545
546 /*!
547 * @brief Set the FlexCAN RX global mask.
548 *
549 * @param base FlexCAN base pointer.
550 * @param mask Rx Global mask.
551 */
552 void FLEXCAN_SetRxGlobalMask(CAN_Type* base, uint32_t mask);
553
554 /*!
555 * @brief Set the FlexCAN Rx individual mask for ID filtering in the Rx MBs and the Rx FIFO.
556 *
557 * @param base FlexCAN base pointer.
558 * @param msgBufIdx Index of the message buffer.
559 * @param mask Individual mask
560 */
561 void FLEXCAN_SetRxIndividualMask(CAN_Type* base, uint32_t msgBufIdx, uint32_t mask);
562
563 /*!
564 * @brief Set the FlexCAN RX Message Buffer BUF14 mask.
565 *
566 * @param base FlexCAN base pointer.
567 * @param mask Message Buffer BUF14 mask.
568 */
569 void FLEXCAN_SetRxMsgBuff14Mask(CAN_Type* base, uint32_t mask);
570
571 /*!
572 * @brief Set the FlexCAN RX Message Buffer BUF15 mask.
573 *
574 * @param base FlexCAN base pointer.
575 * @param mask Message Buffer BUF15 mask.
576 */
577 void FLEXCAN_SetRxMsgBuff15Mask(CAN_Type* base, uint32_t mask);
578
579 /*!
580 * @brief Set the FlexCAN RX Fifo global mask.
581 *
582 * @param base FlexCAN base pointer.
583 * @param mask Rx Fifo Global mask.
584 */
585 void FLEXCAN_SetRxFifoGlobalMask(CAN_Type* base, uint32_t mask);
586
587 /*@}*/
588
589 /*!
590 * @name Misc. Functions
591 * @{
592 */
593
594 /*!
595 * @brief Enable/disable the FlexCAN self wakeup feature.
596 *
597 * @param base FlexCAN base pointer.
598 * @param lpfEnable The low pass filter for Rx self wakeup feature enablement.
599 * @param enable The self wakeup feature enablement.
600 */
601 void FLEXCAN_SetSelfWakeUpCmd(CAN_Type* base, bool lpfEnable, bool enable);
602
603 /*!
604 * @brief Enable/Disable the FlexCAN self reception feature.
605 *
606 * @param base FlexCAN base pointer.
607 * @param enable Enable/Disable self reception feature.
608 * - true: Enable self reception feature.
609 * - false: Disable self reception feature.
610 */
611 void FLEXCAN_SetSelfReceptionCmd(CAN_Type* base, bool enable);
612
613 /*!
614 * @brief Enable/disable the enhance FlexCAN Rx vote.
615 *
616 * @param base FlexCAN base pointer.
617 * @param enable Enable/Disable FlexCAN Rx vote mechanism
618 * - true: Three samples are used to determine the value of the received bit.
619 * - false: Just one sample is used to determine the bit value.
620 */
621 void FLEXCAN_SetRxVoteCmd(CAN_Type* base, bool enable);
622
623 /*!
624 * @brief Enable/disable the Auto Busoff recover feature.
625 *
626 * @param base FlexCAN base pointer.
627 * @param enable Enable/Disable Auto Busoff Recover
628 * - true: Enable Auto Bus Off recover feature.
629 * - false: Disable Auto Bus Off recover feature.
630 */
631 void FLEXCAN_SetAutoBusOffRecoverCmd(CAN_Type* base, bool enable);
632
633 /*!
634 * @brief Enable/disable the Time Sync feature.
635 *
636 * @param base FlexCAN base pointer.
637 * @param enable Enable/Disable the Time Sync
638 * - true: Enable Time Sync feature.
639 * - false: Disable Time Sync feature.
640 */
641 void FLEXCAN_SetTimeSyncCmd(CAN_Type* base, bool enable);
642
643 /*!
644 * @brief Enable/disable the Auto Remote Response feature.
645 *
646 * @param base FlexCAN base pointer.
647 * @param enable Enable/Disable the Auto Remote Response feature
648 * - true: Enable Auto Remote Response feature.
649 * - false: Disable Auto Remote Response feature.
650 */
651 void FLEXCAN_SetAutoRemoteResponseCmd(CAN_Type* base, bool enable);
652
653 /*!
654 * @brief Enable/disable the Glitch Filter Width when FLEXCAN enters the STOP mode.
655 *
656 * @param base FlexCAN base pointer.
657 * @param filterWidth The Glitch Filter Width.
658 */
FLEXCAN_SetGlitchFilterWidth(CAN_Type * base,uint8_t filterWidth)659 static inline void FLEXCAN_SetGlitchFilterWidth(CAN_Type* base, uint8_t filterWidth)
660 {
661 CAN_GFWR_REG(base) = filterWidth;
662 }
663
664 /*!
665 * @brief Get the lowest inactive message buffer number.
666 *
667 * @param base FlexCAN base pointer.
668 * @return bit 22-16 : The lowest number inactive Mailbox.
669 * bit 14 : Indicates whether the number content is valid or not.
670 * bit 13 : This bit indicates whether there is any inactive Mailbox.
671 */
FLEXCAN_GetLowestInactiveMsgBuf(CAN_Type * base)672 static inline uint32_t FLEXCAN_GetLowestInactiveMsgBuf(CAN_Type* base)
673 {
674 return CAN_ESR2_REG(base);
675 }
676
677 /*!
678 * @brief Set the Tx Arbitration Start Delay number.
679 * This function is used to optimize the transmit performance.
680 * For more information about to set this value, see the Chip Reference Manual.
681 *
682 * @param base FlexCAN base pointer.
683 * @param tasd The lowest number inactive Mailbox.
684 */
FLEXCAN_SetTxArbitrationStartDelay(CAN_Type * base,uint8_t tasd)685 static inline void FLEXCAN_SetTxArbitrationStartDelay(CAN_Type* base, uint8_t tasd)
686 {
687 assert(tasd < 32);
688 CAN_CTRL2_REG(base) = (CAN_CTRL2_REG(base) & ~CAN_CTRL2_TASD_MASK) | CAN_CTRL2_TASD(tasd);
689 }
690
691 /*@}*/
692
693 #if defined(__cplusplus)
694 }
695 #endif
696
697 /*! @}*/
698
699 #if defined(__ARMCC_VERSION)
700 #pragma pop
701 #elif defined(__GNUC__)
702 /* leave anonymous unions enabled */
703 #elif defined(__IAR_SYSTEMS_ICC__)
704 #pragma language=default
705 #else
706 #error Not supported compiler type
707 #endif
708
709 #endif /* __FLEXCAN_H__ */
710 /*******************************************************************************
711 * EOF
712 ******************************************************************************/
713