1 /*
2 * Copyright 2021-2023 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 #include "SchM_Can_43_CANEXCEL.h"
18
19 static CANEXCEL_StructType CANEXCEL;
20
21 static CANXL_SIC_Type * EXL_SIC_PTR[] = IP_CANXL_SIC_BASE_PTRS;
22 static MC_RGM_Type * EXL_RGM_PTR[] = IP_MC_RGM_BASE_PTRS;
23 static CANXL_MRU_Type * EXL_MRU_PTR[] = IP_CANXL_MRU_BASE_PTRS;
24 static CANXL_GRP_CONTROL_Type * EXL_GRP_PTR[] = IP_CANXL_GRP_CONTROL_BASE_PTRS;
25 static CANXL_DSC_CONTROL_Type * EXL_DESC_CTR_PTR[] = IP_CANXL_DSC_CONTROL_BASE_PTRS;
26 static CANXL_MSG_DESCRIPTORS_Type * EXL_MSGD_PTR[] = IP_CANXL_MSG_DESCRIPTORS_BASE_PTRS;
27 static CANXL_RXFIFO_CONTROL_Type * EXL_RXF_CNT_PTR[] = IP_CANXL_RXFIFO_CONTROL_BASE_PTRS;
28 static CANXL_RXFIFO_Type * EXL_RXFIFO_PTR[] = IP_CANXL_RXFIFO_BASE_PTRS;
29 static CANXL_FILTER_BANK_Type * EXL_FILTER_PTR[] = IP_CANXL_FILTER_BANK_BASE_PTRS;
30 #if (CANEXCEL_IP_HAS_TS_ENABLE == STD_ON)
31 static CAN_TBS_Type * EXL_TBS_PTR[] = IP_CANXL_TBS_BASE_PTRS;
32 #endif
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
38 static Canexcel_Ip_StatusType Canexcel_GetControllerMRU(uint8 instance, uint32 * pValue, uint8 command);
39
40 static void Canexcel_Ip_ConfInit(uint8 instance, const Canexcel_Ip_ConfigType * Config);
41 /*FUNCTION**********************************************************************
42 *
43 * Function Name : Canexcel_GetControllerMRU
44 * Description : This function will handle MRU operation, by read MRU requested value
45 * This is not a public API as it is called from other driver functions.
46 *
47 *END**************************************************************************/
Canexcel_GetControllerMRU(uint8 instance,uint32 * pValue,uint8 command)48 static Canexcel_Ip_StatusType Canexcel_GetControllerMRU(uint8 instance, uint32 * pValue, uint8 command)
49 {
50 CANXL_MRU_Type * base = CANEXCEL.EXL_MRU[instance];
51 Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[instance];
52 Canexcel_Ip_StatusType status = CANEXCEL_STATUS_SUCCESS;
53 uint32 uS2Ticks = OsIf_MicrosToTicks(CANEXCEL_IP_TIMEOUT_DURATION, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
54 uint32 timeStart = 0U;
55 uint32 timeElapsed = 0U;
56 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
57 DevAssert(instance < CANXL_SIC_INSTANCE_COUNT);
58 DevAssert(pValue != NULL_PTR);
59 #endif
60 CanXL_MruEnable(base);
61 /* Check the is available MRU Mailbox */
62 if ((base->CHXCONFIG[0u].CH_MBSTAT & CANXL_MRU_CH_MBSTAT_MBS0_MASK) != 0U)
63 {
64 status = CANEXCEL_STATUS_ERROR;
65 }
66 if (status == CANEXCEL_STATUS_SUCCESS)
67 {
68 SchM_Enter_Can_43_CANEXCEL_CAN_EXCLUSIVE_AREA_08();
69 base->CHXCONFIG[0u].CH_CFG0 |= CANXL_MRU_CH_CFG0_MBE0_MASK | CANXL_MRU_CH_CFG0_MBE3_MASK | CANXL_MRU_CH_CFG0_IE_MASK;
70 base->CHXCONFIG[0u].CH_CFG1 |= CANXL_MRU_CH_CFG1_MBIC3_MASK;
71 base->CHXCONFIG[0u].CH_MBSTAT |= CANXL_MRU_CH_MBSTAT_MBS3_MASK;
72 state->u8MruMailboxAct &= (uint8)(~(1U<<CANXL_MRU_MBOX3));
73 SchM_Exit_Can_43_CANEXCEL_CAN_EXCLUSIVE_AREA_08();
74 base->CH1_MB0 = command;
75 timeStart = OsIf_GetCounter(CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
76 while ((state->u8MruMailboxAct & (1U<<CANXL_MRU_MBOX3)) == 0U)
77 {
78 timeElapsed += OsIf_GetElapsed(&timeStart, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
79 if (timeElapsed >= uS2Ticks)
80 {
81 status = CANEXCEL_STATUS_TIMEOUT;
82 break;
83 }
84 }
85 if ((state->u8MruMailboxAct & (1U<<CANXL_MRU_MBOX3)) == (1U<<CANXL_MRU_MBOX3))
86 {
87 * pValue = base->CH1_MB3;
88 }
89 }
90 CanXL_MruDisable(base);
91 return status;
92 }
93 /*FUNCTION**********************************************************************
94 *
95 * Function Name : Canexcel_Ip_MainFunction
96 * Description : This function will process in polling Mode an Tx\Rx operation
97 * This is not a public API as it is called from other driver functions.
98 *
99 *END**************************************************************************/
Canexcel_Ip_MainFunction(uint8 instance,uint8 mb_idx)100 static void Canexcel_Ip_MainFunction(uint8 instance, uint8 mb_idx)
101 {
102 Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[instance];
103 uint32 flag_reg;
104 uint8 total_mb = (uint8)((((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)));
105 /* Check if instance initialized */
106 if ((NULL_PTR != state) && (mb_idx <= total_mb))
107 {
108 flag_reg = CanXL_GetMsgDescIntStatusFlag(CANEXCEL.EXL_GRP[instance], mb_idx);
109
110 if (0U != flag_reg)
111 {
112 CanXL_ClearMsgDescIntStatusFlag(CANEXCEL.EXL_GRP[instance], mb_idx);
113 state->msgDesc[mb_idx].noPointers = (uint8)((CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[mb_idx].STA.DCSTA & CANXL_DSC_CONTROL_DCSTA_HWPOINTER_MASK) >> CANXL_DSC_CONTROL_DCSTA_HWPOINTER_SHIFT);
114 /* First descriptors are always allocated for Transmission */
115 if (mb_idx <= CANEXCEL.EXL_GRP[instance]->DSCCTRL)
116 {
117 /* Process Tx MDESC */
118 if (NULL_PTR != state->callback)
119 {
120 state->callback(instance, CANEXCEL_EVENT_TX_COMPLETE, mb_idx, state);
121 }
122 }
123 else
124 {
125 /* Process Rx MDESC */
126 if (NULL_PTR != state->callback)
127 {
128 state->callback(instance, CANEXCEL_EVENT_RX_COMPLETE, mb_idx, state);
129 }
130 }
131 }
132 }
133 if((NULL_PTR != state) && (mb_idx == CANEXCEL_IP_MB_RXFIFO))
134 {
135 if (CANEXCEL.EXL_RXF_CNT[instance]->RXFSYSACT == 1U)
136 {
137 if (((CANEXCEL.EXL_RXF_CNT[instance]->RXFIEN & CANXL_RXFIFO_CONTROL_RXFIEN_RXFIE_MASK) != 0U) && ((CANEXCEL.EXL_RXF_CNT[instance]->RXFS & CANXL_RXFIFO_CONTROL_RXFS_RXFF_MASK) != 0U))
138 {
139 if ((CANEXCEL.EXL_RXF_CNT[instance]->RXFS & CANXL_RXFIFO_CONTROL_RXFS_RXFF_MASK) == CANXL_RXFIFO_CONTROL_RXFS_RXFF_MASK)
140 {
141 CANEXCEL.EXL_RXF_CNT[instance]->RXFS |= CANXL_RXFIFO_CONTROL_RXFS_RXFF_MASK;
142 state->rxFifo.noPointers = (uint8)(((CANEXCEL.EXL_RXF_CNT[instance]->RXFCSTA & CANXL_RXFIFO_CONTROL_RXFCSTA_HWPOINTER_MASK) >> CANXL_RXFIFO_CONTROL_RXFCSTA_HWPOINTER_SHIFT));
143
144 /* Process RxFifo for Reception */
145 if (NULL_PTR != state->callback)
146 {
147 state->callback(instance, CANEXCEL_EVENT_RXFIFO_COMPLETE, mb_idx, state);
148 }
149 }
150 }
151 }
152 }
153 }
154 /*FUNCTION**********************************************************************
155 *
156 * Function Name : CanXL_InitBaudrate
157 * Description : Init baudrate for given controller.
158 * This is not a public API as it is called from other driver functions.
159 *
160 *END**************************************************************************/
CanXL_InitBaudrate(CANXL_SIC_Type * pBase,const Canexcel_Ip_ConfigType * Canxl_Ip_pData)161 static void CanXL_InitBaudrate(CANXL_SIC_Type * pBase, const Canexcel_Ip_ConfigType * Canxl_Ip_pData)
162 {
163 CanXL_SetBaudRate(pBase, &Canxl_Ip_pData->bitrate);
164 if(Canxl_Ip_pData->fd_enable)
165 {
166 CanXL_SetFDBaudRate(pBase, &Canxl_Ip_pData->Fd_bitrate);
167 }
168 if(Canxl_Ip_pData->xl_enable)
169 {
170 CanXL_SetXLBaudRate(pBase, &Canxl_Ip_pData->Xl_bitrate);
171 }
172 }
173
174 /*FUNCTION**********************************************************************
175 *
176 * Function Name : Canexcel_Ip_ConfInit
177 * Description : Partially configure CANEXCEL instance
178 * This is not a public API as it is called from other driver functions.
179 *
180 *END**************************************************************************/
Canexcel_Ip_ConfInit(uint8 instance,const Canexcel_Ip_ConfigType * Config)181 static void Canexcel_Ip_ConfInit(uint8 instance, const Canexcel_Ip_ConfigType * Config)
182 {
183 CanXL_SetFDEnabled(CANEXCEL.EXL_SIC[instance], Config->fd_enable, Config->bitRateSwitch);
184 CanXL_SetXLEnable(CANEXCEL.EXL_SIC[instance], Config->xl_enable);
185 CanXL_InitBaudrate(CANEXCEL.EXL_SIC[instance], Config);
186 CanXL_SetOperationMode(CANEXCEL.EXL_SIC[instance], Config->CanxlMode);
187 /** To be develop for Queue Operation Config */
188 CanXL_SetMDQueueConfigs( CANEXCEL.EXL_GRP[instance], Config->QueueMDConfig);
189 }
190
191 /*FUNCTION**********************************************************************
192 *
193 * Function Name : Canexcel_Ip_GetStartMode
194 * Description : Check if the Canexcel instance is STARTED.
195 *
196 *END**************************************************************************/
197 /* implements Canexcel_Ip_GetStartMode_Activity */
Canexcel_Ip_GetStartMode(uint8 instance)198 boolean Canexcel_Ip_GetStartMode(uint8 instance)
199 {
200 const CANXL_SIC_Type * base = CANEXCEL.EXL_SIC[instance];
201 return ((0U == (base->SYSMC & (CANXL_SIC_SYSMC_LPMREQ_MASK | CANXL_SIC_SYSMC_FRZREQ_MASK))) ? TRUE : FALSE);
202 }
203
204 #if (CANEXCEL_IP_HAS_TS_ENABLE == STD_ON)
205 /*FUNCTION**********************************************************************
206 *
207 * Function Name : Canexcel_Ip_ConfigTimeStamp
208 * Description : Timestamp configuration
209 *
210 *END**************************************************************************/
211 /* implements Canexcel_Ip_ConfigTimeStamp_Activity */
Canexcel_Ip_ConfigTimeStamp(uint8 instance,const Canexcel_Ip_TimeStampConf_Type * time_stamp)212 Canexcel_Ip_StatusType Canexcel_Ip_ConfigTimeStamp(uint8 instance, const Canexcel_Ip_TimeStampConf_Type * time_stamp)
213 {
214 Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_ERROR;
215 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
216 DevAssert(instance < CANXL_SIC_INSTANCE_COUNT);
217 #endif
218
219 if (TRUE == CanXL_IsFreezeMode(CANEXCEL.EXL_SIC[instance]))
220 {
221 CanXL_SetTimeStampCaputre(CANEXCEL.EXL_SIC[instance], time_stamp->capture);
222 /* If ts64bit True will enable the timestamp as 64 bits if false will set to 32 bits */
223 CANEXCEL.EXL_SIC[instance]->BCFG2 |= (time_stamp->ts64bit == TRUE) ? CANXL_SIC_BCFG2_TSS(1U) : CANXL_SIC_BCFG2_TSS(0U);
224 returnResult = CANEXCEL_STATUS_SUCCESS;
225 CanXL_SetTimeBaseSource(CANEXCEL.EXL_TBS[instance], time_stamp->src);
226 }
227 return returnResult;
228 }
229 #endif
230
231 /*FUNCTION**********************************************************************
232 *
233 * Function Name : Canexcel_Ip_SetStopMode
234 * Description : Set the Canexcel instance in STOP mode.
235 *
236 *END**************************************************************************/
237 /* implements Canexcel_Ip_SetStopMode_Activity */
Canexcel_Ip_SetStopMode(uint8 instance)238 Canexcel_Ip_StatusType Canexcel_Ip_SetStopMode(uint8 instance)
239 {
240 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
241 DevAssert(instance < CANXL_SIC_INSTANCE_COUNT);
242 #endif
243 CANXL_SIC_Type * base = CANEXCEL.EXL_SIC[instance];
244 Canexcel_Ip_StatusType status;
245 status = CanXL_EnterFreezeMode(base);
246 return status;
247 }
248 /*FUNCTION**********************************************************************
249 *
250 * Function Name : Canexcel_Ip_Init
251 * Description : Initialize the driver with the configuration
252 *
253 *END**************************************************************************/
254 /* implements Canexcel_Ip_Init_Activity */
Canexcel_Ip_Init(uint8 instance,const Canexcel_Ip_ConfigType * Config,Canexcel_Ip_StateType * pState)255 Canexcel_Ip_StatusType Canexcel_Ip_Init(uint8 instance, const Canexcel_Ip_ConfigType * Config, Canexcel_Ip_StateType * pState)
256 {
257
258 CANEXCEL.EXL_SIC = EXL_SIC_PTR;
259 CANEXCEL.EXL_RGM = EXL_RGM_PTR;
260 CANEXCEL.EXL_MRU = EXL_MRU_PTR;
261 CANEXCEL.EXL_GRP = EXL_GRP_PTR;
262 CANEXCEL.EXL_DESC_CTR = EXL_DESC_CTR_PTR;
263 CANEXCEL.EXL_MSGD = EXL_MSGD_PTR;
264 CANEXCEL.EXL_RXFIFO = EXL_RXFIFO_PTR;
265 CANEXCEL.EXL_RXF_CNT = EXL_RXF_CNT_PTR;
266 CANEXCEL.EXL_FILTER = EXL_FILTER_PTR;
267 #if (CANEXCEL_IP_HAS_TS_ENABLE == STD_ON)
268 CANEXCEL.EXL_TBS = EXL_TBS_PTR;
269 #endif
270 Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_SUCCESS;
271
272 uint32 timeStart = 0U;
273 uint32 timeElapsed = 0U;
274 uint32 uS2Ticks = OsIf_MicrosToTicks(CANEXCEL_IP_TIMEOUT_DURATION, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
275 /* Wait Hardware to became available after clock start */
276 while ((CANEXCEL.EXL_SIC[instance]->SYSS & CANXL_SIC_SYSS_FRZACKF_MASK) == 0U)
277 {
278 timeElapsed += OsIf_GetElapsed(&timeStart, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
279 if (timeElapsed >= uS2Ticks)
280 {
281 returnResult = CANEXCEL_STATUS_TIMEOUT;
282 break;
283 }
284 }
285 if(returnResult == CANEXCEL_STATUS_SUCCESS)
286 {
287 returnResult = CanXL_SoftReset(CANEXCEL.EXL_SIC[instance]);
288 }
289 if(returnResult == CANEXCEL_STATUS_SUCCESS)
290 {
291 returnResult = CanXL_EnterFreezeMode(CANEXCEL.EXL_SIC[instance]);
292 }
293 if (returnResult == CANEXCEL_STATUS_SUCCESS)
294 {
295 /* CANEXCEL Data Memory Write Access Enable for Host */
296 CANEXCEL.EXL_SIC[instance]->SYSMCFG &= ~CANXL_SIC_SYSMCFG_DRWRDIS_MASK;
297 /* Clear Memory ram and initialize it */
298 CanXL_ClearRAM(&CANEXCEL, instance);
299 CANEXCEL.EXL_GRP[instance]->DSCCTRL = CANXL_GRP_CONTROL_DSCCTRL_TXDSC((uint32)Config->tx_mbdesc-1u);
300 CANEXCEL.EXL_SIC[instance]->SYSMCFG |= (CANXL_SIC_SYSMCFG_MAXTXMB(Config->tx_mbdesc) | CANXL_SIC_SYSMCFG_MAXRXMB(Config->rx_mbdesc));
301 Canexcel_Ip_ConfInit(instance, Config);
302
303 returnResult = CanXL_ConfigCtrlOptions(CANEXCEL.EXL_SIC[instance], Config->ctrlOptions);
304 if (CANEXCEL_STATUS_SUCCESS == returnResult)
305 {
306 Canexcel_Ip_apxState[instance] = pState;
307 for(timeElapsed = 0U; timeElapsed<Config->tx_mbdesc; timeElapsed++ )
308 {
309 /* Better to be moved at init because requires Freeze mode */
310 CANEXCEL.EXL_MSGD[instance]->MSGDSC[timeElapsed].LSTPNT.TXLSTPTR = (uint32)&pState->msgDesc[timeElapsed].list;
311 }
312 for(; timeElapsed < ((uint32)Config->rx_mbdesc + (uint32)Config->tx_mbdesc); timeElapsed++ )
313 {
314 /* Better to be moved at init because requires Freeze mode */
315 CANEXCEL.EXL_MSGD[instance]->MSGDSC[timeElapsed].LSTPNT.RXLSTPTR = (uint32)&pState->msgDesc[timeElapsed].list;
316 }
317
318 if (TRUE == Config->is_rx_fifo_needed)
319 {
320 CANEXCEL.EXL_RXF_CNT[instance]->RXFC = CANXL_RXFIFO_CONTROL_RXFC_RXFD((uint32)Config->pRxFifoConfig.Rx_Fifo_Depth-1U)|CANXL_RXFIFO_CONTROL_RXFC_RXFWTM((uint32)Config->pRxFifoConfig.Rx_Fifo_Watermark - 1U);
321 uint16 dlcValue = 0u;
322 if(Config->pRxFifoConfig.frameType == CANEXCEL_XL_FRAME)
323 {
324 Canexcel_Ip_apxState[instance]->rxFifo.isXLFrame = TRUE;
325 dlcValue = Config->pRxFifoConfig.Rx_Fifo_Msg_Size - 1u;
326 const Canexcel_RxXlMsg * RxFifoMsgBuff= (Canexcel_RxXlMsg *)Config->pRxFifoConfig.MsgBuffersPtr;
327 for(uint8 idx = 0; idx < Config->pRxFifoConfig.Rx_Fifo_Depth; idx++)
328 {
329 CANEXCEL.EXL_RXFIFO[instance]->RXFMBP[idx] = (uint32)&RxFifoMsgBuff[idx];
330 }
331 }
332 else
333 {
334 Canexcel_Ip_apxState[instance]->rxFifo.isXLFrame = FALSE;
335 dlcValue = (uint16)CAN_ComputeDLCValue((uint8)(Config->pRxFifoConfig.Rx_Fifo_Msg_Size));
336 const Canexcel_RxFdMsg * RxFifoMsgBuff= (Canexcel_RxFdMsg *)Config->pRxFifoConfig.MsgBuffersPtr;
337 for(uint8 idx = 0; idx < Config->pRxFifoConfig.Rx_Fifo_Depth; idx++)
338 {
339 CANEXCEL.EXL_RXFIFO[instance]->RXFMBP[idx] = (uint32)&RxFifoMsgBuff[idx];
340 }
341 }
342 uint8 aux = (Config->pRxFifoConfig.Rx_Fifo_KeepLast == FALSE) ? 1U : 0U;
343 CANEXCEL.EXL_RXFIFO[instance]->RXFFCTR = (CANXL_RXFIFO_RXFFCTR_MBSIZE((uint32)dlcValue) | CANXL_RXFIFO_RXFFCTR_KEEPLST((uint32)aux));
344 /* Activate RxFifo */
345 CANEXCEL.EXL_RXF_CNT[instance]->RXFSYSACT = CANXL_RXFIFO_CONTROL_RXFSYSACT_ACT_MASK;
346 Canexcel_Ip_apxState[instance]->rxFifo.isPolling = Config->pRxFifoConfig.isPolling;
347 }
348 CanXL_ResetImaskBuff(CANEXCEL.EXL_GRP[instance]);
349 /* Clear Callbacks in case of autovariables garbage */
350 Canexcel_Ip_apxState[instance]->u8MruMailboxAct = 0U;
351 Canexcel_Ip_apxState[instance]->callback = Config->Callback;
352 Canexcel_Ip_apxState[instance]->callbackParam = NULL_PTR;
353 Canexcel_Ip_apxState[instance]->error_callback = Config->ErrorCallback;
354 Canexcel_Ip_apxState[instance]->errorCallbackParam = NULL_PTR;
355 Canexcel_Ip_apxState[instance]->isIntActive = FALSE;
356 #if (CANEXCEL_IP_HAS_TS_ENABLE == STD_ON)
357 returnResult = Canexcel_Ip_ConfigTimeStamp(instance, &Config->TimestampConfig);
358 #endif
359 }
360 }
361 return returnResult;
362 }
363
364 /*FUNCTION**********************************************************************
365 *
366 * Function Name : Canexcel_Ip_SetRxIndividualMask
367 * Description : Set Individual Rx Mask ID for Message Descriptor, and frame type.
368 *
369 *END**************************************************************************/
370 /* implements Canexcel_Ip_SetRxIndividualMask_Activity */
Canexcel_Ip_SetRxIndividualMask(uint8 instance,uint8 descNo,Canexcel_Ip_FrameType frameType,uint32 mask)371 Canexcel_Ip_StatusType Canexcel_Ip_SetRxIndividualMask(uint8 instance, uint8 descNo, Canexcel_Ip_FrameType frameType, uint32 mask)
372 {
373 Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_SUCCESS;
374 if (CANEXCEL_XL_FRAME == frameType)
375 {
376 CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CFG1.MDFLT1XL = mask;
377 }
378 else
379 {
380 CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CFG1.MDFLT1FD = mask;
381 }
382 return returnResult;
383 }
384
385 /*FUNCTION**********************************************************************
386 *
387 * Function Name : Canexcel_Ip_ConfigRx
388 * Description : Set Individual Rx ID for Message Descriptor, and config the frame parameters from DataInfoType.
389 *
390 *END**************************************************************************/
391 /* implements Canexcel_Ip_ConfigRx_Activity */
Canexcel_Ip_ConfigRx(uint8 instance,uint8 descNo,uint32 msgId,const Canexcel_Ip_DataInfoType * info)392 Canexcel_Ip_StatusType Canexcel_Ip_ConfigRx(uint8 instance, uint8 descNo, uint32 msgId,const Canexcel_Ip_DataInfoType * info)
393 {
394 uint16 dlcValue = 0U;
395 uint32 timeStart = 0U;
396 uint32 timeElapsed = 0U;
397 Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[instance];
398 Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_SUCCESS;
399 uint32 uS2Ticks = OsIf_MicrosToTicks(CANEXCEL_IP_TIMEOUT_DURATION, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
400 timeStart = OsIf_GetCounter(CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
401
402 while (CANEXCEL_DESCNTSTATUS_LOCKED_HW == CanXL_GetDescControlStatus(CANEXCEL.EXL_DESC_CTR[instance], descNo))
403 {
404 timeElapsed += OsIf_GetElapsed(&timeStart, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
405 if (timeElapsed >= uS2Ticks)
406 {
407 returnResult = CANEXCEL_STATUS_TIMEOUT;
408 break;
409 }
410 }
411
412 if (CanXL_GetDesciptorState(CANEXCEL.EXL_DESC_CTR[instance], descNo) >= CANEXCEL_DESC_STATE_FULL)
413 {
414 returnResult = CANEXCEL_STATUS_BUSY;
415 }
416 if (returnResult == CANEXCEL_STATUS_SUCCESS)
417 {
418 CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CTRL.RXCTRL = 0U;
419 if(info->frame == CANEXCEL_XL_FRAME)
420 {
421 state->msgDesc[descNo].isXLFrame = TRUE;
422 CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CTRL.RXCTRL = CANXL_MSG_DESCRIPTORS_RXCTRL_RXXLFRM_MASK;
423 dlcValue = info->dataLength - 1U;
424 if (info->idType == CANEXCEL_MSG_ID_EXT)
425 {
426 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
427 /* CanXL frame type supports only STD ID frame types */
428 DevAssert(FALSE);
429 #endif
430 }
431 else
432 {
433 CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CFG2.MDFLT2XL = (CANXL_MSG_DESCRIPTORS_MDFLT2XL_IDSTDa_H(msgId) |
434 ((info->SEC) ? CANXL_MSG_DESCRIPTORS_MDFLT2XL_SEC(1U) : CANXL_MSG_DESCRIPTORS_MDFLT2XL_SEC(0U)) |
435 CANXL_MSG_DESCRIPTORS_MDFLT2XL_RJCT_SDU(info->SDT) |
436 CANXL_MSG_DESCRIPTORS_MDFLT2XL_RJCT_VCAN(info->VCID));
437 }
438 }
439 else if (info->frame == CANEXCEL_FD_FRAME)
440 {
441 state->msgDesc[descNo].isXLFrame = FALSE;
442 CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CTRL.RXCTRL = CANXL_MSG_DESCRIPTORS_RXCTRL_RXFDFRM_MASK;
443 dlcValue = (uint16)CAN_ComputeDLCValue((uint8)(info->dataLength));
444 if (info->idType == CANEXCEL_MSG_ID_EXT)
445 {
446 CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CFG2.MDFLT2FD = CANXL_MSG_DESCRIPTORS_MDFLT2FD_IDE_MASK | msgId;
447 }
448 else
449 {
450 CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CFG2.MDFLT2FD = CANXL_MSG_DESCRIPTORS_MDFLT2FD_IDSTDa_H(msgId);
451 }
452 }
453 else
454 {
455 /* expected Classic Frame Type */
456 state->msgDesc[descNo].isXLFrame = FALSE;
457 dlcValue = (uint16)CAN_ComputeDLCValue((uint8)(info->dataLength));
458 if (info->idType == CANEXCEL_MSG_ID_EXT)
459 {
460 CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CFG2.MDFLT2FD = CANXL_MSG_DESCRIPTORS_MDFLT2FD_IDE_MASK | msgId;
461 }
462 else
463 {
464 CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CFG2.MDFLT2FD = CANXL_MSG_DESCRIPTORS_MDFLT2FD_IDSTDa_H(msgId);
465 }
466 }
467 SchM_Enter_Can_43_CANEXCEL_CAN_EXCLUSIVE_AREA_03();
468 CANEXCEL.EXL_MSGD[instance]->MSGDSC[descNo].CTRL.RXCTRL |= CANXL_MSG_DESCRIPTORS_RXCTRL_MBSIZE(dlcValue);
469 SchM_Exit_Can_43_CANEXCEL_CAN_EXCLUSIVE_AREA_03();
470 }
471 return returnResult;
472 }
473
474 /*FUNCTION**********************************************************************
475 *
476 * Function Name : Canexcel_Ip_RxDescriptor
477 * Description : Push the new memory location for the Rx Message Buffer on the desired Descriptor.
478 *
479 *END**************************************************************************/
480 /* implements Canexcel_Ip_RxDescriptor_Activity */
Canexcel_Ip_RxDescriptor(uint8 instance,uint8 descNo,uint32 rxPtrList)481 Canexcel_Ip_StatusType Canexcel_Ip_RxDescriptor(uint8 instance, uint8 descNo, uint32 rxPtrList)
482 {
483 uint32 timeStart = 0U;
484 uint32 timeElapsed = 0U;
485 Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[instance];
486 Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_SUCCESS;
487 uint32 uS2Ticks = OsIf_MicrosToTicks(CANEXCEL_IP_TIMEOUT_DURATION, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
488 timeStart = OsIf_GetCounter(CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
489 /* Update system lock Status */
490 (void)CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].SYSLOCK.DCSYSLOCK;
491 while (CANEXCEL_DESCNTSTATUS_LOCKED_HW == CanXL_GetDescControlStatus(CANEXCEL.EXL_DESC_CTR[instance], descNo))
492 {
493 timeElapsed += OsIf_GetElapsed(&timeStart, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
494 if (timeElapsed >= uS2Ticks)
495 {
496 returnResult = CANEXCEL_STATUS_TIMEOUT;
497 break;
498 }
499 }
500 if (returnResult == CANEXCEL_STATUS_SUCCESS)
501 { /* Check if the descriptor is empty, notfull or inactive (*/
502 if (CanXL_GetDesciptorState(CANEXCEL.EXL_DESC_CTR[instance], descNo) <= CANEXCEL_DESC_STATE_NOTFULL)
503 {
504 uint8 noOfPtrList = (uint8)((CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].STA.DCSTA & CANXL_DSC_CONTROL_DCSTA_SYSPOINTER_MASK) >> CANXL_DSC_CONTROL_DCSTA_SYSPOINTER_SHIFT);
505 uint8 noOfPtrHW = (uint8)((CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].STA.DCSTA & CANXL_DSC_CONTROL_DCSTA_HWPOINTER_MASK) >> CANXL_DSC_CONTROL_DCSTA_HWPOINTER_SHIFT);
506 sint32 value = (sint32)CanXL_GetMDQueueDepth(CANEXCEL.EXL_GRP[instance], descNo) - (sint32)noOfPtrList + (sint32)noOfPtrHW;
507 if (value >= (sint32)0)
508 {
509 if(noOfPtrList == (CanXL_GetMDQueueDepth(CANEXCEL.EXL_GRP[instance], descNo)+1U))
510 {
511 /* Roll Over */
512 state->msgDesc[descNo].list[0U] = rxPtrList;
513 }
514 else
515 {
516 state->msgDesc[descNo].list[noOfPtrList] = rxPtrList;
517 }
518 CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].ACT.DCACT = 1U;
519 CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].SYSLOCK.DCSYSLOCK = 1U;
520 CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].PUSHPOP.DCSYSPUSH = 0U;
521 }
522 else
523 {
524 returnResult = CANEXCEL_STATUS_BUFF_OUT_OF_RANGE;
525 }
526 }
527 else
528 {
529 returnResult = CANEXCEL_STATUS_ERROR;
530 }
531 }
532 return returnResult;
533 }
534 /*FUNCTION**********************************************************************
535 *
536 * Function Name : Canexcel_Ip_ReceiveFD
537 * Description : Receive a Classic or FD CAN Format Message
538 *
539 *END**************************************************************************/
540 /* implements Canexcel_Ip_ReceiveFD_Activity */
Canexcel_Ip_ReceiveFD(uint8 instance,uint8 descNo,const Canexcel_RxFdMsg * RxMsg,boolean isPolling)541 Canexcel_Ip_StatusType Canexcel_Ip_ReceiveFD(uint8 instance, uint8 descNo, const Canexcel_RxFdMsg * RxMsg, boolean isPolling)
542 {
543 Canexcel_Ip_StatusType returnResult;
544 if (isPolling == FALSE)
545 {
546 CanXL_SetMsgBuffIntCmd(CANEXCEL.EXL_GRP[instance], descNo);
547 }
548 returnResult = Canexcel_Ip_RxDescriptor(instance, descNo, (uint32)&RxMsg->Header.Id);
549 return returnResult;
550 }
551 /*FUNCTION**********************************************************************
552 *
553 * Function Name : Canexcel_Ip_ReceiveXL
554 * Description : Receive a CAN XL Format Message
555 *
556 *END**************************************************************************/
557 /* implements Canexcel_Ip_ReceiveXL_Activity */
Canexcel_Ip_ReceiveXL(uint8 instance,uint8 descNo,const Canexcel_RxXlMsg * RxMsg,boolean isPolling)558 Canexcel_Ip_StatusType Canexcel_Ip_ReceiveXL(uint8 instance, uint8 descNo, const Canexcel_RxXlMsg * RxMsg, boolean isPolling)
559 {
560 Canexcel_Ip_StatusType returnResult;
561 if (isPolling == FALSE)
562 {
563 CanXL_SetMsgBuffIntCmd(CANEXCEL.EXL_GRP[instance], descNo);
564 }
565 returnResult = Canexcel_Ip_RxDescriptor(instance, descNo, (uint32)&RxMsg->Header.Id);
566 return returnResult;
567 }
568
569 /*FUNCTION**********************************************************************
570 *
571 * Function Name : Canexcel_Ip_TxDescriptor
572 * Description : Push the new memory location for the Tx Message Buffer on the desired Descriptor.
573 *
574 *END**************************************************************************/
575 /* implements Canexcel_Ip_TxDescriptor_Activity */
Canexcel_Ip_TxDescriptor(uint8 instance,uint8 descNo,uint32 txPtrList)576 Canexcel_Ip_StatusType Canexcel_Ip_TxDescriptor(uint8 instance, uint8 descNo, uint32 txPtrList)
577 {
578 uint32 timeStart = 0U;
579 uint32 timeElapsed = 0U;
580 Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[instance];
581 Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_SUCCESS;
582 uint32 uS2Ticks = OsIf_MicrosToTicks(CANEXCEL_IP_TIMEOUT_DURATION, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
583 timeStart = OsIf_GetCounter(CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
584 /* Set system lock Status */
585 (void)CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].SYSLOCK.DCSYSLOCK;
586 while (CANEXCEL_DESCNTSTATUS_LOCKED_HW == CanXL_GetDescControlStatus(CANEXCEL.EXL_DESC_CTR[instance], descNo))
587 {
588 timeElapsed += OsIf_GetElapsed(&timeStart, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
589 if (timeElapsed >= uS2Ticks)
590 {
591 returnResult = CANEXCEL_STATUS_TIMEOUT;
592 break;
593 }
594 }
595 if(returnResult == CANEXCEL_STATUS_SUCCESS)
596 {
597 /* Check if the descriptor is empty, notfull or inactive */
598 if (CanXL_GetDesciptorState(CANEXCEL.EXL_DESC_CTR[instance], descNo) <= CANEXCEL_DESC_STATE_NOTFULL)
599 {
600 uint8 noOfPtrList = (uint8)((CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].STA.DCSTA & CANXL_DSC_CONTROL_DCSTA_SYSPOINTER_MASK) >> CANXL_DSC_CONTROL_DCSTA_SYSPOINTER_SHIFT);
601 uint8 noOfPtrHW = (uint8)((CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].STA.DCSTA & CANXL_DSC_CONTROL_DCSTA_HWPOINTER_MASK) >> CANXL_DSC_CONTROL_DCSTA_HWPOINTER_SHIFT);
602 sint32 value = (sint32)CanXL_GetMDQueueDepth(CANEXCEL.EXL_GRP[instance], descNo) - (sint32)noOfPtrList + (sint32)noOfPtrHW;
603 if (value >= (sint32)0)
604 {
605 if(noOfPtrList == (CanXL_GetMDQueueDepth(CANEXCEL.EXL_GRP[instance], descNo)+1U))
606 {
607 /* Roll Over */
608 state->msgDesc[descNo].list[0U] = txPtrList;
609 }
610 else
611 {
612 state->msgDesc[descNo].list[noOfPtrList] = txPtrList;
613 }
614 CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].ACT.DCACT = 1U;
615 CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].SYSLOCK.DCSYSLOCK = 1U;
616 CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].PUSHPOP.DCSYSPUSH = 0U;
617 }
618 else
619 {
620 returnResult = CANEXCEL_STATUS_BUFF_OUT_OF_RANGE;
621 }
622 }
623 else
624 {
625 returnResult = CANEXCEL_STATUS_ERROR;
626 }
627 }
628 return returnResult;
629 }
630
631 /*FUNCTION**********************************************************************
632 *
633 * Function Name : Canexcel_Ip_ConfigXlTx
634 * Description : Config the MessageBuffer for Tx with CAN XL Format and the desired parameters from DataInfoType
635 *
636 *END**************************************************************************/
637 /* implements Canexcel_Ip_ConfigXlTx_Activity */
Canexcel_Ip_ConfigXlTx(uint8 instance,uint8 mbIdx,uint32 id,const Canexcel_Ip_DataInfoType * info,Canexcel_TxXlMsgType * TxMsg)638 void Canexcel_Ip_ConfigXlTx(uint8 instance, uint8 mbIdx, uint32 id,const Canexcel_Ip_DataInfoType * info, Canexcel_TxXlMsgType * TxMsg)
639 {
640 Canexcel_Ip_apxState[instance]->msgDesc[mbIdx].isXLFrame = TRUE;
641 TxMsg->Header.timeStampL = 0U;
642 TxMsg->Header.timeStampL = 0U;
643 TxMsg->Header.word3 = 0U;
644 TxMsg->Header.word2 = 0U;
645 TxMsg->Header.word4 = 0U;
646 TxMsg->Header.word2 = CANXL_TX_HEADER_MODE_MASK | (((uint32)info->priority << CANXL_TX_HEADER_PRIO_SHIFT) & CANXL_TX_HEADER_PRIO_MASK)
647 | (((uint32)info->retransmission << CANXL_TX_HEADER_RETR_SHIFT) & CANXL_TX_HEADER_RETR_MASK );
648 if(info->idType == CANEXCEL_MSG_ID_EXT )
649 {
650 TxMsg->Header.word3 = CANXL_TX_HEADER_IDE_MASK | (id & CANXL_IP_ID_EXT_MASK) | CANXL_TX_HEADER_XLF_MASK;
651 }
652 else
653 {
654 TxMsg->Header.word3 = ((id << CANXL_IP_ID_STD_SHIFT) & CANXL_IP_ID_STD_MASK) | CANXL_TX_HEADER_XLF_MASK;
655 }
656 TxMsg->Header.word4 = (CANXL_TX_HEADER_FDF_MASK | ((((uint32)info->dataLength - 1u) << CANXL_TX_HEADER_DLC_SHIFT) & CANXL_TX_HEADER_DLC_MASK)) | (((uint32)info->SDT << CANXL_TX_HEADER_SDT_SHIFT)&CANXL_TX_HEADER_SDT_MASK);
657 }
658
Canexcel_Ip_ConfigFdTx(uint8 instance,uint8 mbIdx,uint32 id,const Canexcel_Ip_DataInfoType * info,Canexcel_TxFdMsgType * TxMsg)659 static void Canexcel_Ip_ConfigFdTx(uint8 instance, uint8 mbIdx, uint32 id,const Canexcel_Ip_DataInfoType * info, Canexcel_TxFdMsgType * TxMsg)
660 {
661 Canexcel_Ip_apxState[instance]->msgDesc[mbIdx].isXLFrame = FALSE;
662 uint16 dlcValue = 0U;
663 TxMsg->Header.timeStampL = 0U;
664 TxMsg->Header.timeStampL = 0U;
665 TxMsg->Header.word3 = 0U;
666 TxMsg->Header.word2 = 0U;
667 TxMsg->Header.word4 = 0U;
668 TxMsg->Header.word2 = CANXL_TX_HEADER_MODE_MASK | (((uint32)info->priority << CANXL_TX_HEADER_PRIO_SHIFT) & CANXL_TX_HEADER_PRIO_MASK)
669 | (((uint32)info->retransmission << CANXL_TX_HEADER_RETR_SHIFT) & CANXL_TX_HEADER_RETR_MASK );
670 if(info->idType == CANEXCEL_MSG_ID_EXT )
671 {
672 TxMsg->Header.word3 = CANXL_TX_HEADER_IDE_MASK | (id & CANXL_IP_ID_EXT_MASK);
673 }
674 else
675 {
676 TxMsg->Header.word3 = ((id << CANXL_IP_ID_STD_SHIFT) & CANXL_IP_ID_STD_MASK);
677 }
678
679 dlcValue = (uint16)CAN_ComputeDLCValue((uint8)(info->dataLength));
680 if(info->frame == CANEXCEL_FD_FRAME)
681 {
682 if (info->enable_brs == TRUE)
683 {
684 TxMsg->Header.word4 = CANXL_TX_HEADER_BRS_MASK | CANXL_TX_HEADER_FDF_MASK | (((uint32)dlcValue << CANXL_TX_HEADER_DLC_SHIFT) & CANXL_TX_HEADER_DLC_MASK);
685 }
686 else
687 {
688 TxMsg->Header.word4 = CANXL_TX_HEADER_FDF_MASK | (((uint32)dlcValue << CANXL_TX_HEADER_DLC_SHIFT) & CANXL_TX_HEADER_DLC_MASK);
689 }
690 }
691 else
692 {
693 TxMsg->Header.word4 = (((uint32)dlcValue << CANXL_TX_HEADER_DLC_SHIFT) & CANXL_TX_HEADER_DLC_MASK);
694 }
695 }
696 /*FUNCTION**********************************************************************
697 *
698 * Function Name : Canexcel_Ip_SendFDMsg
699 * Description : Send a CAN Classic or FD Format Message
700 *
701 *END**************************************************************************/
702 /* implements Canexcel_Ip_SendFDMsg_Activity */
Canexcel_Ip_SendFDMsg(uint8 instance,uint8 mbIdx,const Canexcel_Ip_DataInfoType * info,uint32 id,const uint8 * dataPtr,Canexcel_TxFdMsgType * TxMsg)703 Canexcel_Ip_StatusType Canexcel_Ip_SendFDMsg(uint8 instance, uint8 mbIdx,const Canexcel_Ip_DataInfoType * info, uint32 id,const uint8 * dataPtr, Canexcel_TxFdMsgType * TxMsg)
704 {
705 Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_ERROR;
706
707 if(!CanXL_IsListenOnlyModeEnabled(CANEXCEL.EXL_SIC[instance]))
708 {
709 if (FALSE == CanXL_IsPwmModeEnable(CANEXCEL.EXL_SIC[instance]))
710 {
711 Canexcel_Ip_ConfigFdTx(instance, mbIdx, id, info, TxMsg);
712 CanXL_SetTxMsgBuffData(info, dataPtr, (uint8 *)&TxMsg->data[0]);
713 if (info->is_polling == FALSE)
714 {
715 CanXL_SetMsgBuffIntCmd(CANEXCEL.EXL_GRP[instance], mbIdx);
716 }
717 returnResult = Canexcel_Ip_TxDescriptor(instance, mbIdx, (uint32)&TxMsg->Header.timeStampL);
718 }
719 }
720 return returnResult;
721 }
722 /*FUNCTION**********************************************************************
723 *
724 * Function Name : Canexcel_Ip_SendXLMsg
725 * Description : Send a CAN XL Format Message
726 *
727 *END**************************************************************************/
728 /* implements Canexcel_Ip_SendXLMsg_Activity */
Canexcel_Ip_SendXLMsg(uint8 instance,uint8 mbIdx,const Canexcel_Ip_DataInfoType * info,uint32 id,const uint8 * dataPtr,Canexcel_TxXlMsgType * TxMsg)729 Canexcel_Ip_StatusType Canexcel_Ip_SendXLMsg(uint8 instance, uint8 mbIdx,const Canexcel_Ip_DataInfoType * info, uint32 id,const uint8 * dataPtr, Canexcel_TxXlMsgType * TxMsg)
730 {
731 Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_ERROR;
732 if(!CanXL_IsListenOnlyModeEnabled(CANEXCEL.EXL_SIC[instance]))
733 {
734 Canexcel_Ip_ConfigXlTx(instance, mbIdx, id, info, TxMsg);
735 CanXL_SetTxMsgBuffData(info, dataPtr, (uint8 *)&TxMsg->data[0]);
736 if (info->is_polling == FALSE)
737 {
738 CanXL_SetMsgBuffIntCmd(CANEXCEL.EXL_GRP[instance], mbIdx);
739 }
740 returnResult = Canexcel_Ip_TxDescriptor(instance, mbIdx, (uint32)&TxMsg->Header.timeStampL);
741 }
742 return returnResult;
743 }
744 /*FUNCTION**********************************************************************
745 *
746 * Function Name : Canexcel_Ip_GetTransferStatus
747 * Description : Check the status transfer for a Message Descriptor
748 *
749 *END**************************************************************************/
750 /* implements Canexcel_Ip_GetTransferStatus_Activity */
Canexcel_Ip_GetTransferStatus(uint8 instance,uint8 descIdx)751 Canexcel_Ip_StatusType Canexcel_Ip_GetTransferStatus(uint8 instance, uint8 descIdx)
752 {
753 Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_NO_TRANSFER_IN_PROGRESS;
754 /* Check if the descriptor is active */
755 if (CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descIdx].ACT.DCACT == CANXL_DSC_CONTROL_DCACT_ACT_MASK)
756 {
757 if (CanXL_GetMDQueueDepth(CANEXCEL.EXL_GRP[instance], descIdx) == 0U)
758 {
759 /* In case of MD Queue depth = 0 */
760 if (CanXL_GetDesciptorState(CANEXCEL.EXL_DESC_CTR[instance], descIdx) == CANEXCEL_DESC_STATE_EMPTY)
761 {
762 returnResult = CANEXCEL_STATUS_SUCCESS;
763 }
764 if (CanXL_GetDesciptorState(CANEXCEL.EXL_DESC_CTR[instance], descIdx) == CANEXCEL_DESC_STATE_FULL)
765 {
766 returnResult = CANEXCEL_STATUS_BUSY;
767 }
768 }
769 else
770 {
771 if (CanXL_GetDesciptorHWIndex(CANEXCEL.EXL_DESC_CTR[instance], descIdx) == CanXL_GetDesciptorSysIndex(CANEXCEL.EXL_DESC_CTR[instance], descIdx))
772 {
773 returnResult = CANEXCEL_STATUS_SUCCESS;
774 }
775 else
776 {
777 returnResult = CANEXCEL_STATUS_BUSY;
778 }
779 }
780 if(CanXL_GetDesciptorState(CANEXCEL.EXL_DESC_CTR[instance], descIdx) == CANEXCEL_DESC_STATE_OVERRUN)
781 {
782 returnResult = CANEXCEL_STATUS_ERROR;
783 }
784 }
785 return returnResult;
786 }
787 /*FUNCTION**********************************************************************
788 *
789 * Function Name : Canexcel_Ip_EnterFreezeMode
790 * Description : Set the HW in FreezeMode
791 *
792 *END**************************************************************************/
793 /* implements Canexcel_Ip_EnterFreezeMode_Activity */
Canexcel_Ip_EnterFreezeMode(uint8 instance)794 Canexcel_Ip_StatusType Canexcel_Ip_EnterFreezeMode(uint8 instance)
795 {
796 return CanXL_EnterFreezeMode(CANEXCEL.EXL_SIC[instance]);
797 }
798 /*FUNCTION**********************************************************************
799 *
800 * Function Name : Canexcel_Ip_ExitFreezeMode
801 * Description : Set the HW in normal Run Mode
802 *
803 *END**************************************************************************/
804 /* implements Canexcel_Ip_ExitFreezeMode_Activity */
Canexcel_Ip_ExitFreezeMode(uint8 instance)805 Canexcel_Ip_StatusType Canexcel_Ip_ExitFreezeMode(uint8 instance)
806 {
807 return CanXL_ExitFreezeMode(CANEXCEL.EXL_SIC[instance]);
808 }
809 /*FUNCTION**********************************************************************
810 *
811 * Function Name : Canexcel_Ip_EnableInterrupts
812 * Description : Enable CanExcel Instance Interrupts
813 *
814 *END**************************************************************************/
815 /* implements Canexcel_Ip_EnableInterrupts_Activity */
Canexcel_Ip_EnableInterrupts(uint8 u8Instance)816 Canexcel_Ip_StatusType Canexcel_Ip_EnableInterrupts(uint8 u8Instance)
817 {
818 Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[u8Instance];
819 Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_ERROR;
820
821 if (TRUE == CanXL_IsFreezeMode(CANEXCEL.EXL_SIC[u8Instance]))
822 {
823 CanXL_EnableInterrupts(CANEXCEL.EXL_SIC[u8Instance]);
824 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))
825 {
826 /* Activate RxFifo Interrupts */
827 CANEXCEL.EXL_RXF_CNT[u8Instance]->RXFIEN = CANXL_RXFIFO_CONTROL_RXFIEN_RXFIE_MASK | CANXL_RXFIFO_CONTROL_RXFIEN_RXFEIE_MASK;
828 }
829 state->isIntActive = TRUE;
830 returnResult = CANEXCEL_STATUS_SUCCESS;
831 }
832
833 return returnResult;
834 }
835 /*FUNCTION**********************************************************************
836 *
837 * Function Name : Canexcel_Ip_DisableInterrupts
838 * Description : Disable CanExcel Instance Interrupts
839 *
840 *END**************************************************************************/
841 /* implements Canexcel_Ip_DisableInterrupts_Activity */
Canexcel_Ip_DisableInterrupts(uint8 u8Instance)842 Canexcel_Ip_StatusType Canexcel_Ip_DisableInterrupts(uint8 u8Instance)
843 {
844 Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[u8Instance];
845 Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_ERROR;
846
847 if (TRUE == CanXL_IsFreezeMode(CANEXCEL.EXL_SIC[u8Instance]))
848 {
849 CanXL_DisableInterrupts(CANEXCEL.EXL_SIC[u8Instance]);
850 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))
851 {
852 /* Clear RxFifo Interrupts */
853 CANEXCEL.EXL_RXF_CNT[u8Instance]->RXFIEN = ~(CANXL_RXFIFO_CONTROL_RXFIEN_RXFIE_MASK | CANXL_RXFIFO_CONTROL_RXFIEN_RXFEIE_MASK);
854 }
855 state->isIntActive = FALSE;
856 returnResult = CANEXCEL_STATUS_SUCCESS;
857 }
858
859 return returnResult;
860 }
861 /*FUNCTION**********************************************************************
862 *
863 * Function Name : Canexcel_Ip_RxTxIRQHandler
864 * Description : IrqHandler for Rx\Tx and RxFIFO
865 *
866 *END**************************************************************************/
867 /* implements CAN_X_MB_Y_ISR_Activity */
Canexcel_Ip_RxTxIRQHandler(uint8 instance)868 void Canexcel_Ip_RxTxIRQHandler(uint8 instance)
869 {
870 Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[instance];
871 uint32 flag_reg;
872 uint32 mb_idx = 0U;
873 uint8 total_mb = (uint8)((((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)));
874 /* Check if instance initialized */
875 if (NULL_PTR != state)
876 {
877 flag_reg = CanXL_GetMsgBuffIntStatusFlag(CANEXCEL.EXL_GRP[instance], mb_idx);
878 while((0U == flag_reg) && (mb_idx < total_mb ))
879 {
880 mb_idx++;
881 flag_reg = CanXL_GetMsgBuffIntStatusFlag(CANEXCEL.EXL_GRP[instance], mb_idx);
882 }
883
884 if (0U != flag_reg)
885 {
886 CanXL_ClearMsgDescIntStatusFlag(CANEXCEL.EXL_GRP[instance], mb_idx);
887 state->msgDesc[mb_idx].noPointers = (uint8)((CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[mb_idx].STA.DCSTA & CANXL_DSC_CONTROL_DCSTA_HWPOINTER_MASK) >> CANXL_DSC_CONTROL_DCSTA_HWPOINTER_SHIFT);
888 /* First descriptors are always allocated for Transmission */
889 if (mb_idx <= CANEXCEL.EXL_GRP[instance]->DSCCTRL)
890 {
891 /* Process Tx MDESC */
892 if (NULL_PTR != state->callback)
893 {
894 state->callback(instance, CANEXCEL_EVENT_TX_COMPLETE, mb_idx, state);
895 }
896 }
897 else
898 {
899 /* Process Rx MDESC */
900 if (NULL_PTR != state->callback)
901 {
902 state->callback(instance, CANEXCEL_EVENT_RX_COMPLETE, mb_idx, state);
903 }
904 }
905 }
906 if (CANEXCEL.EXL_RXF_CNT[instance]->RXFSYSACT == 1U)
907 {
908 if (((CANEXCEL.EXL_RXF_CNT[instance]->RXFIEN & CANXL_RXFIFO_CONTROL_RXFIEN_RXFIE_MASK) != 0U) && ((CANEXCEL.EXL_RXF_CNT[instance]->RXFS & CANXL_RXFIFO_CONTROL_RXFS_RXFF_MASK) != 0U))
909 {
910 /* Clear the fifo flag */
911 CANEXCEL.EXL_RXF_CNT[instance]->RXFS = CANXL_RXFIFO_CONTROL_RXFS_RXFF_MASK;
912 /* Process RxFifo for Reception */
913 if (NULL_PTR != state->callback)
914 {
915 state->callback(instance, CANEXCEL_EVENT_RXFIFO_COMPLETE, CANEXCEL_IP_MB_RXFIFO, state);
916 }
917 }
918 }
919 }
920 }
921 /*FUNCTION**********************************************************************
922 *
923 * Function Name : Canexcel_Ip_ErrIRQHandler
924 * Description : IrqHandler for Errors
925 *
926 *END**************************************************************************/
927 /* implements CAN_X_BUSOFF_ERROR_ISR_Activity */
Canexcel_Ip_ErrIRQHandler(uint8 instance)928 void Canexcel_Ip_ErrIRQHandler(uint8 instance)
929 {
930 const Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[instance];
931 uint32 sysStatus = CANEXCEL.EXL_SIC[instance]->SYSS;
932 uint32 bcanXlStatus = 0U;
933 /* Process CANEXCEL Error */
934 if (NULL_PTR != state->error_callback)
935 {
936 if (CANEXCEL_STATUS_SUCCESS == Canexcel_GetControllerMRU(instance, &bcanXlStatus, CANXL_MRU_CMD_READ_ST))
937 {
938 if (((CANEXCEL.EXL_SIC[instance]->SYSIE & CANXL_SIC_SYSIE_CERRIE_MASK) & sysStatus) == CANXL_SIC_SYSIE_CERRIE_MASK)
939 {
940 CANEXCEL.EXL_SIC[instance]->SYSS = CANXL_SIC_SYSS_CERR_MASK;
941 state->error_callback(instance, CANEXCEL_EVENT_ERROR, bcanXlStatus, state);
942 }
943 if (((CANEXCEL.EXL_SIC[instance]->SYSIE & CANXL_SIC_SYSIE_CFDPERRIE_MASK) & sysStatus) == CANXL_SIC_SYSIE_CFDPERRIE_MASK)
944 {
945 CANEXCEL.EXL_SIC[instance]->SYSS = CANXL_SIC_SYSS_CFDPERR_MASK;
946 state->error_callback(instance, CANEXCEL_EVENT_ERROR_FD, bcanXlStatus, state);
947 }
948 if (((CANEXCEL.EXL_SIC[instance]->SYSIE & CANXL_SIC_SYSIE_CRXWRNIE_MASK) & sysStatus) == CANXL_SIC_SYSIE_CRXWRNIE_MASK)
949 {
950 CANEXCEL.EXL_SIC[instance]->SYSS = CANXL_SIC_SYSS_CRXWRN_MASK;
951 state->error_callback(instance, CANEXCEL_EVENT_RX_WARNING, bcanXlStatus, state);
952 }
953 if (((CANEXCEL.EXL_SIC[instance]->SYSIE & CANXL_SIC_SYSIE_CTXWRNIE_MASK) & sysStatus) == CANXL_SIC_SYSIE_CTXWRNIE_MASK)
954 {
955 CANEXCEL.EXL_SIC[instance]->SYSS = CANXL_SIC_SYSS_CTXWRN_MASK;
956 state->error_callback(instance, CANEXCEL_EVENT_TX_WARNING, bcanXlStatus, state);
957 }
958 if (((CANEXCEL.EXL_SIC[instance]->SYSIE & CANXL_SIC_SYSIE_CDPERRIE_MASK) & sysStatus) == CANXL_SIC_SYSIE_CDPERRIE_MASK)
959 {
960 CANEXCEL.EXL_SIC[instance]->SYSS = CANXL_SIC_SYSS_CXDPERR_MASK;
961 state->error_callback(instance, CANEXCEL_EVENT_ERROR_XL, bcanXlStatus, state);
962 }
963 if (((CANEXCEL.EXL_SIC[instance]->SYSIE & CANXL_SIC_SYSIE_CPERRIE_MASK) & sysStatus) == CANXL_SIC_SYSIE_CPERRIE_MASK)
964 {
965 CANEXCEL.EXL_SIC[instance]->SYSS = CANXL_SIC_SYSS_CPASERR_MASK;
966 state->error_callback(instance, CANEXCEL_EVENT_PASSIVE, bcanXlStatus, state);
967 }
968 if (((CANEXCEL.EXL_SIC[instance]->SYSIE & CANXL_SIC_SYSIE_CBOFFIE_MASK) & sysStatus) == CANXL_SIC_SYSIE_CBOFFIE_MASK)
969 {
970 CANEXCEL.EXL_SIC[instance]->SYSS = CANXL_SIC_SYSS_CBOFF_MASK;
971 state->error_callback(instance, CANEXCEL_EVENT_BUSOFF, bcanXlStatus, state);
972 }
973 }
974 }
975 }
976 /*FUNCTION**********************************************************************
977 *
978 * Function Name : Canexcel_Ip_MruIRQHandler
979 * Description : IrqHandler for MRU service unit
980 *
981 *END**************************************************************************/
982 /* implements Canexcel_Ip_MruIRQHandler_Activity */
Canexcel_Ip_MruIRQHandler(uint8 instance)983 void Canexcel_Ip_MruIRQHandler(uint8 instance)
984 {
985 CANXL_MRU_Type * base = CANEXCEL.EXL_MRU[instance];
986 Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[instance];
987 uint8 mbIdx = 0u;
988 uint32 mask = 0u;
989 if (state != NULL_PTR)
990 {
991 if ((base->CHXCONFIG[0u].CH_CFG0 & CANXL_MRU_CH_CFG0_IE_MASK) == CANXL_MRU_CH_CFG0_IE_MASK)
992 {
993 for(;mbIdx < CANXL_IP_MRU_MAILBOX_NO; mbIdx++)
994 {
995 uint32 tmp = base->CHXCONFIG[0u].CH_CFG1;
996 mask = (uint32)( tmp & ((uint32)1U << ((uint32)mbIdx + (uint32)CANXL_MRU_CH_MBSTAT_MBS0_SHIFT)));
997 if (mask != 0U)
998 {
999 if ((base->CHXCONFIG[0u].CH_MBSTAT & mask) == mask)
1000 {
1001 SchM_Enter_Can_43_CANEXCEL_CAN_EXCLUSIVE_AREA_09();
1002 state->u8MruMailboxAct |= (1U<<mbIdx);
1003 base->CHXCONFIG[0u].CH_MBSTAT |= mask;
1004 SchM_Exit_Can_43_CANEXCEL_CAN_EXCLUSIVE_AREA_09();
1005 }
1006 }
1007 }
1008 }
1009 }
1010 }
1011
1012 /*FUNCTION**********************************************************************
1013 *
1014 * Function Name : Canexcel_Ip_SetErrorInt
1015 * Description : Enable\Disable Error or BusOff Interrupt
1016 *
1017 *END**************************************************************************/
1018 /* implements Canexcel_Ip_SetErrorInt_Activity */
Canexcel_Ip_SetErrorInt(uint8 u8Instance,Canexcel_Ip_ErrorIntType type,boolean enable)1019 Canexcel_Ip_StatusType Canexcel_Ip_SetErrorInt(uint8 u8Instance, Canexcel_Ip_ErrorIntType type, boolean enable)
1020 {
1021 Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_ERROR;
1022 if (TRUE == CanXL_IsFreezeMode(CANEXCEL.EXL_SIC[u8Instance]))
1023 {
1024 switch (type)
1025 {
1026 case CANEXCEL_IP_INT_RX_WARNING:
1027 {
1028 CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_RX_WARNING, enable);
1029 returnResult = CANEXCEL_STATUS_SUCCESS;
1030 break;
1031 }
1032 case CANEXCEL_IP_INT_TX_WARNING:
1033 {
1034 CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_TX_WARNING, enable);
1035 returnResult = CANEXCEL_STATUS_SUCCESS;
1036 break;
1037 }
1038 case CANEXCEL_IP_INT_ERR:
1039 {
1040 CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_ERR, enable);
1041 returnResult = CANEXCEL_STATUS_SUCCESS;
1042 break;
1043 }
1044 case CANEXCEL_IP_INT_ERR_FAST:
1045 {
1046 CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_ERR_FAST, enable);
1047 returnResult = CANEXCEL_STATUS_SUCCESS;
1048 break;
1049 }
1050 case CANEXCEL_IP_INT_ERR_XL:
1051 {
1052 CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_ERR_XL, enable);
1053 returnResult = CANEXCEL_STATUS_SUCCESS;
1054 break;
1055 }
1056 case CANEXCEL_IP_INT_ERR_INT:
1057 {
1058 CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_INT_ERR, enable);
1059 returnResult = CANEXCEL_STATUS_SUCCESS;
1060 break;
1061 }
1062 case CANEXCEL_IP_INT_BUSOFF:
1063 {
1064 CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_BUSOFF, enable);
1065 returnResult = CANEXCEL_STATUS_SUCCESS;
1066 break;
1067 }
1068 case CANEXCEL_IP_INT_BUSOFF_DONE:
1069 {
1070 CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_BUSOFF_DONE, enable);
1071 returnResult = CANEXCEL_STATUS_SUCCESS;
1072 break;
1073 }
1074 case CANEXCEL_IP_INT_FREEZE:
1075 {
1076 CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_FREEZE, enable);
1077 returnResult = CANEXCEL_STATUS_SUCCESS;
1078 break;
1079 }
1080 case CANEXCEL_IP_INT_PASS_ERR:
1081 {
1082 CanXL_SetErrIntCmd(CANEXCEL.EXL_SIC[u8Instance], CANXL_INT_PASIVE_ERR, enable);
1083 returnResult = CANEXCEL_STATUS_SUCCESS;
1084 break;
1085 }
1086 default :
1087 {
1088 /* Do Nothing will report CANEXCEL_STATUS_ERROR */
1089 break;
1090 }
1091 }
1092 }
1093 return returnResult;
1094 }
1095
1096 /*FUNCTION**********************************************************************
1097 *
1098 * Function Name : Canexcel_Ip_MainFunctionRead
1099 * Description : Process received Rx MessageBuffer or RxFifo.
1100 * This function read the messages received as pulling or if the Interrupts are disabled.
1101 *
1102 *END**************************************************************************/
1103 /* implements Canexcel_Ip_MainFunctionRead_Activity */
Canexcel_Ip_MainFunctionRead(uint8 instance,uint8 mb_idx)1104 void Canexcel_Ip_MainFunctionRead(uint8 instance, uint8 mb_idx)
1105 {
1106 Canexcel_Ip_MainFunction(instance, mb_idx);
1107 }
1108
1109 /*FUNCTION**********************************************************************
1110 *
1111 * Function Name : Canexcel_Ip_MainFunctionWrite
1112 * Description : Process sent Tx MessageBuffer or TxFifo.
1113 * This function read the messages received as pulling or if the Interrupts are disabled.
1114 *
1115 *END**************************************************************************/
1116 /* implements Canexcel_Ip_MainFunctionWrite_Activity */
Canexcel_Ip_MainFunctionWrite(uint8 instance,uint8 mb_idx)1117 void Canexcel_Ip_MainFunctionWrite(uint8 instance, uint8 mb_idx)
1118 {
1119 Canexcel_Ip_MainFunction(instance, mb_idx);
1120 }
1121
1122 /*FUNCTION**********************************************************************
1123 *
1124 * Function Name : Canexcel_Ip_GetStopMode
1125 * Description : Check if the CANEXCEL instance is STOPPED.
1126 *
1127 *END**************************************************************************/
1128 /* implements Canexcel_Ip_GetStopMode_Activity */
Canexcel_Ip_GetStopMode(uint8 instance)1129 boolean Canexcel_Ip_GetStopMode(uint8 instance)
1130 {
1131 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1132 DevAssert(instance < CANXL_SIC_INSTANCE_COUNT);
1133 #endif
1134 const CANXL_SIC_Type * base = CANEXCEL.EXL_SIC[instance];
1135 return ((CANXL_SIC_SYSS_LPMACKF_MASK == (base->SYSS & CANXL_SIC_SYSS_LPMACKF_MASK)) ? TRUE : FALSE);
1136 }
1137
1138 /*FUNCTION**********************************************************************
1139 *
1140 * Function Name : Canexcel_Ip_ConfigRxFifo
1141 * Description : Confgure RX FIFO filter table elements.
1142 * This function will confgure RX FIFO filter table elements
1143 *END**************************************************************************/
1144 /* implements Canexcel_Ip_ConfigRxFifo_Activity */
Canexcel_Ip_ConfigRxFifo(uint8 instance,const Canexcel_Ip_RxFifoFilter * filterConfig)1145 Canexcel_Ip_StatusType Canexcel_Ip_ConfigRxFifo(uint8 instance,const Canexcel_Ip_RxFifoFilter * filterConfig)
1146 {
1147 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1148 DevAssert(instance < CANXL_SIC_INSTANCE_COUNT);
1149 DevAssert(filterConfig->noActAddrFilters < CANXL_RXFIFO_ADDRACPTFLTAR_COUNT);
1150 DevAssert(filterConfig->noIdFilters < CANXL_RXFIFO_IDACPTFLTAR_COUNT);
1151 DevAssert(filterConfig->noSduFilters < CANXL_RXFIFO_SDUACPTFLTAR_COUNT);
1152 DevAssert(filterConfig->noVcanFilters < CANXL_RXFIFO_VCANACPTFLTAR_COUNT);
1153 #endif
1154 Canexcel_Ip_StatusType status = CANEXCEL_STATUS_SUCCESS;
1155 CANXL_RXFIFO_Type * base = CANEXCEL.EXL_RXFIFO[instance];
1156 CANXL_RXFIFO_CONTROL_Type * rxFifoCont_base = CANEXCEL.EXL_RXF_CNT[instance];
1157 uint8 idx;
1158 if (CANEXCEL.EXL_RXF_CNT[instance]->RXFSYSACT == 0U)
1159 {
1160 status = CANEXCEL_STATUS_ERROR;
1161 }
1162 else
1163 {
1164 if (TRUE == CanXL_IsFreezeMode(CANEXCEL.EXL_SIC[instance]))
1165 {
1166 /* Lock the RxFIFO by System by reading register */
1167 (void)rxFifoCont_base->RXFSYSLOCK;
1168 base->AFCFG = CANXL_RXFIFO_AFCFG_ACPTID((uint32)filterConfig->noIdFilters-1U);
1169 SchM_Enter_Can_43_CANEXCEL_CAN_EXCLUSIVE_AREA_07();
1170 for(idx = 0U; idx < filterConfig->noIdFilters; idx++)
1171 {
1172 CanXL_ConfigIDFilter(base, &filterConfig->IdFilterPtr[idx], idx);
1173 }
1174 if(filterConfig->noActAddrFilters != 0U)
1175 {
1176 base->AFCFG |= CANXL_RXFIFO_AFCFG_AADDREN_MASK | CANXL_RXFIFO_AFCFG_ACPTADDR((uint32)filterConfig->noActAddrFilters-1U);
1177 for(idx = 0U; idx < filterConfig->noActAddrFilters; idx++)
1178 {
1179 CanXL_ConfigAccAddr(base, &filterConfig->AddrFilterPtr[idx], idx);
1180 }
1181 }
1182 if(filterConfig->noSduFilters != 0U)
1183 {
1184 base->AFCFG |= CANXL_RXFIFO_AFCFG_ASDUEN_MASK | CANXL_RXFIFO_AFCFG_ACPTSDU((uint32)filterConfig->noSduFilters-1U);
1185 for(idx = 0U; idx < filterConfig->noSduFilters; idx++)
1186 {
1187 CanXL_ConfigSDUFilter(base, &filterConfig->SduFilterPtr[idx], idx);
1188 }
1189 }
1190 if(filterConfig->noVcanFilters != 0U)
1191 {
1192 base->AFCFG |= CANXL_RXFIFO_AFCFG_AVCANEN_MASK | CANXL_RXFIFO_AFCFG_ACPTVCAN((uint32)filterConfig->noVcanFilters-1U);
1193 for(idx = 0U; idx < filterConfig->noVcanFilters; idx++)
1194 {
1195 CanXL_ConfigVCANFilter(base, &filterConfig->VcanFilterPtr[idx], idx);
1196 }
1197 }
1198 SchM_Exit_Can_43_CANEXCEL_CAN_EXCLUSIVE_AREA_07();
1199 base->SECAM = filterConfig->SecMask;
1200 base->SECAV = filterConfig->SecFilter;
1201
1202 if ((rxFifoCont_base->RXFCSTA & CANXL_RXFIFO_CONTROL_RXFCSTA_SYSLOCK_MASK) == CANXL_RXFIFO_CONTROL_RXFCSTA_SYSLOCK_MASK)
1203 {
1204 /* Clear the sys lock to enable transfers */
1205 rxFifoCont_base->RXFSYSLOCK = CANXL_RXFIFO_CONTROL_RXFSYSLOCK_SYSLOCK_MASK;
1206 }
1207 status = CANEXCEL_STATUS_SUCCESS;
1208 }
1209 else
1210 {
1211 status = CANEXCEL_STATUS_ERROR;
1212 }
1213 }
1214 return status;
1215 }
1216
1217 /*FUNCTION**********************************************************************
1218 *
1219 * Function Name : Canexcel_Ip_IsXLFrameType
1220 * Description : Check if a MessageDescritptor is set for receive XL frame type
1221 *END**************************************************************************/
1222 /* implements Canexcel_Ip_IsXLFrameType_Activity */
Canexcel_Ip_IsXLFrameType(uint8 instance,uint8 descNo)1223 boolean Canexcel_Ip_IsXLFrameType(uint8 instance, uint8 descNo)
1224 {
1225 const Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[instance];
1226 boolean retVal = FALSE;
1227 if (descNo == CANEXCEL_IP_MB_RXFIFO)
1228 {
1229 retVal = state->rxFifo.isXLFrame;
1230 }
1231 else
1232 {
1233 if(descNo < CANXL_MSG_DESCRIPTORS_MSGDSC_COUNT)
1234 {
1235 retVal = state->msgDesc[descNo].isXLFrame;
1236 }
1237 }
1238 return retVal;
1239 }
1240 /*FUNCTION**********************************************************************
1241 *
1242 * Function Name : Canexcel_Ip_GetControllerTxErrorCounter
1243 * Description : Return the TxErrorCounter
1244 *END**************************************************************************/
1245 /* implements Canexcel_Ip_GetControllerTxErrorCounter_Activity */
Canexcel_Ip_GetControllerTxErrorCounter(uint8 instance,uint8 * pValue)1246 Canexcel_Ip_StatusType Canexcel_Ip_GetControllerTxErrorCounter(uint8 instance, uint8 * pValue)
1247 {
1248 uint32 errorCount = 0;
1249 Canexcel_Ip_StatusType status = Canexcel_GetControllerMRU(instance, &errorCount, CANXL_MRU_CMD_READ_EC);
1250 * pValue = (uint8)((errorCount & BCANXL_EC_TEC_MASK) >> BCANXL_EC_TEC_SHIFT);
1251 return status;
1252 }
1253 /*FUNCTION**********************************************************************
1254 *
1255 * Function Name : Canexcel_Ip_GetControllerRxErrorCounter
1256 * Description : Return the RxErrorCounter
1257 *END**************************************************************************/
1258 /* implements Canexcel_Ip_GetControllerRxErrorCounter_Activity */
Canexcel_Ip_GetControllerRxErrorCounter(uint8 instance,uint8 * pValue)1259 Canexcel_Ip_StatusType Canexcel_Ip_GetControllerRxErrorCounter(uint8 instance, uint8 * pValue)
1260 {
1261 uint32 errorCount = 0;
1262 Canexcel_Ip_StatusType status = Canexcel_GetControllerMRU(instance, &errorCount, CANXL_MRU_CMD_READ_EC);
1263 * pValue = (uint8)((errorCount & BCANXL_EC_REC_MASK) >> BCANXL_EC_REC_SHIFT);
1264 return status;
1265 }
1266 /*FUNCTION**********************************************************************
1267 *
1268 * Function Name : Canexcel_Ip_GetControllerStatus
1269 * Description : Return the Bus Status
1270 *END**************************************************************************/
1271 /* implements Canexcel_Ip_GetControllerStatus_Activity */
Canexcel_Ip_GetControllerStatus(uint8 instance,uint8 * pValue)1272 Canexcel_Ip_StatusType Canexcel_Ip_GetControllerStatus(uint8 instance, uint8 * pValue)
1273 {
1274 uint32 errorCount = 0;
1275 Canexcel_Ip_StatusType status =Canexcel_GetControllerMRU(instance, &errorCount, CANXL_MRU_CMD_READ_ST);
1276 * pValue = (uint8)((errorCount & BCANXL_ST_FLTCONF_MASK) >> BCANXL_ST_FLTCONF_SHIFT);
1277 return status;
1278 }
1279 /*FUNCTION**********************************************************************
1280 *
1281 * Function Name : Canexcel_Ip_MainFunctionBusOff
1282 * Description : Check if BusOff occurred
1283 * This function check the bus off event.
1284 *
1285 *END**************************************************************************/
1286 /* implements Canexcel_Ip_MainFunctionBusOff_Activity */
Canexcel_Ip_MainFunctionBusOff(uint8 instance)1287 Canexcel_Ip_StatusType Canexcel_Ip_MainFunctionBusOff(uint8 instance)
1288 {
1289 Canexcel_Ip_StatusType eRetVal = CANEXCEL_STATUS_ERROR;
1290 CANXL_SIC_Type * base = CANEXCEL.EXL_SIC[instance];;
1291 const Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[instance];
1292 uint32 u32StatusError =0U;
1293 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1294 DevAssert(instance < CANXL_SIC_INSTANCE_COUNT);
1295 #endif
1296 if (0U != (base->SYSS & CANXL_SIC_SYSS_CBOFF_MASK))
1297 {
1298 eRetVal = CANEXCEL_STATUS_SUCCESS;
1299 /* Clear BusOff Status Flag */
1300 base->SYSS = CANXL_SIC_SYSS_CBOFF_MASK;
1301 /* Invoke callback */
1302 if (state->error_callback != NULL_PTR)
1303 {
1304 /* Get error status */
1305 eRetVal = Canexcel_GetControllerMRU(instance, &u32StatusError, CANXL_MRU_CMD_READ_ST);
1306 if (eRetVal == CANEXCEL_STATUS_SUCCESS)
1307 {
1308 state->error_callback(instance, CANEXCEL_EVENT_BUSOFF, u32StatusError, state);
1309 }
1310 }
1311 }
1312 return eRetVal;
1313 }
1314 /*FUNCTION**********************************************************************
1315 *
1316 * Function Name : Canexcel_Ip_ClearErrorStatus
1317 * Description : Clear error status register.
1318 *
1319 *END**************************************************************************/
1320 /* implements Canexcel_Ip_ClearErrorStatus_Activity */
Canexcel_Ip_ClearErrorStatus(uint8 instance,uint32 error)1321 void Canexcel_Ip_ClearErrorStatus(uint8 instance, uint32 error)
1322 {
1323 CANXL_SIC_Type * base = CANEXCEL.EXL_SIC[instance];
1324 base->SYSS = error;
1325 }
1326
1327 /*FUNCTION**********************************************************************
1328 *
1329 * Function Name : Canexcel_Ip_ManualBusOffRecovery
1330 * Description : Recover manually from bus-off if possible.
1331 *
1332 *END**************************************************************************/
1333 /* implements Canexcel_Ip_ManualBusOffRecovery_Activity */
Canexcel_Ip_ManualBusOffRecovery(uint8 instance)1334 Canexcel_Ip_StatusType Canexcel_Ip_ManualBusOffRecovery(uint8 instance)
1335 {
1336 Canexcel_Ip_StatusType eRetVal = CANEXCEL_STATUS_ERROR;
1337 const CANXL_SIC_Type * base = CANEXCEL.EXL_SIC[instance];
1338 uint32 u32AckVal = 255U;
1339
1340 if ((base->BCFG1 & CANXL_SIC_BCFG1_ABRDIS_MASK) == CANXL_SIC_BCFG1_ABRDIS_MASK)
1341 {
1342 eRetVal = Canexcel_GetControllerMRU(instance, &u32AckVal, CANXL_MRU_CMD_BUSOFF);
1343 if((eRetVal == CANEXCEL_STATUS_SUCCESS) && (u32AckVal != CANXL_MRU_CMD_BUSOFF))
1344 {
1345 eRetVal = CANEXCEL_STATUS_ERROR;
1346 }
1347 }
1348 return eRetVal;
1349 }
1350
1351 /*FUNCTION**********************************************************************
1352 *
1353 * Function Name : Canexcel_Ip_SetFDBaudRate
1354 * Description : Set bit rate segments in FD phase.
1355 *
1356 *END**************************************************************************/
1357 /* implements Canexcel_Ip_SetFDBaudRate_Activity */
Canexcel_Ip_SetFDBaudRate(uint8 Instance,const Canexcel_Ip_TimeSegmentType * TimeSeg,boolean BitRateSwitch)1358 Canexcel_Ip_StatusType Canexcel_Ip_SetFDBaudRate(uint8 Instance, const Canexcel_Ip_TimeSegmentType * TimeSeg, boolean BitRateSwitch)
1359 {
1360 Canexcel_Ip_StatusType RetVal = CANEXCEL_STATUS_ERROR;
1361 CANXL_SIC_Type * Base = CANEXCEL.EXL_SIC[Instance];
1362
1363 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1364 DevAssert(Instance < CANXL_SIC_INSTANCE_COUNT);
1365 DevAssert(TimeSeg != NULL_PTR);
1366 #endif
1367
1368 if (TRUE == CanXL_IsFreezeMode(Base))
1369 {
1370 if (TRUE == CanXL_IsFDModeEnabled(Base))
1371 {
1372 CanXL_SetFDEnabled(Base, TRUE, BitRateSwitch);
1373 CanXL_SetFDBaudRate(Base, TimeSeg);
1374 RetVal = CANEXCEL_STATUS_SUCCESS;
1375 }
1376 }
1377
1378 return RetVal;
1379 }
1380
1381 /*FUNCTION**********************************************************************
1382 *
1383 * Function Name : Canexcel_Ip_SetXLBaudRate
1384 * Description : Set bit rate segments in XL phase.
1385 *
1386 *END**************************************************************************/
1387 /* implements Canexcel_Ip_SetXLBaudRate_Activity */
Canexcel_Ip_SetXLBaudRate(uint8 Instance,const Canexcel_Ip_TimeSegmentType * TimeSeg)1388 Canexcel_Ip_StatusType Canexcel_Ip_SetXLBaudRate(uint8 Instance, const Canexcel_Ip_TimeSegmentType * TimeSeg)
1389 {
1390 Canexcel_Ip_StatusType RetVal = CANEXCEL_STATUS_ERROR;
1391 CANXL_SIC_Type * Base = CANEXCEL.EXL_SIC[Instance];
1392
1393 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1394 DevAssert(Instance < CANXL_SIC_INSTANCE_COUNT);
1395 DevAssert(TimeSeg != NULL_PTR);
1396 #endif
1397
1398 if (TRUE == CanXL_IsFreezeMode(Base))
1399 {
1400 if (TRUE == CanXL_IsXLModeEnabled(Base))
1401 {
1402 CanXL_SetXLBaudRate(Base, TimeSeg);
1403 RetVal = CANEXCEL_STATUS_SUCCESS;
1404 }
1405 }
1406
1407 return RetVal;
1408 }
1409
1410 /*FUNCTION**********************************************************************
1411 *
1412 * Function Name : Canexcel_Ip_SetBaudRate
1413 * Description : Set bit rate segments in nomimal phase.
1414 *
1415 *END**************************************************************************/
1416 /* implements Canexcel_Ip_SetBaudRate_Activity */
Canexcel_Ip_SetBaudRate(uint8 Instance,const Canexcel_Ip_TimeSegmentType * TimeSeg)1417 Canexcel_Ip_StatusType Canexcel_Ip_SetBaudRate(uint8 Instance, const Canexcel_Ip_TimeSegmentType * TimeSeg)
1418 {
1419 Canexcel_Ip_StatusType RetVal = CANEXCEL_STATUS_ERROR;
1420 CANXL_SIC_Type * Base = CANEXCEL.EXL_SIC[Instance];
1421 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1422 DevAssert(Instance < CANXL_SIC_INSTANCE_COUNT);
1423 DevAssert(TimeSeg != NULL_PTR);
1424 #endif
1425 if (TRUE == CanXL_IsFreezeMode(Base))
1426 {
1427 CanXL_SetBaudRate(Base, TimeSeg);
1428 RetVal = CANEXCEL_STATUS_SUCCESS;
1429 }
1430 return RetVal;
1431 }
1432 /*FUNCTION**********************************************************************
1433 *
1434 * Function Name : Canexcel_Ip_GetFDBaudRate
1435 * Description : Get bit rate segments in FD phase.
1436 *
1437 *END**************************************************************************/
1438 /* implements Canexcel_Ip_GetFDBaudRate_Activity */
Canexcel_Ip_GetFDBaudRate(uint8 Instance,Canexcel_Ip_TimeSegmentType * TimeSeg)1439 void Canexcel_Ip_GetFDBaudRate(uint8 Instance, Canexcel_Ip_TimeSegmentType * TimeSeg)
1440 {
1441 const CANXL_SIC_Type * Base = CANEXCEL.EXL_SIC[Instance];
1442
1443 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1444 DevAssert(Instance < CANXL_SIC_INSTANCE_COUNT);
1445 DevAssert(TimeSeg != NULL_PTR);
1446 #endif
1447 CanXL_GetFDBaudRate(Base, TimeSeg);
1448 }
1449
1450 /*FUNCTION**********************************************************************
1451 *
1452 * Function Name : Canexcel_Ip_GetXLBaudRate
1453 * Description : Get bit rate segments in XL phase.
1454 *
1455 *END**************************************************************************/
1456 /* implements Canexcel_Ip_GetXLBaudRate_Activity */
Canexcel_Ip_GetXLBaudRate(uint8 Instance,Canexcel_Ip_TimeSegmentType * TimeSeg)1457 void Canexcel_Ip_GetXLBaudRate(uint8 Instance, Canexcel_Ip_TimeSegmentType * TimeSeg)
1458 {
1459 const CANXL_SIC_Type * Base = CANEXCEL.EXL_SIC[Instance];
1460 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1461 DevAssert(Instance < CANXL_SIC_INSTANCE_COUNT);
1462 DevAssert(TimeSeg != NULL_PTR);
1463 #endif
1464 CanXL_GetXLBaudRate(Base, TimeSeg);
1465 }
1466
1467 /*FUNCTION**********************************************************************
1468 *
1469 * Function Name : Canexcel_Ip_GetBaudRate
1470 * Description : Get bit rate segments in nomimal phase.
1471 *
1472 *END**************************************************************************/
1473 /* implements Canexcel_Ip_GetBaudRate_Activity */
Canexcel_Ip_GetBaudRate(uint8 Instance,Canexcel_Ip_TimeSegmentType * TimeSeg)1474 void Canexcel_Ip_GetBaudRate(uint8 Instance, Canexcel_Ip_TimeSegmentType * TimeSeg)
1475 {
1476 const CANXL_SIC_Type * Base = CANEXCEL.EXL_SIC[Instance];
1477 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1478 DevAssert(Instance < CANXL_SIC_INSTANCE_COUNT);
1479 DevAssert(TimeSeg != NULL_PTR);
1480 #endif
1481 CanXL_GetBaudRate(Base, TimeSeg);
1482 }
1483 /*FUNCTION**********************************************************************
1484 *
1485 * Function Name : Canexcel_Ip_SetListenOnlyMode
1486 * Description : Enable/disable Listen Only Mode.
1487 *
1488 *END**************************************************************************/
1489 /* implements Canexcel_Ip_SetListenOnlyMode_Activity */
Canexcel_Ip_SetListenOnlyMode(uint8 Instance,boolean Enable)1490 Canexcel_Ip_StatusType Canexcel_Ip_SetListenOnlyMode(uint8 Instance, boolean Enable)
1491 {
1492 Canexcel_Ip_StatusType RetVal = CANEXCEL_STATUS_ERROR;
1493 CANXL_SIC_Type * Base = CANEXCEL.EXL_SIC[Instance];
1494
1495 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1496 DevAssert(Instance < CANXL_SIC_INSTANCE_COUNT);
1497 #endif
1498 if (TRUE == CanXL_IsFreezeMode((const CANXL_SIC_Type *)Base))
1499 {
1500 CanXL_SetListenOnlyMode(Base, Enable);
1501 RetVal = CANEXCEL_STATUS_SUCCESS;
1502 }
1503 return RetVal;
1504 }
1505 /*FUNCTION**********************************************************************
1506 *
1507 * Function Name : Canexcel_Ip_GetListenOnlyMode
1508 * Description : Get Listen Only Mode.
1509 *
1510 *END**************************************************************************/
1511 /* implements Canexcel_Ip_GetListenOnlyMode_Activity */
Canexcel_Ip_GetListenOnlyMode(uint8 Instance)1512 boolean Canexcel_Ip_GetListenOnlyMode(uint8 Instance)
1513 {
1514 const CANXL_SIC_Type * Base = CANEXCEL.EXL_SIC[Instance];
1515
1516 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1517 DevAssert(Instance < CANXL_SIC_INSTANCE_COUNT);
1518 #endif
1519
1520 return CanXL_IsListenOnlyModeEnabled(Base);
1521 }
1522 /*FUNCTION**********************************************************************
1523 *
1524 * Function Name : Canexcel_Ip_SetTDCOffsetFD
1525 * Description : Enables/Disables the FD Transceiver Delay Compensation feature
1526 * and sets the FD Transceiver Delay Compensation Offset.
1527 *
1528 *END**************************************************************************/
1529 /* implements Canexcel_Ip_SetTDCOffsetFD_Activity */
Canexcel_Ip_SetTDCOffsetFD(uint8 Instance,boolean TDCEnable,boolean TDCMEnable,uint8 Offset)1530 Canexcel_Ip_StatusType Canexcel_Ip_SetTDCOffsetFD(uint8 Instance, boolean TDCEnable, boolean TDCMEnable, uint8 Offset)
1531 {
1532 CANXL_SIC_Type * Base = CANEXCEL.EXL_SIC[Instance];
1533 Canexcel_Ip_StatusType RetVal = CANEXCEL_STATUS_ERROR;
1534
1535 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1536 DevAssert(Instance < CANXL_SIC_INSTANCE_COUNT);
1537 /* When TDC disabled, TDC Measurement has no meaning! */
1538 DevAssert(!((FALSE == TDCEnable) && (TRUE == TDCMEnable)));
1539 #endif
1540 if (TRUE == CanXL_IsFreezeMode(Base))
1541 {
1542 CanXL_SetTDCOffsetFD(Base, TDCEnable, TDCMEnable, Offset);
1543 RetVal = CANEXCEL_STATUS_SUCCESS;
1544 }
1545 return RetVal;
1546 }
1547
1548 /*FUNCTION**********************************************************************
1549 *
1550 * Function Name : Canexcel_Ip_SetTDCOffsetXL
1551 * Description : Enables/Disables the XL Transceiver Delay Compensation feature
1552 * and sets the XL Transceiver Delay Compensation Offset.
1553 *
1554 *END**************************************************************************/
1555 /* implements Canexcel_Ip_SetTDCOffsetXL_Activity */
Canexcel_Ip_SetTDCOffsetXL(uint8 Instance,boolean TDCEnable,boolean TDCMEnable,uint8 Offset)1556 Canexcel_Ip_StatusType Canexcel_Ip_SetTDCOffsetXL(uint8 Instance, boolean TDCEnable, boolean TDCMEnable, uint8 Offset)
1557 {
1558 CANXL_SIC_Type * Base = CANEXCEL.EXL_SIC[Instance];
1559 Canexcel_Ip_StatusType RetVal = CANEXCEL_STATUS_ERROR;
1560
1561 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1562 DevAssert(Instance < CANXL_SIC_INSTANCE_COUNT);
1563 /* When TDC disabled, TDC Measurement has no meaning! */
1564 DevAssert(!((FALSE == TDCEnable) && (TRUE == TDCMEnable)));
1565 #endif
1566
1567 if (TRUE == CanXL_IsFreezeMode(Base))
1568 {
1569 CanXL_SetTDCOffsetXL(Base, TDCEnable, TDCMEnable, Offset);
1570 RetVal = CANEXCEL_STATUS_SUCCESS;
1571 }
1572 return RetVal;
1573 }
1574
1575 /*FUNCTION**********************************************************************
1576 *
1577 * Function Name : Canexcel_Ip_ConfigTransceiverMode
1578 * Description : Configure PWM Short Phase, PWM Long Phase, PWM Offset, protocol exception
1579 *
1580 *END**************************************************************************/
1581 /* implements Canexcel_Ip_ConfigTransceiverMode_Activity */
Canexcel_Ip_ConfigTransceiverMode(uint8 Instance,const Canexcel_Ip_TransceiverModeType * Config)1582 Canexcel_Ip_StatusType Canexcel_Ip_ConfigTransceiverMode(uint8 Instance, const Canexcel_Ip_TransceiverModeType * Config)
1583 {
1584 CANXL_SIC_Type * Base = CANEXCEL.EXL_SIC[Instance];
1585 Canexcel_Ip_StatusType RetVal = CANEXCEL_STATUS_ERROR;
1586
1587 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1588 DevAssert(Instance < CANXL_SIC_INSTANCE_COUNT);
1589 DevAssert(NULL_PTR != Config);
1590 /* when PWM mode enabled, protocol exception must be enabled */
1591 DevAssert(!((TRUE == Config->PwmModeEnable) && (FALSE == Config->ProtocolExceptionEnable)));
1592 /* when PWM mode enabled, PWMS must be in range [1:63] */
1593 DevAssert(!((TRUE == Config->PwmModeEnable) && ((0U == Config->PwmShortPhase) || (Config->PwmShortPhase > 63U))));
1594 /* when PWM mode enabled, PWML must be in range [1:63] */
1595 DevAssert(!((TRUE == Config->PwmModeEnable) && ((0U == Config->PwmLongPhase) || (Config->PwmLongPhase > 63U))));
1596 /* when PWM mode enabled, PWMO must be in range [0:63] */
1597 DevAssert(!((TRUE == Config->PwmModeEnable) && (Config->PwmOffset > 63U)));
1598 #endif
1599 if (TRUE == CanXL_IsFreezeMode(Base))
1600 {
1601 SchM_Enter_Can_43_CANEXCEL_CAN_EXCLUSIVE_AREA_12();
1602 CanXL_SetPwmModeEnable(Base, Config->PwmModeEnable);
1603 CanXL_SetPWMPhases(Base, Config->PwmShortPhase, Config->PwmLongPhase, Config->PwmOffset);
1604 CanXL_SetXLErrorResponse(Base, Config->ProtocolExceptionEnable);
1605 SchM_Exit_Can_43_CANEXCEL_CAN_EXCLUSIVE_AREA_12();
1606 RetVal = CANEXCEL_STATUS_SUCCESS;
1607 }
1608 return RetVal;
1609 }
1610 /*FUNCTION**********************************************************************
1611 *
1612 * Function Name : Canexcel_Ip_ConfigAccFltBank0
1613 * Description : Configures the 32 AF, VCAN, SDU Acceptance Filters from Filter Bank 0
1614 * note: This Filters Affect only the MessageDescriptors config for XL Frame reception
1615 *END**************************************************************************/
1616 /* implements Canexcel_Ip_ConfigAccFltBank0_Activity */
Canexcel_Ip_ConfigAccFltBank0(uint8 Instance,const Canexcel_Ip_BankFilter * Config)1617 Canexcel_Ip_StatusType Canexcel_Ip_ConfigAccFltBank0(uint8 Instance, const Canexcel_Ip_BankFilter * Config)
1618 {
1619 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1620 DevAssert(Instance < CANXL_SIC_INSTANCE_COUNT);
1621 DevAssert(Config->noActAddrFilters <= CANEXCEL_IP_MAX_FILTER_BANK);
1622 DevAssert(Config->noSduFilters <= CANEXCEL_IP_MAX_FILTER_BANK);
1623 DevAssert(Config->noVcanFilters <= CANEXCEL_IP_MAX_FILTER_BANK);
1624 #endif
1625 Canexcel_Ip_StatusType status = CANEXCEL_STATUS_SUCCESS;
1626 uint8 idx;
1627 CANXL_FILTER_BANK_Type * base = CANEXCEL.EXL_FILTER[Instance];
1628 if (TRUE == CanXL_IsFreezeMode(CANEXCEL.EXL_SIC[Instance]))
1629 {
1630 if (Config->noActAddrFilters != 0U)
1631 {
1632 base->AFCFG0 = CANXL_FILTER_BANK_AFCFG0_AADDREN_MASK | CANXL_FILTER_BANK_AFCFG0_ACPTADDR((uint32)Config->noActAddrFilters-1U);
1633 for(idx = 0U; idx < Config->noActAddrFilters; idx++)
1634 {
1635 CanXL_ConfigAccAddrFilterBank(base, 0U, &Config->AddrFilterPtr[idx], idx);
1636 }
1637 }
1638 if (Config->noSduFilters != 0U)
1639 {
1640 base->AFCFG0 |= CANXL_FILTER_BANK_AFCFG0_ASDUEN_MASK | CANXL_FILTER_BANK_AFCFG0_ACPTSDU((uint32)Config->noSduFilters-1U);
1641 for(idx = 0U; idx < Config->noSduFilters; idx++)
1642 {
1643 CanXL_ConfigSDUFilterBank(base, 0U, &Config->SduFilterPtr[idx], idx);
1644 }
1645 }
1646 if (Config->noVcanFilters != 0U)
1647 {
1648 base->AFCFG0 |= CANXL_FILTER_BANK_AFCFG0_AVCANEN_MASK | CANXL_FILTER_BANK_AFCFG0_ACPTVCAN((uint32)Config->noVcanFilters-1U);
1649 for(idx = 0U; idx < Config->noVcanFilters; idx++)
1650 {
1651 CanXL_ConfigVCANFilterBank(base, 0U, &Config->VcanFilterPtr[idx], idx);
1652 }
1653 }
1654
1655 }
1656 else
1657 {
1658 status = CANEXCEL_STATUS_ERROR;
1659 }
1660 return status;
1661 }
1662 /*FUNCTION**********************************************************************
1663 *
1664 * Function Name : Canexcel_Ip_ConfigAccFltBank1
1665 * Description : Configures the 32 AF, VCAN, SDU Acceptance Filters from Filter Bank 1
1666 * note: This Filters Affect only the MessageDescriptors config for XL Frame reception
1667 *END**************************************************************************/
1668 /* implements Canexcel_Ip_ConfigAccFltBank1_Activity */
Canexcel_Ip_ConfigAccFltBank1(uint8 Instance,const Canexcel_Ip_BankFilter * Config)1669 Canexcel_Ip_StatusType Canexcel_Ip_ConfigAccFltBank1(uint8 Instance, const Canexcel_Ip_BankFilter * Config)
1670 {
1671 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1672 DevAssert(Instance < CANXL_SIC_INSTANCE_COUNT);
1673 DevAssert(Config->noActAddrFilters <= CANEXCEL_IP_MAX_FILTER_BANK);
1674 DevAssert(Config->noSduFilters <= CANEXCEL_IP_MAX_FILTER_BANK);
1675 DevAssert(Config->noVcanFilters <= CANEXCEL_IP_MAX_FILTER_BANK);
1676 #endif
1677 Canexcel_Ip_StatusType status = CANEXCEL_STATUS_SUCCESS;
1678 uint8 idx;
1679 CANXL_FILTER_BANK_Type * base = CANEXCEL.EXL_FILTER[Instance];
1680 if (TRUE == CanXL_IsFreezeMode(CANEXCEL.EXL_SIC[Instance]))
1681 {
1682 if (Config->noActAddrFilters != 0U)
1683 {
1684 base->AFCFG1 = CANXL_FILTER_BANK_AFCFG1_AADDREN_MASK | CANXL_FILTER_BANK_AFCFG1_ACPTADDR((uint32)Config->noActAddrFilters-1U);
1685 for(idx = 0U; idx < Config->noActAddrFilters; idx++)
1686 {
1687 CanXL_ConfigAccAddrFilterBank(base, 1U, &Config->AddrFilterPtr[idx], idx);
1688 }
1689 }
1690 if (Config->noSduFilters != 0U)
1691 {
1692 base->AFCFG1 |= CANXL_FILTER_BANK_AFCFG1_ASDUEN_MASK | CANXL_FILTER_BANK_AFCFG1_ACPTSDU((uint32)Config->noSduFilters-1U);
1693 for(idx = 0U; idx <= Config->noSduFilters; idx++)
1694 {
1695 CanXL_ConfigSDUFilterBank(base, 1U, &Config->SduFilterPtr[idx], idx);
1696 }
1697 }
1698 if (Config->noVcanFilters != 0U)
1699 {
1700 base->AFCFG1 |= CANXL_FILTER_BANK_AFCFG1_AVCANEN_MASK | CANXL_FILTER_BANK_AFCFG1_ACPTVCAN((uint32)Config->noVcanFilters-1U);
1701 for(idx = 0U; idx < Config->noSduFilters; idx++)
1702 {
1703 CanXL_ConfigVCANFilterBank(base, 1U, &Config->VcanFilterPtr[idx], idx);
1704 }
1705 }
1706
1707 }
1708 else
1709 {
1710 status = CANEXCEL_STATUS_ERROR;
1711 }
1712 return status;
1713 }
1714 /*FUNCTION**********************************************************************
1715 *
1716 * Function Name : Canexcel_Ip_ConfigRejFltBank0
1717 * Description : Configures the 32 AF, VCAN, SDU Rejection Filters from Filter Bank 0
1718 * note: This Filters Affect only the MessageDescriptors config for XL Frame reception
1719 *END**************************************************************************/
1720 /* implements Canexcel_Ip_ConfigRejFltBank0_Activity */
Canexcel_Ip_ConfigRejFltBank0(uint8 Instance,const Canexcel_Ip_BankFilter * Config)1721 Canexcel_Ip_StatusType Canexcel_Ip_ConfigRejFltBank0(uint8 Instance, const Canexcel_Ip_BankFilter * Config)
1722 {
1723 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1724 DevAssert(Instance < CANXL_SIC_INSTANCE_COUNT);
1725 DevAssert(Config->noActAddrFilters <= CANEXCEL_IP_MAX_FILTER_BANK);
1726 DevAssert(Config->noSduFilters <= CANEXCEL_IP_MAX_FILTER_BANK);
1727 DevAssert(Config->noVcanFilters <= CANEXCEL_IP_MAX_FILTER_BANK);
1728 #endif
1729 Canexcel_Ip_StatusType status = CANEXCEL_STATUS_SUCCESS;
1730 uint8 idx;
1731 CANXL_FILTER_BANK_Type * base = CANEXCEL.EXL_FILTER[Instance];
1732 if (TRUE == CanXL_IsFreezeMode(CANEXCEL.EXL_SIC[Instance]))
1733 {
1734 if (Config->noActAddrFilters != 0U)
1735 {
1736 base->RFCFG0 = CANXL_FILTER_BANK_RFCFG0_RADDREN_MASK | CANXL_FILTER_BANK_RFCFG0_REJADDR((uint32)Config->noActAddrFilters-1U);
1737 for(idx = 0U; idx < Config->noActAddrFilters; idx++)
1738 {
1739 CanXL_ConfigAccAddrRejectBank(base, 0U, &Config->AddrFilterPtr[idx], idx);
1740 }
1741 }
1742 if (Config->noSduFilters != 0U)
1743 {
1744 base->RFCFG0 |= CANXL_FILTER_BANK_RFCFG0_RSDUEN_MASK | CANXL_FILTER_BANK_RFCFG0_REJSDU((uint32)Config->noSduFilters-1U);
1745 for(idx = 0U; idx < Config->noSduFilters; idx++)
1746 {
1747 CanXL_ConfigSDURejectBank(base, 0U, &Config->SduFilterPtr[idx], idx);
1748 }
1749 }
1750 if (Config->noVcanFilters != 0U)
1751 {
1752 base->RFCFG0 |= CANXL_FILTER_BANK_RFCFG0_RVCANEN_MASK | CANXL_FILTER_BANK_RFCFG0_REJVCAN((uint32)Config->noVcanFilters-1U);
1753 for(idx = 0U; idx < Config->noVcanFilters; idx++)
1754 {
1755 CanXL_ConfigVCANRejectBank(base, 0U, &Config->VcanFilterPtr[idx], idx);
1756 }
1757 }
1758
1759 }
1760 else
1761 {
1762 status = CANEXCEL_STATUS_ERROR;
1763 }
1764 return status;
1765 }
1766 /*FUNCTION**********************************************************************
1767 *
1768 * Function Name : Canexcel_Ip_ConfigRejFltBank1
1769 * Description : Configures the 32 AF, VCAN, SDU Rejection Filters from Filter Bank 1
1770 * note: This Filters Affect only the MessageDescriptors config for XL Frame reception
1771 *END**************************************************************************/
1772 /* implements Canexcel_Ip_ConfigRejFltBank1_Activity */
Canexcel_Ip_ConfigRejFltBank1(uint8 Instance,const Canexcel_Ip_BankFilter * Config)1773 Canexcel_Ip_StatusType Canexcel_Ip_ConfigRejFltBank1(uint8 Instance, const Canexcel_Ip_BankFilter * Config)
1774 {
1775 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1776 DevAssert(Instance < CANXL_SIC_INSTANCE_COUNT);
1777 DevAssert(Config->noActAddrFilters <= CANEXCEL_IP_MAX_FILTER_BANK);
1778 DevAssert(Config->noSduFilters <= CANEXCEL_IP_MAX_FILTER_BANK);
1779 DevAssert(Config->noVcanFilters <= CANEXCEL_IP_MAX_FILTER_BANK);
1780 #endif
1781 Canexcel_Ip_StatusType status = CANEXCEL_STATUS_SUCCESS;
1782 uint8 idx;
1783 CANXL_FILTER_BANK_Type * base = CANEXCEL.EXL_FILTER[Instance];
1784 if (TRUE == CanXL_IsFreezeMode(CANEXCEL.EXL_SIC[Instance]))
1785 {
1786 if (Config->noActAddrFilters != 0U)
1787 {
1788 base->RFCFG1 = CANXL_FILTER_BANK_RFCFG1_RADDREN_MASK | CANXL_FILTER_BANK_RFCFG1_REJADDR((uint32)Config->noActAddrFilters-1U);
1789 for(idx = 0U; idx < Config->noActAddrFilters; idx++)
1790 {
1791 CanXL_ConfigAccAddrRejectBank(base, 1U, &Config->AddrFilterPtr[idx], idx);
1792 }
1793 }
1794 if (Config->noSduFilters != 0U)
1795 {
1796 base->RFCFG1 |= CANXL_FILTER_BANK_RFCFG1_RSDUEN_MASK | CANXL_FILTER_BANK_RFCFG1_REJSDU((uint32)Config->noSduFilters-1U);
1797 for(idx = 0U; idx < Config->noSduFilters; idx++)
1798 {
1799 CanXL_ConfigSDURejectBank(base, 1U, &Config->SduFilterPtr[idx], idx);
1800 }
1801 }
1802 if (Config->noVcanFilters != 0U)
1803 {
1804 base->RFCFG1 |= CANXL_FILTER_BANK_RFCFG1_RVCANEN_MASK | CANXL_FILTER_BANK_RFCFG1_REJVCAN((uint32)Config->noVcanFilters-1U);
1805 for(idx = 0U; idx < Config->noVcanFilters; idx++)
1806 {
1807 CanXL_ConfigVCANRejectBank(base, 1U, &Config->VcanFilterPtr[idx], idx);
1808 }
1809 }
1810
1811 }
1812 else
1813 {
1814 status = CANEXCEL_STATUS_ERROR;
1815 }
1816 return status;
1817 }
1818 /*FUNCTION**********************************************************************
1819 *
1820 * Function Name : Canexcel_Ip_ConfigAccAddrFilter
1821 * Description : Configures the ACC Filter No from Bank0 or Bank1
1822 * note: This Filters Affect only the MessageDescriptors config for XL Frame reception
1823 *END**************************************************************************/
1824 /* implements Canexcel_Ip_ConfigAccAddrFilter_Activity */
Canexcel_Ip_ConfigAccAddrFilter(uint8 Instance,const Canexcel_Ip_RxFifoFilterID_ADDR * filterValue,uint8 * filterNo)1825 Canexcel_Ip_StatusType Canexcel_Ip_ConfigAccAddrFilter(uint8 Instance,const Canexcel_Ip_RxFifoFilterID_ADDR * filterValue, uint8 * filterNo)
1826 {
1827 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1828 DevAssert(Instance < CANXL_SIC_INSTANCE_COUNT);
1829 DevAssert(filterValue != NULL_PTR);
1830 DevAssert(filterNo != NULL_PTR);
1831 #endif
1832 Canexcel_Ip_StatusType status = CANEXCEL_STATUS_SUCCESS;
1833 uint8 noFilter = 0U;
1834 if (TRUE == CanXL_IsFreezeMode(CANEXCEL.EXL_SIC[Instance]))
1835 {
1836 noFilter = (uint8)((CANEXCEL.EXL_FILTER[Instance]->AFCFG0 & CANXL_FILTER_BANK_AFCFG0_ACPTADDR_MASK) >> CANXL_FILTER_BANK_AFCFG0_ACPTADDR_SHIFT);
1837 if ((CANEXCEL.EXL_FILTER[Instance]->AFCFG0 & CANXL_FILTER_BANK_AFCFG0_AADDREN_MASK) == 0U)
1838 {
1839 CANEXCEL.EXL_FILTER[Instance]->AFCFG0 |= CANXL_FILTER_BANK_AFCFG0_AADDREN_MASK;
1840 }
1841 else
1842 {
1843 noFilter++;
1844
1845 }
1846 if (noFilter < CANEXCEL_IP_MAX_FILTER_BANK)
1847 {
1848 * filterNo = noFilter;
1849 CanXL_ConfigAccAddrFilterBank(CANEXCEL.EXL_FILTER[Instance], 0U, filterValue, noFilter);
1850 CANEXCEL.EXL_FILTER[Instance]->AFCFG0 |= CANXL_FILTER_BANK_AFCFG0_ACPTADDR(noFilter);
1851 }
1852 else
1853 {
1854 if ((CANEXCEL.EXL_SIC[Instance]->SYSMCFG & CANXL_SIC_SYSMCFG_FB1EN_MASK) == CANXL_SIC_SYSMCFG_FB1EN_MASK)
1855 {
1856 noFilter = (uint8)((CANEXCEL.EXL_FILTER[Instance]->AFCFG1 & CANXL_FILTER_BANK_AFCFG1_ACPTADDR_MASK) >> CANXL_FILTER_BANK_AFCFG1_ACPTADDR_SHIFT);
1857 if ((CANEXCEL.EXL_FILTER[Instance]->AFCFG1 & CANXL_FILTER_BANK_AFCFG0_AADDREN_MASK) == 0U)
1858 {
1859 CANEXCEL.EXL_FILTER[Instance]->AFCFG1 |= CANXL_FILTER_BANK_AFCFG1_AADDREN_MASK;
1860 }
1861 else
1862 {
1863 noFilter++;
1864 }
1865 if ((CANEXCEL_IP_MAX_FILTER_BANK + noFilter) < (2U*CANEXCEL_IP_MAX_FILTER_BANK))
1866 {
1867 * filterNo = (CANEXCEL_IP_MAX_FILTER_BANK + noFilter);
1868 CanXL_ConfigAccAddrFilterBank(CANEXCEL.EXL_FILTER[Instance], 1U, filterValue, noFilter);
1869 }
1870 else
1871 {
1872 status = CANEXCEL_STATUS_BUFF_OUT_OF_RANGE;
1873 }
1874 }
1875 else
1876 {
1877 status = CANEXCEL_STATUS_BUFF_OUT_OF_RANGE;
1878 }
1879 }
1880 }
1881 else
1882 {
1883 status = CANEXCEL_STATUS_ERROR;
1884 }
1885 return status;
1886 }
1887 /*FUNCTION**********************************************************************
1888 *
1889 * Function Name : Canexcel_Ip_GetDescriptorStatus
1890 * Description : Return the Message Descriptor State, and HW and SYStem pointers indexes
1891 *END**************************************************************************/
1892 /* implements Canexcel_Ip_GetDescriptorStatus_Activity */
Canexcel_Ip_GetDescriptorStatus(uint8 Instance,uint8 descNo,uint8 * sysPoint,uint8 * hwPoint)1893 Canexcel_Ip_DescState Canexcel_Ip_GetDescriptorStatus(uint8 Instance, uint8 descNo, uint8 * sysPoint, uint8 * hwPoint)
1894 {
1895 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1896 DevAssert(Instance < CANXL_SIC_INSTANCE_COUNT);
1897 DevAssert(sysPoint != NULL_PTR);
1898 DevAssert(hwPoint != NULL_PTR);
1899 #endif
1900 * hwPoint = CanXL_GetDesciptorHWIndex(CANEXCEL.EXL_DESC_CTR[Instance], descNo);
1901 * sysPoint = CanXL_GetDesciptorSysIndex(CANEXCEL.EXL_DESC_CTR[Instance], descNo);
1902 return CanXL_GetDesciptorState(CANEXCEL.EXL_DESC_CTR[Instance], descNo);
1903 }
1904 /*FUNCTION**********************************************************************
1905 *
1906 * Function Name : Canexcel_Ip_SetMsgBuffInterrupt
1907 * Description : Enable\Disable the Message Descriptor Interrupt
1908 *END**************************************************************************/
1909 /* implements Canexcel_Ip_SetMsgBuffInterrupt_Activity */
Canexcel_Ip_SetMsgBuffInterrupt(uint8 instance,uint8 descNo,boolean enable)1910 void Canexcel_Ip_SetMsgBuffInterrupt(uint8 instance, uint8 descNo, boolean enable)
1911 {
1912 if(enable == TRUE)
1913 {
1914 CanXL_SetMsgBuffIntCmd(CANEXCEL.EXL_GRP[instance], descNo);
1915 }
1916 else
1917 {
1918 CanXL_ClearMsgBuffIntCmd(CANEXCEL.EXL_GRP[instance], descNo);
1919 }
1920 }
1921 /*FUNCTION**********************************************************************
1922 *
1923 * Function Name : Canexcel_Ip_GetMsgDescIntStatusFlag
1924 * Description : Retur the Message Descriptor Interrupt Status Flag
1925 *END**************************************************************************/
1926 /* implements Canexcel_Ip_GetMsgDescIntStatusFlag_Activity */
Canexcel_Ip_GetMsgDescIntStatusFlag(uint8 instance,uint8 descNo)1927 uint8 Canexcel_Ip_GetMsgDescIntStatusFlag(uint8 instance, uint8 descNo)
1928 {
1929 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1930 DevAssert(instance < CANXL_SIC_INSTANCE_COUNT);
1931 #endif
1932 const CANXL_GRP_CONTROL_Type * Base = CANEXCEL.EXL_GRP[instance];
1933 return CanXL_GetMsgDescIntStatusFlag(Base, descNo);
1934 }
1935
Canexcel_Ip_DeactivateMD(uint8 instance,uint8 descNo)1936 Canexcel_Ip_StatusType Canexcel_Ip_DeactivateMD(uint8 instance, uint8 descNo)
1937 {
1938 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1939 DevAssert(instance < CANXL_SIC_INSTANCE_COUNT);
1940 #endif
1941 uint32 timeStart = 0U;
1942 uint32 timeElapsed = 0U;
1943 Canexcel_Ip_StateType * state = Canexcel_Ip_apxState[instance];
1944 Canexcel_Ip_StatusType returnResult = CANEXCEL_STATUS_SUCCESS;
1945 uint32 uS2Ticks = OsIf_MicrosToTicks(CANEXCEL_IP_TIMEOUT_DURATION, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
1946
1947 /* It requires syslock before deactivation the MD */
1948 (void)CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].SYSLOCK.DCSYSLOCK;
1949
1950 /* Wait until syslock is retrieved */
1951 timeStart = OsIf_GetCounter(CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
1952 while (CANEXCEL_DESCNTSTATUS_LOCKED_SYS != CanXL_GetDescControlStatus(CANEXCEL.EXL_DESC_CTR[instance], descNo))
1953 {
1954 timeElapsed += OsIf_GetElapsed(&timeStart, CANEXCEL_IP_SERVICE_TIMEOUT_TYPE);
1955 if (timeElapsed >= uS2Ticks)
1956 {
1957 returnResult = CANEXCEL_STATUS_TIMEOUT;
1958 break;
1959 }
1960 /* It requires syslock before deactivation the MD */
1961 (void)CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].SYSLOCK.DCSYSLOCK;
1962 }
1963 /* If syslock retrieved, deactivate the MD */
1964 if(returnResult == CANEXCEL_STATUS_SUCCESS)
1965 {
1966 /* as result, the MD is deactivated(syspointer and hwpointer are reset).
1967 * And it can't participate in the message Tx or Rx process.
1968 */
1969 CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].ACT.DCACT = 0U;
1970 /* Release syslock */
1971 CANEXCEL.EXL_DESC_CTR[instance]->DSCMBCTRLAR[descNo].SYSLOCK.DCSYSLOCK = 1U;
1972 /* Clear IFLAG */
1973 CanXL_ClearMsgDescIntStatusFlag(CANEXCEL.EXL_GRP[instance], descNo);
1974 /* Reset noPointers */
1975 state->msgDesc[descNo].noPointers = 0U;
1976 }
1977 return returnResult;
1978 }
1979 /*FUNCTION**********************************************************************
1980 * Function Name : Canexcel_Ip_Deinit
1981 * Description : DeInitilize the Canexecel Module and restore the reset Values
1982 *END**************************************************************************/
1983 /* implements Canexcel_Ip_Deinit_Activity */
Canexcel_Ip_Deinit(uint8 u8Instance)1984 Canexcel_Ip_StatusType Canexcel_Ip_Deinit(uint8 u8Instance)
1985 {
1986 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
1987 DevAssert(u8Instance < CANXL_SIC_INSTANCE_COUNT);
1988 #endif
1989 Canexcel_Ip_StatusType retVal;
1990 retVal = CanXL_EnterFreezeMode(CANEXCEL.EXL_SIC[u8Instance]);
1991 if (CANEXCEL_STATUS_SUCCESS == retVal)
1992 {
1993 retVal = CanXL_SoftReset(CANEXCEL.EXL_SIC[u8Instance]);
1994 }
1995 if (CANEXCEL_STATUS_SUCCESS == retVal)
1996 {
1997 /* Clear status to default values */
1998 CANEXCEL.EXL_SIC[u8Instance]->SYSS = CANEXCEL_IP_SYSS_CLEAR_DEFAULT_VALUE_U32;
1999 /* Clear Memory ram and initialize it */
2000 CanXL_ClearRAM(&CANEXCEL, u8Instance);
2001 /* Restore Default Values */
2002 CANEXCEL.EXL_SIC[u8Instance]->BBPRS = 0U;
2003 CANEXCEL.EXL_SIC[u8Instance]->BCFG1 = 0U;
2004 CANEXCEL.EXL_SIC[u8Instance]->BCFG2 = CANEXCEL_IP_BCFG2_DEFAULT_VALUE_U32;
2005 CANEXCEL.EXL_SIC[u8Instance]->BNCBT = CANEXCEL_IP_BNCBT_DEFAULT_VALUE_U32;
2006 CANEXCEL.EXL_SIC[u8Instance]->BFDCBT = CANEXCEL_IP_BFDCBT_DEFAULT_VALUE_U32;
2007 CANEXCEL.EXL_SIC[u8Instance]->BXDCBT = CANEXCEL_IP_BXDCBT_DEFAULT_VALUE_U32;
2008 CANEXCEL.EXL_SIC[u8Instance]->BTDCC = 0U;
2009 CANEXCEL.EXL_SIC[u8Instance]->BMICI = 0U;
2010 }
2011 return retVal;
2012 }
2013 /** @} */
2014
2015