S32 SDK
flexcan_driver.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
18 
65 #include <assert.h>
66 #include <stdint.h>
67 #include <stdbool.h>
68 #include <stddef.h>
69 #include "flexcan_hw_access.h"
70 #include "flexcan_irq.h"
71 #include "interrupt_manager.h"
72 
73 /*******************************************************************************
74  * Definitions
75  ******************************************************************************/
76 
77 #define FLEXCAN_MB_HANDLE_RXFIFO 0U
78 
79 /*******************************************************************************
80  * Variables
81  ******************************************************************************/
82 
83 /* Table of base addresses for CAN instances. */
85 
86 /* Tables to save CAN IRQ enum numbers defined in CMSIS header file. */
87 #if FEATURE_CAN_HAS_WAKE_UP_IRQ
88 static const IRQn_Type g_flexcanWakeUpIrqId[] = CAN_Wake_Up_IRQS;
89 #endif
94 
95 /* Pointer to runtime state structure.*/
97 
98 /*******************************************************************************
99  * Private Functions
100  ******************************************************************************/
102  uint8_t instance,
103  uint8_t mb_idx,
104  const flexcan_data_info_t *tx_info,
105  uint32_t msg_id,
106  const uint8_t *mb_data,
107  bool isBlocking
108  );
110  uint8_t instance,
111  uint8_t mb_idx,
112  flexcan_msgbuff_t *data,
113  bool isBlocking
114  );
116  uint8_t instance,
117  flexcan_msgbuff_t *data,
118  bool isBlocking
119  );
120 static void FLEXCAN_CompleteTransfer(uint8_t instance, uint32_t mb_idx);
121 static void FLEXCAN_CompleteRxMessageFifoData(uint8_t instance);
122 #if FEATURE_CAN_HAS_DMA_ENABLE
123 static void FLEXCAN_CompleteRxFifoDataDMA(void *parameter, edma_chn_status_t status);
124 #endif
125 /*******************************************************************************
126  * Code
127  ******************************************************************************/
128 
129 /*FUNCTION**********************************************************************
130  *
131  * Function Name : FLEXCAN_DRV_SetBitrate
132  * Description : Set FlexCAN baudrate.
133  * This function will set up all the time segment values for classical frames or the
134  * extended time segments for the arbitration phase of FD frames. Those time segment
135  * values are passed in by the user and are based on the required baudrate.
136  *
137  * Implements : FLEXCAN_DRV_SetBitrate_Activity
138  *END**************************************************************************/
139 void FLEXCAN_DRV_SetBitrate(uint8_t instance, const flexcan_time_segment_t *bitrate)
140 {
141  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
142  DEV_ASSERT(bitrate != NULL);
143 
144  CAN_Type * base = g_flexcanBase[instance];
145  bool fdEnabled = FLEXCAN_IsFDEnabled(base);
146 
147  FLEXCAN_EnterFreezeMode(base);
148 
149  if (fdEnabled)
150  {
151  /* Set extended time segments*/
152  FLEXCAN_SetExtendedTimeSegments(base, bitrate);
153  }
154  else
155  {
156  /* Set time segments*/
157  FLEXCAN_SetTimeSegments(base, bitrate);
158  }
159 
160  FLEXCAN_ExitFreezeMode(base);
161 }
162 
163 /*FUNCTION**********************************************************************
164  *
165  * Function Name : FLEXCAN_DRV_SetBitrateCbt
166  * Description : Set FlexCAN bitrate.
167  * This function will set up all the time segment values for the data phase of
168  * FD frames. Those time segment values are passed in by the user and are based
169  * on the required baudrate.
170  *
171  * Implements : FLEXCAN_DRV_SetBitrateCbt_Activity
172  *END**************************************************************************/
173 void FLEXCAN_DRV_SetBitrateCbt(uint8_t instance, const flexcan_time_segment_t *bitrate)
174 {
175  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
176  DEV_ASSERT(bitrate != NULL);
177 
178  CAN_Type * base = g_flexcanBase[instance];
179 
180  FLEXCAN_EnterFreezeMode(base);
181 
182  /* Set time segments*/
183  FLEXCAN_SetFDTimeSegments(base, bitrate);
184 
185  FLEXCAN_ExitFreezeMode(base);
186 }
187 
188 /*FUNCTION**********************************************************************
189  *
190  * Function Name : FLEXCAN_DRV_GetBitrate
191  * Description : Get FlexCAN baudrate.
192  * This function will be return the current bit rate settings for classical frames
193  * or the arbitration phase of FD frames.
194  *
195  * Implements : FLEXCAN_DRV_GetBitrate_Activity
196  *END**************************************************************************/
197 void FLEXCAN_DRV_GetBitrate(uint8_t instance, flexcan_time_segment_t *bitrate)
198 {
199  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
200  DEV_ASSERT(bitrate != NULL);
201 
202  CAN_Type * base = g_flexcanBase[instance];
203 
204  FLEXCAN_EnterFreezeMode(base);
205 
206  /* Get the time segments*/
207  FLEXCAN_GetTimeSegments(base, bitrate);
208 
209  FLEXCAN_ExitFreezeMode(base);
210 }
211 
212 /*FUNCTION**********************************************************************
213  *
214  * Function Name : FLEXCAN_DRV_GetBitrateFD
215  * Description : Get FlexCAN baudrate.
216  * This function will be return the current bit rate settings for the data phase
217  * of FD frames.
218  *
219  * Implements : FLEXCAN_DRV_GetBitrateFD_Activity
220  *END**************************************************************************/
221 void FLEXCAN_DRV_GetBitrateFD(uint8_t instance, flexcan_time_segment_t *bitrate)
222 {
223  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
224  DEV_ASSERT(bitrate != NULL);
225 
226  CAN_Type * base = g_flexcanBase[instance];
227 
228  FLEXCAN_EnterFreezeMode(base);
229 
230  /* Get the time segments*/
231  FLEXCAN_GetFDTimeSegments(base, bitrate);
232 
233  FLEXCAN_ExitFreezeMode(base);
234 }
235 
236 /*FUNCTION**********************************************************************
237  *
238  * Function Name : FLEXCAN_DRV_SetMasktype
239  * Description : Set RX masking type.
240  * This function will set RX masking type as RX global mask or RX individual
241  * mask.
242  *
243  * Implements : FLEXCAN_DRV_SetRxMaskType_Activity
244  *END**************************************************************************/
246 {
247  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
248 
249  CAN_Type * base = g_flexcanBase[instance];
250 
251  FLEXCAN_EnterFreezeMode(base);
252 
253  FLEXCAN_SetRxMaskType(base, type);
254 
255  FLEXCAN_ExitFreezeMode(base);
256 }
257 
258 /*FUNCTION**********************************************************************
259  *
260  * Function Name : FLEXCAN_DRV_SetRxFifoGlobalMask
261  * Description : Set Rx FIFO global mask as the 11-bit standard mask or the
262  * 29-bit extended mask.
263  *
264  * Implements : FLEXCAN_DRV_SetRxFifoGlobalMask_Activity
265  *END**************************************************************************/
267  uint8_t instance,
269  uint32_t mask)
270 {
271  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
272 
273  CAN_Type * base = g_flexcanBase[instance];
274 
275  FLEXCAN_EnterFreezeMode(base);
276 
277  if (id_type == FLEXCAN_MSG_ID_STD)
278  {
279  /* Set standard global mask for RX FIOF*/
280  FLEXCAN_SetRxFifoGlobalStdMask(base, mask);
281  }
282  else if (id_type == FLEXCAN_MSG_ID_EXT)
283  {
284  /* Set extended global mask for RX FIFO*/
285  FLEXCAN_SetRxFifoGlobalExtMask(base, mask);
286  }
287  else {
288  /* Should not get here */
289  }
290 
291  FLEXCAN_ExitFreezeMode(base);
292 }
293 
294 /*FUNCTION**********************************************************************
295  *
296  * Function Name : FLEXCAN_DRV_SetRxMbGlobalMask
297  * Description : Set Rx Message Buffer global mask as the 11-bit standard mask
298  * or the 29-bit extended mask.
299  *
300  * Implements : FLEXCAN_DRV_SetRxMbGlobalMask_Activity
301  *END**************************************************************************/
303  uint8_t instance,
305  uint32_t mask)
306 {
307  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
308 
309  CAN_Type * base = g_flexcanBase[instance];
310 
311  FLEXCAN_EnterFreezeMode(base);
312 
313  if (id_type == FLEXCAN_MSG_ID_STD)
314  {
315  /* Set standard global mask for RX MB*/
316  FLEXCAN_SetRxMsgBuffGlobalStdMask(base, mask);
317  }
318  else if (id_type == FLEXCAN_MSG_ID_EXT)
319  {
320  /* Set extended global mask for RX MB*/
321  FLEXCAN_SetRxMsgBuffGlobalExtMask(base, mask);
322  }
323  else {
324  /* Should not get here */
325  }
326 
327  FLEXCAN_ExitFreezeMode(base);
328 }
329 
330 /*FUNCTION**********************************************************************
331  *
332  * Function Name : FLEXCAN_DRV_SetRxMb14Mask
333  * Description : Set Rx Message Buffer 14 mask as the 11-bit standard mask
334  * or the 29-bit extended mask.
335  *
336  * Implements : FLEXCAN_DRV_SetRxMb14Mask_Activity
337  *END**************************************************************************/
339  uint8_t instance,
341  uint32_t mask)
342 {
343  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
344 
345  CAN_Type * base = g_flexcanBase[instance];
346 
347  FLEXCAN_EnterFreezeMode(base);
348 
349  if (id_type == FLEXCAN_MSG_ID_STD)
350  {
351  /* Set standard global mask for RX MB*/
352  FLEXCAN_SetRxMsgBuff14StdMask(base, mask);
353  }
354  else if (id_type == FLEXCAN_MSG_ID_EXT)
355  {
356  /* Set extended global mask for RX MB*/
357  FLEXCAN_SetRxMsgBuff14ExtMask(base, mask);
358  }
359  else {
360  /* Should not get here */
361  }
362 
363  FLEXCAN_ExitFreezeMode(base);
364 }
365 
366 /*FUNCTION**********************************************************************
367  *
368  * Function Name : FLEXCAN_DRV_SetRxMb15Mask
369  * Description : Set Rx Message Buffer 15 mask as the 11-bit standard mask
370  * or the 29-bit extended mask.
371  *
372  * Implements : FLEXCAN_DRV_SetRxMb15Mask_Activity
373  *END**************************************************************************/
375  uint8_t instance,
377  uint32_t mask)
378 {
379  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
380 
381  CAN_Type * base = g_flexcanBase[instance];
382 
383  FLEXCAN_EnterFreezeMode(base);
384 
385  if (id_type == FLEXCAN_MSG_ID_STD)
386  {
387  /* Set standard global mask for RX MB*/
388  FLEXCAN_SetRxMsgBuff15StdMask(base, mask);
389  }
390  else if (id_type == FLEXCAN_MSG_ID_EXT)
391  {
392  /* Set extended global mask for RX MB*/
393  FLEXCAN_SetRxMsgBuff15ExtMask(base, mask);
394  }
395  else {
396  /* Should not get here */
397  }
398 
399  FLEXCAN_ExitFreezeMode(base);
400 }
401 
402 /*FUNCTION**********************************************************************
403  *
404  * Function Name : FLEXCAN_DRV_SetRxIndividualMask
405  * Description : Set Rx individual mask as the 11-bit standard mask or the
406  * 29-bit extended mask.
407  *
408  * Implements : FLEXCAN_DRV_SetRxIndividualMask_Activity
409  *END**************************************************************************/
411  uint8_t instance,
413  uint8_t mb_idx,
414  uint32_t mask)
415 {
416  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
417 
418  CAN_Type * base = g_flexcanBase[instance];
419  status_t stat = STATUS_SUCCESS;
420 
421  FLEXCAN_EnterFreezeMode(base);
422 
423  if (mb_idx >= FLEXCAN_GetMaxMsgBuffNum(base))
424  {
426  }
427 
428  if (id_type == FLEXCAN_MSG_ID_STD)
429  {
430  /* Set standard individual mask*/
431  FLEXCAN_SetRxIndividualStdMask(base, mb_idx, mask);
432  }
433  else if (id_type == FLEXCAN_MSG_ID_EXT)
434  {
435  /* Set extended individual mask*/
436  FLEXCAN_SetRxIndividualExtMask(base, mb_idx, mask);
437  }
438  else {
439  /* Should not get here */
440  }
441 
442  FLEXCAN_ExitFreezeMode(base);
443 
444  return stat;
445 }
446 
447 /*FUNCTION**********************************************************************
448  *
449  * Function Name : FLEXCAN_DRV_Init
450  * Description : Initialize FlexCAN driver.
451  * This function will select a source clock, reset FlexCAN module, set maximum
452  * number of message buffers, initialize all message buffers as inactive, enable
453  * RX FIFO if needed, mask all mask bits, disable all MB interrupts, enable
454  * FlexCAN normal mode, and enable all the error interrupts if needed.
455  *
456  * Implements : FLEXCAN_DRV_Init_Activity
457  *END**************************************************************************/
459  uint8_t instance,
460  flexcan_state_t *state,
461  const flexcan_user_config_t *data)
462 {
463  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
464  DEV_ASSERT(state != NULL);
465 
466  status_t result;
467  CAN_Type * base = g_flexcanBase[instance];
468  flexcan_time_segment_t bitrate;
469  status_t osifStat;
470  uint32_t i, j;
471 
472  FLEXCAN_Disable(base);
473 
474 #if FEATURE_CAN_HAS_PE_CLKSRC_SELECT
475  /* Select a source clock for the FlexCAN engine */
476  FLEXCAN_SelectClock(base, data->pe_clock);
477 #endif
478 
479  /* Enable the CAN clock */
480  FLEXCAN_Enable(base);
481 
482  FLEXCAN_EnterFreezeMode(base);
483 
484  /* Initialize FLEXCAN device */
485  FLEXCAN_Init(base);
486 
487  /* Enable/Disable FD and check FD was set as expected. Setting FD as enabled
488  * might fail if the current CAN instance does not support FD. */
489  FLEXCAN_SetFDEnabled(base, data->fd_enable);
490  if (FLEXCAN_IsFDEnabled(base) != data->fd_enable)
491  {
492  return STATUS_ERROR;
493  }
494 
495  /* If the FD feature is enabled, enable the Stuff Bit Count, in order to be
496  * ISO-compliant. */
497  FLEXCAN_SetStuffBitCount(base, data->fd_enable);
498 
499  /* Disable the self reception feature if FlexCAN is not in loopback mode. */
500  if (data->flexcanMode != FLEXCAN_LOOPBACK_MODE)
501  {
502  FLEXCAN_SetSelfReception(base, false);
503  }
504 
505  /* Enable RxFIFO feature, if requested. This might fail if the FD mode is
506  * enabled. */
507  if (data->is_rx_fifo_needed)
508  {
509  result = FLEXCAN_EnableRxFifo(base, (uint32_t)data->num_id_filters);
510  if (result != STATUS_SUCCESS)
511  {
512  return result;
513  }
514  }
515 
516 #if FEATURE_CAN_HAS_DMA_ENABLE
517  /* Enable DMA support for RxFIFO transfer, if requested. */
519  {
520  if (FLEXCAN_IsRxFifoEnabled(base))
521  {
522  FLEXCAN_SetRxFifoDMA(base, true);
523  }
524  else
525  {
526  return STATUS_ERROR;
527  }
528  }
529 #endif
530 
531  /* Select mode */
532  FLEXCAN_SetOperationMode(base, data->flexcanMode);
533 
534  /* Set payload size. */
535  FLEXCAN_SetPayloadSize(base, data->payload);
536 
537  result = FLEXCAN_SetMaxMsgBuffNum(base, data->max_num_mb);
538  if (result != STATUS_SUCCESS)
539  {
540  return result;
541  }
542 
543  /* Set bit rate. */
544  if (FLEXCAN_IsFDEnabled(base))
545  {
546  bitrate = data->bitrate;
547  FLEXCAN_SetExtendedTimeSegments(base, &bitrate);
548  bitrate = data->bitrate_cbt;
549  FLEXCAN_SetFDTimeSegments(base, &bitrate);
550  }
551  else
552  {
553  bitrate = data->bitrate;
554  FLEXCAN_SetTimeSegments(base, &bitrate);
555  }
556 
557  FLEXCAN_ExitFreezeMode(base);
558 
559  /* Enable FlexCAN interrupts.*/
560 #if FEATURE_CAN_HAS_WAKE_UP_IRQ
561  if (g_flexcanWakeUpIrqId[instance] != NotAvail_IRQn)
562  {
563  INT_SYS_EnableIRQ(g_flexcanWakeUpIrqId[instance]);
564  }
565 #endif
568  for (i = 0; i < FEATURE_CAN_MB_IRQS_MAX_COUNT; i++)
569  {
571  {
573  }
574  }
575 
576  for (i = 0; i < FEATURE_CAN_MAX_MB_NUM; i++)
577  {
578  osifStat = OSIF_SemaCreate(&state->mbs[i].mbSema, 0U);
579  if (osifStat != STATUS_SUCCESS)
580  {
581  for (j = 0; j < i; j++)
582  {
583  (void)OSIF_SemaDestroy(&state->mbs[j].mbSema);
584  }
585  return STATUS_ERROR;
586  }
587  state->mbs[i].isBlocking = false;
588  state->mbs[i].mb_message = NULL;
589  state->mbs[i].state = FLEXCAN_MB_IDLE;
590  }
591 
592  /* Store transfer type and DMA channel number used in transfer */
593  state->transferType = data->transfer_type;
594 #if FEATURE_CAN_HAS_DMA_ENABLE
595  state->rxFifoDMAChannel = data->rxFifoDMAChannel;
596 #endif
597 
598  /* Save runtime structure pointers so irq handler can point to the correct state structure */
599  g_flexcanStatePtr[instance] = state;
600 
601  return (STATUS_SUCCESS);
602 }
603 
604 /*FUNCTION**********************************************************************
605  *
606  * Function Name : FLEXCAN_DRV_ConfigTxMb
607  * Description : Configure a Tx message buffer.
608  * This function will first check if RX FIFO is enabled. If RX FIFO is enabled,
609  * the function will make sure if the MB requested is not occupied by RX FIFO
610  * and ID filter table. Then this function will set up the message buffer fields,
611  * configure the message buffer code for Tx buffer as INACTIVE, and enable the
612  * Message Buffer interrupt.
613  *
614  * Implements : FLEXCAN_DRV_ConfigTxMb_Activity
615  *END**************************************************************************/
617  uint8_t instance,
618  uint8_t mb_idx,
619  const flexcan_data_info_t *tx_info,
620  uint32_t msg_id)
621 {
622  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
623  DEV_ASSERT(tx_info != NULL);
624 
625  flexcan_msgbuff_code_status_t cs;
626  CAN_Type * base = g_flexcanBase[instance];
627 
628  /* Initialize transmit mb*/
629  cs.dataLen = tx_info->data_length;
630  cs.msgIdType = tx_info->msg_id_type;
631  if (tx_info->is_remote)
632  {
633  cs.code = (uint32_t)FLEXCAN_TX_REMOTE;
634  }
635  else
636  {
637  cs.code = (uint32_t)FLEXCAN_TX_INACTIVE;
638  }
639  return FLEXCAN_SetTxMsgBuff(base, mb_idx, &cs, msg_id, NULL);
640 }
641 
642 /*FUNCTION**********************************************************************
643  *
644  * Function Name : FLEXCAN_DRV_SendBlocking
645  * Description : This function sends a CAN frame using a configured message
646  * buffer. The function blocks until either the frame was sent, or the specified
647  * timeout expired.
648  *
649  * Implements : FLEXCAN_DRV_SendBlocking_Activity
650  *END**************************************************************************/
652  uint8_t instance,
653  uint8_t mb_idx,
654  const flexcan_data_info_t *tx_info,
655  uint32_t msg_id,
656  const uint8_t *mb_data,
657  uint32_t timeout_ms)
658 {
659  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
660  DEV_ASSERT(tx_info != NULL);
661 
662  status_t result;
663  flexcan_state_t * state = g_flexcanStatePtr[instance];
664  CAN_Type * base = g_flexcanBase[instance];
665 
666  result = FLEXCAN_StartSendData(instance, mb_idx, tx_info, msg_id, mb_data, true);
667 
668  if (result == STATUS_SUCCESS)
669  {
670  status_t status;
671 
672  /* Enable message buffer interrupt*/
673  (void)FLEXCAN_SetMsgBuffIntCmd(base, mb_idx, true);
674  /* Enable error interrupts */
675  FLEXCAN_SetErrIntCmd(base,FLEXCAN_INT_ERR,true);
676 
677  status = OSIF_SemaWait(&state->mbs[mb_idx].mbSema, timeout_ms);
678 
679  if (status == STATUS_TIMEOUT)
680  {
681  /* Disable message buffer interrupt */
682  (void)FLEXCAN_SetMsgBuffIntCmd(base, mb_idx, false);
683  /* Disable error interrupts */
684  FLEXCAN_SetErrIntCmd(base,FLEXCAN_INT_ERR,false);
685 
686  result = STATUS_TIMEOUT;
687  }
688 
689  state->mbs[mb_idx].state = FLEXCAN_MB_IDLE;
690  }
691 
692  return result;
693 }
694 
695 /*FUNCTION**********************************************************************
696  *
697  * Function Name : FLEXCAN_DRV_Send
698  * Description : This function sends a CAN frame using a configured message
699  * buffer. The function returns immediately. If a callback is installed, it will
700  * be invoked after the frame was sent.
701  *
702  * Implements : FLEXCAN_DRV_Send_Activity
703  *END**************************************************************************/
705  uint8_t instance,
706  uint8_t mb_idx,
707  const flexcan_data_info_t *tx_info,
708  uint32_t msg_id,
709  const uint8_t *mb_data)
710 {
711  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
712  DEV_ASSERT(tx_info != NULL);
713 
714  status_t result;
715  CAN_Type * base = g_flexcanBase[instance];
716 
717  result = FLEXCAN_StartSendData(instance, mb_idx, tx_info, msg_id, mb_data, false);
718  if(result == STATUS_SUCCESS)
719  {
720  /* Enable message buffer interrupt*/
721  result = FLEXCAN_SetMsgBuffIntCmd(base, mb_idx, true);
722  /* Enable error interrupts */
723  FLEXCAN_SetErrIntCmd(base,FLEXCAN_INT_ERR,true);
724  }
725 
726  return result;
727 }
728 
729 /*FUNCTION**********************************************************************
730  *
731  * Function Name : FLEXCAN_DRV_ConfigMb
732  * Description : Configure a Rx message buffer.
733  * This function will first check if RX FIFO is enabled. If RX FIFO is enabled,
734  * the function will make sure if the MB requested is not occupied by RX FIFO
735  * and ID filter table. Then this function will set up the message buffer fields,
736  * configure the message buffer code for Rx message buffer as NOT_USED, enable
737  * the Message Buffer interrupt, configure the message buffer code for Rx
738  * message buffer as INACTIVE, copy user's buffer into the message buffer data
739  * area, and configure the message buffer code for Rx message buffer as EMPTY.
740  *
741  * Implements : FLEXCAN_DRV_ConfigRxMb_Activity
742  *END**************************************************************************/
744  uint8_t instance,
745  uint8_t mb_idx,
746  const flexcan_data_info_t *rx_info,
747  uint32_t msg_id)
748 {
749  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
750  DEV_ASSERT(rx_info != NULL);
751 
752  status_t result;
753  flexcan_msgbuff_code_status_t cs;
754  CAN_Type * base = g_flexcanBase[instance];
755 
756  cs.dataLen = rx_info->data_length;
757  cs.msgIdType = rx_info->msg_id_type;
758  cs.fd_enable = rx_info->fd_enable;
759  /* Initialize rx mb*/
760  cs.code = (uint32_t)FLEXCAN_RX_NOT_USED;
761  result = FLEXCAN_SetRxMsgBuff(base, mb_idx, &cs, msg_id);
762  if (result != STATUS_SUCCESS)
763  {
764  return result;
765  }
766 
767  /* Initialize receive MB*/
768  cs.code = (uint32_t)FLEXCAN_RX_INACTIVE;
769  result = FLEXCAN_SetRxMsgBuff(base, mb_idx, &cs, msg_id);
770  if (result != STATUS_SUCCESS)
771  {
772  return result;
773  }
774 
775  /* Set up FlexCAN message buffer fields for receiving data*/
776  cs.code = (uint32_t)FLEXCAN_RX_EMPTY;
777  return FLEXCAN_SetRxMsgBuff(base, mb_idx, &cs, msg_id);
778 }
779 
780 /*FUNCTION**********************************************************************
781  *
782  * Function Name : FLEXCAN_DRV_ConfigRxFifo
783  * Description : Confgure RX FIFO ID filter table elements.
784  * This function will confgure RX FIFO ID filter table elements, and enable RX
785  * FIFO interrupts.
786  *
787  * Implements : FLEXCAN_DRV_ConfigRxFifo_Activity
788  *END**************************************************************************/
790  uint8_t instance,
792  const flexcan_id_table_t *id_filter_table)
793 {
794  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
795 
796  CAN_Type * base = g_flexcanBase[instance];
797 
798  FLEXCAN_EnterFreezeMode(base);
799 
800  /* Initialize rx fifo*/
801  FLEXCAN_SetRxFifoFilter(base, id_format, id_filter_table);
802 
803  FLEXCAN_ExitFreezeMode(base);
804 }
805 
806 /*FUNCTION**********************************************************************
807  *
808  * Function Name : FLEXCAN_DRV_ReceiveBlocking
809  * Description : This function receives a CAN frame into a configured message
810  * buffer. The function blocks until either a frame was received, or the
811  * specified timeout expired.
812  *
813  * Implements : FLEXCAN_DRV_ReceiveBlocking_Activity
814  *END**************************************************************************/
816  uint8_t instance,
817  uint8_t mb_idx,
818  flexcan_msgbuff_t *data,
819  uint32_t timeout_ms)
820 {
821  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
822 
823  status_t result;
824  flexcan_state_t * state = g_flexcanStatePtr[instance];
825  CAN_Type * base = g_flexcanBase[instance];
826 
827  result = FLEXCAN_StartRxMessageBufferData(instance, mb_idx, data, true);
828 
829  if(result == STATUS_SUCCESS)
830  {
831  status_t status;
832 
833  status = OSIF_SemaWait(&state->mbs[mb_idx].mbSema, timeout_ms);
834 
835  if (status == STATUS_SUCCESS)
836  {
837  result = FLEXCAN_GetMsgBuff(base, mb_idx, data);
838  }
839  else
840  {
841  /* Disable message buffer interrupt */
842  (void)FLEXCAN_SetMsgBuffIntCmd(base, mb_idx, false);
843  /* Disable error interrupts */
844  FLEXCAN_SetErrIntCmd(base,FLEXCAN_INT_ERR,false);
845 
846  result = STATUS_TIMEOUT;
847  }
848 
849  state->mbs[mb_idx].state = FLEXCAN_MB_IDLE;
850  }
851 
852  return result;
853 }
854 
855 /*FUNCTION**********************************************************************
856  *
857  * Function Name : FLEXCAN_DRV_Receive
858  * Description : This function receives a CAN frame into a configured message
859  * buffer. The function returns immediately. If a callback is installed, it will
860  * be invoked after the frame was received and read into the specified buffer.
861  *
862  * Implements : FLEXCAN_DRV_Receive_Activity
863  *END**************************************************************************/
865  uint8_t instance,
866  uint8_t mb_idx,
867  flexcan_msgbuff_t *data)
868 {
869  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
870 
871  status_t result;
872 
873  result = FLEXCAN_StartRxMessageBufferData(instance, mb_idx, data, false);
874 
875  return result;
876 }
877 
878 /*FUNCTION**********************************************************************
879  *
880  * Function Name : FLEXCAN_DRV_RxFifoBlocking
881  * Description : This function receives a CAN frame using the Rx FIFO. The
882  * function blocks until either a frame was received, or the specified timeout
883  * expired.
884  *
885  * Implements : FLEXCAN_DRV_RxFifoBlocking_Activity
886  *END**************************************************************************/
888  uint8_t instance,
889  flexcan_msgbuff_t *data,
890  uint32_t timeout_ms)
891 {
892  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
893 
894  status_t result;
895  flexcan_state_t * state = g_flexcanStatePtr[instance];
896  CAN_Type * base = g_flexcanBase[instance];
897 
898  result = FLEXCAN_StartRxMessageFifoData(instance, data, true);
899 
900  if (result == STATUS_SUCCESS)
901  {
902  result = OSIF_SemaWait(&state->mbs[FLEXCAN_MB_HANDLE_RXFIFO].mbSema, timeout_ms);
903 
904  if (result == STATUS_TIMEOUT)
905  {
906  /* Disable RX FIFO interrupts*/
907  (void)FLEXCAN_SetMsgBuffIntCmd(base, FEATURE_CAN_RXFIFO_FRAME_AVAILABLE, false);
908  (void)FLEXCAN_SetMsgBuffIntCmd(base, FEATURE_CAN_RXFIFO_WARNING, false);
909  (void)FLEXCAN_SetMsgBuffIntCmd(base, FEATURE_CAN_RXFIFO_OVERFLOW, false);
910 
911  /* Disable error interrupts */
912  FLEXCAN_SetErrIntCmd(base,FLEXCAN_INT_ERR,false);
913 
914  result = STATUS_TIMEOUT;
915  }
916 
918  }
919 
920  return result;
921 }
922 
923 /*FUNCTION**********************************************************************
924  *
925  * Function Name : FLEXCAN_DRV_RxFifo
926  * Description : This function receives a CAN frame using the Rx FIFO. The
927  * function returns immediately. If a callback is installed, it will be invoked
928  * after the frame was received and read into the specified buffer.
929  *
930  * Implements : FLEXCAN_DRV_RxFifo_Activity
931  *END**************************************************************************/
933  uint8_t instance,
934  flexcan_msgbuff_t *data)
935 {
936  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
937 
938  status_t result;
939 
940  result = FLEXCAN_StartRxMessageFifoData(instance, data, false);
941 
942  return result;
943 }
944 
945 /*FUNCTION**********************************************************************
946  *
947  * Function Name : FLEXCAN_DRV_Deinit
948  * Description : Shutdown a FlexCAN module.
949  * This function will disable all FlexCAN interrupts, and disable the FlexCAN.
950  *
951  * Implements : FLEXCAN_DRV_Deinit_Activity
952  *END**************************************************************************/
953 status_t FLEXCAN_DRV_Deinit(uint8_t instance)
954 {
955  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
956 
957  const flexcan_state_t * state = g_flexcanStatePtr[instance];
958  status_t result = STATUS_SUCCESS;
959  status_t osifStat;
960  uint32_t i;
961 
962  /* Disable FlexCAN interrupts.*/
963 #if FEATURE_CAN_HAS_WAKE_UP_IRQ
964  if (g_flexcanWakeUpIrqId[instance] != NotAvail_IRQn)
965  {
966  INT_SYS_DisableIRQ(g_flexcanWakeUpIrqId[instance]);
967  }
968 #endif
971  for (i = 0; i < FEATURE_CAN_MB_IRQS_MAX_COUNT; i++)
972  {
974  {
976  }
977  }
978 
979  /* Disable FlexCAN.*/
980  FLEXCAN_Disable(g_flexcanBase[instance]);
981 
982  for (i = 0; i < FEATURE_CAN_MAX_MB_NUM; i++)
983  {
984  osifStat = OSIF_SemaDestroy(&state->mbs[i].mbSema);
985  if (osifStat != STATUS_SUCCESS)
986  {
987  result = STATUS_ERROR;
988  }
989  }
990 
991  return result;
992 }
993 
994 /*FUNCTION**********************************************************************
995  *
996  * Function Name : FLEXCAN_DRV_SetTDCOffset
997  * Description : Enables/Disables the Transceiver Delay Compensation feature and sets
998  * the Transceiver Delay Compensation Offset.
999  *
1000  * Implements : FLEXCAN_DRV_SetTDCOffset_Activity
1001  *END**************************************************************************/
1002 void FLEXCAN_DRV_SetTDCOffset(uint8_t instance, bool enable, uint8_t offset)
1003 {
1004  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
1005 
1006  CAN_Type * base = g_flexcanBase[instance];
1007 
1008  FLEXCAN_EnterFreezeMode(base);
1009 
1010  /* Enable/Disable TDC and set the TDC Offset */
1011  FLEXCAN_SetTDCOffset(base, enable, offset);
1012 
1013  FLEXCAN_ExitFreezeMode(base);
1014 }
1015 
1016 /*FUNCTION**********************************************************************
1017  *
1018  * Function Name : FLEXCAN_DRV_GetTDCValue
1019  * Description : Gets the value of the Transceiver Delay Compensation.
1020  *
1021  * Implements : FLEXCAN_DRV_GetTDCValue_Activity
1022  *END**************************************************************************/
1023 uint8_t FLEXCAN_DRV_GetTDCValue(uint8_t instance)
1024 {
1025  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
1026 
1027  const CAN_Type * base = g_flexcanBase[instance];
1028 
1029  return (uint8_t)((base->FDCTRL & CAN_FDCTRL_TDCVAL_MASK) >> CAN_FDCTRL_TDCVAL_SHIFT);
1030 }
1031 
1032 /*FUNCTION**********************************************************************
1033  *
1034  * Function Name : FLEXCAN_DRV_GetTDCFail
1035  * Description : Gets the value of the TDC Fail flag.
1036  *
1037  * Implements : FLEXCAN_DRV_GetTDCFail_Activity
1038  *END**************************************************************************/
1039 bool FLEXCAN_DRV_GetTDCFail(uint8_t instance)
1040 {
1041  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
1042 
1043  const CAN_Type * base = g_flexcanBase[instance];
1044 
1045  return (((base->FDCTRL & CAN_FDCTRL_TDCFAIL_MASK) >> CAN_FDCTRL_TDCFAIL_SHIFT) != 0U);
1046 }
1047 
1048 /*FUNCTION**********************************************************************
1049  *
1050  * Function Name : FLEXCAN_DRV_ClearTDCFail
1051  * Description : Clears the TDC Fail flag.
1052  *
1053  * Implements : FLEXCAN_DRV_ClearTDCFail_Activity
1054  *END**************************************************************************/
1055 void FLEXCAN_DRV_ClearTDCFail(uint8_t instance)
1056 {
1057  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
1058 
1059  CAN_Type * base = g_flexcanBase[instance];
1060 
1061  base->FDCTRL = base->FDCTRL | CAN_FDCTRL_TDCFAIL_MASK;
1062 }
1063 
1064 /*FUNCTION**********************************************************************
1065  *
1066  * Function Name : FLEXCAN_IRQHandler
1067  * Description : Interrupt handler for FLEXCAN.
1068  * This handler read data from MB or FIFO, and then clear the interrupt flags.
1069  * This is not a public API as it is called whenever an interrupt occurs.
1070  *
1071  *END**************************************************************************/
1072 void FLEXCAN_IRQHandler(uint8_t instance)
1073 {
1074  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
1075 
1076  uint32_t flag_reg = 0;
1077  CAN_Type * base = g_flexcanBase[instance];
1078  flexcan_state_t * state = g_flexcanStatePtr[instance];
1079  status_t result = STATUS_SUCCESS;
1080 
1081  /* Get the interrupts that are enabled and ready */
1082  uint32_t mb_idx = 0;
1083  flag_reg = FLEXCAN_GetMsgBuffIntStatusFlag(base, mb_idx);
1084 
1085  while ((flag_reg & 1U) == 0U)
1086  {
1087  mb_idx++;
1088  flag_reg = FLEXCAN_GetMsgBuffIntStatusFlag(base, mb_idx);
1089 
1090  if (mb_idx > FEATURE_CAN_MAX_MB_NUM)
1091  {
1092  break;
1093  }
1094  }
1095 
1096  /* Check Tx/Rx interrupt flag and clear the interrupt */
1097  if(flag_reg != 0U)
1098  {
1099  bool rxfifoEnabled = FLEXCAN_IsRxFifoEnabled(base);
1100  if ((mb_idx == FEATURE_CAN_RXFIFO_FRAME_AVAILABLE) && rxfifoEnabled)
1101  {
1103  {
1104  /* Get RX FIFO field values */
1105  FLEXCAN_ReadRxFifo(base, state->mbs[FLEXCAN_MB_HANDLE_RXFIFO].mb_message);
1106 
1107  /* Complete receive data */
1109  FLEXCAN_ClearMsgBuffIntStatusFlag(base, mb_idx);
1110 
1111  /* Invoke callback */
1112  if (state->callback != NULL)
1113  {
1114  state->callback(instance, FLEXCAN_EVENT_RXFIFO_COMPLETE, state);
1115  }
1116  }
1117  }
1118  else
1119  {
1120  /* Check mailbox completed reception */
1121  if (state->mbs[mb_idx].state == FLEXCAN_MB_RX_BUSY)
1122  {
1123  /* Lock RX message buffer and RX FIFO*/
1124  result = FLEXCAN_LockRxMsgBuff(base, mb_idx);
1125  if (result == STATUS_SUCCESS)
1126  {
1127  /* Get RX MB field values*/
1128  result = FLEXCAN_GetMsgBuff(base, mb_idx, state->mbs[mb_idx].mb_message);
1129  }
1130  if (result == STATUS_SUCCESS)
1131  {
1132  /* Unlock RX message buffer and RX FIFO*/
1133  FLEXCAN_UnlockRxMsgBuff(base);
1134 
1135  /* Complete receive data */
1136  FLEXCAN_CompleteTransfer(instance, mb_idx);
1137  FLEXCAN_ClearMsgBuffIntStatusFlag(base, mb_idx);
1138 
1139  /* Invoke callback */
1140  if (state->callback != NULL)
1141  {
1142  state->callback(instance, FLEXCAN_EVENT_RX_COMPLETE, state);
1143  }
1144  }
1145  }
1146  }
1147 
1148  /* Check mailbox completed transmission */
1149  if (state->mbs[mb_idx].state == FLEXCAN_MB_TX_BUSY)
1150  {
1151  /* Complete transmit data */
1152  FLEXCAN_CompleteTransfer(instance, mb_idx);
1153 
1154  if (state->mbs[mb_idx].isRemote)
1155  {
1156  /* If the frame was a remote frame, clear the flag only if the response was
1157  * not received yet. If the response was received, leave the flag set in order
1158  * to be handled when the user calls FLEXCAN_DRV_RxMessageBuffer. */
1159  flexcan_msgbuff_t mb;
1160  (void) FLEXCAN_LockRxMsgBuff(base, mb_idx);
1161  (void) FLEXCAN_GetMsgBuff(base, mb_idx, &mb);
1162  FLEXCAN_UnlockRxMsgBuff(base);
1163 
1164  if (((mb.cs & CAN_CS_CODE_MASK) >> CAN_CS_CODE_SHIFT) == (uint32_t)FLEXCAN_RX_EMPTY)
1165  {
1166  FLEXCAN_ClearMsgBuffIntStatusFlag(base, mb_idx);
1167  }
1168  }
1169  else
1170  {
1171  FLEXCAN_ClearMsgBuffIntStatusFlag(base, mb_idx);
1172  }
1173 
1174  /* Invoke callback */
1175  if (state->callback != NULL)
1176  {
1177  state->callback(instance, FLEXCAN_EVENT_TX_COMPLETE, state);
1178  }
1179  }
1180  }
1181 
1182  /* Clear all other interrupts in ERRSTAT register (Error, Busoff, Wakeup) */
1183  FLEXCAN_ClearErrIntStatusFlag(base);
1184 
1185  return;
1186 }
1187 
1188 #if FEATURE_CAN_HAS_PRETENDED_NETWORKING
1189 
1190 /*FUNCTION**********************************************************************
1191  *
1192  * Function Name : FLEXCAN_WakeUpHandler
1193  * Description : Wake up handler for FLEXCAN.
1194  * This handler verifies the event which caused the wake up and invokes the
1195  * user callback, if configured.
1196  * This is not a public API as it is called whenever an wake up event occurs.
1197  *
1198  *END**************************************************************************/
1199 void FLEXCAN_WakeUpHandler(uint8_t instance)
1200 {
1201  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
1202 
1203  CAN_Type * base = g_flexcanBase[instance];
1204  flexcan_state_t * state = g_flexcanStatePtr[instance];
1205 
1206  uint32_t flag = base->WU_MTC;
1207 
1208  /* Invoke callback */
1209  if (state->callback != NULL)
1210  {
1211  if ((flag & CAN_WU_MTC_WTOF_MASK) != 0U)
1212  {
1213  base->WU_MTC |= CAN_WU_MTC_WTOF_MASK;
1214  state->callback(instance, FLEXCAN_EVENT_WAKEUP_TIMEOUT, state);
1215  }
1216  if ((flag & CAN_WU_MTC_WUMF_MASK) != 0U)
1217  {
1218  base->WU_MTC |= CAN_WU_MTC_WUMF_MASK;
1219  state->callback(instance, FLEXCAN_EVENT_WAKEUP_MATCH, state);
1220  }
1221  }
1222 }
1223 
1224 #endif /* FEATURE_CAN_HAS_PRETENDED_NETWORKING */
1225 
1226 /*FUNCTION**********************************************************************
1227  *
1228  * Function Name : FLEXCAN_DRV_GetTransferStatus
1229  * Description : This function returns whether the previous FLEXCAN receive is
1230  * completed.
1231  * When performing a non-blocking receive, the user can call this function to
1232  * ascertain the state of the current receive progress: in progress (or busy)
1233  * or complete (success).
1234  *
1235  * Implements : FLEXCAN_DRV_GetTransferStatus_Activity
1236  *END**************************************************************************/
1237 status_t FLEXCAN_DRV_GetTransferStatus(uint8_t instance, uint8_t mb_idx)
1238 {
1239  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
1240 
1241  const flexcan_state_t * state = g_flexcanStatePtr[instance];
1242  status_t status;
1243 
1244  if (state->mbs[mb_idx].state == FLEXCAN_MB_IDLE)
1245  {
1246  status = STATUS_SUCCESS;
1247  }
1248  else
1249  {
1250  status = STATUS_BUSY;
1251  }
1252 
1253  return status;
1254 }
1255 
1256 /*FUNCTION**********************************************************************
1257  *
1258  * Function Name : FLEXCAN_DRV_AbortTransfer
1259  * Description : This function shuts down the FLEXCAN by disabling interrupts and
1260  * the transmitter/receiver.
1261  * This function disables the FLEXCAN interrupts, disables the transmitter and
1262  * receiver.
1263  *
1264  * Implements : FLEXCAN_DRV_AbortTransfer_Activity
1265  *END**************************************************************************/
1266 status_t FLEXCAN_DRV_AbortTransfer(uint8_t instance, uint8_t mb_idx)
1267 {
1268  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
1269 
1270  const flexcan_state_t * state = g_flexcanStatePtr[instance];
1271 
1272  /* Check if a transfer is running. */
1273  if (state->mbs[mb_idx].state == FLEXCAN_MB_IDLE)
1274  {
1276  }
1277 
1278  /* Stop the running transfer. */
1279  FLEXCAN_CompleteTransfer(instance, mb_idx);
1280 
1281  return STATUS_SUCCESS;
1282 }
1283 
1284 /*FUNCTION**********************************************************************
1285  *
1286  * Function Name : FLEXCAN_DRV_StartSendData
1287  * Description : Initiate (start) a transmit by beginning the process of
1288  * sending data.
1289  * This is not a public API as it is called from other driver functions.
1290  *
1291  *END**************************************************************************/
1293  uint8_t instance,
1294  uint8_t mb_idx,
1295  const flexcan_data_info_t *tx_info,
1296  uint32_t msg_id,
1297  const uint8_t *mb_data,
1298  bool isBlocking
1299  )
1300 {
1301  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
1302  DEV_ASSERT(tx_info != NULL);
1303 
1304  status_t result;
1305  flexcan_msgbuff_code_status_t cs;
1306  flexcan_state_t * state = g_flexcanStatePtr[instance];
1307  CAN_Type * base = g_flexcanBase[instance];
1308 
1309  if (state->mbs[mb_idx].state != FLEXCAN_MB_IDLE)
1310  {
1311  return STATUS_BUSY;
1312  }
1313  state->mbs[mb_idx].state = FLEXCAN_MB_TX_BUSY;
1314  state->mbs[mb_idx].isBlocking = isBlocking;
1315  state->mbs[mb_idx].isRemote = tx_info->is_remote;
1316 
1317  cs.dataLen = tx_info->data_length;
1318  cs.msgIdType = tx_info->msg_id_type;
1319 
1320  cs.fd_enable = tx_info->fd_enable;
1321  cs.fd_padding = tx_info->fd_padding;
1322  cs.enable_brs = tx_info->enable_brs;
1323  if (tx_info->is_remote)
1324  {
1325  cs.code = (uint32_t)FLEXCAN_TX_REMOTE;
1326  }
1327  else
1328  {
1329  cs.code = (uint32_t)FLEXCAN_TX_DATA;
1330  }
1331  result = FLEXCAN_SetTxMsgBuff(base, mb_idx, &cs, msg_id, mb_data);
1332 
1333  if (result != STATUS_SUCCESS)
1334  {
1335  state->mbs[mb_idx].state = FLEXCAN_MB_IDLE;
1336  }
1337 
1338  return result;
1339 }
1340 
1341 /*FUNCTION**********************************************************************
1342  *
1343  * Function Name : FLEXCAN_DRV_StartRxMessageBufferData
1344  * Description : Initiate (start) a receive by beginning the process of
1345  * receiving data and enabling the interrupt.
1346  * This is not a public API as it is called from other driver functions.
1347  *
1348  *END**************************************************************************/
1350  uint8_t instance,
1351  uint8_t mb_idx,
1352  flexcan_msgbuff_t *data,
1353  bool isBlocking
1354  )
1355 {
1356  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
1357 
1358  status_t result = STATUS_SUCCESS;
1359  CAN_Type * base = g_flexcanBase[instance];
1360  flexcan_state_t * state = g_flexcanStatePtr[instance];
1361 
1362  /* Start receiving mailbox */
1363  if(state->mbs[mb_idx].state != FLEXCAN_MB_IDLE)
1364  {
1365  return STATUS_BUSY;
1366  }
1367  state->mbs[mb_idx].state = FLEXCAN_MB_RX_BUSY;
1368  state->mbs[mb_idx].mb_message = data;
1369  state->mbs[mb_idx].isBlocking = isBlocking;
1370 
1371  /* Enable MB interrupt*/
1372  result = FLEXCAN_SetMsgBuffIntCmd(base, mb_idx, true);
1373  /* Enable error interrupts */
1374  FLEXCAN_SetErrIntCmd(base,FLEXCAN_INT_ERR,true);
1375 
1376  if (result != STATUS_SUCCESS)
1377  {
1378  state->mbs[mb_idx].state = FLEXCAN_MB_IDLE;
1379  }
1380 
1381  return result;
1382 }
1383 
1384 
1385 /*FUNCTION**********************************************************************
1386  *
1387  * Function Name : FLEXCAN_DRV_StartRxMessageFifoData
1388  * Description : Initiate (start) a receive by beginning the process of
1389  * receiving data and enabling the interrupt.
1390  * This is not a public API as it is called from other driver functions.
1391  *
1392  *END**************************************************************************/
1394  uint8_t instance,
1395  flexcan_msgbuff_t *data,
1396  bool isBlocking
1397  )
1398 {
1399  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
1400 
1401  CAN_Type * base = g_flexcanBase[instance];
1402  flexcan_state_t * state = g_flexcanStatePtr[instance];
1403 #if FEATURE_CAN_HAS_DMA_ENABLE
1404  status_t edmaStat;
1405 #endif
1406 
1407  /* Start receiving fifo */
1409  {
1410  return STATUS_BUSY;
1411  }
1412  /* Check if RxFIFO feature is enabled */
1413  if (!FLEXCAN_IsRxFifoEnabled(base))
1414  {
1415  return STATUS_ERROR;
1416  }
1417 
1419 
1420  state->mbs[FLEXCAN_MB_HANDLE_RXFIFO].isBlocking = isBlocking;
1421 
1422  /* This will get filled by the interrupt handler */
1423  state->mbs[FLEXCAN_MB_HANDLE_RXFIFO].mb_message = data;
1424 
1425 #if FEATURE_CAN_HAS_DMA_ENABLE
1426  if (state->transferType == FLEXCAN_RXFIFO_USING_DMA)
1427  {
1428  status_t edmaStatus;
1429 
1430  edmaStatus = EDMA_DRV_InstallCallback(state->rxFifoDMAChannel,
1431  FLEXCAN_CompleteRxFifoDataDMA,
1432  (void *)((uint32_t)instance));
1433 
1434  if (edmaStatus != STATUS_SUCCESS)
1435  {
1437  return STATUS_ERROR;
1438  }
1439 
1440  edmaStatus = EDMA_DRV_ConfigSingleBlockTransfer(state->rxFifoDMAChannel,
1442  (uint32_t)(base->RAMn),
1443  (uint32_t)(state->mbs[FLEXCAN_MB_HANDLE_RXFIFO].mb_message),
1445  16U);
1446 
1447  if (edmaStatus != STATUS_SUCCESS)
1448  {
1450  return STATUS_ERROR;
1451  }
1452 
1453  edmaStat = EDMA_DRV_StartChannel(state->rxFifoDMAChannel);
1454  if (edmaStat != STATUS_SUCCESS)
1455  {
1457  return STATUS_ERROR;
1458  }
1459  }
1460 #endif
1461 
1462  /* Enable RX FIFO interrupts*/
1463  (void)FLEXCAN_SetMsgBuffIntCmd(base, FEATURE_CAN_RXFIFO_FRAME_AVAILABLE, true);
1464  (void)FLEXCAN_SetMsgBuffIntCmd(base, FEATURE_CAN_RXFIFO_WARNING, true);
1465  (void)FLEXCAN_SetMsgBuffIntCmd(base, FEATURE_CAN_RXFIFO_OVERFLOW, true);
1466 
1467  /* Enable error interrupts */
1468  FLEXCAN_SetErrIntCmd(base,FLEXCAN_INT_ERR,true);
1469 
1470  return STATUS_SUCCESS;
1471 }
1472 
1473 /*FUNCTION**********************************************************************
1474  *
1475  * Function Name : FLEXCAN_DRV_CompleteTransfer
1476  * Description : Finish up a transmit by completing the process of sending
1477  * data and disabling the interrupt.
1478  * This is not a public API as it is called from other driver functions.
1479  *
1480  *END**************************************************************************/
1481 static void FLEXCAN_CompleteTransfer(uint8_t instance, uint32_t mb_idx)
1482 {
1483  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
1484 
1485  CAN_Type * base = g_flexcanBase[instance];
1486  flexcan_state_t * state = g_flexcanStatePtr[instance];
1487 
1488  /* Disable the transmitter data register empty interrupt */
1489  (void)FLEXCAN_SetMsgBuffIntCmd(base, mb_idx, false);
1490  /* Disable error interrupts */
1491  FLEXCAN_SetErrIntCmd(base,FLEXCAN_INT_ERR,false);
1492 
1493  /* Update the information of the module driver state */
1494  if (state->mbs[mb_idx].isBlocking)
1495  {
1496  (void)OSIF_SemaPost(&state->mbs[mb_idx].mbSema);
1497  }
1498  state->mbs[mb_idx].state = FLEXCAN_MB_IDLE;
1499 }
1500 
1501 #if FEATURE_CAN_HAS_DMA_ENABLE
1502 /*FUNCTION**********************************************************************
1503  *
1504  * Function Name : FLEXCAN_DRV_CompleteRxFifoDataDMA
1505  * Description : Finish up a DMA transfer (this is just a wrapper over
1506  * FLEXCAN_DRV_CompleteRxMessageFifoData).
1507  * This is not a public API as it is called from other driver functions.
1508  *
1509  *END**************************************************************************/
1510 static void FLEXCAN_CompleteRxFifoDataDMA(void *parameter, edma_chn_status_t status)
1511 {
1512  uint32_t instance = (uint32_t)parameter;
1513  (void)status;
1514 
1515  FLEXCAN_CompleteRxMessageFifoData((uint8_t)instance);
1516 }
1517 #endif
1518 
1519 /*FUNCTION**********************************************************************
1520  *
1521  * Function Name : FLEXCAN_DRV_CompleteRxMessageFifoData
1522  * Description : Finish up a receive by completing the process of receiving
1523  * data and disabling the interrupt.
1524  * This is not a public API as it is called from other driver functions.
1525  *
1526  *END**************************************************************************/
1527 static void FLEXCAN_CompleteRxMessageFifoData(uint8_t instance)
1528 {
1529  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
1530 
1531  CAN_Type * base = g_flexcanBase[instance];
1532  flexcan_state_t * state = g_flexcanStatePtr[instance];
1533 
1535  {
1536  /* Disable RX FIFO interrupts*/
1537  (void)FLEXCAN_SetMsgBuffIntCmd(base, FEATURE_CAN_RXFIFO_FRAME_AVAILABLE, false);
1538  (void)FLEXCAN_SetMsgBuffIntCmd(base, FEATURE_CAN_RXFIFO_WARNING, false);
1539  (void)FLEXCAN_SetMsgBuffIntCmd(base, FEATURE_CAN_RXFIFO_OVERFLOW, false);
1540 
1541  /* Disable error interrupts */
1542  FLEXCAN_SetErrIntCmd(base,FLEXCAN_INT_ERR,false);
1543  }
1544 #if FEATURE_CAN_HAS_DMA_ENABLE
1545  else
1546  {
1547  flexcan_msgbuff_t *fifo_message = state->mbs[FLEXCAN_MB_HANDLE_RXFIFO].mb_message;
1548  uint32_t *msgData_32 = (uint32_t *)fifo_message->data;
1549 
1550  (void) EDMA_DRV_StopChannel(state->rxFifoDMAChannel);
1551  /* Adjust the ID if it is not extended */
1552  if (((fifo_message->cs) & CAN_CS_IDE_MASK) == 0U)
1553  {
1554  fifo_message->msgId = fifo_message->msgId >> CAN_ID_STD_SHIFT;
1555  }
1556  /* Extract the data length */
1557  fifo_message->dataLen = (uint8_t)((fifo_message->cs & CAN_CS_DLC_MASK) >> CAN_CS_DLC_SHIFT);
1558  /* Reverse the endianness */
1559  REV_BYTES_32(msgData_32[0], msgData_32[0]);
1560  REV_BYTES_32(msgData_32[1], msgData_32[1]);
1561  }
1562 #endif
1563  /* Clear fifo message*/
1564  state->mbs[FLEXCAN_MB_HANDLE_RXFIFO].mb_message = NULL;
1565 
1566  /* Update status for receive by using fifo*/
1568  {
1570  }
1572 }
1573 
1574 /*FUNCTION**********************************************************************
1575  *
1576  * Function Name : FLEXCAN_DRV_InstallEventCallback
1577  * Description : Installs a callback function for the IRQ handler.
1578  *
1579  * Implements : FLEXCAN_DRV_InstallEventCallback_Activity
1580  *END**************************************************************************/
1581 void FLEXCAN_DRV_InstallEventCallback(uint8_t instance, flexcan_callback_t callback, void *callbackParam)
1582 {
1583  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
1584 
1585  flexcan_state_t * state = g_flexcanStatePtr[instance];
1586 
1587  state->callback = callback;
1588  state->callbackParam = callbackParam;
1589 }
1590 
1591 #if FEATURE_CAN_HAS_PRETENDED_NETWORKING
1592 
1593 /*FUNCTION**********************************************************************
1594  *
1595  * Function Name : FLEXCAN_DRV_ConfigPN
1596  * Description : Configures Pretended Networking settings.
1597  *
1598  * Implements : FLEXCAN_DRV_ConfigPN_Activity
1599  *END**************************************************************************/
1600 void FLEXCAN_DRV_ConfigPN(uint8_t instance, bool enable, const flexcan_pn_config_t *pnConfig)
1601 {
1602  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
1603 
1604  CAN_Type * base = g_flexcanBase[instance];
1605 
1606  FLEXCAN_EnterFreezeMode(base);
1607 
1608  if (enable)
1609  {
1610  FLEXCAN_ConfigPN(base, pnConfig);
1611 #if FEATURE_CAN_HAS_SELF_WAKE_UP
1612  (void)FLEXCAN_SetSelfWakeUp(base, false);
1613 #endif
1614  }
1615 
1616  FLEXCAN_SetPN(base, enable);
1617 
1618  FLEXCAN_ExitFreezeMode(base);
1619 }
1620 
1621 /*FUNCTION**********************************************************************
1622  *
1623  * Function Name : FLEXCAN_DRV_GetWMB
1624  * Description : Extracts one of the frames which triggered the wake up event.
1625  *
1626  * Implements : FLEXCAN_DRV_GetWMB_Activity
1627  *END**************************************************************************/
1628 void FLEXCAN_DRV_GetWMB(uint8_t instance, uint8_t wmbIndex, flexcan_msgbuff_t *wmb)
1629 {
1630  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
1631  DEV_ASSERT(wmb != NULL);
1632 
1633  uint32_t *tmp, wmbData;
1634  const CAN_Type *base = g_flexcanBase[instance];
1635 
1636  tmp = (uint32_t *)&wmb->data[0];
1637  wmbData = base->WMB[wmbIndex].WMBn_D03;
1638  REV_BYTES_32(wmbData, *tmp);
1639 
1640  tmp = (uint32_t *)&wmb->data[4];
1641  wmbData = base->WMB[wmbIndex].WMBn_D47;
1642  REV_BYTES_32(wmbData, *tmp);
1643 
1644  wmb->cs = base->WMB[wmbIndex].WMBn_CS;
1645 
1646  if ((wmb->cs & CAN_CS_IDE_MASK) != 0U)
1647  {
1648  wmb->msgId = base->WMB[wmbIndex].WMBn_ID;
1649  }
1650  else
1651  {
1652  wmb->msgId = base->WMB[wmbIndex].WMBn_ID >> CAN_ID_STD_SHIFT;
1653  }
1654 
1655  wmb->dataLen = (uint8_t)((wmb->cs & CAN_CS_DLC_MASK) >> 16);
1656 }
1657 
1658 #endif /* FEATURE_CAN_HAS_PRETENDED_NETWORKING */
1659 
1660 #if FEATURE_CAN_HAS_SELF_WAKE_UP
1661 
1662 /*FUNCTION**********************************************************************
1663  *
1664  * Function Name : FLEXCAN_DRV_ConfigSelfWakeUp
1665  * Description : Enables/Disables Self Wake Up mode and low pass filter
1666  * applied to Rx input.
1667  *
1668  * Implements : FLEXCAN_DRV_ConfigSelfWakeUp_Activity
1669  *END**************************************************************************/
1670 status_t FLEXCAN_DRV_ConfigSelfWakeUp(uint8_t instance, bool enable, bool lowPassFilterEn)
1671 {
1672  DEV_ASSERT(instance < CAN_INSTANCE_COUNT);
1673 
1674  CAN_Type *base = g_flexcanBase[instance];
1675  status_t status = STATUS_SUCCESS;
1676 
1677  /* Enable Self Wake Up */
1678  status = FLEXCAN_SetSelfWakeUp(base, enable);
1679 
1680  if (status == STATUS_SUCCESS)
1681  {
1682  FLEXCAN_EnterFreezeMode(base);
1683 
1684  /* Enable Low Pass Filter */
1685  FLEXCAN_SetWakSrc(base, lowPassFilterEn);
1686 
1687  FLEXCAN_ExitFreezeMode(base);
1688  }
1689 
1690  return status;
1691 }
1692 
1693 #endif /* FEATURE_CAN_HAS_SELF_WAKE_UP */
1694 
1695 /*FUNCTION**********************************************************************
1696  *
1697  * Function Name : FLEXCAN_DRV_GetDefaultConfig
1698  * Description : Gets the default configuration structure
1699  *
1700  * Implements : FLEXCAN_DRV_GetDefaultConfig_Activity
1701  *END**************************************************************************/
1703 {
1704  /* Checks input parameter. */
1705  DEV_ASSERT(config != NULL);
1706 
1707 #if FEATURE_CAN_HAS_PE_CLKSRC_SELECT
1708  /* Table to save FlexCAN clock indexes in PE clock configuration */
1709  static const flexcan_clk_source_t flexcanPEClkNames[FEATURE_CAN_PE_CLK_NUM] = FLEXCAN_PE_CLOCK_NAMES;
1710 #endif
1711 
1712  /* Time segments computed for PE clock = 8 MHz, bitrate = 500 Kbit/s, sample point = 87.5 */
1713  flexcan_time_segment_t bitrate = {
1714  .propSeg = 7,
1715  .phaseSeg1 = 4,
1716  .phaseSeg2 = 1,
1717  .preDivider = 0,
1718  .rJumpwidth = 1
1719  };
1720 
1721  /* Maximum number of message buffers */
1722  config->max_num_mb = 16;
1723  /* Flexible data rate is disabled */
1724  config->fd_enable = false;
1725  /* Rx FIFO is disabled */
1726  config->is_rx_fifo_needed = false;
1727  /* Number of Rx FIFO ID filters */
1729  /* Normal operation mode */
1730  config->flexcanMode = FLEXCAN_NORMAL_MODE;
1731  /* Payload size */
1732  config->payload = FLEXCAN_PAYLOAD_SIZE_8;
1733 #if FEATURE_CAN_HAS_PE_CLKSRC_SELECT
1734  /* Protocol engine clock is System Oscillator div 2 */
1735  config->pe_clock = flexcanPEClkNames[0];
1736 #endif
1737  /* Time segments for the arbitration phase */
1738  config->bitrate = bitrate;
1739  /* Time segments for the data phase of FD frames */
1740  config->bitrate_cbt = bitrate;
1741  /* Rx FIFO transfer type */
1743  /* Rx FIFO DMA channel */
1744  config->rxFifoDMAChannel = 0U;
1745 }
1746 
1747 /*******************************************************************************
1748  * EOF
1749  ******************************************************************************/
status_t FLEXCAN_DRV_Receive(uint8_t instance, uint8_t mb_idx, flexcan_msgbuff_t *data)
Receives a CAN frame using the specified message buffer.
void FLEXCAN_DRV_GetBitrateFD(uint8_t instance, flexcan_time_segment_t *bitrate)
Gets the FlexCAN bit rate for the data phase of FD frames (BRS enabled).
status_t FLEXCAN_DRV_Deinit(uint8_t instance)
Shuts down a FlexCAN instance.
Internal driver state information.
flexcan_msgbuff_id_type_t
FlexCAN Message Buffer ID type Implements : flexcan_msgbuff_id_type_t_Class.
#define CAN_BASE_PTRS
Definition: S32K142.h:919
flexcan_operation_modes_t flexcanMode
flexcan_fd_payload_size_t payload
status_t FLEXCAN_DRV_ConfigTxMb(uint8_t instance, uint8_t mb_idx, const flexcan_data_info_t *tx_info, uint32_t msg_id)
FlexCAN transmit message buffer field configuration.
status_t OSIF_SemaDestroy(const semaphore_t *const pSem)
Destroys a previously created semaphore.
void FLEXCAN_DRV_GetDefaultConfig(flexcan_user_config_t *config)
Gets the default configuration structure.
flexcan_time_segment_t bitrate
static const IRQn_Type g_flexcanErrorIrqId[]
void * callbackParam
flexcan_rx_mask_type_t
FlexCAN Rx mask type. Implements : flexcan_rx_mask_type_t_Class.
__IO uint32_t WU_MTC
Definition: S32K142.h:882
__IO uint32_t RAMn[CAN_RAMn_COUNT]
Definition: S32K142.h:876
static const IRQn_Type g_flexcanOredMessageBufferIrqId[FEATURE_CAN_MB_IRQS_MAX_COUNT][CAN_INSTANCE_COUNT]
flexcan_rx_fifo_id_filter_num_t num_id_filters
void FLEXCAN_DRV_SetTDCOffset(uint8_t instance, bool enable, uint8_t offset)
Enables/Disables the Transceiver Delay Compensation feature and sets the Transceiver Delay Compensati...
static status_t FLEXCAN_StartRxMessageFifoData(uint8_t instance, flexcan_msgbuff_t *data, bool isBlocking)
status_t FLEXCAN_DRV_RxFifo(uint8_t instance, flexcan_msgbuff_t *data)
Receives a CAN frame using the message FIFO.
__IO uint32_t FDCTRL
Definition: S32K142.h:898
status_t EDMA_DRV_StopChannel(uint8_t channel)
Stops the eDMA channel.
Definition: edma_driver.c:838
uint8_t data[64]
#define FEATURE_CAN_RXFIFO_WARNING
#define CAN_Error_IRQS
Definition: S32K142.h:940
void FLEXCAN_DRV_ConfigRxFifo(uint8_t instance, flexcan_rx_fifo_id_element_format_t id_format, const flexcan_id_table_t *id_filter_table)
FlexCAN Rx FIFO field configuration.
#define CAN_FDCTRL_TDCFAIL_MASK
Definition: S32K142.h:1599
status_t FLEXCAN_DRV_GetTransferStatus(uint8_t instance, uint8_t mb_idx)
Returns whether the previous FlexCAN transfer has finished.
status_t OSIF_SemaCreate(semaphore_t *const pSem, const uint8_t initValue)
Creates a semaphore with a given value.
flexcan_msgbuff_id_type_t msg_id_type
#define CAN_Wake_Up_IRQS
Definition: S32K142.h:939
void FLEXCAN_DRV_InstallEventCallback(uint8_t instance, flexcan_callback_t callback, void *callbackParam)
Installs a callback function for the IRQ handler.
#define CAN_WU_MTC_WTOF_MASK
Definition: S32K142.h:1427
static flexcan_state_t * g_flexcanStatePtr[CAN_INSTANCE_COUNT]
#define REV_BYTES_32(a, b)
Reverse byte order in a word.
Definition: s32_core_cm4.h:125
void INT_SYS_DisableIRQ(IRQn_Type irqNumber)
Disables an interrupt for a given IRQ number.
#define FLEXCAN_MB_HANDLE_RXFIFO
#define CAN_INSTANCE_COUNT
Definition: S32K142.h:904
static void FLEXCAN_CompleteTransfer(uint8_t instance, uint32_t mb_idx)
__I uint32_t WMBn_CS
Definition: S32K142.h:892
#define DEV_ASSERT(x)
Definition: devassert.h:77
void FLEXCAN_DRV_ClearTDCFail(uint8_t instance)
Clears the TDC Fail flag.
static status_t FLEXCAN_StartSendData(uint8_t instance, uint8_t mb_idx, const flexcan_data_info_t *tx_info, uint32_t msg_id, const uint8_t *mb_data, bool isBlocking)
__I uint32_t WMBn_D03
Definition: S32K142.h:894
edma_chn_status_t
Channel status for eDMA channel.
Definition: edma_driver.h:193
flexcan_rxfifo_transfer_type_t transferType
status_t FLEXCAN_DRV_AbortTransfer(uint8_t instance, uint8_t mb_idx)
Ends a non-blocking FlexCAN transfer early.
static const IRQn_Type g_flexcanBusOffIrqId[]
void FLEXCAN_DRV_SetRxMb15Mask(uint8_t instance, flexcan_msgbuff_id_type_t id_type, uint32_t mask)
Sets the FlexCAN Rx MB 15 mask (standard or extended).
#define CAN_WU_MTC_WUMF_MASK
Definition: S32K142.h:1423
void FLEXCAN_DRV_SetRxMaskType(uint8_t instance, flexcan_rx_mask_type_t type)
Sets the Rx masking type.
FlexCAN bitrate related structures Implements : flexcan_time_segment_t_Class.
status_t FLEXCAN_DRV_ConfigRxMb(uint8_t instance, uint8_t mb_idx, const flexcan_data_info_t *rx_info, uint32_t msg_id)
FlexCAN receive message buffer field configuration.
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:44
void(* flexcan_callback_t)(uint8_t instance, flexcan_event_type_t eventType, flexcan_state_t *flexcanState)
FlexCAN Driver callback function type Implements : flexcan_callback_t_Class.
#define FEATURE_CAN_RXFIFO_FRAME_AVAILABLE
flexcan_clk_source_t
bool FLEXCAN_DRV_GetTDCFail(uint8_t instance)
Gets the value of the TDC Fail flag.
FlexCAN message buffer structure Implements : flexcan_msgbuff_t_Class.
flexcan_rx_fifo_id_element_format_t
ID formats for Rx FIFO Implements : flexcan_rx_fifo_id_element_format_t_Class.
status_t FLEXCAN_DRV_SendBlocking(uint8_t instance, uint8_t mb_idx, const flexcan_data_info_t *tx_info, uint32_t msg_id, const uint8_t *mb_data, uint32_t timeout_ms)
Sends a CAN frame using the specified message buffer, in a blocking manner.
#define CAN_FDCTRL_TDCVAL_MASK
Definition: S32K142.h:1591
FlexCAN Rx FIFO ID filter table structure Implements : flexcan_id_table_t_Class.
status_t FLEXCAN_DRV_RxFifoBlocking(uint8_t instance, flexcan_msgbuff_t *data, uint32_t timeout_ms)
Receives a CAN frame using the message FIFO, in a blocking manner.
void(* callback)(uint8_t instance, flexcan_event_type_t eventType, struct FlexCANState *state)
flexcan_time_segment_t bitrate_cbt
flexcan_rxfifo_transfer_type_t transfer_type
flexcan_mb_state_t state
status_t OSIF_SemaWait(semaphore_t *const pSem, const uint32_t timeout)
Decrement a semaphore with timeout.
uint8_t FLEXCAN_DRV_GetTDCValue(uint8_t instance)
Gets the value of the Transceiver Delay Compensation.
status_t EDMA_DRV_StartChannel(uint8_t channel)
Starts an eDMA channel.
Definition: edma_driver.c:813
#define CAN_FDCTRL_TDCFAIL_SHIFT
Definition: S32K142.h:1600
void FLEXCAN_DRV_SetRxFifoGlobalMask(uint8_t instance, flexcan_msgbuff_id_type_t id_type, uint32_t mask)
Sets the FlexCAN Rx FIFO global mask (standard or extended).
__I uint32_t WMBn_D47
Definition: S32K142.h:895
status_t OSIF_SemaPost(semaphore_t *const pSem)
Increment a semaphore.
static CAN_Type *const g_flexcanBase[]
struct CAN_Type::@0 WMB[CAN_WMB_COUNT]
status_t FLEXCAN_DRV_ReceiveBlocking(uint8_t instance, uint8_t mb_idx, flexcan_msgbuff_t *data, uint32_t timeout_ms)
Receives a CAN frame using the specified message buffer, in a blocking manner.
static status_t FLEXCAN_StartRxMessageBufferData(uint8_t instance, uint8_t mb_idx, flexcan_msgbuff_t *data, bool isBlocking)
void FLEXCAN_DRV_SetBitrateCbt(uint8_t instance, const flexcan_time_segment_t *bitrate)
Sets the FlexCAN bit rate for the data phase of FD frames (BRS enabled).
#define FEATURE_CAN_MB_IRQS_MAX_COUNT
void FLEXCAN_IRQHandler(uint8_t instance)
Interrupt handler for a FlexCAN instance.
#define FEATURE_CAN_MB_IRQS
void INT_SYS_EnableIRQ(IRQn_Type irqNumber)
Enables an interrupt for a given IRQ number.
#define FLEXCAN_PE_CLOCK_NAMES
flexcan_msgbuff_t * mb_message
void FLEXCAN_DRV_SetRxMbGlobalMask(uint8_t instance, flexcan_msgbuff_id_type_t id_type, uint32_t mask)
Sets the FlexCAN Rx MB global mask (standard or extended).
FlexCAN data info from user Implements : flexcan_data_info_t_Class.
#define CAN_Bus_Off_IRQS
Definition: S32K142.h:941
status_t FLEXCAN_DRV_Init(uint8_t instance, flexcan_state_t *state, const flexcan_user_config_t *data)
Initializes the FlexCAN peripheral.
status_t EDMA_DRV_ConfigSingleBlockTransfer(uint8_t channel, edma_transfer_type_t type, uint32_t srcAddr, uint32_t destAddr, edma_transfer_size_t transferSize, uint32_t dataBufferSize)
Configures a simple single block data transfer with DMA.
Definition: edma_driver.c:495
status_t FLEXCAN_DRV_Send(uint8_t instance, uint8_t mb_idx, const flexcan_data_info_t *tx_info, uint32_t msg_id, const uint8_t *mb_data)
Sends a CAN frame using the specified message buffer.
status_t FLEXCAN_DRV_SetRxIndividualMask(uint8_t instance, flexcan_msgbuff_id_type_t id_type, uint8_t mb_idx, uint32_t mask)
Sets the FlexCAN Rx individual mask (standard or extended).
volatile flexcan_mb_handle_t mbs[FEATURE_CAN_MAX_MB_NUM]
__I uint32_t WMBn_ID
Definition: S32K142.h:893
#define CAN_FDCTRL_TDCVAL_SHIFT
Definition: S32K142.h:1592
status_t EDMA_DRV_InstallCallback(uint8_t channel, edma_callback_t callback, void *parameter)
Registers the callback function and the parameter for eDMA channel.
Definition: edma_driver.c:293
void FLEXCAN_DRV_SetBitrate(uint8_t instance, const flexcan_time_segment_t *bitrate)
Sets the FlexCAN bit rate for standard frames or the arbitration phase of FD frames.
static void FLEXCAN_CompleteRxMessageFifoData(uint8_t instance)
FlexCAN configuration.
#define FEATURE_CAN_RXFIFO_OVERFLOW
void FLEXCAN_DRV_SetRxMb14Mask(uint8_t instance, flexcan_msgbuff_id_type_t id_type, uint32_t mask)
Sets the FlexCAN Rx MB 14 mask (standard or extended).
void FLEXCAN_DRV_GetBitrate(uint8_t instance, flexcan_time_segment_t *bitrate)
Gets the FlexCAN bit rate for standard frames or the arbitration phase of FD frames.
#define FEATURE_CAN_MAX_MB_NUM
IRQn_Type
Defines the Interrupt Numbers definitions.
Definition: S32K142.h:192
#define FEATURE_CAN_PE_CLK_NUM
Number of FlexCAN PE clock sources.