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 #include "flexcan.h"
32 
33 /*******************************************************************************
34  * Definitions
35  ******************************************************************************/
36 
37 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATAB_RTR_SHIFT (31U)            /*! format A&B RTR mask.*/
38 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATAB_IDE_SHIFT (30U)            /*! format A&B IDE mask.*/
39 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_RTR_SHIFT  (15U)            /*! format B RTR-2 mask.*/
40 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_IDE_SHIFT  (14U)            /*! format B IDE-2 mask.*/
41 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATA_EXT_MASK   (0x3FFFFFFFU)    /*! format A extended mask.*/
42 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATA_EXT_SHIFT  (1U)             /*! format A extended shift.*/
43 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATA_STD_MASK   (0x3FF80000U)    /*! format A standard mask.*/
44 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATA_STD_SHIFT  (19U)            /*! format A standard shift.*/
45 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_EXT_MASK   (0x3FFFU)        /*! format B extended mask.*/
46 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_EXT_SHIFT1 (16U)            /*! format B extended mask.*/
47 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_EXT_SHIFT2 (0U)             /*! format B extended mask.*/
48 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_STD_MASK   (0x7FFU)         /*! format B standard mask.*/
49 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_STD_SHIFT1 (19U)            /*! format B standard shift1.*/
50 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_STD_SHIFT2 (3U)             /*! format B standard shift2.*/
51 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_MASK       (0xFFU)          /*! format C mask.*/
52 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_SHIFT1     (24U)            /*! format C shift1.*/
53 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_SHIFT2     (16U)            /*! format C shift2.*/
54 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_SHIFT3     (8U)             /*! format C shift3.*/
55 #define FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_SHIFT4     (0U)             /*! format C shift4.*/
56 #define FLEXCAN_BYTE_DATA_FIELD_MASK                 (0xFFU)          /*! masks for byte data field.*/
57 #define RxFifoFilterElementNum(x)                    ((x + 1) * 8)
58 
59 /*******************************************************************************
60  * Code
61  ******************************************************************************/
62 
63 /*******************************************************************************
64  * FLEXCAN Freeze control function
65  ******************************************************************************/
66 /*FUNCTION**********************************************************************
67  *
68  * Function Name : FLEXCAN_EnterFreezeMode
69  * Description   : Set FlexCAN module enter freeze mode.
70  *
71  *END**************************************************************************/
FLEXCAN_EnterFreezeMode(CAN_Type * base)72 static void FLEXCAN_EnterFreezeMode(CAN_Type* base)
73 {
74     /* Set Freeze, Halt */
75     CAN_MCR_REG(base) |= CAN_MCR_FRZ_MASK;
76     CAN_MCR_REG(base) |= CAN_MCR_HALT_MASK;
77     /* Wait for entering the freeze mode */
78     while (!(CAN_MCR_REG(base) & CAN_MCR_FRZ_ACK_MASK));
79 }
80 
81 /*FUNCTION**********************************************************************
82  *
83  * Function Name : FLEXCAN_ExitFreezeMode
84  * Description   : Set FlexCAN module exit freeze mode.
85  *
86  *END**************************************************************************/
FLEXCAN_ExitFreezeMode(CAN_Type * base)87 static void FLEXCAN_ExitFreezeMode(CAN_Type* base)
88 {
89     /* De-assert Freeze Mode */
90     CAN_MCR_REG(base) &= ~CAN_MCR_HALT_MASK;
91     CAN_MCR_REG(base) &= ~CAN_MCR_FRZ_MASK;
92     /* Wait for exit the freeze mode */
93     while (CAN_MCR_REG(base) & CAN_MCR_FRZ_ACK_MASK);
94 }
95 
96 /*******************************************************************************
97  * FlexCAN Initialization and Configuration functions
98  ******************************************************************************/
99 /*FUNCTION**********************************************************************
100  *
101  * Function Name : FLEXCAN_Init
102  * Description   : Initialize Flexcan module with given initialize structure.
103  *
104  *END**************************************************************************/
FLEXCAN_Init(CAN_Type * base,const flexcan_init_config_t * initConfig)105 void FLEXCAN_Init(CAN_Type* base, const flexcan_init_config_t* initConfig)
106 {
107     assert(initConfig);
108 
109     /* Enable Flexcan module */
110     FLEXCAN_Enable(base);
111 
112     /* Reset Flexcan module register content to default value */
113     FLEXCAN_Deinit(base);
114 
115     /* Set maximum MessageBox numbers and
116      * Initialize all message buffers as inactive
117      */
118     FLEXCAN_SetMaxMsgBufNum(base, initConfig->maxMsgBufNum);
119 
120     /* Initialize Flexcan module timing character */
121     FLEXCAN_SetTiming(base, &initConfig->timing);
122 
123     /* Set desired operating mode */
124     FLEXCAN_SetOperatingMode(base, initConfig->operatingMode);
125 
126     /* Disable Flexcan module */
127     FLEXCAN_Disable(base);
128 }
129 
130 /*FUNCTION**********************************************************************
131  *
132  * Function Name : FLEXCAN_Deinit
133  * Description   : This function reset Flexcan module register content to its
134  *                 default value.
135  *
136  *END**************************************************************************/
FLEXCAN_Deinit(CAN_Type * base)137 void FLEXCAN_Deinit(CAN_Type* base)
138 {
139     uint32_t i;
140 
141     /* Reset the FLEXCAN module */
142     CAN_MCR_REG(base) |= CAN_MCR_SOFT_RST_MASK;
143     /* Wait for reset cycle to complete */
144     while (CAN_MCR_REG(base) & CAN_MCR_SOFT_RST_MASK);
145 
146     /* Assert Flexcan module Freeze */
147     FLEXCAN_EnterFreezeMode(base);
148 
149     /* Reset CTRL1 Register */
150     CAN_CTRL1_REG(base) = 0x0;
151 
152     /* Reset CTRL2 Register */
153     CAN_CTRL2_REG(base) = 0x0;
154 
155     /* Reset All Message Buffer Content */
156     for (i = 0; i < CAN_CS_COUNT; i++)
157     {
158         base->MB[i].CS = 0x0;
159         base->MB[i].ID = 0x0;
160         base->MB[i].WORD0 = 0x0;
161         base->MB[i].WORD1 = 0x0;
162     }
163 
164     /* Reset Rx Individual Mask */
165     for (i = 0; i < CAN_RXIMR_COUNT; i++)
166         CAN_RXIMR_REG(base, i) = 0x0;
167 
168     /* Reset Rx Mailboxes Global Mask */
169     CAN_RXMGMASK_REG(base) = 0xFFFFFFFF;
170 
171     /* Reset Rx Buffer 14 Mask */
172     CAN_RX14MASK_REG(base) = 0xFFFFFFFF;
173 
174     /* Reset Rx Buffer 15 Mask */
175     CAN_RX15MASK_REG(base) = 0xFFFFFFFF;
176 
177     /* Rx FIFO Global Mask */
178     CAN_RXFGMASK_REG(base) = 0xFFFFFFFF;
179 
180     /* Disable all MB interrupts */
181     CAN_IMASK1_REG(base) = 0x0;
182     CAN_IMASK2_REG(base) = 0x0;
183 
184     // Clear all MB interrupt flags
185     CAN_IFLAG1_REG(base) = 0xFFFFFFFF;
186     CAN_IFLAG2_REG(base) = 0xFFFFFFFF;
187 
188     // Clear all Error interrupt flags
189     CAN_ESR1_REG(base) = 0xFFFFFFFF;
190 
191     /* De-assert Freeze Mode */
192     FLEXCAN_ExitFreezeMode(base);
193 }
194 
195 /*FUNCTION**********************************************************************
196  *
197  * Function Name : FLEXCAN_Enable
198  * Description   : This function is used to Enable the Flexcan Module.
199  *
200  *END**************************************************************************/
FLEXCAN_Enable(CAN_Type * base)201 void FLEXCAN_Enable(CAN_Type* base)
202 {
203     /* Enable clock */
204     CAN_MCR_REG(base) &= ~CAN_MCR_MDIS_MASK;
205     /* Wait until enabled */
206     while (CAN_MCR_REG(base) & CAN_MCR_LPM_ACK_MASK);
207 }
208 
209 /*FUNCTION**********************************************************************
210  *
211  * Function Name : FLEXCAN_Disable
212  * Description   : This function is used to Disable the CAN Module.
213  *
214  *END**************************************************************************/
FLEXCAN_Disable(CAN_Type * base)215 void FLEXCAN_Disable(CAN_Type* base)
216 {
217     /* Disable clock*/
218     CAN_MCR_REG(base) |= CAN_MCR_MDIS_MASK;
219     /* Wait until disabled */
220     while (!(CAN_MCR_REG(base) & CAN_MCR_LPM_ACK_MASK));
221 }
222 
223 /*FUNCTION**********************************************************************
224  *
225  * Function Name : FLEXCAN_SetTiming
226  * Description   : Sets the FlexCAN time segments for setting up bit rate.
227  *
228  *END**************************************************************************/
FLEXCAN_SetTiming(CAN_Type * base,const flexcan_timing_t * timing)229 void FLEXCAN_SetTiming(CAN_Type* base, const flexcan_timing_t* timing)
230 {
231     assert(timing);
232 
233     /* Assert Flexcan module Freeze */
234     FLEXCAN_EnterFreezeMode(base);
235 
236     /* Set Flexcan module Timing Character */
237     CAN_CTRL1_REG(base) &= ~(CAN_CTRL1_PRESDIV_MASK | \
238                              CAN_CTRL1_RJW_MASK     | \
239                              CAN_CTRL1_PSEG1_MASK   | \
240                              CAN_CTRL1_PSEG2_MASK   | \
241                              CAN_CTRL1_PROP_SEG_MASK);
242     CAN_CTRL1_REG(base) |= (CAN_CTRL1_PRESDIV(timing->preDiv)  | \
243                             CAN_CTRL1_RJW(timing->rJumpwidth)  | \
244                             CAN_CTRL1_PSEG1(timing->phaseSeg1) | \
245                             CAN_CTRL1_PSEG2(timing->phaseSeg2) | \
246                             CAN_CTRL1_PROP_SEG(timing->propSeg));
247 
248     /* De-assert Freeze Mode */
249     FLEXCAN_ExitFreezeMode(base);
250 }
251 
252 /*FUNCTION**********************************************************************
253  *
254  * Function Name : FLEXCAN_SetOperatingMode
255  * Description   : Set operation mode.
256  *
257  *END**************************************************************************/
FLEXCAN_SetOperatingMode(CAN_Type * base,uint8_t mode)258 void FLEXCAN_SetOperatingMode(CAN_Type* base, uint8_t mode)
259 {
260     assert((mode & flexcanNormalMode) ||
261            (mode & flexcanListenOnlyMode) ||
262            (mode & flexcanLoopBackMode));
263 
264     /* Assert Freeze mode*/
265     FLEXCAN_EnterFreezeMode(base);
266 
267     if (mode & flexcanNormalMode)
268         CAN_MCR_REG(base) &= ~CAN_MCR_SUPV_MASK;
269     else
270         CAN_MCR_REG(base) |= CAN_MCR_SUPV_MASK;
271 
272     if (mode & flexcanListenOnlyMode)
273         CAN_CTRL1_REG(base) |= CAN_CTRL1_LOM_MASK;
274     else
275         CAN_CTRL1_REG(base) &= ~CAN_CTRL1_LOM_MASK;
276 
277     if (mode & flexcanLoopBackMode)
278         CAN_CTRL1_REG(base) |= CAN_CTRL1_LPB_MASK;
279     else
280         CAN_CTRL1_REG(base) &= ~CAN_CTRL1_LPB_MASK;
281 
282     /* De-assert Freeze Mode */
283     FLEXCAN_ExitFreezeMode(base);
284 }
285 
286 /*FUNCTION**********************************************************************
287  *
288  * Function Name : FLEXCAN_SetMaxMsgBufNum
289  * Description   : Set the maximum number of Message Buffers.
290  *
291  *END**************************************************************************/
FLEXCAN_SetMaxMsgBufNum(CAN_Type * base,uint32_t bufNum)292 void FLEXCAN_SetMaxMsgBufNum(CAN_Type* base, uint32_t bufNum)
293 {
294     assert((bufNum <= CAN_CS_COUNT) && (bufNum > 0));
295 
296     /* Assert Freeze mode*/
297     FLEXCAN_EnterFreezeMode(base);
298 
299     /* Set the maximum number of MBs*/
300     CAN_MCR_REG(base) = (CAN_MCR_REG(base) & (~CAN_MCR_MAXMB_MASK)) | CAN_MCR_MAXMB(bufNum-1);
301 
302     /* De-assert Freeze Mode*/
303     FLEXCAN_ExitFreezeMode(base);
304 }
305 
306 /*FUNCTION**********************************************************************
307  *
308  * Function Name : FLEXCAN_SetAbortCmd
309  * Description   : Set the Transmit abort feature enablement.
310  *
311  *END**************************************************************************/
FLEXCAN_SetAbortCmd(CAN_Type * base,bool enable)312 void FLEXCAN_SetAbortCmd(CAN_Type* base, bool enable)
313 {
314     /* Assert Freeze mode*/
315     FLEXCAN_EnterFreezeMode(base);
316 
317     if (enable)
318         CAN_MCR_REG(base) |= CAN_MCR_AEN_MASK;
319     else
320         CAN_MCR_REG(base) &= ~CAN_MCR_AEN_MASK;
321 
322     /* De-assert Freeze Mode*/
323     FLEXCAN_ExitFreezeMode(base);
324 }
325 
326 /*FUNCTION**********************************************************************
327  *
328  * Function Name : FLEXCAN_SetLocalPrioCmd
329  * Description   : Set the local transmit priority enablement.
330  *
331  *END**************************************************************************/
FLEXCAN_SetLocalPrioCmd(CAN_Type * base,bool enable)332 void FLEXCAN_SetLocalPrioCmd(CAN_Type* base, bool enable)
333 {
334     /* Assert Freeze mode*/
335     FLEXCAN_EnterFreezeMode(base);
336 
337     if (enable)
338     {
339         CAN_MCR_REG(base) |= CAN_MCR_LPRIO_EN_MASK;
340         CAN_CTRL1_REG(base) &= ~CAN_CTRL1_LBUF_MASK;
341     }
342     else
343     {
344         CAN_CTRL1_REG(base) |= CAN_CTRL1_LBUF_MASK;
345         CAN_MCR_REG(base) &= ~CAN_MCR_LPRIO_EN_MASK;
346     }
347 
348     /* De-assert Freeze Mode*/
349     FLEXCAN_ExitFreezeMode(base);
350 }
351 
352 /*FUNCTION**********************************************************************
353  *
354  * Function Name : FLEXCAN_SetMatchPrioCmd
355  * Description   : Set the Rx matching process priority.
356  *
357  *END**************************************************************************/
FLEXCAN_SetMatchPrioCmd(CAN_Type * base,bool priority)358 void FLEXCAN_SetMatchPrioCmd(CAN_Type* base, bool priority)
359 {
360     /* Assert Freeze mode*/
361     FLEXCAN_EnterFreezeMode(base);
362 
363     if (priority)
364         CAN_CTRL2_REG(base) |= CAN_CTRL2_MRP_MASK;
365     else
366         CAN_CTRL2_REG(base) &= ~CAN_CTRL2_MRP_MASK;
367 
368     /* De-assert Freeze Mode*/
369     FLEXCAN_ExitFreezeMode(base);
370 }
371 
372 /*******************************************************************************
373  * FlexCAN Message buffer control functions
374  ******************************************************************************/
375 /*FUNCTION**********************************************************************
376  *
377  * Function Name : FLEXCAN_GetMsgBufPtr
378  * Description   : Get message buffer pointer for transition.
379  *
380  *END**************************************************************************/
FLEXCAN_GetMsgBufPtr(CAN_Type * base,uint8_t msgBufIdx)381 flexcan_msgbuf_t* FLEXCAN_GetMsgBufPtr(CAN_Type* base, uint8_t msgBufIdx)
382 {
383     assert(msgBufIdx < CAN_CS_COUNT);
384 
385     return (flexcan_msgbuf_t*) &base->MB[msgBufIdx];
386 }
387 
388 /*FUNCTION**********************************************************************
389  *
390  * Function Name : FLEXCAN_LockRxMsgBuf
391  * Description   : Locks the FlexCAN Rx message buffer.
392  *
393  *END**************************************************************************/
FLEXCAN_LockRxMsgBuf(CAN_Type * base,uint8_t msgBufIdx)394 bool FLEXCAN_LockRxMsgBuf(CAN_Type* base, uint8_t msgBufIdx)
395 {
396     volatile uint32_t temp;
397 
398     /* Check if the MB to be Locked is enabled */
399     if (msgBufIdx > (CAN_MCR_REG(base) & CAN_MCR_MAXMB_MASK))
400         return false;
401 
402     /* ARM Core read MB's CS to lock MB */
403     temp = base->MB[msgBufIdx].CS;
404 
405     /* Read temp itself to avoid ARMGCC warning */
406     temp++;
407 
408     return true;
409 }
410 
411 /*FUNCTION**********************************************************************
412  *
413  * Function Name : FLEXCAN_UnlockAllRxMsgBuf
414  * Description   : Unlocks the FlexCAN Rx message buffer.
415  *
416  *END**************************************************************************/
FLEXCAN_UnlockAllRxMsgBuf(CAN_Type * base)417 uint16_t FLEXCAN_UnlockAllRxMsgBuf(CAN_Type* base)
418 {
419     /* Read Free Running Timer to unlock all MessageBox */
420     return CAN_TIMER_REG(base);
421 }
422 
423 /*******************************************************************************
424  * FlexCAN Interrupts and flags management functions
425  ******************************************************************************/
426 /*FUNCTION**********************************************************************
427  *
428  * Function Name : FLEXCAN_SetMsgBufIntCmd
429  * Description   : Enables/Disables the FlexCAN Message Buffer interrupt.
430  *
431  *END**************************************************************************/
FLEXCAN_SetMsgBufIntCmd(CAN_Type * base,uint8_t msgBufIdx,bool enable)432 void FLEXCAN_SetMsgBufIntCmd(CAN_Type* base, uint8_t msgBufIdx, bool enable)
433 {
434     volatile uint32_t* interruptMaskPtr;
435     uint8_t index;
436 
437     assert(msgBufIdx < CAN_CS_COUNT);
438 
439     if (msgBufIdx > 0x31)
440     {
441         index = msgBufIdx - 32;
442         interruptMaskPtr = &base->IMASK2;
443     }
444     else
445     {
446         index = msgBufIdx;
447         interruptMaskPtr = &base->IMASK1;
448     }
449 
450     if (enable)
451         *interruptMaskPtr |= 0x1 << index;
452     else
453         *interruptMaskPtr &= ~(0x1 << index);
454 }
455 
456 /*FUNCTION**********************************************************************
457  *
458  * Function Name : FLEXCAN_GetMsgBufStatusFlag
459  * Description   : Gets the individual FlexCAN MB interrupt flag.
460  *
461  *END**************************************************************************/
FLEXCAN_GetMsgBufStatusFlag(CAN_Type * base,uint8_t msgBufIdx)462 bool FLEXCAN_GetMsgBufStatusFlag(CAN_Type* base, uint8_t msgBufIdx)
463 {
464     volatile uint32_t* interruptFlagPtr;
465     volatile uint8_t index;
466 
467     assert(msgBufIdx < CAN_CS_COUNT);
468 
469     if (msgBufIdx > 0x31)
470     {
471         index = msgBufIdx - 32;
472         interruptFlagPtr = &base->IFLAG2;
473     }
474     else
475     {
476         index = msgBufIdx;
477         interruptFlagPtr = &base->IFLAG1;
478     }
479 
480     return (bool)((*interruptFlagPtr >> index) & 0x1);
481 }
482 
483 /*FUNCTION**********************************************************************
484  *
485  * Function Name : FLEXCAN_ClearMsgBufStatusFlag
486  * Description   : Clears the interrupt flag of the message buffers.
487  *
488  *END**************************************************************************/
FLEXCAN_ClearMsgBufStatusFlag(CAN_Type * base,uint32_t msgBufIdx)489 void FLEXCAN_ClearMsgBufStatusFlag(CAN_Type* base, uint32_t msgBufIdx)
490 {
491     volatile uint8_t index;
492 
493     assert(msgBufIdx < CAN_CS_COUNT);
494 
495     if (msgBufIdx > 0x31)
496     {
497         index = msgBufIdx - 32;
498         /* write 1 to clear. */
499         base->IFLAG2 = 0x1 << index;
500     }
501     else
502     {
503         index = msgBufIdx;
504         /* write 1 to clear. */
505         base->IFLAG1 = 0x1 << index;
506     }
507 }
508 
509 /*FUNCTION**********************************************************************
510  *
511  * Function Name : FLEXCAN_SetErrIntCmd
512  * Description   : Enables error interrupt of the FlexCAN module.
513  *
514  *END**************************************************************************/
FLEXCAN_SetErrIntCmd(CAN_Type * base,uint32_t errorType,bool enable)515 void FLEXCAN_SetErrIntCmd(CAN_Type* base, uint32_t errorType, bool enable)
516 {
517     assert((errorType & flexcanIntRxWarning) ||
518            (errorType & flexcanIntTxWarning) ||
519            (errorType & flexcanIntWakeUp) ||
520            (errorType & flexcanIntBusOff) ||
521            (errorType & flexcanIntError));
522 
523     if (enable)
524     {
525         if (errorType & flexcanIntRxWarning)
526         {
527             CAN_MCR_REG(base) |= CAN_MCR_WRN_EN_MASK;
528             CAN_CTRL1_REG(base) |= CAN_CTRL1_RWRN_MSK_MASK;
529         }
530 
531         if (errorType & flexcanIntTxWarning)
532         {
533             CAN_MCR_REG(base) |= CAN_MCR_WRN_EN_MASK;
534             CAN_CTRL1_REG(base) |= CAN_CTRL1_TWRN_MSK_MASK;
535         }
536 
537         if (errorType & flexcanIntWakeUp)
538             CAN_MCR_REG(base) |= CAN_MCR_WAK_MSK_MASK;
539 
540         if (errorType & flexcanIntBusOff)
541             CAN_CTRL1_REG(base) |= CAN_CTRL1_BOFF_MSK_MASK;
542 
543         if (errorType & flexcanIntError)
544             CAN_CTRL1_REG(base) |= CAN_CTRL1_ERR_MSK_MASK;
545     }
546     else
547     {
548         if (errorType & flexcanIntRxWarning)
549             CAN_CTRL1_REG(base) &= ~CAN_CTRL1_RWRN_MSK_MASK;
550 
551         if (errorType & flexcanIntTxWarning)
552             CAN_CTRL1_REG(base) &= ~CAN_CTRL1_TWRN_MSK_MASK;
553 
554         if (errorType & flexcanIntWakeUp)
555             CAN_MCR_REG(base) &= ~CAN_MCR_WAK_MSK_MASK;
556 
557         if (errorType & flexcanIntBusOff)
558             CAN_CTRL1_REG(base) &= ~CAN_CTRL1_BOFF_MSK_MASK;
559 
560         if (errorType & flexcanIntError)
561             CAN_CTRL1_REG(base) &= ~CAN_CTRL1_ERR_MSK_MASK;
562     }
563 }
564 
565 /*FUNCTION**********************************************************************
566  *
567  * Function Name : FLEXCAN_GetErrStatusFlag
568  * Description   : Gets the FlexCAN module interrupt flag.
569  *
570  *END**************************************************************************/
FLEXCAN_GetErrStatusFlag(CAN_Type * base,uint32_t errFlags)571 uint32_t FLEXCAN_GetErrStatusFlag(CAN_Type* base, uint32_t errFlags)
572 {
573     return CAN_ESR1_REG(base) & errFlags;
574 }
575 
576 /*FUNCTION**********************************************************************
577  *
578  * Function Name : FLEXCAN_ClearErrStatusFlag
579  * Description   : Clears the interrupt flag of the FlexCAN module.
580  *
581  *END**************************************************************************/
FLEXCAN_ClearErrStatusFlag(CAN_Type * base,uint32_t errorType)582 void FLEXCAN_ClearErrStatusFlag(CAN_Type* base, uint32_t errorType)
583 {
584     /* The Interrupt flag must be cleared by writing it to '1'.
585      * Writing '0' has no effect.
586      */
587     CAN_ESR1_REG(base) = errorType;
588 }
589 
590 /*FUNCTION**********************************************************************
591  *
592  * Function Name : FLEXCAN_GetErrCounter
593  * Description   : Get the error counter of FlexCAN module.
594  *
595  *END**************************************************************************/
FLEXCAN_GetErrCounter(CAN_Type * base,uint8_t * txError,uint8_t * rxError)596 void FLEXCAN_GetErrCounter(CAN_Type* base, uint8_t* txError, uint8_t* rxError)
597 {
598     *txError = CAN_ECR_REG(base) & CAN_ECR_Tx_Err_Counter_MASK;
599     *rxError = (CAN_ECR_REG(base) & CAN_ECR_Rx_Err_Counter_MASK) >> \
600                CAN_ECR_Rx_Err_Counter_SHIFT;
601 }
602 
603 /*******************************************************************************
604  * Rx FIFO management functions
605  ******************************************************************************/
606 /*FUNCTION**********************************************************************
607  *
608  * Function Name : FLEXCAN_EnableRxFifo
609  * Description   : Enables the Rx FIFO.
610  *
611  *END**************************************************************************/
FLEXCAN_EnableRxFifo(CAN_Type * base,uint8_t numOfFilters)612 void FLEXCAN_EnableRxFifo(CAN_Type* base, uint8_t numOfFilters)
613 {
614     uint8_t maxNumMb;
615 
616     assert(numOfFilters <= 0xF);
617 
618     /* Set Freeze mode*/
619     FLEXCAN_EnterFreezeMode(base);
620 
621     /* Set the number of the RX FIFO filters needed*/
622     CAN_CTRL2_REG(base) = (CAN_CTRL2_REG(base) & ~CAN_CTRL2_RFFN_MASK) | CAN_CTRL2_RFFN(numOfFilters);
623 
624     /* Enable RX FIFO*/
625     CAN_MCR_REG(base) |= CAN_MCR_RFEN_MASK;
626 
627     /* RX FIFO global mask*/
628     CAN_RXFGMASK_REG(base) = CAN_RXFGMASK_FGM31_FGM0_MASK;
629 
630     maxNumMb = (CAN_MCR_REG(base) & CAN_MCR_MAXMB_MASK) + 1;
631 
632     for (uint8_t i = 0; i < maxNumMb; i++)
633     {
634         /* RX individual mask*/
635         CAN_RXIMR_REG(base,i) = CAN_RXIMR0_RXIMR63_MI31_MI0_MASK;
636     }
637 
638     /* De-assert Freeze Mode*/
639     FLEXCAN_ExitFreezeMode(base);
640 }
641 
642 /*FUNCTION**********************************************************************
643  *
644  * Function Name : FLEXCAN_DisableRxFifo
645  * Description   : Disables the Rx FIFO.
646  *
647  *END**************************************************************************/
FLEXCAN_DisableRxFifo(CAN_Type * base)648 void FLEXCAN_DisableRxFifo(CAN_Type* base)
649 {
650     /* Set Freeze mode*/
651     FLEXCAN_EnterFreezeMode(base);
652 
653     /* Disable RX FIFO*/
654     CAN_MCR_REG(base) &= ~CAN_MCR_RFEN_MASK;
655 
656     /* De-assert Freeze Mode*/
657     FLEXCAN_ExitFreezeMode(base);
658 }
659 
660 /*FUNCTION**********************************************************************
661  *
662  * Function Name : FLEXCAN_SetRxFifoFilterNum
663  * Description   : Set the number of the Rx FIFO filters.
664  *
665  *END**************************************************************************/
FLEXCAN_SetRxFifoFilterNum(CAN_Type * base,uint32_t numOfFilters)666 void FLEXCAN_SetRxFifoFilterNum(CAN_Type* base, uint32_t numOfFilters)
667 {
668     assert(numOfFilters <= 0xF);
669 
670     /* Set Freeze mode*/
671     FLEXCAN_EnterFreezeMode(base);
672 
673     /* Set the number of RX FIFO ID filters*/
674     CAN_CTRL2_REG(base) = (CAN_CTRL2_REG(base) & ~CAN_CTRL2_RFFN_MASK) | CAN_CTRL2_RFFN(numOfFilters);
675 
676     /* De-assert Freeze Mode*/
677     FLEXCAN_ExitFreezeMode(base);
678 }
679 
680 /*FUNCTION**********************************************************************
681  *
682  * Function Name : FLEXCAN_SetRxFifoFilter
683  * Description   : Set the FlexCAN Rx FIFO fields.
684  *
685  *END**************************************************************************/
FLEXCAN_SetRxFifoFilter(CAN_Type * base,uint32_t idFormat,flexcan_id_table_t * idFilterTable)686 void FLEXCAN_SetRxFifoFilter(CAN_Type* base, uint32_t idFormat, flexcan_id_table_t *idFilterTable)
687 {
688     /* Set RX FIFO ID filter table elements*/
689     uint32_t i, j, numOfFilters;
690     uint32_t val1 = 0, val2 = 0, val = 0;
691     volatile uint32_t *filterTable;
692 
693     numOfFilters = (CAN_CTRL2_REG(base) & CAN_CTRL2_RFFN_MASK) >> CAN_CTRL2_RFFN_SHIFT;
694     /* Rx FIFO Ocuppied First Message Box is MB6 */
695     filterTable = (volatile uint32_t *)&(base->MB[6]);
696 
697     CAN_MCR_REG(base) |= CAN_MCR_IDAM(idFormat);
698 
699     switch (idFormat)
700     {
701         case flexcanRxFifoIdElementFormatA:
702             /* One full ID (standard and extended) per ID Filter Table element.*/
703             if (idFilterTable->isRemoteFrame)
704             {
705                 val = (uint32_t)0x1 << FLEXCAN_RX_FIFO_ID_FILTER_FORMATAB_RTR_SHIFT;
706             }
707             if (idFilterTable->isExtendedFrame)
708             {
709                 val |= 0x1 << FLEXCAN_RX_FIFO_ID_FILTER_FORMATAB_IDE_SHIFT;
710             }
711             for (i = 0; i < RxFifoFilterElementNum(numOfFilters); i++)
712             {
713                 if(idFilterTable->isExtendedFrame)
714                 {
715                     filterTable[i] = val + ((*(idFilterTable->idFilter + i)) <<
716                                              FLEXCAN_RX_FIFO_ID_FILTER_FORMATA_EXT_SHIFT &
717                                              FLEXCAN_RX_FIFO_ID_FILTER_FORMATA_EXT_MASK);
718                 }else
719                 {
720                     filterTable[i] = val + ((*(idFilterTable->idFilter + i)) <<
721                                              FLEXCAN_RX_FIFO_ID_FILTER_FORMATA_STD_SHIFT &
722                                              FLEXCAN_RX_FIFO_ID_FILTER_FORMATA_STD_MASK);
723                 }
724             }
725             break;
726         case flexcanRxFifoIdElementFormatB:
727             /* Two full standard IDs or two partial 14-bit (standard and extended) IDs*/
728             /* per ID Filter Table element.*/
729             if (idFilterTable->isRemoteFrame)
730             {
731                 val1 = (uint32_t)0x1 << FLEXCAN_RX_FIFO_ID_FILTER_FORMATAB_RTR_SHIFT;
732                 val2 = 0x1 << FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_RTR_SHIFT;
733             }
734             if (idFilterTable->isExtendedFrame)
735             {
736                 val1 |= 0x1 << FLEXCAN_RX_FIFO_ID_FILTER_FORMATAB_IDE_SHIFT;
737                 val2 |= 0x1 << FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_IDE_SHIFT;
738             }
739             j = 0;
740             for (i = 0; i < RxFifoFilterElementNum(numOfFilters); i++)
741             {
742                 if (idFilterTable->isExtendedFrame)
743                 {
744                     filterTable[i] = val1 + (((*(idFilterTable->idFilter + j)) &
745                                               FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_EXT_MASK) <<
746                                               FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_EXT_SHIFT1);
747                     filterTable[i] |= val2 + (((*(idFilterTable->idFilter + j + 1)) &
748                                               FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_EXT_MASK) <<
749                                               FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_EXT_SHIFT2);
750                 }else
751                 {
752                     filterTable[i] = val1 + (((*(idFilterTable->idFilter + j)) &
753                                               FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_STD_MASK) <<
754                                               FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_STD_SHIFT1);
755                     filterTable[i] |= val2 + (((*(idFilterTable->idFilter + j + 1)) &
756                                               FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_STD_MASK) <<
757                                               FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_STD_SHIFT2);
758                 }
759                 j = j + 2;
760             }
761             break;
762         case flexcanRxFifoIdElementFormatC:
763             /* Four partial 8-bit Standard IDs per ID Filter Table element.*/
764             j = 0;
765             for (i = 0; i < RxFifoFilterElementNum(numOfFilters); i++)
766             {
767                 filterTable[i] = (((*(idFilterTable->idFilter + j)) &
768                                   FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_MASK) <<
769                                   FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_SHIFT1);
770                 filterTable[i] = (((*(idFilterTable->idFilter + j + 1)) &
771                                   FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_MASK) <<
772                                   FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_SHIFT2);
773                 filterTable[i] = (((*(idFilterTable->idFilter + j + 2)) &
774                                   FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_MASK) <<
775                                   FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_SHIFT3);
776                 filterTable[i] = (((*(idFilterTable->idFilter + j + 3)) &
777                                   FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_MASK) <<
778                                   FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_SHIFT4);
779                 j = j + 4;
780             }
781             break;
782         case flexcanRxFifoIdElementFormatD:
783             /* All frames rejected.*/
784             break;
785     }
786 }
787 
788 /*FUNCTION**********************************************************************
789  *
790  * Function Name : FLEXCAN_GetRxFifoPtr
791  * Description   : Gets the FlexCAN Rx FIFO data pointer.
792  *
793  *END**************************************************************************/
FLEXCAN_GetRxFifoPtr(CAN_Type * base)794 flexcan_msgbuf_t* FLEXCAN_GetRxFifoPtr(CAN_Type* base)
795 {
796     /* Rx-Fifo occupy MB0 ~ MB5 */
797     return (flexcan_msgbuf_t*)&base->MB;
798 }
799 
800 /*FUNCTION**********************************************************************
801  *
802  * Function Name : FLEXCAN_GetRxFifoInfo
803  * Description   : Set the FlexCAN RX Fifo global mask.
804  *
805  *END**************************************************************************/
FLEXCAN_GetRxFifoInfo(CAN_Type * base)806 uint16_t FLEXCAN_GetRxFifoInfo(CAN_Type* base)
807 {
808     return CAN_RXFIR_REG(base) & CAN_RXFIR_IDHIT_MASK;
809 }
810 
811 /*******************************************************************************
812  * Rx Mask Setting functions
813  ******************************************************************************/
814 /*FUNCTION**********************************************************************
815  *
816  * Function Name : FLEXCAN_SetRxMaskMode
817  * Description   : Set the Rx masking mode.
818  *
819  *END**************************************************************************/
FLEXCAN_SetRxMaskMode(CAN_Type * base,uint32_t mode)820 void FLEXCAN_SetRxMaskMode(CAN_Type* base, uint32_t mode)
821 {
822     assert((mode == flexcanRxMaskGlobal) ||
823            (mode == flexcanRxMaskIndividual));
824 
825     /* Assert Freeze mode */
826     FLEXCAN_EnterFreezeMode(base);
827 
828     if (mode == flexcanRxMaskIndividual)
829         CAN_MCR_REG(base) |= CAN_MCR_IRMQ_MASK;
830     else
831         CAN_MCR_REG(base) &= ~CAN_MCR_IRMQ_MASK;
832 
833     /* De-assert Freeze Mode */
834     FLEXCAN_ExitFreezeMode(base);
835 }
836 
837 /*FUNCTION**********************************************************************
838  *
839  * Function Name : FLEXCAN_SetRxMaskRtrCmd
840  * Description   : Set the remote trasmit request mask enablement.
841  *
842  *END**************************************************************************/
FLEXCAN_SetRxMaskRtrCmd(CAN_Type * base,bool enable)843 void FLEXCAN_SetRxMaskRtrCmd(CAN_Type* base, bool enable)
844 {
845     /* Assert Freeze mode */
846     FLEXCAN_EnterFreezeMode(base);
847 
848     if (enable)
849         CAN_CTRL2_REG(base) |= CAN_CTRL2_EACEN_MASK;
850     else
851         CAN_CTRL2_REG(base) &= ~CAN_CTRL2_EACEN_MASK;
852 
853     /* De-assert Freeze Mode */
854     FLEXCAN_ExitFreezeMode(base);
855 }
856 
857 /*FUNCTION**********************************************************************
858  *
859  * Function Name : FLEXCAN_SetRxGlobalMask
860  * Description   : Set the FlexCAN RX global mask.
861  *
862  *END**************************************************************************/
FLEXCAN_SetRxGlobalMask(CAN_Type * base,uint32_t mask)863 void FLEXCAN_SetRxGlobalMask(CAN_Type* base, uint32_t mask)
864 {
865     /* Set Freeze mode */
866     FLEXCAN_EnterFreezeMode(base);
867 
868     /* load mask */
869     CAN_RXMGMASK_REG(base) = mask;
870 
871     /* De-assert Freeze Mode */
872     FLEXCAN_ExitFreezeMode(base);
873 }
874 
875 /*FUNCTION**********************************************************************
876  *
877  * Function Name : FLEXCAN_SetRxIndividualMask
878  * Description   : Set the FlexCAN Rx individual mask for ID filtering in
879  *                 the Rx MBs and the Rx FIFO.
880  *
881  *END**************************************************************************/
FLEXCAN_SetRxIndividualMask(CAN_Type * base,uint32_t msgBufIdx,uint32_t mask)882 void FLEXCAN_SetRxIndividualMask(CAN_Type* base, uint32_t msgBufIdx, uint32_t mask)
883 {
884     assert(msgBufIdx < CAN_RXIMR_COUNT);
885 
886     /* Assert Freeze mode */
887     FLEXCAN_EnterFreezeMode(base);
888 
889     CAN_RXIMR_REG(base,msgBufIdx) = mask;
890 
891     /* De-assert Freeze Mode */
892     FLEXCAN_ExitFreezeMode(base);
893 }
894 
895 /*FUNCTION**********************************************************************
896  *
897  * Function Name : FLEXCAN_SetRxMsgBuff14Mask
898  * Description   : Set the FlexCAN RX Message Buffer BUF14 mask.
899  *
900  *END**************************************************************************/
FLEXCAN_SetRxMsgBuff14Mask(CAN_Type * base,uint32_t mask)901 void FLEXCAN_SetRxMsgBuff14Mask(CAN_Type* base, uint32_t mask)
902 {
903     /* Set Freeze mode */
904     FLEXCAN_EnterFreezeMode(base);
905 
906     /* load mask */
907     CAN_RX14MASK_REG(base) = mask;
908 
909     /* De-assert Freeze Mode */
910     FLEXCAN_ExitFreezeMode(base);
911 }
912 
913 /*FUNCTION**********************************************************************
914  *
915  * Function Name : FLEXCAN_SetRxMsgBuff15Mask
916  * Description   : Set the FlexCAN RX Message Buffer BUF15 mask.
917  *
918  *END**************************************************************************/
FLEXCAN_SetRxMsgBuff15Mask(CAN_Type * base,uint32_t mask)919 void FLEXCAN_SetRxMsgBuff15Mask(CAN_Type* base, uint32_t mask)
920 {
921     /* Set Freeze mode */
922     FLEXCAN_EnterFreezeMode(base);
923 
924     /* load mask */
925     CAN_RX15MASK_REG(base) = mask;
926 
927     /* De-assert Freeze Mode */
928     FLEXCAN_ExitFreezeMode(base);
929 }
930 
931 /*FUNCTION**********************************************************************
932  *
933  * Function Name : FLEXCAN_SetRxFifoGlobalMask
934  * Description   : Set the FlexCAN RX Fifo global mask.
935  *
936  *END**************************************************************************/
FLEXCAN_SetRxFifoGlobalMask(CAN_Type * base,uint32_t mask)937 void FLEXCAN_SetRxFifoGlobalMask(CAN_Type* base, uint32_t mask)
938 {
939     /* Set Freeze mode */
940     FLEXCAN_EnterFreezeMode(base);
941 
942     /* load mask */
943     CAN_RXFGMASK_REG(base) = mask;
944 
945     /* De-assert Freeze Mode */
946     FLEXCAN_ExitFreezeMode(base);
947 }
948 
949 /*******************************************************************************
950  * Misc. Functions
951  ******************************************************************************/
952 /*FUNCTION**********************************************************************
953  *
954  * Function Name : FLEXCAN_SetSelfWakeUpCmd
955  * Description   : Enable/disable the FlexCAN self wakeup feature.
956  *
957  *END**************************************************************************/
FLEXCAN_SetSelfWakeUpCmd(CAN_Type * base,bool lpfEnable,bool enable)958 void FLEXCAN_SetSelfWakeUpCmd(CAN_Type* base, bool lpfEnable, bool enable)
959 {
960     /* Set Freeze mode */
961     FLEXCAN_EnterFreezeMode(base);
962 
963     if (lpfEnable)
964         CAN_MCR_REG(base) |= CAN_MCR_WAK_SRC_MASK;
965     else
966         CAN_MCR_REG(base) &= ~CAN_MCR_WAK_SRC_MASK;
967 
968     if (enable)
969         CAN_MCR_REG(base) |= CAN_MCR_SLF_WAK_MASK;
970     else
971         CAN_MCR_REG(base) &= ~CAN_MCR_SLF_WAK_MASK;
972 
973     /* De-assert Freeze Mode */
974     FLEXCAN_ExitFreezeMode(base);
975 }
976 
977 /*FUNCTION**********************************************************************
978  *
979  * Function Name : FLEXCAN_SetSelfReceptionCmd
980  * Description   : Enable/disable the FlexCAN self reception feature.
981  *
982  *END**************************************************************************/
FLEXCAN_SetSelfReceptionCmd(CAN_Type * base,bool enable)983 void FLEXCAN_SetSelfReceptionCmd(CAN_Type* base, bool enable)
984 {
985     /* Set Freeze mode */
986     FLEXCAN_EnterFreezeMode(base);
987 
988     if (enable)
989         CAN_MCR_REG(base) &= ~CAN_MCR_SRX_DIS_MASK;
990     else
991         CAN_MCR_REG(base) |= CAN_MCR_SRX_DIS_MASK;
992 
993     /* De-assert Freeze Mode */
994     FLEXCAN_ExitFreezeMode(base);
995 }
996 
997 /*FUNCTION**********************************************************************
998  *
999  * Function Name : FLEXCAN_SetRxVoteCmd
1000  * Description   : Enable/disable the enhance FlexCAN Rx vote.
1001  *
1002  *END**************************************************************************/
FLEXCAN_SetRxVoteCmd(CAN_Type * base,bool enable)1003 void FLEXCAN_SetRxVoteCmd(CAN_Type* base, bool enable)
1004 {
1005     /* Set Freeze mode */
1006     FLEXCAN_EnterFreezeMode(base);
1007 
1008     if (enable)
1009         CAN_CTRL1_REG(base) |= CAN_CTRL1_SMP_MASK;
1010     else
1011         CAN_CTRL1_REG(base) &= ~CAN_CTRL1_SMP_MASK;
1012 
1013     /* De-assert Freeze Mode */
1014     FLEXCAN_ExitFreezeMode(base);
1015 }
1016 
1017 /*FUNCTION**********************************************************************
1018  *
1019  * Function Name : FLEXCAN_SetAutoBusOffRecoverCmd
1020  * Description   : Enable/disable the Auto Busoff recover feature.
1021  *
1022  *END**************************************************************************/
FLEXCAN_SetAutoBusOffRecoverCmd(CAN_Type * base,bool enable)1023 void FLEXCAN_SetAutoBusOffRecoverCmd(CAN_Type* base, bool enable)
1024 {
1025     if (enable)
1026         CAN_CTRL1_REG(base) &= ~CAN_CTRL1_BOFF_MSK_MASK;
1027     else
1028         CAN_CTRL1_REG(base) |= CAN_CTRL1_BOFF_MSK_MASK;
1029 }
1030 
1031 /*FUNCTION**********************************************************************
1032  *
1033  * Function Name : FLEXCAN_SetTimeSyncCmd
1034  * Description   : Enable/disable the Time Sync feature.
1035  *
1036  *END**************************************************************************/
FLEXCAN_SetTimeSyncCmd(CAN_Type * base,bool enable)1037 void FLEXCAN_SetTimeSyncCmd(CAN_Type* base, bool enable)
1038 {
1039     /* Set Freeze mode */
1040     FLEXCAN_EnterFreezeMode(base);
1041 
1042     if (enable)
1043         CAN_CTRL1_REG(base) |= CAN_CTRL1_TSYN_MASK;
1044     else
1045         CAN_CTRL1_REG(base) &= ~CAN_CTRL1_TSYN_MASK;
1046 
1047     /* De-assert Freeze Mode */
1048     FLEXCAN_ExitFreezeMode(base);
1049 }
1050 
1051 /*FUNCTION**********************************************************************
1052  *
1053  * Function Name : FLEXCAN_SetAutoRemoteResponseCmd
1054  * Description   : Enable/disable the Auto Remote Response feature.
1055  *
1056  *END**************************************************************************/
FLEXCAN_SetAutoRemoteResponseCmd(CAN_Type * base,bool enable)1057 void FLEXCAN_SetAutoRemoteResponseCmd(CAN_Type* base, bool enable)
1058 {
1059     /* Set Freeze mode */
1060     FLEXCAN_EnterFreezeMode(base);
1061 
1062     if (enable)
1063         CAN_CTRL2_REG(base) &= ~CAN_CTRL2_RRS_MASK;
1064     else
1065         CAN_CTRL2_REG(base) |= CAN_CTRL2_RRS_MASK;
1066 
1067     /* De-assert Freeze Mode */
1068     FLEXCAN_ExitFreezeMode(base);
1069 }
1070 
1071 /*******************************************************************************
1072  * EOF
1073  ******************************************************************************/
1074