1 /*
2  * Copyright 2021-2024 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef CANEXCEL_IP_HWACCESS_H_
8 #define CANEXCEL_IP_HWACCESS_H_
9 
10 /**
11 *   @file CanEXCEL_Ip_HwAccess.h
12 *
13 *   @addtogroup CanEXCEL
14 *   @{
15 */
16 
17 #ifdef __cplusplus
18 extern "C"{
19 #endif
20 /*==================================================================================================
21 *                                        INCLUDE FILES
22 * 1) system and project includes
23 * 2) needed interfaces from external units
24 * 3) internal and external interfaces from this unit
25 ==================================================================================================*/
26 #include "CanEXCEL_Ip.h"
27 #include "Mcal.h"
28 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
29 #include "Devassert.h"
30 #endif
31 #include "SchM_Can_43_CANEXCEL.h"
32 
33 /*==================================================================================================
34 *                              SOURCE FILE VERSION INFORMATION
35 ==================================================================================================*/
36 #define CANEXCEL_IP_HWACCESS_VENDOR_ID_H                      43
37 #define CANEXCEL_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION_H       4
38 #define CANEXCEL_IP_HWACCESS_AR_RELEASE_MINOR_VERSION_H       7
39 #define CANEXCEL_IP_HWACCESS_AR_RELEASE_REVISION_VERSION_H    0
40 #define CANEXCEL_IP_HWACCESS_SW_MAJOR_VERSION_H               2
41 #define CANEXCEL_IP_HWACCESS_SW_MINOR_VERSION_H               0
42 #define CANEXCEL_IP_HWACCESS_SW_PATCH_VERSION_H               0
43 /*==================================================================================================
44 *                                     FILE VERSION CHECKS
45 ==================================================================================================*/
46 /* Check if current file and CanEXCEL_Ip.h are of the same vendor */
47 #if (CANEXCEL_IP_HWACCESS_VENDOR_ID_H != CANEXCEL_IP_VENDOR_ID_H)
48     #error "CanEXCEL_Ip_HwAccess.h and CanEXCEL_Ip.h have different vendor ids"
49 #endif
50 /* Check if current file and CanEXCEL_Ip.h are of the same Autosar version */
51 #if ((CANEXCEL_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION_H    != CANEXCEL_IP_AR_RELEASE_MAJOR_VERSION_H) || \
52      (CANEXCEL_IP_HWACCESS_AR_RELEASE_MINOR_VERSION_H    != CANEXCEL_IP_AR_RELEASE_MINOR_VERSION_H) || \
53      (CANEXCEL_IP_HWACCESS_AR_RELEASE_REVISION_VERSION_H != CANEXCEL_IP_AR_RELEASE_REVISION_VERSION_H) \
54 )
55     #error "AutoSar Version Numbers of CanEXCEL_Ip_HwAccess.h and CanEXCEL_Ip.h are different"
56 #endif
57 /* Check if current file and CanEXCEL_Ip.h are of the same Software version */
58 #if ((CANEXCEL_IP_HWACCESS_SW_MAJOR_VERSION_H != CANEXCEL_IP_SW_MAJOR_VERSION_H) || \
59      (CANEXCEL_IP_HWACCESS_SW_MINOR_VERSION_H != CANEXCEL_IP_SW_MINOR_VERSION_H) || \
60      (CANEXCEL_IP_HWACCESS_SW_PATCH_VERSION_H != CANEXCEL_IP_SW_PATCH_VERSION_H) \
61 )
62     #error "Software Version Numbers of CanEXCEL_Ip_HwAccess.h and CanEXCEL_Ip.h are different"
63 #endif
64 
65 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
66     /* Check if current file and Mcal.h header file are of the same version */
67     #if ((CANEXCEL_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION_H != MCAL_AR_RELEASE_MAJOR_VERSION) || \
68         (CANEXCEL_IP_HWACCESS_AR_RELEASE_MINOR_VERSION_H != MCAL_AR_RELEASE_MINOR_VERSION) \
69 )
70         #error "Software Version Numbers of CanEXCEL_Ip_HwAccess.h and Mcal.h are different"
71     #endif
72 
73     #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
74         /* Check if current file and Devassert.h header file are of the same version */
75         #if ((CANEXCEL_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION_H != DEVASSERT_AR_RELEASE_MAJOR_VERSION) || \
76             (CANEXCEL_IP_HWACCESS_AR_RELEASE_MINOR_VERSION_H != DEVASSERT_AR_RELEASE_MINOR_VERSION) \
77    )
78             #error "Software Version Numbers of CanEXCEL_Ip_HwAccess.h and Devassert.h are different"
79         #endif
80     #endif
81 
82     /* Check if current file and SchM_Can_43_CANEXCEL.h header file are of the same version */
83     #if ((CANEXCEL_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION_H    !=  SCHM_CAN_43_CANEXCEL_AR_RELEASE_MAJOR_VERSION) || \
84         (CANEXCEL_IP_HWACCESS_AR_RELEASE_MINOR_VERSION_H     !=  SCHM_CAN_43_CANEXCEL_AR_RELEASE_MINOR_VERSION) \
85 )
86         #error "AUTOSAR Version Numbers of CanEXCEL_Ip_HwAccess.c and SchM_Can_43_CANEXCEL.h are different"
87     #endif
88 #endif
89 
90 /*==================================================================================================
91 *                                      DEFINES AND MACROS
92 ==================================================================================================*/
93 
94 #define CANXL_IP_ID_EXT_MASK                                   (0x1FFFFFFFU)
95 #define CANXL_IP_ID_EXT_SHIFT                                  0
96 #define CANXL_IP_ID_EXT_WIDTH                                  18
97 #define CANXL_IP_ID_STD_MASK                                   0x1FFC0000u
98 #define CANXL_IP_ID_STD_SHIFT                                  18
99 #define CANXL_IP_ID_STD_WIDTH                                  11
100 
101 
102 #define CANXL_TX_HEADER_MODE_MASK                              0x80000000u
103 #define CANXL_TX_HEADER_MODE_SHIFT                             31
104 #define CANXL_TX_HEADER_PRIO_MASK                              0x0F000000u
105 #define CANXL_TX_HEADER_PRIO_SHIFT                             24
106 #define CANXL_TX_HEADER_RETR_MASK                              0x70000u
107 #define CANXL_TX_HEADER_RETR_SHIFT                             16
108 #define CANXL_TX_HEADER_RTR_MASK                               0x80000000u
109 #define CANXL_TX_HEADER_RTR_SHIFT                              31
110 #define CANXL_TX_HEADER_IDE_MASK                               0x40000000u
111 #define CANXL_TX_HEADER_IDE_SHIFT                              30
112 #define CANXL_TX_HEADER_IDE_WIDTH                              1
113 #define CANXL_TX_HEADER_XLF_MASK                               0x20000000u
114 #define CANXL_TX_HEADER_XLF_SHIFT                              29
115 #define CANXL_TX_HEADER_XLF_WIDTH                              1
116 #define CANXL_TX_HEADER_FDF_MASK                               0x80000000u
117 #define CANXL_TX_HEADER_FDF_SHIFT                              31
118 #define CANXL_TX_HEADER_FDF_WIDTH                              1
119 #define CANXL_TX_HEADER_BRS_MASK                               0x20000000u
120 #define CANXL_TX_HEADER_BRS_SHIFT                              29
121 #define CANXL_TX_HEADER_BRS_WIDTH                              1
122 #define CANXL_TX_HEADER_XLF_MASK                               0x20000000u
123 #define CANXL_TX_HEADER_XLF_SHIFT                              29
124 #define CANXL_TX_HEADER_XLF_WIDTH                              1
125 #define CANXL_TX_HEADER_SDT_MASK                               0x0FF00000u
126 #define CANXL_TX_HEADER_SDT_SHIFT                              20
127 #define CANXL_TX_HEADER_SDT_WIDTH                              8
128 #define CANXL_TX_HEADER_DLC_MASK                               0x7FF00u
129 #define CANXL_TX_HEADER_DLC_SHIFT                              8
130 #define CANXL_TX_HEADER_DLC_WIDTH                              11
131 
132 #define CANXL_MRU_MBOX0                                           0x0u
133 #define CANXL_MRU_MBOX1                                           0x1u
134 #define CANXL_MRU_MBOX2                                           0x2u
135 #define CANXL_MRU_MBOX3                                           0x3u
136 
137 #define CANXL_MRU_CMD_BUSOFF                                      0x0u
138 #define CANXL_MRU_CMD_READ_EC                                     0x4u
139 #define CANXL_MRU_CMD_READ_ST                                     0x5u
140 #define CANXL_MRU_CMD_READ_TDCS                                   0x6u
141 #define CANXL_MRU_CMD_WRITE_TDCS                                  0x7u
142 #define CANXL_MRU_CMD_LAST_ST                                     0x8u
143 
144 #define BCANXL_EC_TEC_MASK                                        (0xFF00u)
145 #define BCANXL_EC_TEC_SHIFT                                       (8u)
146 #define BCANXL_EC_TEC_WIDTH                                       (8u)
147 
148 #define BCANXL_EC_REC_MASK                                        (0xFFu)
149 #define BCANXL_EC_REC_SHIFT                                       (0u)
150 #define BCANXL_EC_REC_WIDTH                                       (8u)
151 
152 #define BCANXL_ST_FLTCONF_MASK                                    (0x0Cu)
153 #define BCANXL_ST_FLTCONF_SHIFT                                   (2u)
154 #define BCANXL_ST_FLTCONF_WIDTH                                   (2u)
155 /*==================================================================================================
156 *                                             ENUMS
157 ==================================================================================================*/
158 
159 /*! @brief CANXL error interrupt types
160  */
161 typedef enum
162 {
163     CANXL_INT_FREEZE      = CANXL_SIC_SYSIE_FRZACKIE_MASK,     /*!< Un\Freeze Ack Interrupt */
164     CANXL_INT_RX_WARNING  = CANXL_SIC_SYSIE_CRXWRNIE_MASK,     /*!< RX warning interrupt*/
165     CANXL_INT_TX_WARNING  = CANXL_SIC_SYSIE_CTXWRNIE_MASK,     /*!< TX warning interrupt*/
166     CANXL_INT_INT_ERR     = CANXL_SIC_SYSIE_IERRIE_MASK,       /*!< Internal Error Interrupt */
167     CANXL_INT_PASIVE_ERR  = CANXL_SIC_SYSIE_CPERRIE_MASK,      /*!< Passive Error Interrupt */
168     CANXL_INT_ERR         = CANXL_SIC_SYSIE_CERRIE_MASK,       /*!< Bus Error interrupt*/
169     CANXL_INT_ERR_FAST    = CANXL_SIC_SYSIE_CFDPERRIE_MASK,    /*!< Error Fast interrupt*/
170     CANXL_INT_ERR_XL      = CANXL_SIC_SYSIE_CDPERRIE_MASK,     /*!< Error XL Interrupt */
171     CANXL_INT_BUSOFF_DONE = CANXL_SIC_SYSIE_CBDONEIE_MASK,     /*!< Error BusOff Done Interrupt */
172     CANXL_INT_BUSOFF      = CANXL_SIC_SYSIE_CBOFFIE_MASK,      /*!< Bus off interrupt*/
173     CANXL_INT_RXSMB_OVER  = CANXL_SIC_SYSIE_CRXSOERRIE_MASK,   /*!< RX SMB Overrun Error Interrupt*/
174     CANXL_INT_MD_UNDER    = CANXL_SIC_SYSIE_CMDUERRIE_MASK,    /*!< MD Underrun Error Interrupt */
175     CANXL_INT_MD_OVER     = CANXL_SIC_SYSIE_CMDOERRIE_MASK,    /*!< MD Overrun Error Interrupt */
176     CANXL_INT_LOM         = CANXL_SIC_SYSIE_CLSERRIE_MASK,     /*!< LOM State Error Interrupt */
177     CANXL_INT_RXFIFO_OVER = CANXL_SIC_SYSIE_CRFOERRIR_MASK,    /*!< RX FIFO Overflow Interrupt */
178     CANXL_INT_TXFIFO_UNDER= CANXL_SIC_SYSIE_CTFUERRIR_MASK     /*!< TX FIFO Underflow Interrupt */
179 } canxl_int_type_t;
180 
181 /*==================================================================================================
182 *                                    FUNCTION PROTOTYPES
183 ==================================================================================================*/
184 #define CAN_43_CANEXCEL_START_SEC_CODE
185 #include "Can_43_CANEXCEL_MemMap.h"
186 
187  /*!
188  * @brief Set the Message Descriptors Queue Depths and WaterMark Levels
189  *
190  * @param   base        The CanXL MSG Grup Control base address
191  * @param   pConfigs    Pointer to Configuration Structure for Message Descriptors Depths and WaterMarks
192  */
193 void CanXL_SetMDQueueConfigs(CANXL_GRP_CONTROL_Type * base, const Canexcel_Ip_QueueConf * pConfigs);
194  /*!
195  * @brief Return the Message Descriptor Queue Depth
196  *
197  * @param   base        The CanXL MSG Grup Control base address
198  * @param   MDindex      Index of the message descriptor
199  * @return  The Value of the Queue Depth
200  */
201 uint8 CanXL_GetMDQueueDepth(const CANXL_GRP_CONTROL_Type * base, const uint8 MDindex);
202 /*!
203  * @brief   Enable Error Interrupt type
204  *
205  * @param   base        The CanXL SIC base address
206  * @param   errType     Error type
207  * @param   enable      Enable\Disable Interrupt
208  */
209 void CanXL_SetErrIntCmd(CANXL_SIC_Type * base, canxl_int_type_t errType, boolean enable);
210 /*!
211  * @brief   Copy the data in the Tx Message Buffer location, based on the frame length
212  *
213  * @param   info        The Frame Information Parameters as length, frame type
214  * @param   data        Pointer to Data to be transmit
215  * @param   MB          Pointer to the Message Buffer Ram Location
216  */
217 void CanXL_SetTxMsgBuffData(const Canexcel_Ip_DataInfoType * info, const uint8 * data, uint8 * MB);
218 /*!
219  * @brief   Disable interrupt for all Message Descriptors
220  *
221  * @param   base        The CanXL Grup Control base address
222  */
223 void CanXL_ResetImaskBuff(CANXL_GRP_CONTROL_Type * base);
224 /*!
225  * @brief   Execute Controller SoftReset action
226  *
227  * @param   base        The CanXL SIC base address
228  * @return  CANEXCEL_STATUS_SUCCESS request was accepted,
229  *          CANEXCEL_STATUS_TIMEOUT request fail
230  */
231 Canexcel_Ip_StatusType CanXL_SoftReset(CANXL_SIC_Type * base);
232  /*!
233  * @brief Calculate the DLC code Value for the payload length
234  *
235  * @param   payloadSize        The frame payload size in bytes
236  * @return  The DLC Code Value
237  */
238 uint8 CAN_ComputeDLCValue(uint8 payloadSize);
239  /*!
240  * @brief Clears and initilize all RAM area used by CANEXCEL Peripheral
241  *
242  * @param   CANXL        The CANXL colection of base addresses for periperals embbeded in CANEXCEL
243  * @param   instance    The CanXL Instance Number
244  */
245 void CanXL_ClearRAM(const CANEXCEL_StructType * CANXL, uint8 instance);
246 /*!
247  * @brief Return the Contol Lock status for Message Descriptor
248  *
249  * @param   base        The CanXL Message Descriptor Control base address
250  * @return  CANEXCEL_DESCNTSTATUS_UNLOCKED Descriptor is unlocked,
251  *          CANEXCEL_DESCNTSTATUS_LOCKED_HW Descriptor is lock by HW,
252             CANEXCEL_DESCNTSTATUS_LOCKED_SYS Descriptor is lock by Driver,
253             CANEXCEL_DESCNTSTATUS_INVALID Descriptor Status is Invalid.
254  */
255 void CanXL_SetOperationMode(CANXL_SIC_Type * base, Canexcel_Ip_ModesType mode);
256 /*!
257  * @brief Return the Contol Lock status for Message Descriptor
258  *
259  * @param   base        The CanXL Message Descriptor Control base address
260  * @return  CANEXCEL_DESCNTSTATUS_UNLOCKED Descriptor is unlocked,
261  *          CANEXCEL_DESCNTSTATUS_LOCKED_HW Descriptor is lock by HW,
262             CANEXCEL_DESCNTSTATUS_LOCKED_SYS Descriptor is lock by Driver,
263             CANEXCEL_DESCNTSTATUS_INVALID Descriptor Status is Invalid.
264  */
265  Canexcel_Ip_DesCntStatus CanXL_GetDescControlStatus(const CANXL_DSC_CONTROL_Type * base, uint8 descNo);
266 /*!
267  * @brief   Set contoller to FreezeMode
268  *
269  * @param   base        The CanXL SIC base address
270  * @return  CANEXCEL_STATUS_SUCCESS request was accepted,
271  *          CANEXCEL_STATUS_TIMEOUT request fail
272  */
273 Canexcel_Ip_StatusType CanXL_EnterFreezeMode(CANXL_SIC_Type * base);
274 /*!
275  * @brief   Remove contoller from FreezeMode to RunMode
276  *
277  * @param   base        The CanXL SIC base address
278  * @return  CANEXCEL_STATUS_SUCCESS request was accepted,
279  *          CANEXCEL_STATUS_TIMEOUT request fail
280  */
281 Canexcel_Ip_StatusType CanXL_ExitFreezeMode(CANXL_SIC_Type * base);
282 /*!
283  * @brief Configure controller depending options like protocol exception, autobus Off Recovery
284  *
285  * @param   base        The CanXL SIC base address
286  * @param   u32Options  Controller Options encoding based on bit position
287  * @return  CANEXCEL_STATUS_SUCCESS if configuration was succefully set.
288  *          CANEXCEL_STATUS_ERROR configuration is not allowed.
289  */
290 Canexcel_Ip_StatusType CanXL_ConfigCtrlOptions(CANXL_SIC_Type * base, uint32 u32Options);
291  /*!
292  * @brief Disable config Interrupts on HW
293  *
294  * @param   base        The CanXL SIC base address
295  */
296 void CanXL_DisableInterrupts(CANXL_SIC_Type * base);
297  /*!
298  * @brief Enable config Interrupts on HW
299  *
300  * @param   base        The CanXL SIC base address
301  */
302 void CanXL_EnableInterrupts(CANXL_SIC_Type * base);
303 
304 #if (CANEXCEL_IP_HAS_TS_ENABLE == STD_ON)
305  /*!
306  * @brief Set the corresponding Timestamp Configuration TimeBase Selector
307  *
308  * @param   base     The CanXL TimebaseSelector Grup Control base address
309  * @param   type     Position in frame for timestamp capture point
310  */
CanXL_SetTimeBaseSource(CAN_TBS_Type * base,Canexcel_Ip_TimeBaseSelType type)311 static inline void CanXL_SetTimeBaseSource(CAN_TBS_Type * base, Canexcel_Ip_TimeBaseSelType type)
312 {
313     base->CAN_TS_SEL |= CAN_TBS_CAN_TS_SEL_TS_SEL(type);
314 }
315  /*!
316  * @brief Set the corresponding Timestamp Configuration Capture point from the frame
317  *
318  * @param   base        The CanXL MSG Grup Control base address
319  * @param   type      Position in frame for timestamp capture point
320  */
CanXL_SetTimeStampCaputre(CANXL_SIC_Type * base,Canexcel_Ip_TimeStampCaptureType type)321 static inline void CanXL_SetTimeStampCaputre(CANXL_SIC_Type * base, Canexcel_Ip_TimeStampCaptureType type)
322 {
323     base->BCFG2 |= CANXL_SIC_BCFG2_TSCAP(type);
324 }
325 #endif /* (CANEXCEL_IP_HAS_TS_ENABLE == STD_ON) */
326 
327 
328 /*!
329  * @brief Clears the interrupt flag of the message descriptor.
330  *
331  * @param   base        The CanXL MSG Grup Control base address
332  * @param   msgBuffIdx  Index of the message descriptor
333  */
CanXL_ClearMsgDescIntStatusFlag(CANXL_GRP_CONTROL_Type * base,uint32 msgBuffIdx)334 static inline void CanXL_ClearMsgDescIntStatusFlag(CANXL_GRP_CONTROL_Type * base, uint32 msgBuffIdx)
335 {
336     uint32 flag = ((uint32)1U << (msgBuffIdx % 32U));
337     uint8 ImaskCnt = (uint8)(msgBuffIdx/32U);
338     base->MSGIFLAG[ImaskCnt] = flag;
339 }
340 /*!
341  * @brief Gets the individual CanXL MD interrupt flag.
342  *
343  * @param   base             The CanEXCEL Decriptor Control base address
344  * @param   msgBuffIdx       Index of the message descriptor
345  * @return  The individual Message Descriptor interrupt flag (0 and 1 are the flag value)
346  */
CanXL_GetMsgDescIntStatusFlag(const CANXL_GRP_CONTROL_Type * base,uint32 msgBuffIdx)347 static inline uint8 CanXL_GetMsgDescIntStatusFlag(const CANXL_GRP_CONTROL_Type * base, uint32 msgBuffIdx)
348 {
349     /* TODO: This need to be protected multithread access*/
350     uint8 flag = 0;
351     uint8 ImaskCnt = (uint8)(msgBuffIdx/32U);
352     flag = (uint8)((((uint32)base->MSGIFLAG[ImaskCnt] & ((uint32)1U << (msgBuffIdx % 32U))) >> (msgBuffIdx % 32U)) & 1U);
353     return flag;
354 }
355 /*!
356  * @brief Gets the individual CanXL MB interrupt flag.
357  *
358  * @param   base             The CanEXCEL Decriptor Control base address
359  * @param   msgBuffIdx       Index of the message descriptor
360  * @return  The individual Message Descriptor interrupt flag (0 and 1 are the flag value)
361  */
CanXL_GetMsgBuffIntStatusFlag(const CANXL_GRP_CONTROL_Type * base,uint32 msgBuffIdx)362 static inline uint8 CanXL_GetMsgBuffIntStatusFlag(const CANXL_GRP_CONTROL_Type * base, uint32 msgBuffIdx)
363 {
364     /* TODO: This need to be protected multithread access*/
365     uint8 flag = 0;
366     uint32 mask;
367     uint8 ImaskCnt = (uint8)(msgBuffIdx/32U);
368 
369     mask = base->MSGIMASK[ImaskCnt];
370     flag = (uint8)(((base->MSGIFLAG[ImaskCnt] & mask) >> (msgBuffIdx % 32U)) & 1U);
371 
372     return flag;
373 }
374 
375 /*!
376  * @brief Check if controller is in freeze mode or not.
377  *
378  * @param   base  The CanEXCEL base address
379  * @return  TRUE if controller is in freeze mode
380  *          FALSE if controller is not in freeze mode
381  */
CanXL_IsFreezeMode(const CANXL_SIC_Type * base)382 static inline boolean CanXL_IsFreezeMode(const CANXL_SIC_Type * base)
383 {
384     return ((((base->SYSMC &  CANXL_SIC_SYSMC_FRZREQ_MASK) & (base->SYSS & CANXL_SIC_SYSS_FRZACKF_MASK)) != 0U)? TRUE : FALSE);
385 }
386 
387 /*!
388  * @brief Check if controller is in FD mode or not.
389  *
390  * @param   base  The CanEXCEL base address
391  * @return  TRUE if controller is in FD mode
392  *          FALSE if controller is not in FD mode
393  */
CanXL_IsFDModeEnabled(const CANXL_SIC_Type * base)394 static inline boolean CanXL_IsFDModeEnabled(const CANXL_SIC_Type * base)
395 {
396     return (((base->BCFG2 & (CANXL_SIC_BCFG2_FDEN_MASK)) != 0U) ? TRUE : FALSE);
397 }
398 
399 /*!
400  * @brief Check if controller is in XL mode or not.
401  *
402  * @param   base  The CanEXCEL base address
403  * @return  TRUE if controller is in XL mode
404  *          FALSE if controller is not in XL mode
405  */
CanXL_IsXLModeEnabled(const CANXL_SIC_Type * base)406 static inline boolean CanXL_IsXLModeEnabled(const CANXL_SIC_Type * base)
407 {
408     return (((base->BCFG2 & (CANXL_SIC_BCFG2_XLEN_MASK)) != 0U) ? TRUE : FALSE);
409 }
410 /*!
411  * @brief Return Descriptor State.
412  *
413  * @param   base  The CanEXCEL base address
414  * @param   descNo  Index of the message descriptor
415  * @return  The drescriptor state based on states
416  * enumerated by Canexcel_Ip_DescState type
417  */
CanXL_GetDesciptorState(const CANXL_DSC_CONTROL_Type * base,uint8 descNo)418 static inline Canexcel_Ip_DescState CanXL_GetDesciptorState(const CANXL_DSC_CONTROL_Type * base, uint8 descNo)
419 {
420     Canexcel_Ip_DescState retval;
421     switch (base->DSCMBCTRLAR[descNo].DCSTA & CANXL_DSC_CONTROL_DCSTA_STATE_MASK)
422     {
423         case 0u:
424             retval = CANEXCEL_DESC_STATE_INACTIVE;
425             break;
426         case 1u:
427             retval = CANEXCEL_DESC_STATE_EMPTY;
428             break;
429         case 2u:
430             retval = CANEXCEL_DESC_STATE_NOTFULL;
431             break;
432         case 3u:
433             retval = CANEXCEL_DESC_STATE_FULL;
434             break;
435         default:
436             retval = CANEXCEL_DESC_STATE_OVERRUN;
437             break;
438     }
439     return retval;
440 }
441 /*!
442  * @brief Return Descriptor Status of Hw Index
443  *
444  * @param   base  The CanEXCEL base address
445  * @param   descNo  Index of the message descriptor
446  * @return  The drescriptor HW index Value
447  */
CanXL_GetDesciptorHWIndex(const CANXL_DSC_CONTROL_Type * base,uint8 descNo)448 static inline uint8 CanXL_GetDesciptorHWIndex(const CANXL_DSC_CONTROL_Type * base, uint8 descNo)
449 {
450     return (uint8)((base->DSCMBCTRLAR[descNo].DCSTA & CANXL_DSC_CONTROL_DCSTA_HWPOINTER_MASK) >> CANXL_DSC_CONTROL_DCSTA_HWPOINTER_SHIFT);
451 }
452 /*!
453  * @brief Return Descriptor Status of System Index
454  *
455  * @param   base  The CanEXCEL base address
456  * @param   descNo  Index of the message descriptor
457  * @return  The drescriptor System index Value
458  */
CanXL_GetDesciptorSysIndex(const CANXL_DSC_CONTROL_Type * base,uint8 descNo)459  static inline uint8 CanXL_GetDesciptorSysIndex(const CANXL_DSC_CONTROL_Type * base, uint8 descNo)
460 {
461     return (uint8)((base->DSCMBCTRLAR[descNo].DCSTA & CANXL_DSC_CONTROL_DCSTA_SYSPOINTER_MASK) >> CANXL_DSC_CONTROL_DCSTA_SYSPOINTER_SHIFT);
462 }
463 /*!
464  * @brief Enables/Disables the Self Reception feature.
465  *
466  * If enabled, CanExcel is allowed to receive frames transmitted by itself.
467  *
468  * @param   base  The CanExcel SIC base address
469  * @param   enable Enable/Disable Self Reception
470  */
CanXL_SetSelfReception(CANXL_SIC_Type * base,boolean enable)471 static inline void CanXL_SetSelfReception(CANXL_SIC_Type * base,
472                                           boolean enable)
473 {
474     base->BCFG2 = (base->BCFG2 & ~CANXL_SIC_BCFG2_SRXEN_MASK) | CANXL_SIC_BCFG2_SRXEN(enable ? 1UL : 0UL);
475 }
476 
477 /*!
478  * @brief Checks if the listen only mode is enabled.
479  *
480  * @param   base    The FlexCAN base address
481  * @return  TRUE if enabled; FALSE if disabled
482  */
CanXL_IsListenOnlyModeEnabled(const CANXL_SIC_Type * base)483 static inline boolean CanXL_IsListenOnlyModeEnabled(const CANXL_SIC_Type * base)
484 {
485     return (((base->BCFG2 & (CANXL_SIC_BCFG2_LOM_MASK)) != 0U) ? TRUE : FALSE);
486 }
487 
488 
489 /*!
490  * @brief Sets the CanEXCEL FD time segments for setting up data bit rate.
491  *
492  * @param   base The CanEXCEL base address
493  * @param   timeSeg    CanEXCEL time segments, which need to be set for the bit rate.
494  */
CanXL_SetFDBaudRate(CANXL_SIC_Type * base,const Canexcel_Ip_TimeSegmentType * timeSeg)495 static inline void CanXL_SetFDBaudRate(CANXL_SIC_Type * base, const Canexcel_Ip_TimeSegmentType * timeSeg)
496 {
497 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
498 DevAssert(timeSeg != NULL_PTR);
499 #endif
500 (base->BFDCBT) = 0U;
501 
502 (base->BFDCBT) = (CANXL_SIC_BFDCBT_FTSEG1(timeSeg->phaseSeg1 + timeSeg->propSeg) |
503                   CANXL_SIC_BFDCBT_FTSEG2(timeSeg->phaseSeg2) |
504                   CANXL_SIC_BFDCBT_FRJW(timeSeg->rJumpwidth)
505        );
506 }
507 
508 /*!
509  * @brief Sets the CanEXCEL XL time segments for setting up data bit rate.
510  *
511  * @param   base The CanEXCEL base address
512  * @param   timeSeg    CanEXCEL time segments, which need to be set for the bit rate.
513  */
CanXL_SetXLBaudRate(CANXL_SIC_Type * base,const Canexcel_Ip_TimeSegmentType * timeSeg)514 static inline void CanXL_SetXLBaudRate(CANXL_SIC_Type * base, const Canexcel_Ip_TimeSegmentType * timeSeg)
515 {
516 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
517 DevAssert(timeSeg != NULL_PTR);
518 #endif
519 (base->BXDCBT) = 0U;
520 
521 (base->BXDCBT) = (CANXL_SIC_BXDCBT_XTSEG1(timeSeg->phaseSeg1 + timeSeg->propSeg) |
522                   CANXL_SIC_BXDCBT_XTSEG2(timeSeg->phaseSeg2) |
523                   CANXL_SIC_BXDCBT_XRJW(timeSeg->rJumpwidth)
524        );
525 }
526 
527 /*!
528  * @brief Sets the CanEXCEL nominal time segments for setting up data bit rate.
529  *
530  * @param   base The CanEXCEL base address
531  * @param   timeSeg    CanEXCEL time segments, which need to be set for the bit rate.
532  */
CanXL_SetBaudRate(CANXL_SIC_Type * base,const Canexcel_Ip_TimeSegmentType * timeSeg)533 static inline void CanXL_SetBaudRate(CANXL_SIC_Type * base, const Canexcel_Ip_TimeSegmentType * timeSeg)
534 {
535 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
536 DevAssert(timeSeg != NULL_PTR);
537 #endif
538 (base->BNCBT) = 0U;
539 (base->BBPRS) = 0U;
540 
541 (base->BBPRS) = CANXL_SIC_BBPRS_PRESDIV(timeSeg->preDivider);
542 (base->BNCBT) = (CANXL_SIC_BNCBT_NTSEG1(timeSeg->phaseSeg1 + timeSeg->propSeg) |
543                   CANXL_SIC_BNCBT_NTSEG2(timeSeg->phaseSeg2) |
544                   CANXL_SIC_BNCBT_NRJW(timeSeg->rJumpwidth)
545        );
546 }
547 
548 
549 /*!
550  * @brief Enables/Disables Error Response
551  *
552  * @param   Base    The CanXL SIC base address
553  * @param   Enable  TRUE to signalize errors as protocol exception; FALSE to signalize errors with Error frames
554  */
CanXL_SetXLErrorResponse(CANXL_SIC_Type * Base,boolean Enable)555 static inline void CanXL_SetXLErrorResponse(CANXL_SIC_Type * Base, boolean Enable)
556 {
557     Base->BCFG2 = (Base->BCFG2 & ~CANXL_SIC_BCFG2_XLER_MASK) | CANXL_SIC_BCFG2_XLER(Enable ? 1UL : 0UL);
558 }
559 /*!
560  * @brief Enables/Disables PWM mode
561  *
562  * @param   Base    The CanXL SIC base address
563  * @param   Enable  TRUE to enable; FALSE to disable
564  */
CanXL_SetPwmModeEnable(CANXL_SIC_Type * Base,boolean Enable)565 static inline void CanXL_SetPwmModeEnable(CANXL_SIC_Type * Base, boolean Enable)
566 {
567     Base->BCFG2 = (Base->BCFG2 & ~CANXL_SIC_BCFG2_TMSE_MASK) | CANXL_SIC_BCFG2_TMSE(Enable ? 1UL : 0UL);
568 }
569 
570 /*!
571  * @brief Checks if the Transceiver PWM mode is enabled.
572  *
573  * @param   Base    The FlexCAN base address
574  * @return  TRUE if enabled; FALSE if disabled
575  */
CanXL_IsPwmModeEnable(const CANXL_SIC_Type * Base)576 static inline boolean CanXL_IsPwmModeEnable(const CANXL_SIC_Type * Base)
577 {
578     return (((Base->BCFG2 & (CANXL_SIC_BCFG2_TMSE_MASK)) != 0U) ? TRUE : FALSE);
579 }
580 
581 /*!
582  * @brief Configure PWM phases
583  *
584  */
CanXL_SetPWMPhases(CANXL_SIC_Type * Base,uint8 PWMS,uint8 PWML,uint8 PWMO)585 static inline void CanXL_SetPWMPhases(CANXL_SIC_Type * Base, uint8 PWMS, uint8 PWML, uint8 PWMO)
586 {
587     Base->BMICI &= ~(CANXL_SIC_BMICI_PWMS_MASK | CANXL_SIC_BMICI_PWML_MASK | CANXL_SIC_BMICI_PWMO_MASK);
588     Base->BMICI |= (CANXL_SIC_BMICI_PWMS(PWMS) | CANXL_SIC_BMICI_PWML(PWML) | CANXL_SIC_BMICI_PWMO(PWMO));
589 }
590 
591 
592 /*!
593  * @brief Gets the CanEXCEL FD time segment.
594  *
595  * @param   base The CanEXCEL base address
596  * @param   timeSeg    CanEXCEL time segments.
597  */
CanXL_GetFDBaudRate(const CANXL_SIC_Type * base,Canexcel_Ip_TimeSegmentType * timeSeg)598 static inline void CanXL_GetFDBaudRate(const CANXL_SIC_Type * base, Canexcel_Ip_TimeSegmentType * timeSeg)
599 {
600 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
601     DevAssert(timeSeg != NULL_PTR);
602 #endif
603 
604     timeSeg->propSeg = 0U;
605     timeSeg->phaseSeg1 = ((base->BFDCBT & CANXL_SIC_BFDCBT_FTSEG1_MASK) >> CANXL_SIC_BFDCBT_FTSEG1_SHIFT);
606     timeSeg->phaseSeg2 = ((base->BFDCBT & CANXL_SIC_BFDCBT_FTSEG2_MASK) >> CANXL_SIC_BFDCBT_FTSEG2_SHIFT);
607     timeSeg->rJumpwidth = ((base->BFDCBT & CANXL_SIC_BFDCBT_FRJW_MASK) >> CANXL_SIC_BFDCBT_FRJW_SHIFT);
608     timeSeg->preDivider = ((base->BBPRS & CANXL_SIC_BBPRS_PRESDIV_MASK) >> CANXL_SIC_BBPRS_PRESDIV_SHIFT);
609 }
610 
611 /*!
612  * @brief Gets the CanEXCEL XL time segments.
613  *
614  * @param   base The CanEXCEL base address
615  * @param   timeSeg    CanEXCEL time segments.
616  */
CanXL_GetXLBaudRate(const CANXL_SIC_Type * base,Canexcel_Ip_TimeSegmentType * timeSeg)617 static inline void CanXL_GetXLBaudRate(const CANXL_SIC_Type * base, Canexcel_Ip_TimeSegmentType * timeSeg)
618 {
619 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
620     DevAssert(timeSeg != NULL_PTR);
621 #endif
622 
623     timeSeg->propSeg = 0U;
624     timeSeg->phaseSeg1 = ((base->BXDCBT & CANXL_SIC_BXDCBT_XTSEG1_MASK) >> CANXL_SIC_BXDCBT_XTSEG1_SHIFT);
625     timeSeg->phaseSeg2 = ((base->BXDCBT & CANXL_SIC_BXDCBT_XTSEG2_MASK) >> CANXL_SIC_BXDCBT_XTSEG2_SHIFT);
626     timeSeg->rJumpwidth = ((base->BXDCBT & CANXL_SIC_BXDCBT_XRJW_MASK) >> CANXL_SIC_BXDCBT_XRJW_SHIFT);
627     timeSeg->preDivider = ((base->BBPRS & CANXL_SIC_BBPRS_PRESDIV_MASK) >> CANXL_SIC_BBPRS_PRESDIV_SHIFT);
628 }
629 /*!
630  * @brief Gets the CanEXCEL nominal time segments.
631  *
632  * @param   base The CanEXCEL base address
633  * @param   timeSeg    CanEXCEL time segments.
634  */
CanXL_GetBaudRate(const CANXL_SIC_Type * base,Canexcel_Ip_TimeSegmentType * timeSeg)635 static inline void CanXL_GetBaudRate(const CANXL_SIC_Type * base, Canexcel_Ip_TimeSegmentType * timeSeg)
636 {
637 #if (CANEXCEL_IP_DEV_ERROR_DETECT == STD_ON)
638     DevAssert(timeSeg != NULL_PTR);
639 #endif
640 
641     timeSeg->propSeg = 0U;
642     timeSeg->phaseSeg1 = ((base->BNCBT & CANXL_SIC_BNCBT_NTSEG1_MASK) >> CANXL_SIC_BNCBT_NTSEG1_SHIFT);
643     timeSeg->phaseSeg2 = ((base->BNCBT & CANXL_SIC_BNCBT_NTSEG2_MASK) >> CANXL_SIC_BNCBT_NTSEG2_SHIFT);
644     timeSeg->rJumpwidth = ((base->BNCBT & CANXL_SIC_BNCBT_NRJW_MASK) >> CANXL_SIC_BNCBT_NRJW_SHIFT);
645     timeSeg->preDivider = ((base->BBPRS & CANXL_SIC_BBPRS_PRESDIV_MASK) >> CANXL_SIC_BBPRS_PRESDIV_SHIFT);
646 }
647 /*!
648  * @brief Enable the CanEXCEL MRU Services.
649  *
650  * @param   base The CanEXCEL base address
651  */
CanXL_MruEnable(CANXL_MRU_Type * base)652 static inline void CanXL_MruEnable(CANXL_MRU_Type * base)
653 {
654     base->CHXCONFIG[0u].CH_CFG0 = CANXL_MRU_CH_CFG0_CHR_MASK;
655     base->CHXCONFIG[0u].CH_CFG0 = CANXL_MRU_CH_CFG0_CHE_MASK;
656 }
657 /*!
658  * @brief Disable the CanEXCEL MRU Services.
659  *
660  * @param   base The CanEXCEL base address
661  */
CanXL_MruDisable(CANXL_MRU_Type * base)662 static inline void CanXL_MruDisable(CANXL_MRU_Type * base)
663 {
664     base->CHXCONFIG[0u].CH_CFG0 = CANXL_MRU_CH_CFG0_CHR_MASK;
665     base->CHXCONFIG[0u].CH_CFG0 &= ~CANXL_MRU_CH_CFG0_CHE_MASK;
666 }
667  /*!
668  * @brief Config the Acceptance Address Filter for RxFIFO
669  *
670  * @param   base The CanEXCEL RxFIFO Filters base address
671  * @param   filter  The Acceptance filter configuration pointer
672  * @param   filtIdx  Filter Position
673  */
674 void CanXL_ConfigAccAddr(CANXL_RXFIFO_Type * base,const Canexcel_Ip_RxFifoFilterID_ADDR * filter, uint8 filtIdx);
675  /*!
676  * @brief Config the Accept ID Filter for RxFIFO
677  *
678  * @param   base The CanEXCEL RxFIFO Filters base address
679  * @param   filter  The ID filter configuration pointer
680  * @param   filtIdx  Filter Position
681  */
682 void CanXL_ConfigIDFilter(CANXL_RXFIFO_Type * base,const Canexcel_Ip_RxFifoFilterID_ADDR * filter, uint8 filtIdx);
683  /*!
684  * @brief Config the Accept SDU Filter for RxFIFO
685  *
686  * @param   base The CanEXCEL RxFIFO Filters base address
687  * @param   filter  The SDU filter configuration pointer
688  * @param   filtIdx  Filter Position
689  */
690 void CanXL_ConfigSDUFilter(CANXL_RXFIFO_Type * base,const Canexcel_Ip_RxFifoFilterSDU_CAN * filter, uint8 filtIdx);
691  /*!
692  * @brief Config the Accept VCAN Filter for RxFIFO
693  *
694  * @param   base The CanEXCEL RxFIFO Filters base address
695  * @param   filter  The VCAN filter configuration pointer
696  * @param   filtIdx  Filter Position
697  */
698 void CanXL_ConfigVCANFilter(CANXL_RXFIFO_Type * base,const Canexcel_Ip_RxFifoFilterSDU_CAN * filter, uint8 filtIdx);
699  /*!
700  * @brief Config the Acceptance Address Filter for FilterBanks Part of MessageDescriptors Filter Process
701  *
702  * @param   base The CanEXCEL Filter Bank base address
703  * @param   bank Filter Bank 0\1
704  * @param   filter  Pointer to AF filter configuration
705  * @param   filtIdx  Filter Position in the Bank
706  */
707 void CanXL_ConfigAccAddrFilterBank(CANXL_FILTER_BANK_Type * base, uint8 bank,const Canexcel_Ip_RxFifoFilterID_ADDR * filter, uint8 filtIdx);
708  /*!
709  * @brief Config the Acceptance SDU for FilterBanks Part of MessageDescriptors Filter Process
710  *
711  * @param   base The CanEXCEL Filter Bank base address
712  * @param   bank Filter Bank 0\1
713  * @param   filter  Pointer to SDU configuration
714  * @param   filtIdx  Filter Position in the Bank
715  */
716 void CanXL_ConfigSDUFilterBank(CANXL_FILTER_BANK_Type * base, uint8 bank,const Canexcel_Ip_RxFifoFilterSDU_CAN * filter, uint8 filtIdx);
717  /*!
718  * @brief Config the Acceptance VCAN Filter for FilterBanks Part of MessageDescriptors Filter Process
719  *
720  * @param   base The CanEXCEL Filter Bank base address
721  * @param   bank Filter Bank 0\1
722  * @param   filter  Pointer to VCAN filter configuration
723  * @param   filtIdx  Filter Position in the Bank
724  */
725 void CanXL_ConfigVCANFilterBank(CANXL_FILTER_BANK_Type * base, uint8 bank,const Canexcel_Ip_RxFifoFilterSDU_CAN * filter, uint8 filtIdx);
726  /*!
727  * @brief Config the Rejection Address Filter for FilterBanks Part of MessageDescriptors Filter Process
728  *
729  * @param   base The CanEXCEL Filter Bank base address
730  * @param   bank Filter Bank 0\1
731  * @param   filter  Pointer to AF filter configuration
732  * @param   filtIdx  Filter Position in the Bank
733  */
734 void CanXL_ConfigAccAddrRejectBank(CANXL_FILTER_BANK_Type * base, uint8 bank,const Canexcel_Ip_RxFifoFilterID_ADDR * filter, uint8 filtIdx);
735  /*!
736  * @brief Config the Rejection VCAN Filter for FilterBanks Part of MessageDescriptors Filter Process
737  *
738  * @param   base The CanEXCEL Filter Bank base address
739  * @param   bank Filter Bank 0\1
740  * @param   filter  Pointer to VCAN filter configuration
741  * @param   filtIdx  Filter Position in the Bank
742  */
743 void CanXL_ConfigSDURejectBank(CANXL_FILTER_BANK_Type * base, uint8 bank,const Canexcel_Ip_RxFifoFilterSDU_CAN * filter, uint8 filtIdx);
744  /*!
745  * @brief Config the Rejection VCAN Filter for FilterBanks Part of MessageDescriptors Filter Process
746  *
747  * @param   base The CanEXCEL Filter Bank base address
748  * @param   bank Filter Bank 0\1
749  * @param   filter  Pointer to VCAN filter configuration
750  * @param   filtIdx  Filter Position in the Bank
751  */
752 void CanXL_ConfigVCANRejectBank(CANXL_FILTER_BANK_Type * base, uint8 bank,const Canexcel_Ip_RxFifoFilterSDU_CAN * filter, uint8 filtIdx);
753 
754  /*!
755  * @brief IrqHandler for Rx\Tx and RxFIFO
756  *
757  * @param   instance The CanXL Instance Number
758  */
759 void Canexcel_Ip_RxTxIRQHandler(uint8 instance);
760 
761  /*!
762  * @brief IrqHandler for MRU service unit
763  *
764  * @param   instance The CanXL Instance Number
765  */
766 void Canexcel_Ip_MruIRQHandler(uint8 instance);
767 
768  /*!
769  * @brief IrqHandler for Errors
770  *
771  * @param   instance The CanXL Instance Number
772  */
773 void Canexcel_Ip_ErrIRQHandler(uint8 instance);
774 
775 #define CAN_43_CANEXCEL_STOP_SEC_CODE
776 #include "Can_43_CANEXCEL_MemMap.h"
777 
778 #ifdef __cplusplus
779 }
780 #endif /* __cplusplus */
781 
782 /** @} */
783 
784 #endif /* CANEXCEL_IP_HWACCESS_H_ */
785