1 /*
2  * Copyright 2022 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /**
8 *   @file CanEXCEL_Ip.c
9 *
10 *   @addtogroup CanEXCEL
11 *   @{
12 */
13 
14 #include "CanEXCEL_Ip.h"
15 #include "CanEXCEL_Ip_Irq.h"
16 #include "CanEXCEL_Ip_HwAccess.h"
17 
18 CANXL_SIC_Type * EXL_SIC[] = IP_CANXL_SIC_BASE_PTRS;
19 MC_RGM_Type * EXL_RGM[] = IP_MC_RGM_BASE_PTRS;
20 CANXL_MRU_Type * EXL_MRU[] = IP_CANXL_MRU_BASE_PTRS;
21 CANXL_GRP_CONTROL_Type * EXL_GRP[] = IP_CANXL_GRP_CONTROL_BASE_PTRS;
22 CANXL_DSC_CONTROL_Type * EXL_DESC_CTR[] = IP_CANXL_DSC_CONTROL_BASE_PTRS;
23 CANXL_MSG_DESCRIPTORS_Type * EXL_MSGD[] = IP_CANXL_MSG_DESCRIPTORS_BASE_PTRS;
24 CANXL_RXFIFO_CONTROL_Type * EXL_RXF_CNT[] = IP_CANXL_RXFIFO_CONTROL_BASE_PTRS;
25 CANXL_RXFIFO_Type * EXL_RXFIFO[] = IP_CANXL_RXFIFO_BASE_PTRS;
26 CANXL_FILTER_BANK_Type * EXL_FILTER[] = IP_CANXL_FILTER_BANK_BASE_PTRS;
27 #if (CANEXCEL_IP_HAS_TS_ENABLE == STD_ON)
28 CAN_TBS_Type * EXL_TBS[] = IP_CANXL_TBS_BASE_PTRS;
29 #endif
30 static CANEXCEL_StructType CANEXCEL;
31 
32 
33 /* Pointer to runtime state structure.*/
34 static Canexcel_Ip_StateType * Canexcel_Ip_apxState[CANXL_SIC_INSTANCE_COUNT];
35 
36 static void Canexcel_Ip_MainFunction(uint8 instance, uint8 mb_idx);
37 
Canexcel_Ip_MainFunction(uint8 instance,uint8 mb_idx)38 static void Canexcel_Ip_MainFunction(uint8 instance, uint8 mb_idx)
39 {
40     Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[instance];
41     uint32 flag_reg;
42     uint8 total_mb = (((CANEXCEL.EXL_SIC[instance]->SYSMCFG & CANXL_SIC_SYSMCFG_MAXTXMB_MASK) >> CANXL_SIC_SYSMCFG_MAXTXMB_SHIFT) + ((CANEXCEL.EXL_SIC[instance]->SYSMCFG & CANXL_SIC_SYSMCFG_MAXRXMB_MASK) >> CANXL_SIC_SYSMCFG_MAXRXMB_SHIFT));
43     /* Check if instance initialized */
44     if ((NULL_PTR != state) && (mb_idx <= total_mb))
45     {
46         flag_reg = CanXL_GetMsgDescIntStatusFlag(CANEXCEL.EXL_GRP[instance], mb_idx);
47 
48         if (0U != flag_reg)
49         {
50             CanXL_ClearMsgDescIntStatusFlag(CANEXCEL.EXL_GRP[instance], mb_idx);
51             state->msgDesc[mb_idx].noPointers = (CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[mb_idx].STA.DCSTA & CANXL_DSC_CONTROL_DCSTA_HWPOINTER_MASK) >> CANXL_DSC_CONTROL_DCSTA_HWPOINTER_SHIFT;
52             /* First descriptors are always allocated for Transmission */
53             if (mb_idx <= CANEXCEL.EXL_GRP[instance]->DSCCTRL)
54             {
55                 /* Process Tx MDESC */
56                 if (NULL_PTR != state->callback)
57                 {
58                     state->callback(instance, CANEXCEL_EVENT_TX_COMPLETE, mb_idx, state);
59                 }
60             }
61             else
62             {
63                 /* Process Rx MDESC */
64                 if (NULL_PTR != state->callback)
65                 {
66                     state->callback(instance, CANEXCEL_EVENT_RX_COMPLETE, mb_idx, state);
67                 }
68             }
69         }
70     }
71     if((NULL_PTR != state) && (mb_idx == CANEXCEL_IP_MB_RXFIFO))
72     {
73         if (CANEXCEL.EXL_RXF_CNT[instance]->RXFSYSACT == 1U)
74         {
75             if ((CANEXCEL.EXL_RXF_CNT[instance]->RXFIEN & CANXL_RXFIFO_CONTROL_RXFIEN_RXFIE_MASK) &&  (CANEXCEL.EXL_RXF_CNT[instance]->RXFS & CANXL_RXFIFO_CONTROL_RXFS_RXFF_MASK))
76             {
77             	if((CANEXCEL.EXL_RXF_CNT[instance]->RXFS & CANXL_RXFIFO_CONTROL_RXFS_RXFF_MASK) == CANXL_RXFIFO_CONTROL_RXFS_RXFF_MASK)
78             	{
79             		CANEXCEL.EXL_RXF_CNT[instance]->RXFS |= CANXL_RXFIFO_CONTROL_RXFS_RXFF_MASK;
80             		state->rxFifo.noPointers = ((CANEXCEL.EXL_RXF_CNT[instance]->RXFCSTA & CANXL_RXFIFO_CONTROL_RXFCSTA_HWPOINTER_MASK) >> CANXL_RXFIFO_CONTROL_RXFCSTA_HWPOINTER_SHIFT);
81 
82 						/* Process RxFifo for Reception */
83 					  if (NULL_PTR != state->callback)
84 					  {
85 						  state->callback(instance, CANEXCEL_EVENT_RXFIFO_COMPLETE, mb_idx, state);
86 					  }
87             	}
88             }
89         }
90     }
91 }
92 /*FUNCTION**********************************************************************
93  *
94  * Function Name : CanXL_InitBaudrate
95  * Description   : Init baudrate for given controller.
96  * This is not a public API as it is called from other driver functions.
97  *
98  *END**************************************************************************/
CanXL_InitBaudrate(CANXL_SIC_Type * pBase,const Canexcel_Ip_ConfigType * Canxl_Ip_pData)99 static void CanXL_InitBaudrate(CANXL_SIC_Type * pBase, const Canexcel_Ip_ConfigType * Canxl_Ip_pData)
100 {
101     CanXL_SetBaudRate(pBase, &Canxl_Ip_pData->bitrate);
102     if(Canxl_Ip_pData->fd_enable)
103     {
104         CanXL_SetFDBaudRate(pBase, &Canxl_Ip_pData->Fd_bitrate);
105     }
106     if(Canxl_Ip_pData->xl_enable)
107     {
108         CanXL_SetXLBaudRate(pBase, &Canxl_Ip_pData->Xl_bitrate);
109     }
110 }
111 
112 /*FUNCTION**********************************************************************
113  *
114  * Function Name : Canexcel_Ip_GetStartMode
115  * Description   : Check if the Canexcel instance is STARTED.
116  *
117  *END**************************************************************************/
118 /* implements Canexcel_Ip_GetStartMode_Activity */
Canexcel_Ip_GetStartMode(uint8 instance)119 boolean Canexcel_Ip_GetStartMode(uint8 instance)
120 {
121     const CANXL_SIC_Type * base = CANEXCEL.EXL_SIC[instance];
122     return ((0U == (base->SYSMC & (CANXL_SIC_SYSMC_LPMREQ_MASK | CANXL_SIC_SYSMC_FRZREQ_MASK))) ? TRUE : FALSE);
123 }
124 
125 #if (CANEXCEL_IP_HAS_TS_ENABLE == STD_ON)
126 /*FUNCTION**********************************************************************
127  *
128  * Function Name : Canexcel_Ip_ConfigTimeStamp
129  * Description   : Timestamp configuration
130  *
131  *END**************************************************************************/
132 /* implements  Canexcel_Ip_ConfigTimeStamp_Activity */
Canexcel_Ip_ConfigTimeStamp(uint8 instance,const Canexcel_Ip_TimeStampConf_Type * time_stamp)133 Canexcel_Ip_StatusType Canexcel_Ip_ConfigTimeStamp(uint8 instance, const Canexcel_Ip_TimeStampConf_Type * time_stamp)
134 {
135     Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_ERROR;
136 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
137     DevAssert(instance < CANXL_SIC_INSTANCE_COUNT);
138 #endif
139 
140     if (TRUE == CanXL_IsFreezeMode(CANEXCEL.EXL_SIC[instance]))
141     {
142         CanXL_SetTimeStampCaputre(CANEXCEL.EXL_SIC[instance], time_stamp->capture);
143         /* If ts64bit True will enable the timestamp as 64 bits if false will set to 32 bits */
144         CANEXCEL.EXL_SIC[instance]->BCFG2 |= CANXL_SIC_BCFG2_TSS((uint32)time_stamp->ts64bit);
145         returnResult = CANEXCEL_STATUS_SUCCESS;
146         CanXL_SetTimeBaseSource(CANEXCEL.EXL_TBS[instance], time_stamp->src);
147     }
148     return returnResult;
149 }
150 #endif
151 
152 /*FUNCTION**********************************************************************
153  *
154  * Function Name : Canexcel_Ip_SetStopMode
155  * Description   : Set the Canexcel instance in STOP mode.
156  *
157  *END**************************************************************************/
158 /* implements Canexcel_Ip_SetStopMode_Activity */
Canexcel_Ip_SetStopMode(uint8 instance)159 Canexcel_Ip_StatusType Canexcel_Ip_SetStopMode(uint8 instance)
160 {
161 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
162     DevAssert(instance < CANXL_SIC_INSTANCE_COUNT);
163 #endif
164     CANXL_SIC_Type * base = CANEXCEL.EXL_SIC[instance];
165     Canexcel_Ip_StatusType status;
166     status = CanXL_EnterFreezeMode(base);
167     if (CANEXCEL_STATUS_SUCCESS == status)
168     {
169         /* TODO: deactivate all pending tx, this should be move to IPW */
170 
171         /* TODO:Clear all flag */
172 
173         /* TODO: reset MB status */
174 
175         /* TODO: disable all interrupt */
176 
177        /* status = FlexCAN_Disable(pBase); */
178     }
179     return status;
180 }
181 
Canexcel_Ip_Init(uint8 instance,const Canexcel_Ip_ConfigType * Config,Canexcel_Ip_StateType * pState)182 Canexcel_Ip_StatusType Canexcel_Ip_Init(uint8 instance, const Canexcel_Ip_ConfigType * Config, Canexcel_Ip_StateType * pState)
183 {
184   CANEXCEL.EXL_SIC = EXL_SIC;
185   CANEXCEL.EXL_RGM = EXL_RGM;
186   CANEXCEL.EXL_MRU = EXL_MRU;
187   CANEXCEL.EXL_GRP = EXL_GRP;
188   CANEXCEL.EXL_DESC_CTR = EXL_DESC_CTR;
189   CANEXCEL.EXL_MSGD = EXL_MSGD;
190   CANEXCEL.EXL_RXFIFO = EXL_RXFIFO;
191   CANEXCEL.EXL_RXF_CNT = EXL_RXF_CNT;
192   CANEXCEL.EXL_FILTER = EXL_FILTER;
193 #if (CANEXCEL_IP_HAS_TS_ENABLE == STD_ON)
194   CANEXCEL.EXL_TBS = EXL_TBS;
195 #endif
196   Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_SUCCESS;
197 
198   uint32 timeStart = 0U;
199   uint32 timeElapsed = 0U;
200   uint32 uS2Ticks = OsIf_MicrosToTicks(CANEXCEL_IP_TIMEOUT_DURATION, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
201   /* Wait Hardware to became available after clock start */
202   while ((CANEXCEL.EXL_SIC[instance]->SYSS & CANXL_SIC_SYSS_FRZACKF_MASK) == 0U)
203   {
204       timeElapsed += OsIf_GetElapsed(&timeStart, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
205       if (timeElapsed >= uS2Ticks)
206       {
207           returnResult = CANEXCEL_STATUS_TIMEOUT;
208           break;
209       }
210   }
211   if(returnResult == CANEXCEL_STATUS_SUCCESS)
212   {
213       returnResult = CanXL_SoftReset(CANEXCEL.EXL_SIC[instance]);
214   }
215   if(returnResult == CANEXCEL_STATUS_SUCCESS)
216   {
217       returnResult = CanXL_EnterFreezeMode(CANEXCEL.EXL_SIC[instance]);
218   }
219   if (returnResult == CANEXCEL_STATUS_SUCCESS)
220   {
221 
222       /* CANEXCEL Data Memory Write Access Enable for Host */
223       CANEXCEL.EXL_SIC[instance]->SYSMCFG &= ~CANXL_SIC_SYSMCFG_DRWRDIS_MASK;
224       /* Clear Memory ram and initialize it */
225       CanXL_ClearRAM(&CANEXCEL, instance);
226       CANEXCEL.EXL_GRP[instance]->DSCCTRL = CANXL_GRP_CONTROL_DSCCTRL_TXDSC(Config->tx_mbdesc-1u);
227       CANEXCEL.EXL_SIC[instance]->SYSMCFG |= (CANXL_SIC_SYSMCFG_MAXTXMB(Config->tx_mbdesc) | CANXL_SIC_SYSMCFG_MAXRXMB(Config->rx_mbdesc));
228       CanXL_SetFDEnabled(CANEXCEL.EXL_SIC[instance], Config->fd_enable, Config->bitRateSwitch);
229       CanXL_SetXLEnable(CANEXCEL.EXL_SIC[instance], Config->xl_enable);
230       CanXL_InitBaudrate(CANEXCEL.EXL_SIC[instance], Config);
231       CanXL_SetOperationMode(CANEXCEL.EXL_SIC[instance], Config->CanxlMode);
232       returnResult = CanXL_ConfigCtrlOptions(CANEXCEL.EXL_SIC[instance], Config->ctrlOptions);
233       for(timeElapsed = 0U; timeElapsed<Config->tx_mbdesc; timeElapsed++ )
234       {
235           /* Better to be moved at init because requires Freeze mode */
236           CANEXCEL.EXL_MSGD[instance]->MSGDSC[timeElapsed].LSTPNT.TXLSTPTR = (uint32)&pState->msgDesc[timeElapsed].list;
237       }
238       for(; timeElapsed<(Config->rx_mbdesc + Config->tx_mbdesc); timeElapsed++ )
239       {
240           /* Better to be moved at init because requires Freeze mode */
241           CANEXCEL.EXL_MSGD[instance]->MSGDSC[timeElapsed].LSTPNT.RXLSTPTR = (uint32)&pState->msgDesc[timeElapsed].list;
242       }
243       if (TRUE == Config->is_rx_fifo_needed)
244       {
245     	  CANEXCEL.EXL_RXF_CNT[instance]->RXFC = CANXL_RXFIFO_CONTROL_RXFC_RXFD(Config->pRxFifoConfig->Rx_Fifo_Depth-1U)|CANXL_RXFIFO_CONTROL_RXFC_RXFWTM(Config->pRxFifoConfig->Rx_Fifo_Watermark - 1U);
246     	  uint16 dlcValue = 0u;
247     	  if(Config->pRxFifoConfig->frameType == CANEXCEL_XL_FRAME)
248     	  {
249               Canexcel_Ip_apxState[instance]->rxFifo.isXLFrame = TRUE;
250     		  dlcValue = Config->pRxFifoConfig->Rx_Fifo_Msg_Size - 1u;
251     		  Canexcel_RxXlMsg * RxFifoMsgBuff= (Canexcel_RxXlMsg *)Config->pRxFifoConfig->MsgBuffersPtr;
252         	  for(uint8 idx = 0; idx < Config->pRxFifoConfig->Rx_Fifo_Depth; idx++)
253         	  {
254         		  CANEXCEL.EXL_RXFIFO[instance]->RXFMBP[idx] = (uint32)&RxFifoMsgBuff[idx];
255         	  }
256     	  }
257     	  else
258     	  {
259               Canexcel_Ip_apxState[instance]->rxFifo.isXLFrame = FALSE;
260     		  dlcValue = CAN_ComputeDLCValue(Config->pRxFifoConfig->Rx_Fifo_Msg_Size);
261     		  Canexcel_RxFdMsg * RxFifoMsgBuff= (Canexcel_RxFdMsg *)Config->pRxFifoConfig->MsgBuffersPtr;
262         	  for(uint8 idx = 0; idx < Config->pRxFifoConfig->Rx_Fifo_Depth; idx++)
263         	  {
264         		  CANEXCEL.EXL_RXFIFO[instance]->RXFMBP[idx] = (uint32)&RxFifoMsgBuff[idx];
265         	  }
266     	  }
267     	  if (Config->pRxFifoConfig->Rx_Fifo_EnFilterBank1 == TRUE)
268     	  {
269     		  CANEXCEL.EXL_SIC[instance]->SYSMCFG |= CANXL_SIC_SYSMCFG_FB1EN(1U);
270     	  }
271     	  else
272     	  {
273     		  CANEXCEL.EXL_SIC[instance]->SYSMCFG |= CANXL_SIC_SYSMCFG_FB1EN(0U);
274     	  }
275     	  CANEXCEL.EXL_RXFIFO[instance]->RXFFCTR = CANXL_RXFIFO_RXFFCTR_MBSIZE(dlcValue) | CANXL_RXFIFO_RXFFCTR_KEEPLST(Config->pRxFifoConfig->Rx_Fifo_KeepLast);
276     	  /* Activate RxFifo */
277     	  CANEXCEL.EXL_RXF_CNT[instance]->RXFSYSACT = CANXL_RXFIFO_CONTROL_RXFSYSACT_ACT_MASK;
278     	  Canexcel_Ip_apxState[instance]->rxFifo.isPolling = Config->pRxFifoConfig->isPolling;
279       }
280   }
281   if (returnResult == CANEXCEL_STATUS_SUCCESS)
282   {
283       CanXL_ResetImaskBuff(CANEXCEL.EXL_GRP[instance], instance);
284       /* Config Interrupts Line 0, this will not enable them */
285       CanXL_ConfigInterrupts(instance);
286       /* Clear Callbacks in case of autovariables garbage */
287       Canexcel_Ip_apxState[instance] = pState;
288       Canexcel_Ip_apxState[instance]->callback = Config->Callback;
289       Canexcel_Ip_apxState[instance]->callbackParam = NULL_PTR;
290       Canexcel_Ip_apxState[instance]->error_callback = Config->ErrorCallback;
291       Canexcel_Ip_apxState[instance]->errorCallbackParam = NULL_PTR;
292       Canexcel_Ip_apxState[instance]->isIntActive = FALSE;
293   }
294   return returnResult;
295 }
296 
Canexcel_Ip_SetRxIndividualMask(uint8 instance,uint8 descNo,Canexcel_Ip_FrameType frameType,uint32 mask)297 Canexcel_Ip_StatusType Canexcel_Ip_SetRxIndividualMask(uint8 instance, uint8 descNo, Canexcel_Ip_FrameType frameType, uint32 mask)
298 {
299     Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_SUCCESS;
300     if (CANEXCEL_XL_FRAME == frameType)
301     {
302         CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CFG1.MDFLT1XL = mask;
303     }
304     else
305     {
306         CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CFG1.MDFLT1FD = mask;
307     }
308     return returnResult;
309 }
310 
Canexcel_Ip_ConfigRx(uint8 instance,uint8 descNo,uint32 msgId,Canexcel_Ip_DataInfoType * info)311 Canexcel_Ip_StatusType Canexcel_Ip_ConfigRx(uint8 instance, uint8 descNo, uint32 msgId, Canexcel_Ip_DataInfoType * info)
312 {
313     uint16 dlcValue = 0U;
314     uint32 timeStart = 0U;
315     uint32 timeElapsed = 0U;
316     Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[instance];
317     Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_SUCCESS;
318     uint32 uS2Ticks = OsIf_MicrosToTicks(CANEXCEL_IP_TIMEOUT_DURATION, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
319     timeStart = OsIf_GetCounter(CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
320 
321     while (CANEXCEL_DESCNTSTATUS_LOCKED_HW == CanXL_GetDescControlStatus(CANEXCEL.EXL_DESC_CTR[instance], descNo))
322     {
323         timeElapsed += OsIf_GetElapsed(&timeStart, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
324         if (timeElapsed >= uS2Ticks)
325         {
326             returnResult = CANEXCEL_STATUS_TIMEOUT;
327             break;
328         }
329     }
330 
331     if (CanXL_GetDesciptorState(CANEXCEL.EXL_DESC_CTR[instance], descNo) >= CANEXCEL_DESC_STATE_FULL)
332     {
333         returnResult = CANEXCEL_STATUS_BUSY;
334     }
335     if (returnResult == CANEXCEL_STATUS_SUCCESS)
336     {
337         CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CTRL.RXCTRL = 0U;
338         if(info->frame == CANEXCEL_XL_FRAME)
339         {
340             state->msgDesc[descNo].isXLFrame = TRUE;
341             CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CTRL.RXCTRL |= CANXL_MSG_DESCRIPTORS_RXCTRL_RXXLFRM_MASK;
342             dlcValue = info->dataLength - 1U;
343             if (info->idType == CANEXCEL_MSG_ID_EXT)
344             {
345 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
346                 /* CanXL frame type supports only STD ID frame types */
347                 DevAssert(FALSE);
348 #endif
349             }
350             else
351             {
352                 CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CFG2.MDFLT2XL = CANXL_MSG_DESCRIPTORS_MDFLT2XL_IDSTDa_H(msgId);
353                 CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CFG2.MDFLT2XL |= CANXL_MSG_DESCRIPTORS_MDFLT2XL_SEC(info->SEC) | CANXL_MSG_DESCRIPTORS_MDFLT2XL_RJCT_SDU(info->STD) | CANXL_MSG_DESCRIPTORS_MDFLT2XL_RJCT_VCAN(info->VCID);
354             }
355         }
356         else if (info->frame == CANEXCEL_FD_FRAME)
357         {
358             state->msgDesc[descNo].isXLFrame = FALSE;
359             CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CTRL.RXCTRL |= CANXL_MSG_DESCRIPTORS_RXCTRL_RXFDFRM_MASK;
360             dlcValue = CAN_ComputeDLCValue(info->dataLength);
361             if (info->idType == CANEXCEL_MSG_ID_EXT)
362             {
363                 CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CFG2.MDFLT2FD = CANXL_MSG_DESCRIPTORS_MDFLT2FD_IDE_MASK | msgId;
364             }
365             else
366             {
367                 CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CFG2.MDFLT2FD = CANXL_MSG_DESCRIPTORS_MDFLT2FD_IDSTDa_H(msgId);
368             }
369         }
370         else
371         {
372             /* expected Classic Frame Type */
373             state->msgDesc[descNo].isXLFrame = FALSE;
374             dlcValue = CAN_ComputeDLCValue(info->dataLength);
375             if (info->idType == CANEXCEL_MSG_ID_EXT)
376             {
377                 CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CFG2.MDFLT2FD = CANXL_MSG_DESCRIPTORS_MDFLT2FD_IDE_MASK | msgId;
378             }
379             else
380             {
381                 CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CFG2.MDFLT2FD = CANXL_MSG_DESCRIPTORS_MDFLT2FD_IDSTDa_H(msgId);
382             }
383         }
384         CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CTRL.RXCTRL |= CANXL_MSG_DESCRIPTORS_RXCTRL_MBSIZE(dlcValue);
385     }
386     return returnResult;
387 }
388 
Canexcel_Ip_RxDescriptor(uint8 instance,uint8 descNo,uint32 rxPtrList)389 Canexcel_Ip_StatusType Canexcel_Ip_RxDescriptor(uint8 instance, uint8 descNo, uint32 rxPtrList)
390 {
391     uint32 timeStart = 0U;
392     uint32 timeElapsed = 0U;
393     Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[instance];
394     Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_SUCCESS;
395     uint32 uS2Ticks = OsIf_MicrosToTicks(CANEXCEL_IP_TIMEOUT_DURATION, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
396     timeStart = OsIf_GetCounter(CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
397     /* Update system lock Status */
398     (void)CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].SYSLOCK.DCSYSLOCK;
399     while (CANEXCEL_DESCNTSTATUS_LOCKED_HW == CanXL_GetDescControlStatus(CANEXCEL.EXL_DESC_CTR[instance], descNo))
400     {
401         timeElapsed += OsIf_GetElapsed(&timeStart, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
402         if (timeElapsed >= uS2Ticks)
403         {
404             returnResult = CANEXCEL_STATUS_TIMEOUT;
405             break;
406         }
407     }
408     /* Check if the descriptor is empy or inactive (*/
409     if ((CanXL_GetDesciptorState(CANEXCEL.EXL_DESC_CTR[instance], descNo) <= CANEXCEL_DESC_STATE_EMPTY) && (returnResult == CANEXCEL_STATUS_SUCCESS))
410     {
411         state->msgDesc[descNo].list[0U] = rxPtrList;
412         CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].ACT.DCACT = 1U;
413         CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].SYSLOCK.DCSYSLOCK = 1U;
414         CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].PUSHPOP.DCSYSPUSH = 0U;
415     }
416     else
417     {
418         returnResult = CANEXCEL_STATUS_ERROR;
419     }
420     return returnResult;
421 }
422 
Canexcel_Ip_ReceiveFD(uint8 instance,uint8 descNo,Canexcel_RxFdMsg * RxMsg,boolean isPolling)423 Canexcel_Ip_StatusType Canexcel_Ip_ReceiveFD(uint8 instance, uint8 descNo, Canexcel_RxFdMsg * RxMsg, boolean isPolling)
424 {
425     Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_ERROR;
426     if (isPolling == FALSE)
427     {
428         CanXL_SetMsgBuffIntCmd(CANEXCEL.EXL_GRP[instance], descNo);
429     }
430     returnResult = Canexcel_Ip_RxDescriptor(instance, descNo, (uint32)&RxMsg->Header.Id);
431     return returnResult;
432 }
433 
Canexcel_Ip_ReceiveXL(uint8 instance,uint8 descNo,Canexcel_RxXlMsg * RxMsg,boolean isPolling)434 Canexcel_Ip_StatusType Canexcel_Ip_ReceiveXL(uint8 instance, uint8 descNo, Canexcel_RxXlMsg * RxMsg, boolean isPolling)
435 {
436     Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_ERROR;
437     if (isPolling == FALSE)
438     {
439         CanXL_SetMsgBuffIntCmd(CANEXCEL.EXL_GRP[instance], descNo);
440     }
441     returnResult = Canexcel_Ip_RxDescriptor(instance, descNo, (uint32)&RxMsg->Header.Id);
442     return returnResult;
443 }
444 
Canexcel_Ip_TxDescriptor(uint8 instance,uint8 descNo,uint32 txPtrList)445 Canexcel_Ip_StatusType Canexcel_Ip_TxDescriptor(uint8 instance, uint8 descNo, uint32 txPtrList)
446 {
447     uint32 timeStart = 0U;
448     uint32 timeElapsed = 0U;
449     Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[instance];
450     Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_SUCCESS;
451     uint32 uS2Ticks = OsIf_MicrosToTicks(CANEXCEL_IP_TIMEOUT_DURATION, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
452     timeStart = OsIf_GetCounter(CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
453     /* Set system lock Status */
454     (void)CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].SYSLOCK.DCSYSLOCK;
455     while (CANEXCEL_DESCNTSTATUS_LOCKED_HW == CanXL_GetDescControlStatus(CANEXCEL.EXL_DESC_CTR[instance], descNo))
456     {
457         timeElapsed += OsIf_GetElapsed(&timeStart, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
458         if (timeElapsed >= uS2Ticks)
459         {
460             returnResult = CANEXCEL_STATUS_TIMEOUT;
461             break;
462         }
463     }
464     if(returnResult == CANEXCEL_STATUS_SUCCESS)
465     {
466         state->msgDesc[descNo].list[0u] = txPtrList;
467         CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].ACT.DCACT = 1U;
468         CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].SYSLOCK.DCSYSLOCK = 1U;
469         CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].PUSHPOP.DCSYSPUSH = 0u;
470     }
471     return returnResult;
472 }
473 
Canexcel_Ip_ConfigXlTx(uint8 instance,uint8 mbIdx,uint32 id,Canexcel_Ip_DataInfoType * info,Canexcel_TxXlMsgType * TxMsg)474 void static Canexcel_Ip_ConfigXlTx(uint8 instance, uint8 mbIdx, uint32 id, Canexcel_Ip_DataInfoType * info, Canexcel_TxXlMsgType * TxMsg)
475 {
476     Canexcel_Ip_apxState[instance]->msgDesc[mbIdx].isXLFrame = TRUE;
477     TxMsg->Header.timeStampL = 0U;
478     TxMsg->Header.timeStampL = 0U;
479     TxMsg->Header.word3 = 0U;
480     TxMsg->Header.word2 = 0U;
481     TxMsg->Header.word4 = 0U;
482     TxMsg->Header.word2 = CANXL_TX_HEADER_MODE_MASK | ((info->priority << CANXL_TX_HEADER_PRIO_SHIFT) & CANXL_TX_HEADER_PRIO_MASK)
483                        | ((info->retransmission << CANXL_TX_HEADER_RETR_SHIFT) & CANXL_TX_HEADER_RETR_MASK );
484     if(info->idType == CANEXCEL_MSG_ID_EXT )
485     {
486         TxMsg->Header.word3 = CANXL_TX_HEADER_IDE_MASK | (id & CANXL_IP_ID_EXT_MASK);
487     }
488     else
489     {
490         TxMsg->Header.word3 = ((id << CANXL_IP_ID_STD_SHIFT) & CANXL_IP_ID_STD_MASK);
491     }
492     TxMsg->Header.word4 = CANXL_TX_HEADER_FDF_MASK;
493     TxMsg->Header.word3 |= CANXL_TX_HEADER_XLF_MASK;
494     TxMsg->Header.word4 |= (((info->dataLength - 1u) << CANXL_TX_HEADER_DLC_SHIFT) & CANXL_TX_HEADER_DLC_MASK);
495 }
496 
Canexcel_Ip_ConfigFdTx(uint8 instance,uint8 mbIdx,uint32 id,Canexcel_Ip_DataInfoType * info,Canexcel_TxFdMsgType * TxMsg)497 void static Canexcel_Ip_ConfigFdTx(uint8 instance, uint8 mbIdx, uint32 id, Canexcel_Ip_DataInfoType * info, Canexcel_TxFdMsgType * TxMsg)
498 {
499     Canexcel_Ip_apxState[instance]->msgDesc[mbIdx].isXLFrame = FALSE;
500     uint16 dlcValue = 0U;
501     TxMsg->Header.timeStampL = 0U;
502     TxMsg->Header.timeStampL = 0U;
503     TxMsg->Header.word3 = 0U;
504     TxMsg->Header.word2 = 0U;
505     TxMsg->Header.word4 = 0U;
506     TxMsg->Header.word2 = CANXL_TX_HEADER_MODE_MASK | ((info->priority << CANXL_TX_HEADER_PRIO_SHIFT) & CANXL_TX_HEADER_PRIO_MASK)
507                        | ((info->retransmission << CANXL_TX_HEADER_RETR_SHIFT) & CANXL_TX_HEADER_RETR_MASK );
508     if(info->idType == CANEXCEL_MSG_ID_EXT )
509     {
510         TxMsg->Header.word3 = CANXL_TX_HEADER_IDE_MASK | (id & CANXL_IP_ID_EXT_MASK);
511     }
512     else
513     {
514         TxMsg->Header.word3 = ((id << CANXL_IP_ID_STD_SHIFT) & CANXL_IP_ID_STD_MASK);
515     }
516 
517     dlcValue = CAN_ComputeDLCValue(info->dataLength);
518     if(info->frame == CANEXCEL_FD_FRAME)
519     {
520         TxMsg->Header.word4 = CANXL_TX_HEADER_FDF_MASK;
521         if (info->enable_brs == TRUE)
522         {
523             TxMsg->Header.word4 |= CANXL_TX_HEADER_BRS_MASK;
524         }
525     }
526     TxMsg->Header.word4 |= ((dlcValue << CANXL_TX_HEADER_DLC_SHIFT) & CANXL_TX_HEADER_DLC_MASK);
527 }
528 
Canexcel_Ip_SendFDMsg(uint8 instance,uint8 mbIdx,Canexcel_Ip_DataInfoType * info,uint32 id,uint8 * dataPtr,Canexcel_TxFdMsgType * TxMsg)529 Canexcel_Ip_StatusType Canexcel_Ip_SendFDMsg(uint8 instance, uint8 mbIdx, Canexcel_Ip_DataInfoType * info, uint32 id, uint8 * dataPtr,Canexcel_TxFdMsgType * TxMsg)
530 {
531     Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_ERROR;
532     if(!CanXL_IsListenOnlyModeEnabled(CANEXCEL.EXL_SIC[instance]))
533     {
534         Canexcel_Ip_ConfigFdTx(instance, mbIdx, id, info, TxMsg);
535         CanXL_SetTxMsgBuffData(info, dataPtr, (uint8 *)&TxMsg->data[0]);
536         if (info->is_polling == FALSE)
537         {
538             CanXL_SetMsgBuffIntCmd(CANEXCEL.EXL_GRP[instance], mbIdx);
539         }
540         returnResult = Canexcel_Ip_TxDescriptor(instance, mbIdx, (uint32)&TxMsg->Header.timeStampL);
541     }
542     return returnResult;
543 }
544 
Canexcel_Ip_SendXLMsg(uint8 instance,uint8 mbIdx,Canexcel_Ip_DataInfoType * info,uint32 id,uint8 * dataPtr,Canexcel_TxXlMsgType * TxMsg)545 Canexcel_Ip_StatusType Canexcel_Ip_SendXLMsg(uint8 instance, uint8 mbIdx, Canexcel_Ip_DataInfoType * info, uint32 id, uint8 * dataPtr,Canexcel_TxXlMsgType * TxMsg)
546 {
547     Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_ERROR;
548     if(!CanXL_IsListenOnlyModeEnabled(CANEXCEL.EXL_SIC[instance]))
549     {
550         Canexcel_Ip_ConfigXlTx(instance, mbIdx, id, info, TxMsg);
551         CanXL_SetTxMsgBuffData(info, dataPtr, (uint8 *)&TxMsg->data[0]);
552         if (info->is_polling == FALSE)
553         {
554             CanXL_SetMsgBuffIntCmd(CANEXCEL.EXL_GRP[instance], mbIdx);
555         }
556         returnResult = Canexcel_Ip_TxDescriptor(instance, mbIdx, (uint32)&TxMsg->Header.timeStampL);
557     }
558     return returnResult;
559 }
560 
Canexcel_Ip_GetTransferStatus(uint8 instance,uint8 mbIdx)561 Canexcel_Ip_StatusType Canexcel_Ip_GetTransferStatus(uint8 instance, uint8 mbIdx)
562 {
563     Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_NO_TRANSFER_IN_PROGRESS;
564     /* Check if the descriptor is active */
565     if (CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[mbIdx].ACT.DCACT == CANXL_DSC_CONTROL_DCACT_ACT_MASK)
566     {
567         if (CanXL_GetDesciptorState(CANEXCEL.EXL_DESC_CTR[instance], mbIdx) == CANEXCEL_DESC_STATE_EMPTY)
568         {
569             returnResult = CANEXCEL_STATUS_SUCCESS;
570         }
571         if (CanXL_GetDesciptorState(CANEXCEL.EXL_DESC_CTR[instance], mbIdx) == CANEXCEL_DESC_STATE_FULL)
572         {
573             returnResult = CANEXCEL_STATUS_BUSY;
574         }
575         if(CanXL_GetDesciptorState(CANEXCEL.EXL_DESC_CTR[instance], mbIdx) == CANEXCEL_DESC_STATE_OVERRUN)
576         {
577             returnResult = CANEXCEL_STATUS_ERROR;
578         }
579     }
580     return returnResult;
581 }
582 
Canexcel_Ip_EnterFreezeMode(uint8 instance)583 Canexcel_Ip_StatusType Canexcel_Ip_EnterFreezeMode(uint8 instance)
584 {
585     return CanXL_EnterFreezeMode(CANEXCEL.EXL_SIC[instance]);
586 }
587 
Canexcel_Ip_ExitFreezeMode(uint8 instance)588 Canexcel_Ip_StatusType Canexcel_Ip_ExitFreezeMode(uint8 instance)
589 {
590     return CanXL_ExitFreezeMode(CANEXCEL.EXL_SIC[instance]);
591 }
592 
Canexcel_Ip_EnableInterrupts(uint8 u8Instance)593 void Canexcel_Ip_EnableInterrupts(uint8 u8Instance)
594 {
595     Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[u8Instance];
596     CanXL_EnableInterrupts(CANEXCEL.EXL_SIC[u8Instance], u8Instance);
597     if(((CANEXCEL.EXL_RXF_CNT[u8Instance]->RXFSYSACT & CANXL_RXFIFO_CONTROL_RXFSYSACT_ACT_MASK) == CANXL_RXFIFO_CONTROL_RXFSYSACT_ACT_MASK ) && (Canexcel_Ip_apxState[u8Instance]->rxFifo.isPolling == FALSE))
598     {
599     	/* Activate RxFifo Interrupts */
600     	CANEXCEL.EXL_RXF_CNT[u8Instance]->RXFIEN = CANXL_RXFIFO_CONTROL_RXFIEN_RXFIE_MASK | CANXL_RXFIFO_CONTROL_RXFIEN_RXFEIE_MASK;
601     }
602     state->isIntActive = TRUE;
603 }
604 
Canexcel_Ip_DisableInterrupts(uint8 u8Instance)605 void Canexcel_Ip_DisableInterrupts(uint8 u8Instance)
606 {
607     Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[u8Instance];
608     CanXL_DisableInterrupts(CANEXCEL.EXL_SIC[u8Instance], u8Instance);
609     if(((CANEXCEL.EXL_RXF_CNT[u8Instance]->RXFSYSACT & CANXL_RXFIFO_CONTROL_RXFSYSACT_ACT_MASK) == CANXL_RXFIFO_CONTROL_RXFSYSACT_ACT_MASK ) && (Canexcel_Ip_apxState[u8Instance]->rxFifo.isPolling == FALSE))
610     {
611     	/* Clear RxFifo Interrupts */
612     	CANEXCEL.EXL_RXF_CNT[u8Instance]->RXFIEN = ~(CANXL_RXFIFO_CONTROL_RXFIEN_RXFIE_MASK | CANXL_RXFIFO_CONTROL_RXFIEN_RXFEIE_MASK);
613     }
614     state->isIntActive = FALSE;
615 }
616 
Canexcel_Ip_RxTxIRQHandler(uint8 instance)617 void Canexcel_Ip_RxTxIRQHandler(uint8 instance)
618 {
619     Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[instance];
620     uint32 flag_reg;
621     uint32 mb_idx = 0U;
622     uint8 total_mb = (((CANEXCEL.EXL_SIC[instance]->SYSMCFG & CANXL_SIC_SYSMCFG_MAXTXMB_MASK) >> CANXL_SIC_SYSMCFG_MAXTXMB_SHIFT) + ((CANEXCEL.EXL_SIC[instance]->SYSMCFG & CANXL_SIC_SYSMCFG_MAXRXMB_MASK) >> CANXL_SIC_SYSMCFG_MAXRXMB_SHIFT));
623     /* Check if instance initialized */
624     if (NULL_PTR != state)
625     {
626         flag_reg = CanXL_GetMsgBuffIntStatusFlag(CANEXCEL.EXL_GRP[instance], mb_idx);
627         while((0U == flag_reg) && (mb_idx < total_mb ))
628         {
629             mb_idx++;
630             flag_reg = CanXL_GetMsgBuffIntStatusFlag(CANEXCEL.EXL_GRP[instance], mb_idx);
631         }
632 
633         if (0U != flag_reg)
634         {
635             CanXL_ClearMsgDescIntStatusFlag(CANEXCEL.EXL_GRP[instance], mb_idx);
636             state->msgDesc[mb_idx].noPointers = (CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[mb_idx].STA.DCSTA & CANXL_DSC_CONTROL_DCSTA_HWPOINTER_MASK) >> CANXL_DSC_CONTROL_DCSTA_HWPOINTER_SHIFT;
637             /* First descriptors are always allocated for Transmission */
638             if (mb_idx <= CANEXCEL.EXL_GRP[instance]->DSCCTRL)
639             {
640                 /* Process Tx MDESC */
641                 if (NULL_PTR != state->callback)
642                 {
643                     state->callback(instance, CANEXCEL_EVENT_TX_COMPLETE, mb_idx, state);
644                 }
645             }
646             else
647             {
648                 /* Process Rx MDESC */
649                 if (NULL_PTR != state->callback)
650                 {
651                     state->callback(instance, CANEXCEL_EVENT_RX_COMPLETE, mb_idx, state);
652                 }
653             }
654         }
655         if (CANEXCEL.EXL_RXF_CNT[instance]->RXFSYSACT == 1U)
656         {
657             if ((CANEXCEL.EXL_RXF_CNT[instance]->RXFIEN & CANXL_RXFIFO_CONTROL_RXFIEN_RXFIE_MASK) &&  (CANEXCEL.EXL_RXF_CNT[instance]->RXFS & CANXL_RXFIFO_CONTROL_RXFS_RXFF_MASK))
658             {
659             	/* Clear the fifo flag */
660               CANEXCEL.EXL_RXF_CNT[instance]->RXFS = CANXL_RXFIFO_CONTROL_RXFS_RXFF_MASK;
661               /* Process RxFifo for Reception */
662 			  if (NULL_PTR != state->callback)
663 			  {
664 				  state->callback(instance, CANEXCEL_EVENT_RXFIFO_COMPLETE, CANEXCEL_IP_MB_RXFIFO, state);
665 			  }
666             }
667         }
668     }
669 }
670 
Canexcel_Ip_ErrIRQHandler(uint8 instance)671 void Canexcel_Ip_ErrIRQHandler(uint8 instance)
672 {
673     Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[instance];
674     uint32 sysStatus = CANEXCEL.EXL_SIC[instance]->SYSS;
675 
676     /* Process CANEXCEL Error */
677     if (NULL_PTR != state->error_callback)
678     {
679         if ((CANEXCEL.EXL_SIC[instance]->SYSIE & CANXL_SIC_SYSIE_CERRIE_MASK) & sysStatus)
680         {
681             CANEXCEL.EXL_SIC[instance]->SYSS |= CANXL_SIC_SYSS_CERR_MASK;
682             state->error_callback(instance, CANEXCEL_EVENT_ERROR, sysStatus, state);
683         }
684         if ((CANEXCEL.EXL_SIC[instance]->SYSIE & CANXL_SIC_SYSIE_CFDPERRIE_MASK) & sysStatus)
685         {
686             CANEXCEL.EXL_SIC[instance]->SYSS |= CANXL_SIC_SYSS_CFDPERR_MASK;
687             state->error_callback(instance, CANEXCEL_EVENT_ERROR_FD, sysStatus, state);
688         }
689         if ((CANEXCEL.EXL_SIC[instance]->SYSIE & CANXL_SIC_SYSIE_CRXWRNIE_MASK) & sysStatus)
690         {
691             CANEXCEL.EXL_SIC[instance]->SYSS |= CANXL_SIC_SYSS_CRXWRN_MASK;
692             state->error_callback(instance, CANEXCEL_EVENT_RX_WARNING, sysStatus, state);
693         }
694         if ((CANEXCEL.EXL_SIC[instance]->SYSIE & CANXL_SIC_SYSIE_CTXWRNIE_MASK) & sysStatus)
695         {
696             CANEXCEL.EXL_SIC[instance]->SYSS |= CANXL_SIC_SYSS_CTXWRN_MASK;
697             state->error_callback(instance, CANEXCEL_EVENT_TX_WARNING, sysStatus, state);
698         }
699         if ((CANEXCEL.EXL_SIC[instance]->SYSIE & CANXL_SIC_SYSIE_CDPERRIE_MASK) & sysStatus)
700         {
701             CANEXCEL.EXL_SIC[instance]->SYSS |= CANXL_SIC_SYSS_CXDPERR_MASK;
702             state->error_callback(instance, CANEXCEL_EVENT_ERROR_XL, sysStatus, state);
703         }
704         if ((CANEXCEL.EXL_SIC[instance]->SYSIE & CANXL_SIC_SYSIE_CPERRIE_MASK) & sysStatus)
705         {
706             CANEXCEL.EXL_SIC[instance]->SYSS |= CANXL_SIC_SYSS_CPASERR_MASK;
707             state->error_callback(instance, CANEXCEL_EVENT_ERROR_XL, sysStatus, state);
708         }
709     }
710 }
711 
712 /*FUNCTION**********************************************************************
713  *
714  * Function Name : Canexcel_Ip_SetErrorInt
715  * Description   : Enable\Disable Error or BusOff Interrupt
716  *
717  *END**************************************************************************/
718 /* implements Canexcel_Ip_SetErrorInt_Activity */
Canexcel_Ip_SetErrorInt(uint8 u8Instance,Canexcel_Ip_ErrorIntType type,boolean enable)719 Canexcel_Ip_StatusType Canexcel_Ip_SetErrorInt(uint8 u8Instance, Canexcel_Ip_ErrorIntType type, boolean enable)
720 {
721     Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_ERROR;
722     if (TRUE == CanXL_IsFreezeMode(CANEXCEL.EXL_SIC[u8Instance]))
723     {
724         switch (type)
725         {
726         case CANEXCEL_IP_INT_RX_WARNING:
727         {
728             CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_RX_WARNING, enable);
729             returnResult = CANEXCEL_STATUS_SUCCESS;
730             break;
731         }
732         case CANEXCEL_IP_INT_TX_WARNING:
733         {
734             CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_TX_WARNING, enable);
735             returnResult = CANEXCEL_STATUS_SUCCESS;
736             break;
737         }
738         case CANEXCEL_IP_INT_ERR:
739         {
740             CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_ERR, enable);
741             returnResult = CANEXCEL_STATUS_SUCCESS;
742             break;
743         }
744         case CANEXCEL_IP_INT_ERR_FAST:
745         {
746             CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_ERR_FAST, enable);
747             returnResult = CANEXCEL_STATUS_SUCCESS;
748             break;
749         }
750         case CANEXCEL_IP_INT_ERR_XL:
751         {
752             CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_ERR_XL, enable);
753             returnResult = CANEXCEL_STATUS_SUCCESS;
754             break;
755         }
756         case CANEXCEL_IP_INT_ERR_INT:
757         {
758             CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_INT_ERR, enable);
759             returnResult = CANEXCEL_STATUS_SUCCESS;
760             break;
761         }
762         case CANEXCEL_IP_INT_BUSOFF:
763         {
764             CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_BUSOFF, enable);
765             returnResult = CANEXCEL_STATUS_SUCCESS;
766             break;
767         }
768         case CANEXCEL_IP_INT_BUSOFF_DONE:
769         {
770             CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_BUSOFF_DONE, enable);
771             returnResult = CANEXCEL_STATUS_SUCCESS;
772             break;
773         }
774         case CANEXCEL_IP_INT_FREEZE:
775         {
776             CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_FREEZE, enable);
777             returnResult = CANEXCEL_STATUS_SUCCESS;
778             break;
779         }
780         case CANEXCEL_IP_INT_PASS_ERR:
781         {
782             CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_PASIVE_ERR, enable);
783             returnResult = CANEXCEL_STATUS_SUCCESS;
784             break;
785         }
786         default :
787         {
788             /* Do Nothing will report CANEXCEL_STATUS_ERROR */
789         }
790         }
791     }
792     return returnResult;
793 }
794 
795 /*FUNCTION**********************************************************************
796  *
797  * Function Name : Canexcel_Ip_MainFunctionRead
798  * Description   : Process received Rx MessageBuffer or RxFifo.
799  * This function read the messages received as pulling or if the Interrupts are disabled.
800  *
801  *END**************************************************************************/
802 /* implements Canexcel_Ip_MainFunctionRead_Activity */
Canexcel_Ip_MainFunctionRead(uint8 instance,uint8 mb_idx)803 void Canexcel_Ip_MainFunctionRead(uint8 instance, uint8 mb_idx)
804 {
805     Canexcel_Ip_MainFunction(instance, mb_idx);
806 }
807 
808 
809 /*FUNCTION**********************************************************************
810  *
811  * Function Name : Canexcel_Ip_MainFunctionWrite
812  * Description   : Process sent Tx MessageBuffer or TxFifo.
813  * This function read the messages received as pulling or if the Interrupts are disabled.
814  *
815  *END**************************************************************************/
816 /* implements Canexcel_Ip_MainFunctionWrite_Activity */
Canexcel_Ip_MainFunctionWrite(uint8 instance,uint8 mb_idx)817 void Canexcel_Ip_MainFunctionWrite(uint8 instance, uint8 mb_idx)
818 {
819     Canexcel_Ip_MainFunction(instance, mb_idx);
820 }
821 
822 /*FUNCTION**********************************************************************
823  *
824  * Function Name : Canexcel_Ip_GetStopMode
825  * Description   : Check if the CANEXCEL instance is STOPPED.
826  *
827  *END**************************************************************************/
828 /* implements Canexcel_Ip_GetStopMode_Activity */
Canexcel_Ip_GetStopMode(uint8 instance)829 boolean Canexcel_Ip_GetStopMode(uint8 instance)
830 {
831 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
832     DevAssert(instance < CANXL_SIC_INSTANCE_COUNT);
833 #endif
834     const CANXL_SIC_Type * base = CANEXCEL.EXL_SIC[instance];
835     return ((CANXL_SIC_SYSS_LPMACKF_MASK == (base->SYSS & CANXL_SIC_SYSS_LPMACKF_MASK)) ? TRUE : FALSE);
836 }
837 
838 /*FUNCTION**********************************************************************
839  *
840  * Function Name : Canexcel_Ip_ConfigRxFifo
841  * Description   : Confgure RX FIFO filter table elements.
842  * This function will confgure RX FIFO filter table elements
843  *END**************************************************************************/
844 /* implements Canexcel_Ip_ConfigRxFifo_Activity */
Canexcel_Ip_ConfigRxFifo(uint8 instance,Canexcel_Ip_RxFifoFilter * filterConfig)845 Canexcel_Ip_StatusType Canexcel_Ip_ConfigRxFifo(uint8 instance, Canexcel_Ip_RxFifoFilter * filterConfig)
846 {
847 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
848     DevAssert(instance < CANXL_SIC_INSTANCE_COUNT);
849     DevAssert(filterConfig->noActAddrFilters < CANXL_RXFIFO_ADDRACPTFLTAR_COUNT);
850     DevAssert(filterConfig->noIdFilters < CANXL_RXFIFO_IDACPTFLTAR_COUNT);
851     DevAssert(filterConfig->noSduFilters < CANXL_RXFIFO_SDUACPTFLTAR_COUNT);
852     DevAssert(filterConfig->noVcanFilters < CANXL_RXFIFO_VCANACPTFLTAR_COUNT);
853 #endif
854     Canexcel_Ip_StatusType status = CANEXCEL_STATUS_SUCCESS;
855     CANXL_RXFIFO_Type * base = CANEXCEL.EXL_RXFIFO[instance];
856     CANXL_RXFIFO_CONTROL_Type * rxFifoCont_base = CANEXCEL.EXL_RXF_CNT[instance];
857     uint8 idx;
858     if (CANEXCEL.EXL_RXF_CNT[instance]->RXFSYSACT == 0U)
859     {
860     	status = CANEXCEL_STATUS_ERROR;
861     }
862     else
863     {
864 		if (TRUE == CanXL_IsFreezeMode(CANEXCEL.EXL_SIC[instance]))
865 		{
866 			/* Lock the RxFIFO by System by reading register */
867 			(void)rxFifoCont_base->RXFSYSLOCK;
868 			base->AFCFG = CANXL_RXFIFO_AFCFG_ACPTID(filterConfig->noIdFilters-1U);
869 			for(idx = 0U; idx < filterConfig->noIdFilters; idx++)
870 			{
871 				CanXL_ConfigIDFilter(base, &filterConfig->IdFilterPtr[idx], idx);
872 			}
873 			if(filterConfig->noActAddrFilters != 0)
874 			{
875 				base->AFCFG |= CANXL_RXFIFO_AFCFG_AADDREN_MASK | CANXL_RXFIFO_AFCFG_ACPTADDR(filterConfig->noActAddrFilters-1U);
876 				for(idx = 0U; idx < filterConfig->noActAddrFilters; idx++)
877 				{
878 					CanXL_ConfigAccAddr(base, &filterConfig->AddrFilterPtr[idx], idx);
879 				}
880 			}
881 			if(filterConfig->noSduFilters != 0)
882 			{
883 				base->AFCFG |= CANXL_RXFIFO_AFCFG_ASDUEN_MASK | CANXL_RXFIFO_AFCFG_ACPTSDU(filterConfig->noSduFilters-1U);
884 				for(idx = 0U; idx < filterConfig->noSduFilters; idx++)
885 				{
886 					CanXL_ConfigSDUFilter(base, &filterConfig->SduFilterPtr[idx], idx);
887 				}
888 			}
889 			if(filterConfig->noVcanFilters != 0)
890 			{
891 				base->AFCFG |= CANXL_RXFIFO_AFCFG_AVCANEN_MASK | CANXL_RXFIFO_AFCFG_ACPTVCAN(filterConfig->noVcanFilters-1U);
892 				for(idx = 0U; idx < filterConfig->noVcanFilters; idx++)
893 				{
894 					CanXL_ConfigSDUFilter(base, &filterConfig->VcanFilterPtr[idx], idx);
895 				}
896 			}
897 			base->SECAM = filterConfig->SecMask;
898 			base->SECAV = filterConfig->SecFilter;
899 
900 			if ((rxFifoCont_base->RXFCSTA & CANXL_RXFIFO_CONTROL_RXFCSTA_SYSLOCK_MASK) == CANXL_RXFIFO_CONTROL_RXFCSTA_SYSLOCK_MASK)
901 			{
902 				/* Clear the sys lock to enable transfers */
903 				rxFifoCont_base->RXFSYSLOCK = CANXL_RXFIFO_CONTROL_RXFSYSLOCK_SYSLOCK_MASK;
904 			}
905 			status = CANEXCEL_STATUS_SUCCESS;
906 		}
907 		else
908 		{
909 			status = CANEXCEL_STATUS_ERROR;
910 		}
911     }
912     return status;
913 }
914 
Canexcel_Ip_IsXLFrameType(uint8 instance,uint8 descNo)915 boolean Canexcel_Ip_IsXLFrameType(uint8 instance, uint8 descNo)
916 {
917     Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[instance];
918     if (descNo < CANEXCEL_IP_MB_RXFIFO)
919     {
920         return (state->msgDesc[descNo].isXLFrame);
921     }
922     else
923     {
924         return (state->rxFifo.isXLFrame);
925     }
926 
927 }
928 /** @} */
929 
930