1 /*
2  * Copyright 2022 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef CANEXCEL_IP_TYPES_H_
8 #define CANEXCEL_IP_TYPES_H_
9 
10 /**
11 *   @file CanEXCEL_Ip_Types.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_Cfg.h"
27 #include "CanEXCEL_Ip_DevReg.h"
28 
29 /*==================================================================================================
30 *                              SOURCE FILE VERSION INFORMATION
31 ==================================================================================================*/
32 #define CANEXCEL_IP_TYPES_VENDOR_ID_H                      43
33 #define CANEXCEL_IP_TYPES_AR_RELEASE_MAJOR_VERSION_H       4
34 #define CANEXCEL_IP_TYPES_AR_RELEASE_MINOR_VERSION_H       7
35 #define CANEXCEL_IP_TYPES_AR_RELEASE_REVISION_VERSION_H    0
36 #define CANEXCEL_IP_TYPES_SW_MAJOR_VERSION_H               0
37 #define CANEXCEL_IP_TYPES_SW_MINOR_VERSION_H               9
38 #define CANEXCEL_IP_TYPES_SW_PATCH_VERSION_H               0
39 /*==================================================================================================
40 *                                      DEFINES AND MACROS
41 ==================================================================================================*/
42 /**@brief This will enable Restricted Operation Mode  */
43 #define CANXL_IP_ROM_U32                         ((uint32)0x00000001U)
44 /**@brief Tx SMB Error Response  */
45 #define CANXL_IP_TX_ERROR_RESPONSE_U32           ((uint32)0x00000002U)
46 /**@brief Define how controller recover from bus off state */
47 #define CANXL_IP_BUSOFF_RECOVERY_U32             ((uint32)0x00000004U)
48 /**@brief Protocol Exception */
49 #define CANXL_IP_PROTOCOL_EXCEPTION_U32          ((uint32)0x00000008U)
50 /**@brief Edge Filter Enable */
51 #define CANXL_IP_EDGE_FILTER_U32                 ((uint32)0x00000010U)
52 /**@brief CAN XL Error Response as protocol exception */
53 #define CANXL_IP_XLER_U32                        ((uint32)0x00000020U)
54 
55 /** @brief CanEXCEL SubModules Instances Pointers Structure
56  *  @details CanEXCEL Cotains base address pointers to the subModules from CanEXCEL
57  */
58 /* implements CANEXCEL_StructType_structure */
59 typedef struct {
60     CANXL_SIC_Type ** EXL_SIC;
61     MC_RGM_Type ** EXL_RGM;
62     CANXL_MRU_Type ** EXL_MRU;
63     CANXL_GRP_CONTROL_Type ** EXL_GRP;
64     CANXL_DSC_CONTROL_Type ** EXL_DESC_CTR;
65     CANXL_MSG_DESCRIPTORS_Type ** EXL_MSGD;
66     CANXL_RXFIFO_CONTROL_Type ** EXL_RXF_CNT;
67     CANXL_RXFIFO_Type ** EXL_RXFIFO;
68     CANXL_FILTER_BANK_Type ** EXL_FILTER;
69 #if (CANEXCEL_IP_HAS_TS_ENABLE == STD_ON)
70     CAN_TBS_Type ** EXL_TBS;
71 #endif
72 } CANEXCEL_StructType;
73 
74 /** @brief CanEXCEL Message Buffer ID type
75  *  @details CanEXCEL Id Type, Standard or Extended
76  */
77 /* implements Canexcel_Ip_MsgBuffIdType_enum */
78 typedef enum
79 {
80     CANEXCEL_MSG_ID_STD = 0,     /**< Standard ID*/
81     CANEXCEL_MSG_ID_EXT          /**< Extended ID*/
82 } Canexcel_Ip_MsgBuffIdType;
83 
84 /** @brief CanEXCEL Message Format type
85  *  @details CanEXCEL CAN Frame type, Classic, FastData(FD), and XL
86  */
87 /* implements Canexcel_Ip_FrameType_enum */
88 typedef enum
89 {
90     CANEXCEL_CLASIC_FRAME,
91     CANEXCEL_FD_FRAME,
92     CANEXCEL_XL_FRAME
93 } Canexcel_Ip_FrameType;
94 
95 /** @brief The status of data coherency mechanism for semaphore-based access to device RAM.
96  *  @details The descriptor control Status mechanism
97  */
98 typedef enum
99 {
100     CANEXCEL_DESCNTSTATUS_UNLOCKED,         /**< Descriptor is not locked. */
101     CANEXCEL_DESCNTSTATUS_LOCKED_HW,        /**< Descriptor is locked by CANEXCEL hardware. */
102     CANEXCEL_DESCNTSTATUS_LOCKED_SYS,       /**< Descriptor is locked by system host. */
103     CANEXCEL_DESCNTSTATUS_INVALID           /**< Invalid configuration, not possible. */
104 } Canexcel_Ip_DesCntStatus;
105 
106 /** @brief The status of descriptor state.
107  *  @details The descriptor control Status mechanism
108  */
109 typedef enum
110 {
111     CANEXCEL_DESC_STATE_INACTIVE,
112     CANEXCEL_DESC_STATE_EMPTY,
113     CANEXCEL_DESC_STATE_NOTFULL,
114     CANEXCEL_DESC_STATE_FULL,
115     CANEXCEL_DESC_STATE_OVERRUN
116 } Canexcel_Ip_DescState;
117 
118 /** @brief Canexcel error interrupt types
119  */
120 /* implements  Canexcel_Ip_ErrorIntType_enum */
121 typedef enum
122 {
123     CANEXCEL_IP_INT_RX_WARNING,     /*!< RX warning interrupt*/
124     CANEXCEL_IP_INT_TX_WARNING,     /*!< TX warning interrupt*/
125     CANEXCEL_IP_INT_ERR,            /*!< Error interrupt*/
126     CANEXCEL_IP_INT_ERR_FAST,       /*!< Error Fast interrupt*/
127     CANEXCEL_IP_INT_ERR_XL,         /*!< Error XL interrupt*/
128     CANEXCEL_IP_INT_ERR_INT,        /*!< Error Internal interrupt*/
129     CANEXCEL_IP_INT_BUSOFF,         /*!< Bus off interrupt*/
130     CANEXCEL_IP_INT_BUSOFF_DONE,    /*!< Bus off done interrupt*/
131     CANEXCEL_IP_INT_PASS_ERR,       /*!< Passive error interrupt*/
132     CANEXCEL_IP_INT_FREEZE,         /*!< ACk Freeze event interrupt*/
133 } Canexcel_Ip_ErrorIntType;
134 
135 /** @brief Canexcel Timestamp Clock Sources
136  * THis are define based on the resource file of each Chip support source selection */
137 /* implements  Canexcel_Ip_TimeBaseSelType_enum */
138 typedef enum
139 {
140 CANTBS_TIMESURCE_BUS0,  /*!< This is NETC Source */
141 CANTBS_TIMESURCE_BUS1,  /*!< This is GTM TBU0 Source */
142 CANTBS_TIMESURCE_BUS2,  /*!< This is GTM TBU1 Source */
143 CANTBS_TIMESURCE_BUS3  /*!< This is CE_STM_0 Source */
144 }Canexcel_Ip_TimeBaseSelType;
145 /** @brief Canexcel Timestamp Capture Point
146  */
147 /* implements  Canexcel_Ip_TimeStampCaptureType_enum */
148 typedef enum
149 {
150     CANEXCEL_TIMESTAMPCAPTURE_DISABLE, /**< The high resolution time stamp capture is disabled. */
151     CANEXCEL_TIMESTAMPCAPTURE_END,     /**< The high resolution time stamp is captured in the end of the CAN frame */
152     CANEXCEL_TIMESTAMPCAPTURE_START,   /**< The high resolution time stamp is captured in the start of the CAN frame */
153     CANEXCEL_TIMESTAMPCAPTURE_FD       /**< The high resolution time stamp is captured in the start of frame for classical CAN frames and
154                                           in res bit for CAN FD frames and in the res XL bit for CAN XL frames */
155 }Canexcel_Ip_TimeStampCaptureType;
156 
157 /** @brief The status used and reported by Canexcel Ip driver.
158  *  @details The CanEXCEL specific error codes
159  */
160 /* implements  Canexcel_Ip_StatusType */
161 typedef enum
162 {
163     CANEXCEL_STATUS_SUCCESS  = E_OK,          /**< Successfull Operation Completed */
164     CANEXCEL_STATUS_ERROR = E_NOT_OK,         /**< Error Operation Completed */
165     CANEXCEL_STATUS_BUSY,                     /**< Busy Operation Completed */
166     CANEXCEL_STATUS_TIMEOUT,                  /**< TimeOut Operation Completed */
167     CANEXCEL_STATUS_BUFF_OUT_OF_RANGE,        /**< The specified MB index is out of the configurable range */
168     CANEXCEL_STATUS_NO_TRANSFER_IN_PROGRESS,  /**< There is no transmission or reception in progress */
169 } Canexcel_Ip_StatusType;
170 
171 /*! @brief CANXL operation modes
172  */
173 /*  implements  Canexcel_Ip_ModesType_enum */
174 typedef enum
175 {
176     CANEXCEL_NORMAL_MODE,        /**< Normal mode or user mode @internal gui name="Normal" */
177     CANEXCEL_LISTEN_ONLY_MODE,   /**< Listen-only mode @internal gui name="Listen-only" */
178     CANEXCEL_LOOPBACK_MODE       /**< Loop-back mode @internal gui name="Loop back" */
179 } Canexcel_Ip_ModesType;
180 
181 /*! @brief The type of the event which occurred when the callback was invoked.
182  */
183 /* implements Canexcel_Ip_EventType_enum */
184 typedef enum
185 {
186     CANEXCEL_EVENT_RX_COMPLETE = 0U,     /**< A frame was received in the configured Rx Descriptor. */
187     CANEXCEL_EVENT_TX_COMPLETE,          /**< A frame was sent from the configured Tx Descriptor. */
188     CANEXCEL_EVENT_RXFIFO_COMPLETE,      /**< A frame was received in the Rx FIFO. */
189     CANEXCEL_EVENT_RXFIFO_OVERFLOW,     /**< Rx FIFO is full (incoming message was lost). */
190     CANEXCEL_EVENT_ERROR,               /**<  Errors detected in CAN frames of any format (interrupt mode only) */
191     CANEXCEL_EVENT_ERROR_FD,            /**< Errors detected in the data phase of CAN FD frames with the BRS bit set only (interrupt mode only) */
192     CANEXCEL_EVENT_ERROR_XL,            /**< Errors detected in the data phase of CAN XL frames*/
193     CANEXCEL_EVENT_PASSIVE,             /**< The module enters in Passive State */
194     CANEXCEL_EVENT_BUSOFF,              /**< The module enters in BusOff State */
195     CANEXCEL_EVENT_RX_WARNING,          /**< The Rx error counter transitioned from less than 96 to greater than or equal to 96 (interrupt mode only) */
196     CANEXCEL_EVENT_TX_WARNING           /**< The Tx error counter transitioned from less than 96 to greater than or equal to 96 (interrupt mode only) */
197 } Canexcel_Ip_EventType;
198 
199 /*! @brief CanExcel Rx FIFO filter type */
200 /* implements  Canexcel_Ip_RxFifoFilterType_enum */
201 typedef enum
202 {
203     CANEXCEL_IP_RX_FIFO_RANGE_FILTER = 0U,      /*!< Filter element with range scheme*/
204 	CANEXCEL_IP_RX_FIFO_MASK_FILTER,       		/*!< Filter element with filter + mask scheme*/
205 } Canexcel_Ip_RxFifoFilterType;
206 
207 
208 typedef struct{
209 	Canexcel_Ip_RxFifoFilterType filterType;
210 	uint32 idAddrFilterH;	/* Filter ID/ADDR element in case of mask filter type this is ID/ADDR value, in case of range filter type this is the higher value. */
211 	uint32 idAddrFilterL;	/* Filter ID/ADDR element in case of mask filter type this is mask value, in case of range filter type this is the lower value. */
212 } Canexcel_Ip_RxFifoFilterID_ADDR;
213 
214 typedef struct{
215 	Canexcel_Ip_RxFifoFilterType filterType;
216 	uint8 sduVcanFilterH;	/* Filter SDU/VCAN element in case of mask filter type this is SDU/VCAN value, in case of range filter type this is the higher value. */
217 	uint8 sduVcanFilterL;	/* Filter SDU/VCAN element in case of mask filter type this is mask value, in case of range filter type this is the lower value. */
218 } Canexcel_Ip_RxFifoFilterSDU_CAN;
219 
220 typedef struct{
221 	uint32 SecMask;
222 	uint32 SecFilter;
223 	uint8  noIdFilters;
224 	uint8  noActAddrFilters;
225 	uint8  noSduFilters;
226 	uint8  noVcanFilters;
227 	Canexcel_Ip_RxFifoFilterID_ADDR * IdFilterPtr; /* Pointer to the array with ID filter configs */
228 	Canexcel_Ip_RxFifoFilterID_ADDR * AddrFilterPtr; /* Pointer to the array with Acceptance Address filter configs */
229 	Canexcel_Ip_RxFifoFilterSDU_CAN * SduFilterPtr; /* Pointer to the array with Sdu Filter configs */
230 	Canexcel_Ip_RxFifoFilterSDU_CAN * VcanFilterPtr; /* Pointer to the array with VCAN Filter configs */
231 } Canexcel_Ip_RxFifoFilter;
232 
233 typedef struct{
234     Canexcel_Ip_FrameType frame;
235     Canexcel_Ip_MsgBuffIdType idType;
236     uint8 priority;
237     uint8 retransmission;
238     boolean enable_brs;                    /**< Enable bit rate switch inside a CAN FD format frame*/
239     uint8 fd_padding;                      /**< Set a value for padding. It will be used when the data length code (DLC)
240                                                 specifies a bigger payload size than data_length to fill the MB */
241     uint16 dataLength;                     /**< Length of data in bytes */
242     uint8 STD;
243     boolean SEC;
244     uint8 VCID;
245     boolean is_polling;
246 } Canexcel_Ip_DataInfoType;
247 
248 /*! @brief Canexcel message buffer structure
249  */
250 /*  implements  Canexcel_Ip_MsgBuffType_structure */
251 typedef struct
252 {
253     uint32 msgId;                     /**< Message Buffer ID*/
254     uint8 data[64];                   /**< Data bytes of the FlexCAN message*/
255     uint8 dataLen;                    /**< Length of data in bytes */
256 } Canexcel_Ip_MsgBuffType;
257 
258 typedef struct
259 {
260     uint32 timeStampL;
261     uint32 timeStampH;
262     uint32 word2;
263     uint32 word3;
264     uint32 word4;
265 } Canexcel_TxMsgHeaderType;
266 
267 typedef struct{
268     Canexcel_TxMsgHeaderType Header;
269     uint8 data[64];
270 } Canexcel_TxFdMsgType;
271 
272 typedef struct{
273     Canexcel_TxMsgHeaderType Header;
274     uint32 AF;
275     uint8 data[2048];
276 } Canexcel_TxXlMsgType;
277 
278 typedef struct{
279     uint32 Id;
280     uint32 Control;
281 } Canexcel_RxHeader;
282 
283 typedef struct{
284     Canexcel_RxHeader Header;
285     uint8 data[64];
286     uint32 timeStampL;
287     uint32 timeStampH;
288 }Canexcel_RxFdMsg;
289 
290 typedef struct{
291     Canexcel_RxHeader Header;
292     uint32 AF;
293     uint8 data[2048];
294     uint32 timeStampL;
295     uint32 timeStampH;
296 }Canexcel_RxXlMsg;
297 
298 /*! @brief CAN Excel bitrate related structures
299  */
300 /* implements  Canexcel_Ip_TimeSegmentType_structure */
301 typedef struct
302 {
303     uint32 propSeg;         /**< Propagation segment*/
304     uint32 phaseSeg1;       /**< Phase segment 1*/
305     uint32 phaseSeg2;       /**< Phase segment 2*/
306     uint32 preDivider;      /**< Clock prescaler division factor*/
307     uint32 rJumpwidth;      /**< Resync jump width*/
308 } Canexcel_Ip_TimeSegmentType;
309 
310 /*! @brief Information needed for internal handling of a given MessageDescriptor. */
311 /* implements  Canexcel_Ip_MDhandleType_structure */
312 typedef struct
313 {
314     uint32  list[16];                  /**< The Can Message Buffer Pointer List array */
315     uint8   noPointers;                /**< The No of Message Pointers List sent\received */
316     boolean isPolling;                 /**< True if the transfer is Polling Mode  */
317     boolean isRemote;                  /**< True if the frame is a remote frame */
318     boolean isXLFrame;                 /**< True for XLFrame Types, False for Classic and FD frames. */
319 } Canexcel_Ip_MDhandleType;
320 
321 /*!
322  * @brief Internal driver state information.
323  *
324  * @note The contents of this structure are internal to the driver and should not be
325  *      modified by users. Also, contents of the structure are subject to change in
326  *      future releases.
327  */
328 /* implements   Canexcel_Ip_StateType_structure */
329 typedef struct CanexcelState
330 {
331    Canexcel_Ip_MDhandleType msgDesc[CANXL_MSG_DESCRIPTORS_MSGDSC_COUNT];
332    Canexcel_Ip_MDhandleType rxFifo;
333    boolean isIntActive;                                       /**< Save status of enabling/disabling interrupts in runtime. */
334    void (*callback)(uint8 instance,
335                     Canexcel_Ip_EventType eventType,
336                     uint32 buffIdx,
337                     const struct CanexcelState *driverState
338                    );                                         /**< IRQ handler callback function. */
339    void * callbackParam;                                       /**< Parameter used to pass user data
340                                                                    when invoking the callback
341                                                                    function. */
342    void (*error_callback)(uint8 instance,
343                           Canexcel_Ip_EventType eventType,
344                           uint32 u32SysStatus,
345                           const struct CanexcelState *driverState
346                          );                                   /**< Error IRQ handler callback
347                                                                    function. */
348    void *errorCallbackParam;                                  /**< Parameter used to pass user data
349                                                                    when invoking the error callback
350                                                                    function. */
351 } Canexcel_Ip_StateType;
352 
353 typedef struct Canexcel_Ip_RxFifoConfig
354 {
355     uint8 Rx_Fifo_Depth;
356     uint8 Rx_Fifo_Watermark;
357     uint16 Rx_Fifo_Msg_Size;
358     boolean Rx_Fifo_KeepLast;
359     boolean Rx_Fifo_EnFilterBank1;
360     boolean isPolling;
361     Canexcel_Ip_FrameType frameType;
362     uint32 * MsgBuffersPtr;
363 }Canexcel_Ip_RxFifoConfig_Type;
364 
365 
366 /*! @brief CanExcel Driver callback function type
367  */
368 /* implements Canexcel_Ip_ErrorCallbackType_typdef */
369 typedef void (* Canexcel_Ip_CallbackType)(uint8 instance,
370                                          Canexcel_Ip_EventType eventType,
371                                          uint32 buffIdx,
372                                          const Canexcel_Ip_StateType * canexcelState
373                                         );
374 
375 /*! @brief CanExcel Driver error callback function type
376  */
377 /* implements  Canexcel_Ip_ErrorCallbackType_typdef  */
378 typedef void (* Canexcel_Ip_ErrorCallbackType)(uint8 instance,
379                                               Canexcel_Ip_EventType eventType,
380                                               uint32 u32SysStatus,
381                                               const Canexcel_Ip_StateType * canexcelState
382                                              );
383 
384 /*! @brief CanEXCEL configuration
385  * @internal gui name="Common configuration" id="canexcelCfg"
386  */
387 /* implements   Canexcel_Ip_ConfigType_structure */
388 typedef struct Canexcel_Ip_Config
389 {
390     uint8 rx_mbdesc;                               /**< No of Rx Descriptor to be used.*/
391     uint8 tx_mbdesc;                               /**< No of Tx Descriptor to be used.*/
392     Canexcel_Ip_ModesType CanxlMode;               /**< User configurable CanEXCEL operation modes.
393                                                    @internal gui name="Canexcel Operation Mode" id="CanxlMode" */
394     boolean fd_enable;                             /**< Enable/Disable the Flexible Data Rate feature. */
395     boolean bitRateSwitch;                         /**< Enable of BitRate Switch support for FD frames */
396     boolean xl_enable;                             /**< Enable/Disable the XL Frame feature. */
397     uint32 ctrlOptions;                            /**< Use of different features support like EDGE_FILTER, AUTO_BussOffRecovery, Protocol_Exception. */
398     boolean is_rx_fifo_needed;                     /**< 1 if needed; 0 if not. This controls whether the Rx FIFO feature is enabled or not.
399                                                          @internal gui name="Use rx fifo" id="is_rx_fifo_needed" */
400     Canexcel_Ip_RxFifoConfig_Type * pRxFifoConfig; /**< Pointer to RxFifo configuration, if RxFifo feature is not enabled can be NULL_PTR */
401     Canexcel_Ip_TimeSegmentType bitrate;           /**< The bitrate used for standard frames or for the arbitration phase of FD frames. */
402     Canexcel_Ip_TimeSegmentType Fd_bitrate;        /**< The bitrate used for the data phase of FD frames. */
403     Canexcel_Ip_TimeSegmentType Xl_bitrate;        /**< The bitrate used for the data phase of XL frames. */
404     Canexcel_Ip_CallbackType Callback;             /**< The Callback for Rx or Tx, FIFO Events */
405     Canexcel_Ip_ErrorCallbackType ErrorCallback;   /**< The ErrorCallback for Error Events */
406 } Canexcel_Ip_ConfigType;
407 
408 typedef struct Canexcel_Ip_TimeStampConf
409 {
410     boolean ts64bit;
411     Canexcel_Ip_TimeStampCaptureType capture;
412     Canexcel_Ip_TimeBaseSelType src;
413 } Canexcel_Ip_TimeStampConf_Type;
414 #ifdef __cplusplus
415 }
416 #endif /* __cplusplus */
417 
418 /** @} */
419 
420 #endif /* CANEXCEL_IP_TYPES_H_ */
421