1 /***************************************************************************//**
2 * \file cy_canfd.h
3 * \version 1.40
4 *
5 * This file provides constants and parameter values for
6 * the CAN FD driver.
7 *
8 ********************************************************************************
9 * \copyright
10 * Copyright 2019-2020 Cypress Semiconductor Corporation
11 * SPDX-License-Identifier: Apache-2.0
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *******************************************************************************/
25
26 /**
27 * \addtogroup group_canfd
28 * \{
29 * The CAN FD driver provides an easy method to access the CAN FD IP block registers
30 * and provides simple functionality for sending and receiving data between
31 * devices in the CAN FD network.
32 * The CAN FD driver provides an API to configure the main features - mode, bit time,
33 * message buffers - and transmit and receive message in all modes:
34 * - Classic CAN using 11-bit identifiers
35 * - Classic CAN using 29-bit identifiers
36 * - CAN Flexible Data using 11-bit identifiers
37 * - CAN Flexible Data using 29-bit identifiers.
38 *
39 * \image html canfd_solution.png "CAN FD Solution" width=948px
40 * \image latex canfd_solution.png
41 *
42 *
43 * \section group_canfd_section_configuration Configuration Considerations
44 * Specification of the sample code is as follows:
45 * - Selectable CAN FD mode or CAN mode
46 * - Configurable CAN clock
47 * - Configurable CAN Bit rate
48 * - Configurable CAN FD Bit rate
49 * - Configurable Standard ID filter
50 * - Configurable Extended Message ID Filter
51 * - Tx-Rx Element Size : 8 bytes (CAN mode)
52 * - Tx-Rx Element Size : 64 bytes (CAN FD mode)
53 * - Rx FIFO configuration
54 * - Interrupts : \n
55 * CY_CANFD_RX_FIFO_0_NEW_MESSAGE (Message stored to Rx FIFO 0) \n
56 * CY_CANFD_RX_FIFO_1_NEW_MESSAGE (Message stored to Rx FIFO 1) \n
57 * CY_CANFD_RX_BUFFER_NEW_MESSAGE (Message stored to Dedicated Rx Buffer). \n
58 *
59 * Sends data of ID:0x200 periodically in the main().
60 * Echobacks received data by incrementing the ID of the received packet in
61 * the receiving interrupt.(CanFDIrqHandler() --- CanFDCallbackRx())
62 *
63 * \subsection group_canfd_section_configuration_personalities Use ModusToolbox Device Configurator Tool to generate initialization code
64 * The steps to generate initialization code using
65 * the ModusToolbox Device Configurator Tool:
66 *
67 * 1. Launch the ModusToolbox Device Configurator Tool.
68 * 2. Switch to the Peripherals tab. Enable the CAN FD channel personality
69 * under Communication and enter Alias (default is canfd_0_chan_0).
70 * 3. Go to the Parameters Pane for the CAN FD Personality and configure it with
71 * the desired parameters (set the Clock Signal divider, set the bit timing
72 * configuration, set the other parameters per Configuration Considerations, etc).
73 * 4. Perform File->Save for the initialization code to generate.
74 *
75 * Now, all required CAN FD initialization code and configuration prerequisites will be generated:
76 *
77 * - The Peripheral Clock Divider assignment and analog routing are parts of the
78 * init_cycfg_all() routine. Place the call of the init_cycfg_all() function
79 * before using any CAN FD API functions to ensure initialization of all external
80 * resources required for the CAN FD operation.
81 * - The CAN FD configuration structure declaration is in the cycfg_peripherals.h
82 * file and its initialization is in the cycfg_peripherals.c file. The variable
83 * name is \<CAN_FD_Alias_Name\>_config (default is canfd_0_chan_0_config). It
84 * must be used with Cy_CANFD_Init() function.
85 * - TX buffers structures are initialized. Use these structures to send data.
86 *
87 * For the CAN FD interrupt service routine, Cy_CANFD_IrqHandler() can be used.
88 * It handles reading data from the dedicated RX buffers and RX FIFO buffers.
89 * Corresponding callback functions are called for error interrupts, RX
90 * interrupts and TX complete interrupt. Put the names of callback functions to
91 * the Callback functions parameters section. Put NULL if no callback function to
92 * be used.
93 * \note Only RX interrupt sources are enabled by default.
94 * Use Cy_CANFD_SetInterruptMask() to enable other interrupt sources.
95 * \note Interrupt flags are set regardless of the interrupt enable register.
96 * Cy_CANFD_IrqHandler will check and process all supported interrupts when
97 * triggered with any enabled interrupt source.
98 *
99 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_ISR
100 *
101 * Set up the interrupt handler to be called with CAN FD events. The CAN FD block
102 * has two interrupt lines which can be assigned to different interrupt
103 * sources using Cy_CANFD_SetInterruptLine(): canfd_0_interrupts0_0_IRQn
104 * and canfd_0_interrupts1_0_IRQn. Also, the CAN FD block has a consolidated interrupt
105 * canfd_0_interrupt0_IRQn. The following code shows how to set up the interrupt
106 * handler.
107 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_Setup_CANFD_Interrupt
108 *
109 * \subsection group_canfd_section_configuration_manual Implement the initialization code manually
110 * Call Cy_CANFD_Init() to initialize the CAN FD module.
111 * It initializes the CAN FD module with the configuration parameters, passed
112 * in the \ref cy_stc_canfd_config_t structure. It consists of several elements
113 * to be defined first.
114 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_Config_Struct
115 * The Cy_CANFD_Init() function also initializes the shared context structure
116 * used later with other API functions.
117 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_context
118 * Although the callback functions are optional, they are recommended for use,
119 * otherwise, there is no report to the API about any error and transmission or reception events.
120 * The example callback function sends received data back to the bus,
121 * incrementing ID by 1:
122 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_RX_callback
123 * CAN FD IP block requires the configuration of a peripheral clock divider.
124 * The following code configures an 8-bit clock divider. The default peripheral
125 * clock frequency is 72 MHz. The desired divider value minus one must be passed.
126 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_Assign_Clock_Divider
127 * The CAN FD block uses the Port 5 pins for receive (P5[0]) and transmit (P5[1]).
128 * - Connect the specified High-Speed Input Output Multiplexer (HSIOM) selection
129 * to the pin.
130 * - Set the pins drive mode for RX and TX.
131 *
132 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_Assign_CANFD_Pins
133 *
134 * For the CANFD interrupt service routine, the Cy_CANFD_IrqHandler() can be used.
135 * It handles reading data from dedicated RX buffers and RX FIFO buffers.
136 * Corresponding callback functions are called for error interrupts, RX
137 * interrupts and TX complete interrupt.
138 * \note Only RX interrupt sources are enabled by default.
139 * Use Cy_CANFD_SetInterruptMask() to enable other interrupt sources.
140 * \note Interrupt flags are set regardless of the interrupt enable register.
141 * Cy_CANFD_IrqHandler will check and process all supported interrupts when
142 * triggered with any enabled interrupt source.
143 *
144 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_ISR
145 *
146 * Setup the interrupt handler to be called with the CAN FD events. The CAN FD block
147 * has two interrupt lines, which can be assigned to different interrupt
148 * sources using Cy_CANFD_SetInterruptLine(): canfd_0_interrupts0_0_IRQn
149 * and canfd_0_interrupts1_0_IRQn. Also, the CAN FD block has a consolidated interrupt
150 * canfd_0_interrupt0_IRQn. The following code shows how to set up the interrupt
151 * handler.
152 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_Setup_CANFD_Interrupt
153 *
154 * CAN FD has two bit rate settings, for arbitration and data phases. Both are
155 * configured with the same structure, containing a pre-scaler, time segment 1,
156 * time segment 2 and synchronization jump width.
157 * \note The actual interpretation by the hardware of configured values is
158 * one more value than programmed.
159 * \note The bit rate configured for the CAN FD data phase must be higher or equal to
160 * the bit rate configured for the arbitration phase.
161 *
162 * The CAN time quantum (tq) may be programmed in the range of 1 to 32 CAN FD clock
163 * periods: tq = (prescaler + 1) mtq, where mtq is CAN FD block's clock period.
164 * The length of the bit time is (programmed values)
165 * [timeSegment1 + timeSegment2 + 3] tq. \n
166 * The example below shows the configuration with the 100 kbps arbitration bit rate
167 * and 200 kbps data bit rate. This assumes the peripheral clock frequency of 72 MHz
168 * divided by 9 to obtain the 8 MHz clock for the CAN FD block.
169 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_Bitrate
170 * CAN FD driver provides API to setup Message ID filtering. There are standard
171 * ID and extended ID filters. The desired count of the filters of each type is
172 * specified in the \ref cy_stc_canfd_config_t structure and is set once during
173 * block initialization. It is possible to change the configured
174 * filters settings with Cy_CANFD_SidFilterSetup() and Cy_CANFD_XidFilterSetup().
175 * Use the cy_stc_id_filter_t structure to set up one standard ID filter:
176 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_SID_Filter
177 * Use the cy_stc_extid_filter_t structure to set up an extended ID filter:
178 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_XID_Filter
179 * Message IDs that do not match any filter are received according to the global
180 * filter set up. The global filter can be set up to receive messages with standard
181 * and extended IDs to different FIFO buffers. It can be configured to reject remote
182 * frames, as shown below.
183 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_Global_Filter
184 * The RX FIFO buffers, FIFO 0 and FIFO 1 are configured once on block
185 * initialization using cy_en_canfd_fifo_config_t structure.
186 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_FIFO_Config
187 * The cy_stc_canfd_config_t structure is used to pass all configuration to
188 * Cy_CANFD_Init() function. It is populated with pointers to other structures
189 * required and constants, defined before.
190 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_Config_Struct
191 * The Cy_CANFD_Init() function initializes the CAN FD block by writing CAN FD
192 * configuration registers. Cy_CANFD_Init() enables the RX interrupts for
193 * new message reception into the dedicated RX buffers, FIFO 0 and FIFO 1.
194 * The code example also shows the test mode configuration which can be used to
195 * enable the Loopback mode. See \ref cy_stc_canfd_test_mode_t for details.
196 * Cy_CANFD_Init() sets test mode configuration to CY_CANFD_TEST_MODE_DISABLE.
197 * Remember to disable the echo functionality in the RX callback when using a loopback.
198 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_Init_Example
199 * To send a CAN FD message, a TX buffer structure must be prepared
200 * which consists of the T0 and T1 registers and data array.
201 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_Prepare_TX
202 * To transmit CAN FD messages, the function \ref Cy_CANFD_UpdateAndTransmitMsgBuffer()
203 * is used. The buffer status can be retrieved by Cy_CANFD_GetTxBufferStatus().
204 * It is possible to set a callback function which will be notified whenever a
205 * message transmission has been completed.
206 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_Send_TX
207 *
208 * \section group_canfd_section_more_information More Information
209 *
210 * For more information on the CAN FD peripheral, refer to the technical
211 * reference manual (TRM).
212 *
213 * \section group_canfd_changelog Changelog
214 * <table class="doxtable">
215 * <tr><th>Version</th><th>Changes</th><th>Reason for Change</th></tr>
216 * <tr>
217 * <td>1.40</td>
218 * <td>Updated APIs \ref Cy_CANFD_Init , \ref Cy_CANFD_CalcRxBufAdrs, \ref Cy_CANFD_CalcRxFifoAdrs, \ref Cy_CANFD_XidFilterSetup. </td>
219 * <td>Bug Fixes.</td>
220 * </tr>
221 * <tr>
222 * <td>1.30</td>
223 * <td>Updated \ref Cy_CANFD_Init() and \ref Cy_CANFD_DeInit() functions. Added volatile qualifier to prevent loop optimization.</td>
224 * <td>Code Enhancement.</td>
225 * </tr>
226 * <tr>
227 * <td>1.20</td>
228 * <td>Added const modifier to the functions parameters where needed.
229 * Improved error handling in \ref Cy_CANFD_Init() and
230 * \ref Cy_CANFD_IrqHandler().
231 * </td>
232 * <td>Source code cleanup.</td>
233 * </tr>
234 * <tr>
235 * <td>1.10</td>
236 * <td>Updated \ref Cy_CANFD_Init() functions.</td>
237 * <td>Allow initing CANFD with 0 number of SID/XID filters.</td>
238 * </tr>
239 * <tr>
240 * <td>1.0.1</td>
241 * <td>Updated description of the \ref Cy_CANFD_Init() and \ref Cy_CANFD_DeInit() functions.</td>
242 * <td>Documentation update and clarification.</td>
243 * </tr>
244 * <tr>
245 * <td>1.0</td>
246 * <td>Initial version</td>
247 * <td></td>
248 * </tr>
249 * </table>
250 *
251 * \defgroup group_canfd_macros Macros
252 * \{
253 \defgroup group_canfd_rx_interrupt_masks RX Interrupt masks
254 \defgroup group_canfd_tx_interrupt_masks TX Interrupt masks
255 \defgroup group_canfd_error_interrupt_masks Error Interrupt masks
256 \defgroup group_canfd_interrupt_line_masks Interrupt line selection masks
257 \defgroup group_canfd_last_state_masks Protocol Status Register (PSR) masks
258 * \}
259 * \defgroup group_canfd_functions Functions
260 * \defgroup group_canfd_data_structures Data Structures
261 * \defgroup group_canfd_enums Enumerated Types
262 *
263 */
264
265 #if !defined(CY_CANFD_H)
266 #define CY_CANFD_H
267
268 #include "cy_device.h"
269
270 #if defined (CY_IP_MXTTCANFD)
271
272 #include <stddef.h>
273 #include "cy_syslib.h"
274
275 #if defined(__cplusplus)
276 extern "C" {
277 #endif
278
279 /** \addtogroup group_canfd_macros
280 * \{
281 * This section describes the CAN FD Macros.
282 * These Macros can be used to check the interrupt and status flags.
283 * Detailed information about the macros is available in each macro description.
284 */
285
286 /** Driver major version */
287 #define CY_CANFD_DRV_VERSION_MAJOR 1U
288
289 /** Driver minor version */
290 #define CY_CANFD_DRV_VERSION_MINOR 40U
291
292 /** CAN FD driver ID */
293 #define CY_CANFD_ID CY_PDL_DRV_ID(0x45U)
294
295 /******************************************************************************
296 * API Constants
297 ******************************************************************************/
298
299 /** Size of word data bytes in a receive or transmit operation (16word = 64byte) */
300 #define CY_CANFD_MESSAGE_DATA_BUFFER_SIZE (16U)
301
302 /** FIFO number 0 */
303 #define CY_CANFD_RX_FIFO0 (0U)
304
305 /** FIFO number 1 */
306 #define CY_CANFD_RX_FIFO1 (1U)
307
308 /** \} group_canfd_macros */
309
310
311 /**
312 * \addtogroup group_canfd_rx_interrupt_masks
313 * \{ This section contains interrupt bit masks to be used with:
314 * - Cy_CANFD_GetInterruptStatus()
315 * - Cy_CANFD_ClearInterrupt()
316 * - Cy_CANFD_GetInterruptMask()
317 * - Cy_CANFD_SetInterruptMask()
318 * - Cy_CANFD_GetInterruptLine()
319 * - Cy_CANFD_SetInterruptLine()
320 */
321 #define CY_CANFD_RX_FIFO_0_NEW_MESSAGE (CANFD_CH_M_TTCAN_IR_RF0N_Msk) /**< Rx FIFO 0 New Message */
322 #define CY_CANFD_RX_FIFO_1_NEW_MESSAGE (CANFD_CH_M_TTCAN_IR_RF1N_Msk) /**< Rx FIFO 1 New Message */
323 #define CY_CANFD_RX_BUFFER_NEW_MESSAGE (CANFD_CH_M_TTCAN_IR_DRX_Msk) /**< Message stored to Dedicated Rx Buffer */
324 #define CY_CANFD_HIGH_PRIORITY_MESSAGE (CANFD_CH_M_TTCAN_IR_HPM_Msk) /**< High Priority Message */
325
326 /** \} group_canfd_rx_interrupt_masks */
327
328 /**
329 * \addtogroup group_canfd_tx_interrupt_masks
330 * \{ This section contains interrupt bit masks to use with:
331 * - Cy_CANFD_GetInterruptStatus()
332 * - Cy_CANFD_ClearInterrupt()
333 * - Cy_CANFD_GetInterruptMask()
334 * - Cy_CANFD_SetInterruptMask()
335 * - Cy_CANFD_GetInterruptLine()
336 * - Cy_CANFD_SetInterruptLine()
337 */
338 #define CY_CANFD_TRANSMISSION_COMPLETE (CANFD_CH_M_TTCAN_IR_TC_Msk) /**< Transmission Completed */
339 #define CY_CANFD_TRANSMISSION_CANCEL_FINISHED (CANFD_CH_M_TTCAN_IR_TCF_Msk) /**< Transmission Cancellation Finished */
340 #define CY_CANFD_TX_FIFO_EMPTY (CANFD_CH_M_TTCAN_IR_TFE_Msk) /**< Tx FIFO Empty */
341 #define CY_CANFD_TX_EVENT_FIFO_NEW_ENTRY (CANFD_CH_M_TTCAN_IR_TEFN_Msk) /**< Tx Event FIFO New Entry */
342
343 /** \} group_canfd_tx_interrupt_masks */
344
345
346 /**
347 * \addtogroup group_canfd_error_interrupt_masks
348 * \{ This section contains interrupt bit masks to be used with:
349 * - Cy_CANFD_GetInterruptStatus()
350 * - Cy_CANFD_ClearInterrupt()
351 * - Cy_CANFD_GetInterruptMask()
352 * - Cy_CANFD_SetInterruptMask()
353 * - Cy_CANFD_GetInterruptLine()
354 * - Cy_CANFD_SetInterruptLine()
355 */
356 #define CY_CANFD_RX_FIFO_0_WATERMARK_REACHED (CANFD_CH_M_TTCAN_IR_RF0W_Msk) /**< Rx FIFO 0 Watermark Reached */
357 #define CY_CANFD_RX_FIFO_0_FULL (CANFD_CH_M_TTCAN_IR_RF0F_Msk) /**< Rx FIFO 0 Full */
358 #define CY_CANFD_RX_FIFO_0_MSG_LOST (CANFD_CH_M_TTCAN_IR_RF0L__Msk) /**< Rx FIFO 0 Message Lost */
359
360 #define CY_CANFD_RX_FIFO_1_WATERMARK_REACHED (CANFD_CH_M_TTCAN_IR_RF1W_Msk) /**< Rx FIFO 1 Watermark Reached */
361 #define CY_CANFD_RX_FIFO_1_FULL (CANFD_CH_M_TTCAN_IR_RF1F_Msk) /**< Rx FIFO 1 Full */
362 #define CY_CANFD_RX_FIFO_1_MSG_LOST (CANFD_CH_M_TTCAN_IR_RF1L__Msk) /**< Rx FIFO 1 Message Lost */
363
364 #define CY_CANFD_TX_FIFO_1_WATERMARK_REACHED (CANFD_CH_M_TTCAN_IR_TEFW_Msk) /**< Tx Event FIFO Watermark Reached */
365 #define CY_CANFD_TX_FIFO_1_FULL (CANFD_CH_M_TTCAN_IR_TEFF_Msk) /**< Tx Event FIFO Full */
366 #define CY_CANFD_TX_FIFO_1_MSG_LOST (CANFD_CH_M_TTCAN_IR_TEFL__Msk) /**< Tx Event FIFO Element Lost */
367
368 #define CY_CANFD_TIMESTAMP_WRAPAROUND (CANFD_CH_M_TTCAN_IR_TSW_Msk) /**< Timestamp Wraparound */
369 #define CY_CANFD_MRAM_ACCESS_FAILURE (CANFD_CH_M_TTCAN_IR_MRAF_Msk) /**< Message RAM Access Failure */
370 #define CY_CANFD_TIMEOUT_OCCURRED (CANFD_CH_M_TTCAN_IR_TOO_Msk) /**< Timeout Occurred */
371
372
373 #define CY_CANFD_BIT_ERROR_CORRECTED (CANFD_CH_M_TTCAN_IR_BEC_Msk) /**< Bit Error Corrected */
374 #define CY_CANFD_BIT_ERROR_UNCORRECTED (CANFD_CH_M_TTCAN_IR_BEU_Msk) /**< Bit Error Uncorrected */
375 #define CY_CANFD_ERROR_LOG_OVERFLOW (CANFD_CH_M_TTCAN_IR_ELO_Msk) /**< Error Logging Overflow */
376 #define CY_CANFD_ERROR_PASSIVE (CANFD_CH_M_TTCAN_IR_EP__Msk) /**< Error Passive */
377 #define CY_CANFD_WARNING_STATUS (CANFD_CH_M_TTCAN_IR_EW__Msk) /**< Warning Status */
378 #define CY_CANFD_BUS_OFF_STATUS (CANFD_CH_M_TTCAN_IR_BO__Msk) /**< Bus_Off Status */
379 #define CY_CANFD_WATCHDOG_INTERRUPT (CANFD_CH_M_TTCAN_IR_WDI_Msk) /**< Watchdog Interrupt */
380 #define CY_CANFD_PROTOCOL_ERROR_ARB_PHASE (CANFD_CH_M_TTCAN_IR_PEA_Msk) /**< Protocol Error in
381 * Arbitration Phase
382 */
383 #define CY_CANFD_PROTOCOL_ERROR_DATA_PHASE (CANFD_CH_M_TTCAN_IR_PED_Msk) /**< Protocol Error in Data Phase */
384 #define CY_CANFD_ACCESS_RESERVED_ADDR (CANFD_CH_M_TTCAN_IR_ARA_Msk) /**< Access to Reserved Address */
385
386 /** \} group_canfd_error_interrupt_masks */
387
388 /**
389 * \addtogroup group_canfd_interrupt_line_masks
390 * \{ Interrupt line selection masks
391 */
392
393
394 #define CY_CANFD_INTERRUPT_LINE_0_EN (CANFD_CH_M_TTCAN_ILE_EINT0_Msk) /**< Enable Interrupt Line 0 */
395 #define CY_CANFD_INTERRUPT_LINE_1_EN (CANFD_CH_M_TTCAN_ILE_EINT1_Msk) /**< Enable Interrupt Line 1 */
396
397 /** \} group_canfd_interrupt_line_masks */
398
399 /**
400 * \addtogroup group_canfd_last_state_masks
401 * \{ Masks and bit positions of the Protocol Status Register (PSR) fields
402 */
403 #define CY_CANFD_PSR_LEC_POS (CANFD_CH_M_TTCAN_PSR_LEC_Pos ) /**< Last Error Code position */
404 #define CY_CANFD_PSR_LEC_MASK (CANFD_CH_M_TTCAN_PSR_LEC_Msk ) /**< Last Error Code bit mask */
405 #define CY_CANFD_PSR_ACT_POS (CANFD_CH_M_TTCAN_PSR_ACT_Pos ) /**< Activity position */
406 #define CY_CANFD_PSR_ACT_MASK (CANFD_CH_M_TTCAN_PSR_ACT_Msk ) /**< Activity bit mask */
407 #define CY_CANFD_PSR_EP (CANFD_CH_M_TTCAN_PSR_EP_Msk ) /**< Error Passive */
408 #define CY_CANFD_PSR_EW (CANFD_CH_M_TTCAN_PSR_EW_Msk ) /**< Warning Status */
409 #define CY_CANFD_PSR_BO (CANFD_CH_M_TTCAN_PSR_BO_Msk ) /**< Bus_Off Status */
410 #define CY_CANFD_PSR_DLEC_POS (CANFD_CH_M_TTCAN_PSR_DLEC_Pos) /**< Data Phase Last Error Code position */
411 #define CY_CANFD_PSR_DLEC_MASK (CANFD_CH_M_TTCAN_PSR_DLEC_Msk) /**< Data Phase Last Error Code bit mask */
412 #define CY_CANFD_PSR_RESI (CANFD_CH_M_TTCAN_PSR_RESI_Msk) /**< ESI flag of last received CAN FD Message */
413 #define CY_CANFD_PSR_RBRS (CANFD_CH_M_TTCAN_PSR_RBRS_Msk) /**< BRS flag of last received CAN FD Message */
414 #define CY_CANFD_PSR_RFDF (CANFD_CH_M_TTCAN_PSR_RFDF_Msk) /**< Received a CAN FD Message */
415 #define CY_CANFD_PSR_PXE (CANFD_CH_M_TTCAN_PSR_PXE_Msk ) /**< Protocol Exception Event */
416 #define CY_CANFD_PSR_TDCV_POS (CANFD_CH_M_TTCAN_PSR_TDCV_Pos) /**< Transmitter Delay Compensation Value position */
417 #define CY_CANFD_PSR_TDCV_MASK (CANFD_CH_M_TTCAN_PSR_TDCV_Msk) /**< Transmitter Delay Compensation Value bit mask */
418
419 /** \} group_canfd_last_state_masks */
420
421 /** \cond INTERNAL_MACROS */
422
423 /** The number loops to make the timeout */
424 #define CY_CANFD_RETRY_COUNT (1000UL)
425
426 /** The delay timeout in usec */
427 #define CY_CANFD_STOP_TIMEOUT_US (1U)
428
429 /** Number clock cycles delay needed after power domain power up */
430 #define CY_CANFD_RAM_PWR_DELAY_CYCLES (150UL)
431
432 /** The maximum number of 32-bit words used for storage of a CAN message's
433 * data field
434 */
435 #define CY_CANFD_DATA_ELEMENTS_MAX (16U)
436 #define CY_CANFD_MESSAGE_RX_BUFFERS_MAX_CNT (64UL)
437 #define CY_CANFD_MESSAGE_TX_BUFFERS_MAX_CNT (32UL)
438 #define CY_CANFD_CLASSIC_CAN_DATA_LENGTH (8U)
439
440 #define CY_CANFD_IS_MESSAGE_BUFFER_IDX_VALID(idx) ((CY_CANFD_MESSAGE_RX_BUFFERS_MAX_CNT) > (idx))
441
442 /* The initialization timeout in usec */
443 #define CY_CANFD_INIT_TIMEOUT_US (1U)
444
445 /* Deprecated */
446 #define CY_CANFD_STOP_TIMEOUT_MS (1UL)
447 #define CY_CANFD_INIT_TIMEOUT_MS (1UL)
448
449 /** \endcond */
450
451 /***************************************
452 * Enumerations
453 ***************************************/
454 /**
455 * \addtogroup group_canfd_enums
456 * \{
457 */
458
459 /** CAN FD status enumeration */
460 typedef enum
461 {
462 CY_CANFD_SUCCESS = 0x00U, /**< Returned successful */
463 CY_CANFD_BAD_PARAM = CY_CANFD_ID | CY_PDL_STATUS_ERROR | 0x01u, /**< Bad parameter was passed */
464 CY_CANFD_ERROR_TIMEOUT = CY_CANFD_ID | CY_PDL_STATUS_ERROR | 0x02u, /**< A Time out error occurred */
465 } cy_en_canfd_status_t;
466
467 /** CAN FD Tx Buffer status enumeration */
468 typedef enum
469 {
470 CY_CANFD_TX_BUFFER_IDLE = 0u,
471 CY_CANFD_TX_BUFFER_PENDING = 1u, /**< Pending transmission */
472 CY_CANFD_TX_BUFFER_TRANSMIT_OCCURRED = 2u, /**< Transmission occurred */
473 CY_CANFD_TX_BUFFER_CANCEL_REQUESTED = 3u, /**< Cancellation requested */
474 CY_CANFD_TX_BUFFER_CANCEL_FINISHED = 4u /**< Cancellation finished */
475 } cy_en_canfd_tx_buffer_status_t;
476
477 /** CAN FD Tx/Rx buffer element size */
478 typedef enum
479 {
480 CY_CANFD_BUFFER_DATA_SIZE_8 = 0u, /**< 8 byte data field */
481 CY_CANFD_BUFFER_DATA_SIZE_12 = 1u, /**< 12 byte data field */
482 CY_CANFD_BUFFER_DATA_SIZE_16 = 2u, /**< 16 byte data field */
483 CY_CANFD_BUFFER_DATA_SIZE_20 = 3u, /**< 20 byte data field */
484 CY_CANFD_BUFFER_DATA_SIZE_24 = 4u, /**< 24 byte data field */
485 CY_CANFD_BUFFER_DATA_SIZE_32 = 5u, /**< 32 byte data field */
486 CY_CANFD_BUFFER_DATA_SIZE_48 = 6u, /**< 48 byte data field */
487 CY_CANFD_BUFFER_DATA_SIZE_64 = 7u /**< 64 byte data field */
488 } cy_en_canfd_buffer_data_size_t;
489
490 /** CAN FD Rx FIFO operating mode */
491 typedef enum
492 {
493 CY_CANFD_FIFO_MODE_BLOCKING = 0u, /**< FIFO blocking mode */
494 CY_CANFD_FIFO_MODE_OVERWRITE = 1u /**< FIFO overwrite mode */
495 } cy_en_canfd_fifo_mode_t;
496
497 /** CAN FD accept non matching frames */
498 typedef enum
499 {
500 CY_CANFD_ACCEPT_IN_RXFIFO_0 = 0u, /**< Accept in Rx FIFO 0 */
501 CY_CANFD_ACCEPT_IN_RXFIFO_1 = 1u, /**< Accept in Rx FIFO 1 */
502 CY_CANFD_REJECT_NON_MATCHING = 2u /**< Reject the frames */
503 } cy_en_accept_non_matching_frames_t;
504
505 /** ID Filter element configuration type */
506 typedef enum
507 {
508 CY_CANFD_ID_FILTER_ELEMNT_CONFIG_DISABLE_FILETER_ELEMENT = 0x00u, /**< Disable filter element */
509 CY_CANFD_ID_FILTER_ELEMNT_CONFIG_STORE_RXFIFO0 = 0x01u, /**< Store in Rx FIFO 0, if filter matches */
510 CY_CANFD_ID_FILTER_ELEMNT_CONFIG_STORE_RXFIFO1 = 0x02u, /**< Store in Rx FIFO 1, if filter matches */
511 CY_CANFD_ID_FILTER_ELEMNT_CONFIG_REJECT_ID = 0x03u, /**< Reject ID if filter matches */
512 CY_CANFD_ID_FILTER_ELEMNT_CONFIG_SET_PRIORIY = 0x04u, /**< Set priority if filter matches */
513 CY_CANFD_ID_FILTER_ELEMNT_CONFIG_SET_PIORITY_STORE_RXFIFO0 = 0x05u, /**< Set priority and store in FIFO 0,
514 * if filter matches
515 */
516 CY_CANFD_ID_FILTER_ELEMNT_CONFIG_SET_PIORITY_STORE_RXFIFO1 = 0x06u, /**< Set priority and store in FIFO 1,
517 * if filter matches
518 */
519 CY_CANFD_ID_FILTER_ELEMNT_CONFIG_STORE_RXBUFF_OR_DEBUGMSG = 0x07u /**< Store into Rx Buffer or as debug message,
520 * configuration of SFT[1:0] ignored
521 */
522 }cy_en_canfd_id_filter_element_config_t;
523
524 /** Standard ID filter type */
525 typedef enum
526 {
527 CY_CANFD_STD_ID_FILTER_TYPE_RANGE = 0x00u, /**< The Range filter from SFID1 to SFID2 (SFID2 = SFID1) */
528 CY_CANFD_STD_ID_FILTER_TYPE_DUAL = 0x01u, /**< The Dual ID filter for SFID1 or SFID2 */
529 CY_CANFD_STD_ID_FILTER_TYPE_CLASSIC = 0x02u /**< The Classic filter: SFID1 = filter, SFID2 = mask */
530 }cy_en_canfd_std_id_filter_type_t;
531
532 /** Extended ID filter type */
533 typedef enum
534 {
535 CY_CANFD_EXT_ID_FILTER_TYPE_RANGE_AND_MASK = 0x00u, /**< The range filter from EFID1 to EFID2 (EFID2 = EFID1) */
536 CY_CANFD_EXT_ID_FILTER_TYPE_DUAL = 0x01u, /**< The dual ID filter for EFID1 or EFID2 */
537 CY_CANFD_EXT_ID_FILTER_TYPE_CLASSIC = 0x02u, /**< The classic filter: EFID1 = filter, EFID2 = mask */
538 CY_CANFD_EXT_ID_FILTER_TYPE_RANGE = 0x03u /**< The range filter from EFID1 to EFID2 (EFID2 = EFID1),
539 * XIDAM mask not applied
540 */
541 }cy_en_canfd_ext_id_filter_type_t;
542
543 /** Type for indication of the received frame (Remote Transmission Request) */
544 typedef enum
545 {
546 CY_CANFD_RTR_DATA_FRAME = 0x00u, /**< The received frame is a data frame */
547 CY_CANFD_RTR_REMOTE_FRAME = 0x01u /**< The received frame is a remote frame */
548 }cy_en_canfd_rtr_t;
549
550 /** Extended Identifier type (whether the received frame has a standard or extended identifier) */
551 typedef enum
552 {
553 CY_CANFD_XTD_STANDARD_ID = 0x00u, /**< The 11-bit standard identifier */
554 CY_CANFD_XTD_EXTENDED_ID = 0x01u /**< The 29-bit extended identifier */
555 }cy_en_canfd_xtd_t;
556
557 /** Error State Indicator type */
558 typedef enum
559 {
560 CY_CANFD_ESI_ERROR_ACTIVE = 0x00u, /**< The transmitting node is error active */
561 CY_CANFD_ESI_ERROR_PASSIVE = 0x01u /**< The transmitting node is error passive */
562 }cy_en_canfd_esi_t;
563
564 /** FD Format type */
565 typedef enum
566 {
567 CY_CANFD_FDF_STANDARD_FRAME = 0x00u, /**< The standard frame format */
568 CY_CANFD_FDF_CAN_FD_FRAME = 0x01u /**< The CAN FD frame format (new DLC-coding and CRC) */
569 }cy_en_canfd_fdf_t;
570
571 /** Accepted Non-matching Frame type */
572 typedef enum
573 {
574 CY_CANFD_ANMF_MATCH_FILTER = 0x00u, /**< The received frame matching filter index FIDX */
575 CY_CANFD_ANMF_NOT_MATCH_FILTER = 0x01u /**< The received frame did not match any Rx filter element */
576 }cy_en_canfd_anmf_t;
577
578 /** Standard Filter Element Configuration type */
579 typedef enum
580 {
581 CY_CANFD_SFEC_DISABLE = 0x00u, /**< Disable the filter element */
582 CY_CANFD_SFEC_STORE_RX_FIFO_0 = 0x01u, /**< Store in Rx FIFO 0 if the filter matches */
583 CY_CANFD_SFEC_STORE_RX_FIFO_1 = 0x02u, /**< Store in Rx FIFO 1 if the filter matches */
584 CY_CANFD_SFEC_REJECT_ID = 0x03u, /**< Reject ID if the filter matches */
585 CY_CANFD_SFEC_SET_PRIORITY = 0x04u, /**< Set priority if the filter matches */
586 CY_CANFD_SFEC_SET_PRIORITY_STORE_FIFO_0 = 0x05u, /**< Set priority and store in FIFO 0 if the filter matches */
587 CY_CANFD_SFEC_SET_PRIORITY_STORE_FIFO_1 = 0x06u, /**< Set priority and store in FIFO 1 if filter matches */
588 CY_CANFD_SFEC_STORE_RX_BUFFER = 0x07u /**< Store into Rx Buffer or as debug message,
589 * configuration of SFT[1:0] ignored
590 */
591 }cy_en_canfd_sfec_t;
592
593 /** Standard Filter Type */
594 typedef enum
595 {
596 CY_CANFD_SFT_RANGE_SFID1_SFID2 = 0x00u, /**< The range filter from SFID1 to SFID2 (SFID2 >= SFID1) */
597 CY_CANFD_SFT_DUAL_ID = 0x01u, /**< The Dual ID filter for SFID1 or SFID2 */
598 CY_CANFD_SFT_CLASSIC_FILTER = 0x02u, /**< The Classic filter: SFID1 = filter, SFID2 = mask */
599 CY_CANFD_SFT_DISABLED = 0x03u /**< The Filter element disabled */
600 }cy_en_canfd_sft_t;
601
602 /** Extended Filter Element Configuration type */
603 typedef enum
604 {
605 CY_CANFD_EFEC_DISABLE = 0x00u, /**< Disable the filter element */
606 CY_CANFD_EFEC_STORE_RX_FIFO_0 = 0x01u, /**< Store in Rx FIFO 0 if the filter matches */
607 CY_CANFD_EFEC_STORE_RX_FIFO_1 = 0x02u, /**< Store in Rx FIFO 1 if the filter matches */
608 CY_CANFD_EFEC_REJECT_ID = 0x03u, /**< Reject ID if the filter matches */
609 CY_CANFD_EFEC_SET_PRIORITY = 0x04u, /**< Set priority if the filter matches */
610 CY_CANFD_EFEC_SET_PRIORITY_STORE_FIFO_0 = 0x05u, /**< Set priority and store in FIFO 0 if the filter matches */
611 CY_CANFD_EFEC_SET_PRIORITY_STORE_FIFO_1 = 0x06u, /**< Set priority and store in FIFO 1 if filter matches */
612 CY_CANFD_EFEC_STORE_RX_BUFFER = 0x07u /**< Store into Rx Buffer or as debug message,
613 * configuration of EFT[1:0] ignored
614 */
615 }cy_en_canfd_efec_t;
616
617 /** Extended Filter Type */
618 typedef enum
619 {
620 CY_CANFD_EFT_RANGE_EFID1_EFID2 = 0x00u, /**< The range filter from EFID1 to EFID2 (EFID2 >= EFID1) */
621 CY_CANFD_EFT_DUAL_ID = 0x01u, /**< The Dual ID filter for EFID1 or EFID2 */
622 CY_CANFD_EFT_CLASSIC_FILTER = 0x02u, /**< The Classic filter: EFID1 = filter, EFID2 = mask */
623 CY_CANFD_EFT_RANGE_EFID1_EFID2_NO_MSK = 0x03u /**< The range filter from EFID1 to EFID2 (EFID2 >= EFID1), XIDAM mask not applied */
624 }cy_en_canfd_eft_t;
625
626 /** Test Mode Type */
627 typedef enum
628 {
629 CY_CANFD_TEST_MODE_DISABLE = 0x00u, /**< The normal operation. Test Mode is disabled */
630 CY_CANFD_TEST_MODE_BUS_MONITORING = 0x01u, /**< The Bus Monitoring Mode */
631 CY_CANFD_TEST_MODE_EXTERNAL_LOOP_BACK = 0x02u, /**< The External Loop Back Mode */
632 CY_CANFD_TEST_MODE_INTERNAL_LOOP_BACK = 0x03u /**< The Internal Loop Back Mode */
633 }cy_stc_canfd_test_mode_t;
634
635 /** Last Error Code and Data Phase Last Error Code Type. \n
636 * Used with Cy_CANFD_GetLastError() for LEC and DLEC fields of the
637 * Protocol Status Register.
638 */
639 typedef enum
640 {
641 CY_CANFD_LEC_NO_ERROR = 0x00u, /**< No error occurred since LEC was reset
642 * by successful reception or transmission.
643 */
644 CY_CANFD_LEC_STUFF_ERROR = 0x01u, /**< More than 5 equal bits in a sequence
645 * occurred in a part of a received message
646 */
647 CY_CANFD_LEC_FORM_ERROR = 0x02u, /**< A fixed format part of a received frame
648 * has the wrong format
649 */
650 CY_CANFD_LEC_ACK_ERROR = 0x03u, /**< The message this CAN FD Core transmitted
651 * was not acknowledged by another node
652 */
653 CY_CANFD_LEC_BIT1_ERROR = 0x04u, /**< While trying to send a recessive bit (1)
654 * a dominant level (0) was sampled
655 */
656 CY_CANFD_LEC_BIT0_ERROR = 0x05u, /**< While trying to send a dominant bit (0)
657 * a recessive level (1) was sampled
658 */
659 CY_CANFD_LEC_CRC_ERROR = 0x06u, /**< The CRC checksum was incorrect */
660 CY_CANFD_LEC_NO_CHANGE = 0x07u /**< No CAN bus event was detected since the
661 * last CPU read access to the Protocol
662 * Status Register
663 */
664 }cy_en_canfd_LEC_t;
665
666 /** Bus Activity State field of the PSR
667 * Used with Cy_CANFD_GetLastError() for ACT field of the
668 * Protocol Status Register. */
669 typedef enum
670 {
671 CY_CANFD_PSR_ACT_SYNC = 0x00u, /**< The node is synchronizing on CAN communication */
672 CY_CANFD_PSR_ACT_IDLE = 0x01u, /**< The node is neither receiver nor transmitter */
673 CY_CANFD_PSR_ACT_RX = 0x02u, /**< The node is operating as receiver */
674 CY_CANFD_PSR_ACT_TX = 0x03u /**< The node is operating as transmitter */
675 }cy_en_canfd_PSR_ACT_t;
676
677 /** \} group_canfd_enums */
678
679 /** \cond PARAM_CHECK_MACROS */
680
681 #define CY_CANFD_CHANNEL_MAX_CNT (8U)
682 #define CY_CANFD_IS_CHANNEL_VALID(id) ((CY_CANFD_CHANNEL_MAX_CNT - 1U) >= (id))
683 #define CY_CANFD_IS_CHS_MASK_VALID(channels) (0U == ((channels) & (uint32_t)~CANFD_CTL_STOP_REQ_Msk))
684 #define CY_CANFD_NOM_PRESCALER_MAX (511U)
685 #define CY_CANFD_IS_NOM_PRESCALER_VALID(nbrp) ((CY_CANFD_NOM_PRESCALER_MAX) >= (nbrp))
686 #define CY_CANFD_IS_NOM_TIME_SEG_1_VALID(ntseg1) (0U < (ntseg1))
687 #define CY_CANFD_NOM_TIME_SEG_2_MAX (127U)
688 #define CY_CANFD_IS_NOM_TIME_SEG_2_VALID(ntseg2) (((CY_CANFD_NOM_TIME_SEG_2_MAX) >= (ntseg2)) && (0U < (ntseg2)))
689 #define CY_CANFD_NOM_SYNC_JUMP_WIDTH_MAX (127U)
690 #define CY_CANFD_IS_NOM_SYNC_JUMP_WIDTH_VALID(nsjw) ((CY_CANFD_NOM_SYNC_JUMP_WIDTH_MAX) >= (nsjw))
691 #define CY_CANFD_DAT_PRESCALER_MAX (31U)
692 #define CY_CANFD_IS_DAT_PRESCALER_VALID(dbrp) ((CY_CANFD_DAT_PRESCALER_MAX) >= (dbrp))
693 #define CY_CANFD_DAT_TIME_SEG_1_MAX (31U)
694 #define CY_CANFD_IS_DAT_TIME_SEG_1_VALID(dtseg1) ((CY_CANFD_DAT_TIME_SEG_1_MAX) >= (dtseg1))
695 #define CY_CANFD_DAT_TIME_SEG_2_MAX (15U)
696 #define CY_CANFD_IS_DAT_TIME_SEG_2_VALID(dtseg2) ((CY_CANFD_DAT_TIME_SEG_2_MAX) >= (dtseg2))
697 #define CY_CANFD_DAT_SYNC_JUMP_WIDTH_MAX (15)
698 #define CY_CANFD_IS_DAT_SYNC_JUMP_WIDTH_VALID(dsjw) ((CY_CANFD_DAT_SYNC_JUMP_WIDTH_MAX) >= (dsjw))
699 #define CY_CANFD_IS_ILE_MASK_VALID(intmsk) (0U == ((intmsk) & (uint32_t)~(CANFD_CH_M_TTCAN_ILE_EINT0_Msk |\
700 CANFD_CH_M_TTCAN_ILE_EINT1_Msk)))
701 #define CY_CANFD_TDCO_MAX (0x7FU)
702 #define CY_CANFD_IS_TDCO_VALID(tdco) ((CY_CANFD_TDCO_MAX) >= (tdco))
703 #define CY_CANFD_TDCF_MAX (0x7FU)
704 #define CY_CANFD_IS_TDCF_VALID(tdcf) ((CY_CANFD_TDCF_MAX) >= (tdcf))
705 #define CY_CANFD_SID_FILTERS_MAX_CNT (128U)
706 #define CY_CANFD_IS_SID_FILTERS_VALID(num) ((CY_CANFD_SID_FILTERS_MAX_CNT) >= (num))
707 #define CY_CANFD_XID_FILTERS_MAX_CNT (64U)
708 #define CY_CANFD_IS_XID_FILTERS_VALID(num) ((CY_CANFD_XID_FILTERS_MAX_CNT) >= (num))
709 #define CY_CANFD_SFID_MAX (0x7FFU)
710 #define CY_CANFD_IS_SFID_VALID(sfid) ((CY_CANFD_SFID_MAX) >= (sfid))
711 #define CY_CANFD_IS_SFEC_VALID(sfec) ((CY_CANFD_SFEC_DISABLE == (sfec)) || \
712 (CY_CANFD_SFEC_STORE_RX_FIFO_0 == (sfec)) || \
713 (CY_CANFD_SFEC_STORE_RX_FIFO_1 == (sfec)) || \
714 (CY_CANFD_SFEC_REJECT_ID == (sfec)) || \
715 (CY_CANFD_SFEC_SET_PRIORITY == (sfec)) || \
716 (CY_CANFD_SFEC_SET_PRIORITY_STORE_FIFO_0 == (sfec)) || \
717 (CY_CANFD_SFEC_SET_PRIORITY_STORE_FIFO_1 == (sfec)) || \
718 (CY_CANFD_SFEC_STORE_RX_BUFFER == (sfec)))
719 #define CY_CANFD_IS_SFT_VALID(sft) ((CY_CANFD_SFT_RANGE_SFID1_SFID2 == (sft)) || \
720 (CY_CANFD_SFT_DUAL_ID == (sft)) || \
721 (CY_CANFD_SFT_CLASSIC_FILTER == (sft)) || \
722 (CY_CANFD_SFT_DISABLED == (sft)))
723 #define CY_CANFD_EFID_MAX (0x1FFFFFFFUL)
724 #define CY_CANFD_IS_EFID_VALID(efid) ((CY_CANFD_EFID_MAX) >= (efid))
725 #define CY_CANFD_IS_EFEC_VALID(efec) ((CY_CANFD_EFEC_DISABLE == (efec)) || \
726 (CY_CANFD_EFEC_STORE_RX_FIFO_0 == (efec)) || \
727 (CY_CANFD_EFEC_STORE_RX_FIFO_1 == (efec)) || \
728 (CY_CANFD_EFEC_REJECT_ID == (efec)) || \
729 (CY_CANFD_EFEC_SET_PRIORITY == (efec)) || \
730 (CY_CANFD_EFEC_SET_PRIORITY_STORE_FIFO_0 == (efec)) || \
731 (CY_CANFD_EFEC_SET_PRIORITY_STORE_FIFO_1 == (efec)) || \
732 (CY_CANFD_EFEC_STORE_RX_BUFFER == (efec)))
733 #define CY_CANFD_IS_EFT_VALID(eft) ((CY_CANFD_EFT_RANGE_EFID1_EFID2 == (eft)) || \
734 (CY_CANFD_EFT_DUAL_ID == (eft)) || \
735 (CY_CANFD_EFT_CLASSIC_FILTER == (eft)) || \
736 (CY_CANFD_EFT_RANGE_EFID1_EFID2_NO_MSK == (eft)))
737
738 #define CY_CANFD_IS_ACCEPT_MATCHING_VALID(match) ((CY_CANFD_ACCEPT_IN_RXFIFO_0 == (match)) || \
739 (CY_CANFD_ACCEPT_IN_RXFIFO_1 == (match)) || \
740 (CY_CANFD_REJECT_NON_MATCHING == (match)))
741
742 #define CY_CANFD_IS_BUF_DATA_SIZE_VALID(size, mode) ((mode) ? \
743 ((CY_CANFD_BUFFER_DATA_SIZE_8 == (size)) || \
744 (CY_CANFD_BUFFER_DATA_SIZE_12 == (size)) || \
745 (CY_CANFD_BUFFER_DATA_SIZE_16 == (size)) || \
746 (CY_CANFD_BUFFER_DATA_SIZE_20 == (size)) || \
747 (CY_CANFD_BUFFER_DATA_SIZE_24 == (size)) || \
748 (CY_CANFD_BUFFER_DATA_SIZE_32 == (size)) || \
749 (CY_CANFD_BUFFER_DATA_SIZE_48 == (size)) || \
750 (CY_CANFD_BUFFER_DATA_SIZE_64 == (size))) : \
751 (CY_CANFD_BUFFER_DATA_SIZE_8 == (size)))
752
753 #define CY_CANFD_IS_FIFO_MODE_VALID(mode) ((CY_CANFD_FIFO_MODE_BLOCKING == (mode)) || \
754 (CY_CANFD_FIFO_MODE_OVERWRITE == (mode)))
755
756 #define CY_CANFD_FIFO_MAX_CNT (64U)
757 #define CY_CANFD_IS_FIFO_NUM_VALID(num) ((CY_CANFD_FIFO_MAX_CNT) >= (num))
758
759 #define CY_CANFD_WATERMARK_MAX (127U)
760 #define CY_CANFD_IS_WATERMARK_VALID(watermark) ((CY_CANFD_WATERMARK_MAX) >= (watermark))
761
762 #define CY_CANFD_IS_RX_BUF_NUM_VALID(num) ((CY_CANFD_MESSAGE_RX_BUFFERS_MAX_CNT) >= (num))
763 #define CY_CANFD_IS_TX_BUF_NUM_VALID(num) ((CY_CANFD_MESSAGE_TX_BUFFERS_MAX_CNT) >= (num))
764
765 #define CY_CANFD_ID_MAX (0X1FFFFFFFUL)
766 #define CY_CANFD_IS_ID_VALID(id) ((CY_CANFD_ID_MAX) >= (id))
767 #define CY_CANFD_IS_RTR_VALID(rtr) ((CY_CANFD_RTR_DATA_FRAME == (rtr)) || \
768 (CY_CANFD_RTR_REMOTE_FRAME == (rtr)))
769 #define CY_CANFD_IS_XTD_VALID(xtd) ((CY_CANFD_XTD_STANDARD_ID == (xtd)) || \
770 (CY_CANFD_XTD_EXTENDED_ID == (xtd)))
771 #define CY_CANFD_IS_ESI_VALID(esi) ((CY_CANFD_ESI_ERROR_ACTIVE == (esi)) || \
772 (CY_CANFD_ESI_ERROR_PASSIVE == (esi)))
773
774 #define CY_CANFD_RXTS_MAX (0XFFFFUL)
775 #define CY_CANFD_IS_RXTS_VALID(rxts) ((CY_CANFD_RXTS_MAX) >= (rxts))
776 #define CY_CANFD_DLC_MAX (0XFFFFUL)
777 #define CY_CANFD_IS_DLC_VALID(dlc) ((CY_CANFD_DLC_MAX) >= (dlc))
778 #define CY_CANFD_IS_FDF_VALID(fdf) ((CY_CANFD_FDF_STANDARD_FRAME == (fdf)) || \
779 (CY_CANFD_FDF_CAN_FD_FRAME == (fdf)))
780 #define CY_CANFD_FIDX_MAX (127U)
781 #define CY_CANFD_IS_FIDX_VALID(fidx) ((CY_CANFD_FIDX_MAX) >= (fidx))
782 #define CY_CANFD_IS_ANMF_VALID(anmf) ((CY_CANFD_ANMF_MATCH_FILTER == (anmf)) || \
783 (CY_CANFD_ANMF_NOT_MATCH_FILTER == (anmf)))
784
785 #define CY_CANFD_TX_BUFFER_MM_MAX (255U)
786 #define CY_CANFD_IS_TX_BUFFER_MM_VALID(mm) ((CY_CANFD_TX_BUFFER_MM_MAX) >= (mm))
787
788 /** \endcond */
789
790
791 /***************************************
792 * Configuration Structures
793 ***************************************/
794
795 /**
796 * \addtogroup group_canfd_data_structures
797 * \{
798 */
799
800 /** R0 register */
801 typedef struct
802 {
803 volatile uint32_t id; /**< Identifier */
804 volatile cy_en_canfd_rtr_t rtr; /**< Remote transmission request */
805 volatile cy_en_canfd_xtd_t xtd; /**< Extended identifier */
806 volatile cy_en_canfd_esi_t esi; /**< Error state indicator */
807 } cy_stc_canfd_r0_t;
808
809 /** R1 register */
810 typedef struct
811 {
812 volatile uint32_t rxts; /**< Rx timestamp */
813 volatile uint32_t dlc; /**< Data length code */
814 volatile bool brs; /**< Bit rate switch */
815 volatile cy_en_canfd_fdf_t fdf; /**< Extended data length */
816 volatile uint32_t fidx; /**< Filter index */
817 volatile cy_en_canfd_anmf_t anmf; /**< Accepted non-matching frame */
818 } cy_stc_canfd_r1_t;
819
820 /** Rx buffer */
821 typedef struct
822 {
823 cy_stc_canfd_r0_t *r0_f; /**< Rx buffer element for R0. See \ref cy_stc_canfd_r0_t */
824 cy_stc_canfd_r1_t *r1_f; /**< Rx buffer element for R1. See \ref cy_stc_canfd_r1_t */
825 uint32_t *data_area_f; /**< Rx buffer element for Rn */
826 } cy_stc_canfd_rx_buffer_t;
827
828 /** T0 register */
829 typedef struct
830 {
831 volatile uint32_t id; /**< Identifier */
832 volatile cy_en_canfd_rtr_t rtr; /**< Remote transmission request. 0:data frame, 1:remote frame */
833 volatile cy_en_canfd_xtd_t xtd; /**< Extended identifier. 0:11-bit standard identifier, 1:29-bit
834 * extended identifier
835 */
836 volatile cy_en_canfd_esi_t esi; /**< Error state indicator */
837 } cy_stc_canfd_t0_t;
838
839 /** T1 register */
840 typedef struct
841 {
842 volatile uint32_t dlc; /**< Data length code */
843 volatile bool brs; /**< Bit rate switching */
844 volatile cy_en_canfd_fdf_t fdf; /**< FD Format */
845 volatile bool efc; /**< Event FIFO control. false: Do not store Tx events, true: Store Tx events */
846 volatile uint32_t mm; /**< Message marker */
847 } cy_stc_canfd_t1_t;
848
849 /** Tx buffer register */
850 typedef struct
851 {
852 cy_stc_canfd_t0_t *t0_f; /**< Tx buffer element for T0. See \ref cy_stc_canfd_t0_t */
853 cy_stc_canfd_t1_t *t1_f; /**< Tx buffer element for T1. See \ref cy_stc_canfd_t1_t */
854 uint32_t *data_area_f; /**< Tx buffer element for Tn */
855 } cy_stc_canfd_tx_buffer_t;
856
857 /** Message ID filter register */
858 typedef struct
859 {
860 volatile uint32_t sfid2; /**< Standard filter ID 2 */
861 volatile uint32_t sfid1; /**< Standard filter ID 1 */
862 volatile cy_en_canfd_sfec_t sfec; /**< Standard filter element configuration */
863 volatile cy_en_canfd_sft_t sft; /**< Standard filter Type */
864 } cy_stc_id_filter_t;
865
866 /** F0 register */
867 typedef struct
868 {
869 volatile uint32_t efid1; /**< Extended filter ID 1 */
870 volatile cy_en_canfd_efec_t efec; /**< Extended filter element configuration */
871 } cy_stc_canfd_f0_t;
872
873 /** F1 register */
874 typedef struct
875 {
876 volatile uint32_t efid2; /**< Extended filter ID 2 */
877 volatile cy_en_canfd_eft_t eft; /**< Extended filter type */
878 } cy_stc_canfd_f1_t;
879
880 /** Extended message ID filter register */
881 typedef struct
882 {
883 const cy_stc_canfd_f0_t *f0_f; /**< Extended message ID filter element for F0. See \ref cy_stc_canfd_f0_t */
884 const cy_stc_canfd_f1_t *f1_f; /**< Extended message ID filter element for F1. See \ref cy_stc_canfd_f1_t */
885 } cy_stc_extid_filter_t;
886
887 /** CAN FD bitrate */
888 typedef struct
889 {
890 uint16_t prescaler; /**< Baud rate prescaler */
891 uint8_t timeSegment1; /**< Time segment before sample point */
892 uint8_t timeSegment2; /**< Time segment after sample point */
893 uint8_t syncJumpWidth; /**< Synchronization jump width */
894 } cy_stc_canfd_bitrate_t;
895
896 /** CAN FD transceiver delay compensation offset configuration */
897 typedef struct
898 {
899 bool tdcEnabled; /**< Transceiver delay compensation enabled */
900 uint8_t tdcOffset; /**< Transmitter delay compensation offset */
901 uint8_t tdcFilterWindow; /**< Transmitter delay compensation filter window length */
902 } cy_stc_canfd_transceiver_delay_compensation_t;
903
904 /** Standard ID filter configuration */
905 typedef struct
906 {
907 uint8_t numberOfSIDFilters; /**< Number Of standard ID filters */
908 const cy_stc_id_filter_t *sidFilter; /**< Message ID Filter register */
909 } cy_stc_canfd_sid_filter_config_t;
910
911 /** Extended ID filter configuration */
912 typedef struct
913 {
914 uint8_t numberOfEXTIDFilters; /**< Number Of extended ID filters */
915 const cy_stc_extid_filter_t *extidFilter; /**< Extended message ID filter register */
916 uint32_t extIDANDMask; /**< Extended ID AND Mask */
917 } cy_stc_canfd_extid_filter_config_t;
918
919 /** Global filter configuration */
920 typedef struct
921 {
922 cy_en_accept_non_matching_frames_t nonMatchingFramesStandard; /**< Non matching frames standard */
923 cy_en_accept_non_matching_frames_t nonMatchingFramesExtended; /**< Non matching frames extended */
924 bool rejectRemoteFramesStandard; /**< Reject remote frames standard */
925 bool rejectRemoteFramesExtended; /**< Reject remote frames extended */
926 } cy_stc_canfd_global_filter_config_t;
927
928 /** Rx FIFO configuration */
929 typedef struct
930 {
931 cy_en_canfd_fifo_mode_t mode; /**< CAN FD Rx FIFO operating mode */
932 uint8_t watermark; /**< Watermark */
933 uint8_t numberOfFIFOElements; /**< Number Of FIFO elements. Note:
934 * The Rx FIFO size must be greater than 1 when
935 * FIFO Top Pointer Logic is enabled.
936 */
937 bool topPointerLogicEnabled; /**< Top pointer logic enabled */
938 }cy_en_canfd_fifo_config_t;
939
940 /**
941 * Message transmission complete callback function (cy_canfd_tx_msg_func_ptr_t).
942 * Signals a successful completed transmission.
943 * Triggered with
944 * \ref CY_CANFD_TRANSMISSION_COMPLETE
945 * interrupt event
946 */
947 typedef void (*cy_canfd_tx_msg_func_ptr_t)( void );
948
949 /**
950 * The message reception callback function for message received in the dedicated
951 * Rx Buffer or in Rx FIFO (cy_canfd_rx_msg_func_ptr_t)
952 *
953 * Signals that CAN FD has received a new message.
954 * - If message was received in the dedicated Rx Buffer (0 - 63), rxFIFOMsg is False
955 * and u8MsgBufOrFIFONum indicates the Rx Buffer number.
956 *
957 * - If message was received in Rx FIFO (0/1),
958 * rxFIFOMsg is True and u8MsgBufOrFIFONum indicates the FIFO number.
959 *
960 * Triggered with corresponding \n
961 * \ref CY_CANFD_RX_BUFFER_NEW_MESSAGE \n
962 * \ref CY_CANFD_RX_FIFO_0_NEW_MESSAGE \n
963 * \ref CY_CANFD_RX_FIFO_1_NEW_MESSAGE \n
964 * interrupt events.
965 */
966 typedef void (*cy_canfd_rx_msg_func_ptr_t)(bool rxFIFOMsg,
967 uint8_t msgBufOrRxFIFONum,
968 cy_stc_canfd_rx_buffer_t* basemsg
969 );
970
971 /**
972 * The error callback function (cy_canfd_error_func_ptr_t).
973 * Signals that the CAN bus status changed or an error occurred. \n
974 * Triggered with \n
975 * \ref CY_CANFD_RX_FIFO_0_WATERMARK_REACHED \n
976 * \ref CY_CANFD_RX_FIFO_0_FULL \n
977 * \ref CY_CANFD_RX_FIFO_0_MSG_LOST \n
978 * \ref CY_CANFD_RX_FIFO_1_WATERMARK_REACHED \n
979 * \ref CY_CANFD_RX_FIFO_1_FULL \n
980 * \ref CY_CANFD_RX_FIFO_1_MSG_LOST \n
981 * \ref CY_CANFD_TX_FIFO_1_WATERMARK_REACHED \n
982 * \ref CY_CANFD_TX_FIFO_1_FULL \n
983 * \ref CY_CANFD_TX_FIFO_1_MSG_LOST \n
984 * \ref CY_CANFD_TIMESTAMP_WRAPAROUND \n
985 * \ref CY_CANFD_MRAM_ACCESS_FAILURE \n
986 * \ref CY_CANFD_TIMEOUT_OCCURRED \n
987 * \ref CY_CANFD_BIT_ERROR_CORRECTED \n
988 * \ref CY_CANFD_BIT_ERROR_UNCORRECTED \n
989 * \ref CY_CANFD_ERROR_LOG_OVERFLOW \n
990 * \ref CY_CANFD_ERROR_PASSIVE \n
991 * \ref CY_CANFD_WARNING_STATUS \n
992 * \ref CY_CANFD_BUS_OFF_STATUS \n
993 * \ref CY_CANFD_WATCHDOG_INTERRUPT \n
994 * \ref CY_CANFD_PROTOCOL_ERROR_ARB_PHASE \n
995 * \ref CY_CANFD_PROTOCOL_ERROR_DATA_PHASE \n
996 * \ref CY_CANFD_ACCESS_RESERVED_ADDR \n
997 * interrupt events.
998 */
999 typedef void (*cy_canfd_error_func_ptr_t)(uint32_t errorMask);
1000
1001 /** CAN FD configuration */
1002 typedef struct
1003 {
1004 cy_canfd_tx_msg_func_ptr_t txCallback; /**< Callback function for transmit completed.
1005 * Can be NULL
1006 */
1007 cy_canfd_rx_msg_func_ptr_t rxCallback; /**< Callback function for receive completed.
1008 * Can be NULL
1009 */
1010 cy_canfd_error_func_ptr_t errorCallback; /**< Callback function for CAN related errors.
1011 * Can be NULL
1012 */
1013 bool canFDMode; /**< TRUE:CAN FD mode, FALSE:Classic CAN mode */
1014 const cy_stc_canfd_bitrate_t *bitrate; /**< CAN bitrate setting */
1015 const cy_stc_canfd_bitrate_t *fastBitrate; /**< CAN Fast bitrate setting */
1016 const cy_stc_canfd_transceiver_delay_compensation_t *tdcConfig; /**< CAN transceiver delay compensation setting */
1017
1018 const cy_stc_canfd_sid_filter_config_t *sidFilterConfig; /**< CAN Standard ID filter setting */
1019 const cy_stc_canfd_extid_filter_config_t *extidFilterConfig; /**< CAN Extended ID filter setting */
1020 const cy_stc_canfd_global_filter_config_t *globalFilterConfig; /**< CAN global filter setting */
1021
1022 cy_en_canfd_buffer_data_size_t rxBufferDataSize; /**< Rx Buffer Data Size */
1023 cy_en_canfd_buffer_data_size_t rxFIFO1DataSize; /**< Rx FIFO 1 Data Size */
1024 cy_en_canfd_buffer_data_size_t rxFIFO0DataSize; /**< Rx FIFO 0 Data Size */
1025 cy_en_canfd_buffer_data_size_t txBufferDataSize; /**< Tx Buffer Data Size */
1026
1027 const cy_en_canfd_fifo_config_t *rxFIFO0Config; /**< Rx FIFO 0 configuration */
1028 const cy_en_canfd_fifo_config_t *rxFIFO1Config; /**< Rx FIFO 1 configuration */
1029 uint8_t noOfRxBuffers; /**< Number of Rx Buffers (Max 64) */
1030 uint8_t noOfTxBuffers; /**< Number of Rx Buffers (Max 32) */
1031 uint32_t messageRAMaddress; /**< The start address of Message RAM for the channel */
1032 uint32_t messageRAMsize; /**< The size in bytes of Message RAM for the channel */
1033 } cy_stc_canfd_config_t;
1034
1035
1036 /**
1037 * CAN FD interrupt pointer structure. Holds some pointers to callback functions and buffer
1038 */
1039 typedef struct
1040 {
1041 cy_canfd_tx_msg_func_ptr_t canFDTxInterruptFunction; /**< The pointer to transmit interrupt callback */
1042 cy_canfd_rx_msg_func_ptr_t canFDRxInterruptFunction; /**< The pointer to receive interrupt callback
1043 * (dedicated Rx Buffer or RxFIFO without Top pointer logic)
1044 */
1045 cy_canfd_error_func_ptr_t canFDErrorInterruptFunction; /**< The pointer to error interrupt callback */
1046 } cy_stc_canfd_interrupt_handling_t;
1047
1048 /** Context structure */
1049 typedef struct
1050 {
1051 cy_stc_canfd_interrupt_handling_t canFDInterruptHandling; /**< Interrupt callback */
1052 uint32_t messageRAMaddress; /**< The start address of Message RAM for the channel */
1053 uint32_t messageRAMsize; /**< The size in bytes of Message RAM for the channel */
1054 } cy_stc_canfd_context_t;
1055
1056 /** \} group_canfd_data_structures */
1057
1058
1059 /***************************************
1060 * Function Prototypes
1061 ***************************************/
1062
1063 /**
1064 * \addtogroup group_canfd_functions
1065 * \{
1066 */
1067 __STATIC_INLINE void Cy_CANFD_Enable(CANFD_Type *base, uint32_t channelMask);
1068 __STATIC_INLINE cy_en_canfd_status_t Cy_CANFD_Disable(CANFD_Type *base, uint32_t channelMask);
1069 __STATIC_INLINE void Cy_CANFD_EnableMRAM(CANFD_Type *base, uint32_t channelMask, uint16_t delay);
1070 __STATIC_INLINE cy_en_canfd_status_t Cy_CANFD_DisableMRAM(CANFD_Type *base);
1071 __STATIC_INLINE void Cy_CANFD_SetBitrate(CANFD_Type *base, uint32_t chan, const cy_stc_canfd_bitrate_t *bitrate);
1072 __STATIC_INLINE void Cy_CANFD_SetFastBitrate(CANFD_Type *base, uint32_t chan, const cy_stc_canfd_bitrate_t *fastBitrate);
1073 void Cy_CANFD_SidFilterSetup(CANFD_Type const *base, uint32_t chan,
1074 const cy_stc_id_filter_t *filter,
1075 uint32_t index,
1076 cy_stc_canfd_context_t const *context);
1077 void Cy_CANFD_SidFiltersSetup(CANFD_Type const *base, uint32_t chan,
1078 const cy_stc_canfd_sid_filter_config_t *filterConfig,
1079 cy_stc_canfd_context_t const *context);
1080 void Cy_CANFD_XidFilterSetup(CANFD_Type const *base, uint32_t chan,
1081 const cy_stc_extid_filter_t *filter,
1082 uint32_t index,
1083 cy_stc_canfd_context_t const *context);
1084
1085 void Cy_CANFD_XidFiltersSetup(CANFD_Type const *base, uint32_t chan,
1086 const cy_stc_canfd_extid_filter_config_t *filterConfig,
1087 cy_stc_canfd_context_t const *context);
1088 cy_en_canfd_status_t Cy_CANFD_TxBufferConfig(CANFD_Type const *base, uint32_t chan,
1089 const cy_stc_canfd_tx_buffer_t *txBuffer,
1090 uint8_t index,
1091 cy_stc_canfd_context_t const *context);
1092 uint32_t Cy_CANFD_CalcRxBufAdrs(CANFD_Type const *base, uint32_t chan,
1093 uint32_t index,
1094 cy_stc_canfd_context_t const *context);
1095 uint32_t Cy_CANFD_CalcRxFifoAdrs(CANFD_Type const *base, uint32_t chan,
1096 uint32_t fifoNumber,
1097 uint32_t index,
1098 cy_stc_canfd_context_t const *context);
1099 cy_en_canfd_status_t Cy_CANFD_GetRxBuffer(CANFD_Type const *base, uint32_t chan,
1100 const uint32_t bufferAddress,
1101 cy_stc_canfd_rx_buffer_t const *rxBuffer);
1102 cy_en_canfd_status_t Cy_CANFD_GetFIFOTop(CANFD_Type const *base, uint32_t chan,
1103 const uint8_t FIFONumber,
1104 cy_stc_canfd_rx_buffer_t const *rxBuffer);
1105 cy_en_canfd_status_t Cy_CANFD_ExtractMsgFromRXBuffer(CANFD_Type *base, uint32_t chan, bool rxFIFOMsg,
1106 uint8_t msgBufOrRxFIFONum,
1107 cy_stc_canfd_rx_buffer_t const *rxBuffer,
1108 cy_stc_canfd_context_t const *context);
1109 void Cy_CANFD_AckRxBuf(CANFD_Type *base, uint32_t chan, uint32_t bufNum);
1110 void Cy_CANFD_AckRxFifo(CANFD_Type *base, uint32_t chan, uint32_t FIFOnumber);
1111 __STATIC_INLINE cy_en_canfd_status_t Cy_CANFD_ConfigChangesEnable(CANFD_Type *base, uint32_t chan);
1112 __STATIC_INLINE cy_en_canfd_status_t Cy_CANFD_ConfigChangesDisable(CANFD_Type *base, uint32_t chan);
1113 __STATIC_INLINE void Cy_CANFD_TestModeConfig(CANFD_Type *base, uint32_t chan, cy_stc_canfd_test_mode_t testMode);
1114 __STATIC_INLINE void Cy_CANFD_SetTDC(CANFD_Type *base, uint32_t chan,
1115 const cy_stc_canfd_transceiver_delay_compensation_t *tdcConfig);
1116 uint32_t Cy_CANFD_GetLastError(CANFD_Type const *base, uint32_t chan);
1117
1118 /** \} group_canfd_functions */
1119
1120 /**
1121 * \addtogroup group_canfd_functions
1122 * \{
1123 */
1124
1125 void Cy_CANFD_IrqHandler(CANFD_Type *base, uint32_t chan, cy_stc_canfd_context_t const *context);
1126 cy_en_canfd_status_t Cy_CANFD_Init(CANFD_Type *base, uint32_t chan,
1127 const cy_stc_canfd_config_t *config,
1128 cy_stc_canfd_context_t *context);
1129 cy_en_canfd_status_t Cy_CANFD_DeInit(CANFD_Type *base, uint32_t chan, cy_stc_canfd_context_t *context);
1130 cy_en_canfd_status_t Cy_CANFD_TransmitTxBuffer(CANFD_Type *base, uint32_t chan,
1131 uint8_t index);
1132 cy_en_canfd_status_t Cy_CANFD_UpdateAndTransmitMsgBuffer(CANFD_Type *base, uint32_t chan,
1133 const cy_stc_canfd_tx_buffer_t *txBuffer,
1134 uint8_t index,
1135 cy_stc_canfd_context_t const *context);
1136
1137 cy_en_canfd_tx_buffer_status_t Cy_CANFD_GetTxBufferStatus(CANFD_Type const *base, uint32_t chan, uint8_t index);
1138
1139
1140 /** \} group_canfd_functions */
1141
1142 /**
1143 * \addtogroup group_canfd_functions
1144 * \{
1145 */
1146
1147 __STATIC_INLINE uint32_t Cy_CANFD_GetInterruptStatus(CANFD_Type const *base, uint32_t chan);
1148 __STATIC_INLINE void Cy_CANFD_ClearInterrupt(CANFD_Type *base, uint32_t chan, uint32_t status);
1149 __STATIC_INLINE uint32_t Cy_CANFD_GetInterruptMask(CANFD_Type const *base, uint32_t chan);
1150 __STATIC_INLINE void Cy_CANFD_SetInterruptMask(CANFD_Type *base, uint32_t chan, uint32_t interrupt);
1151 __STATIC_INLINE uint32_t Cy_CANFD_GetInterruptLine(CANFD_Type const *base, uint32_t chan);
1152 __STATIC_INLINE void Cy_CANFD_SetInterruptLine(CANFD_Type *base, uint32_t chan, uint32_t interruptLineMask);
1153 __STATIC_INLINE bool Cy_CANFD_IsInterruptLineEnabled(CANFD_Type const *base, uint32_t chan,
1154 uint32_t interruptLineMask);
1155 __STATIC_INLINE void Cy_CANFD_EnableInterruptLine(CANFD_Type *base, uint32_t chan, uint32_t interruptLineMask);
1156
1157 /** \} group_canfd_functions */
1158
1159 /**
1160 * \addtogroup group_canfd_functions
1161 * \{
1162 */
1163
1164 /*******************************************************************************
1165 * Function Name: Cy_CANFD_Enable
1166 ****************************************************************************//**
1167 *
1168 * Enables the CAN FD channels.
1169 *
1170 * \note
1171 * Call Cy_CANFD_Enable before Cy_CANFD_Init.
1172 *
1173 * \param *base
1174 * The CAN FD registers structure pointer.
1175 *
1176 * \param channelMask
1177 * The channel mask (0-0xFF).
1178 *
1179 * \funcusage
1180 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_Enable
1181 *
1182 *******************************************************************************/
Cy_CANFD_Enable(CANFD_Type * base,uint32_t channelMask)1183 __STATIC_INLINE void Cy_CANFD_Enable(CANFD_Type *base, uint32_t channelMask)
1184 {
1185 CY_ASSERT_L2(CY_CANFD_IS_CHS_MASK_VALID(channelMask));
1186
1187 /* Clock Start Request for the channels */
1188 CANFD_CTL(base) = _CLR_SET_FLD32U(CANFD_CTL(base),
1189 CANFD_CTL_STOP_REQ,
1190 ~channelMask);
1191 }
1192
1193
1194 /*******************************************************************************
1195 * Function Name: Cy_CANFD_Disable
1196 ****************************************************************************//**
1197 *
1198 * Disables the CAN FD channels to stop providing clocks to un-used CAN channels
1199 * for power saving with this functionality.
1200 *
1201 * \note
1202 * Call Cy_CANFD_Disable only after Cy_CANFD_DeInit. Do not access the CAN FD
1203 * registers until calling Cy_CANFD_Enable again.
1204 *
1205 * \param *base
1206 * The CAN FD registers structure pointer.
1207 *
1208 * \param channelMask
1209 * The channel mask (0-0xFF).
1210 *
1211 * \funcusage
1212 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_Disable
1213 *
1214 *******************************************************************************/
Cy_CANFD_Disable(CANFD_Type * base,uint32_t channelMask)1215 __STATIC_INLINE cy_en_canfd_status_t Cy_CANFD_Disable(CANFD_Type *base, uint32_t channelMask)
1216 {
1217 cy_en_canfd_status_t ret = CY_CANFD_ERROR_TIMEOUT;
1218 uint32_t retry = CY_CANFD_RETRY_COUNT;
1219
1220 CY_ASSERT_L2(CY_CANFD_IS_CHS_MASK_VALID(channelMask));
1221
1222 /* Clock Stop Request for the channels */
1223 CANFD_CTL(base) = _CLR_SET_FLD32U(CANFD_CTL(base),
1224 CANFD_CTL_STOP_REQ,
1225 channelMask);
1226
1227 /* Wait for Clock Stop Acknowledge for the channel */
1228 while ((retry > 0UL) &&
1229 !(channelMask == (channelMask & CANFD_STATUS(base))))
1230 {
1231 Cy_SysLib_DelayUs(CY_CANFD_STOP_TIMEOUT_US);
1232 retry--;
1233 }
1234
1235 if (retry > 0UL)
1236 {
1237 ret = CY_CANFD_SUCCESS;
1238 }
1239
1240 return ret;
1241 }
1242
1243
1244 /*******************************************************************************
1245 * Function Name: Cy_CANFD_EnableMRAM
1246 ****************************************************************************//**
1247 *
1248 * Switches MRAM on and enables the channels.
1249 *
1250 * \param *base
1251 * The CAN FD registers structure pointer.
1252 *
1253 * \param channelMask
1254 * The channel mask (0-0xFF).
1255 *
1256 * \param delay
1257 * The delay in usec to wait power up time before MRAM can be used.
1258 * Recommended value is 150 CPU cycles or 6 usec for the 25 MHz CPU clock.
1259 *
1260 * \funcusage
1261 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_EnableMRAM
1262 *
1263 *******************************************************************************/
Cy_CANFD_EnableMRAM(CANFD_Type * base,uint32_t channelMask,uint16_t delay)1264 __STATIC_INLINE void Cy_CANFD_EnableMRAM(CANFD_Type *base, uint32_t channelMask, uint16_t delay)
1265 {
1266 CY_ASSERT_L2(CY_CANFD_IS_CHS_MASK_VALID(channelMask));
1267
1268 /* MRAM power on */
1269 CANFD_CTL(base) = _CLR_SET_FLD32U(CANFD_CTL(base), CANFD_CTL_MRAM_OFF, 0UL);
1270
1271 /* Wait a certain power up time before MRAM can be used,
1272 * i.e. before STOP_REQ can be de-asserted (before Clock Stop reset)
1273 */
1274 Cy_SysLib_DelayUs(delay);
1275
1276 /* Reset the Clock Stop request */
1277 Cy_CANFD_Enable(base, channelMask);
1278 }
1279
1280
1281 /*******************************************************************************
1282 * Function Name: Cy_CANFD_DisableMRAM
1283 ****************************************************************************//**
1284 *
1285 * Disables the channels and switches MRAM off.
1286 *
1287 * \param *base
1288 * The CAN FD registers structure pointer.
1289 *
1290 * \funcusage
1291 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_DisableMRAM
1292 *
1293 *******************************************************************************/
Cy_CANFD_DisableMRAM(CANFD_Type * base)1294 __STATIC_INLINE cy_en_canfd_status_t Cy_CANFD_DisableMRAM(CANFD_Type *base)
1295 {
1296 cy_en_canfd_status_t ret = CY_CANFD_ERROR_TIMEOUT;
1297
1298 /* Request Clock Stop for all channels */
1299 ret = Cy_CANFD_Disable(base, ((1UL << CY_CANFD_CHANNELS_NUM) - 1UL));
1300
1301 /* MRAM power down */
1302 CANFD_CTL(base) = _CLR_SET_FLD32U(CANFD_CTL(base),
1303 CANFD_CTL_MRAM_OFF,
1304 1UL);
1305
1306 return ret;
1307 }
1308
1309
1310 /*******************************************************************************
1311 * Function Name: Cy_CANFD_SetBitrate
1312 ****************************************************************************//**
1313 *
1314 * Sets Nominal Bit Timing and Prescaler Register parameters:
1315 * -Nominal Time segment after sample point;
1316 * -Nominal Time segment before sample point;
1317 * -Nominal Baud Rate Prescaler;
1318 * -Nominal Synchronization Jump Width.
1319 *
1320 * \note Before calling the Cy_CANFD_SetBitrate() function,
1321 * the Cy_CANFD_ConfigChangesEnable() function must be called to set
1322 * bits CCCR.CCE and CCCR.INIT. It is recommended to call
1323 * Cy_CANFD_ConfigChangesDisable() after updating Bitrate.
1324 *
1325 * \param *base
1326 * The pointer to a CAN FD instance.
1327 *
1328 * \param chan
1329 * The CAN FD channel number.
1330 *
1331 * \param *bitrate \ref cy_stc_canfd_bitrate_t
1332 *
1333 * \funcusage
1334 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_SetBitrate
1335 *
1336 *******************************************************************************/
Cy_CANFD_SetBitrate(CANFD_Type * base,uint32_t chan,const cy_stc_canfd_bitrate_t * bitrate)1337 __STATIC_INLINE void Cy_CANFD_SetBitrate(CANFD_Type *base, uint32_t chan, const cy_stc_canfd_bitrate_t *bitrate)
1338 {
1339 if (NULL != bitrate)
1340 {
1341 CY_ASSERT_L2(CY_CANFD_IS_NOM_PRESCALER_VALID(bitrate->prescaler));
1342 CY_ASSERT_L2(CY_CANFD_IS_NOM_TIME_SEG_1_VALID(bitrate->timeSegment1));
1343 CY_ASSERT_L2(CY_CANFD_IS_NOM_TIME_SEG_2_VALID(bitrate->timeSegment2));
1344 CY_ASSERT_L2(CY_CANFD_IS_NOM_SYNC_JUMP_WIDTH_VALID(bitrate->syncJumpWidth));
1345
1346 CANFD_NBTP(base, chan) = _VAL2FLD(CANFD_CH_M_TTCAN_NBTP_NTSEG2, bitrate->timeSegment2) |
1347 _VAL2FLD(CANFD_CH_M_TTCAN_NBTP_NTSEG1, bitrate->timeSegment1) |
1348 _VAL2FLD(CANFD_CH_M_TTCAN_NBTP_NBRP, bitrate->prescaler) |
1349 _VAL2FLD(CANFD_CH_M_TTCAN_NBTP_NSJW, bitrate->syncJumpWidth);
1350 }
1351 }
1352
1353
1354 /*******************************************************************************
1355 * Function Name: Cy_CANFD_SetFastBitrate
1356 ****************************************************************************//**
1357 *
1358 * Sets Data Bit Timing and Prescaler Register parameters for data:
1359 * -Data Time segment after sample point;
1360 * -Data Time segment before sample point;
1361 * -Data Baud Rate Prescaler;
1362 * -Data Synchronization Jump Width.
1363 *
1364 * \note Before calling the Cy_CANFD_SetFastBitrate() function,
1365 * the Cy_CANFD_ConfigChangesEnable() function must be called to set
1366 * bits CCCR.CCE and CCCR.INIT. It is recommended to call
1367 * Cy_CANFD_ConfigChangesDisable() after updating Bitrate.
1368 *
1369 * \param *base
1370 * The pointer to a CAN FD instance.
1371 *
1372 * \param chan
1373 * The CAN FD channel number.
1374 *
1375 * \param *fastBitrate \ref cy_stc_canfd_bitrate_t
1376 *
1377 * \funcusage
1378 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_SetFastBitrate
1379 *
1380 *******************************************************************************/
Cy_CANFD_SetFastBitrate(CANFD_Type * base,uint32_t chan,const cy_stc_canfd_bitrate_t * fastBitrate)1381 __STATIC_INLINE void Cy_CANFD_SetFastBitrate(CANFD_Type *base, uint32_t chan, const cy_stc_canfd_bitrate_t *fastBitrate)
1382 {
1383 uint32_t regValue;
1384
1385 if (NULL != fastBitrate)
1386 {
1387 CY_ASSERT_L2(CY_CANFD_IS_DAT_PRESCALER_VALID(fastBitrate->prescaler));
1388 CY_ASSERT_L2(CY_CANFD_IS_DAT_TIME_SEG_1_VALID(fastBitrate->timeSegment1));
1389 CY_ASSERT_L2(CY_CANFD_IS_DAT_TIME_SEG_2_VALID(fastBitrate->timeSegment2));
1390 CY_ASSERT_L2(CY_CANFD_IS_DAT_SYNC_JUMP_WIDTH_VALID(fastBitrate->syncJumpWidth));
1391
1392 regValue = CANFD_DBTP(base, chan); /* Get Data Bit Timing and Prescaler Register */
1393
1394 regValue &= ~ (CANFD_CH_M_TTCAN_DBTP_DTSEG2_Msk |
1395 CANFD_CH_M_TTCAN_DBTP_DTSEG1_Msk |
1396 CANFD_CH_M_TTCAN_DBTP_DBRP_Msk |
1397 CANFD_CH_M_TTCAN_DBTP_DSJW_Msk);
1398
1399 regValue |= _VAL2FLD(CANFD_CH_M_TTCAN_DBTP_DTSEG2, fastBitrate->timeSegment2) |
1400 _VAL2FLD(CANFD_CH_M_TTCAN_DBTP_DTSEG1, fastBitrate->timeSegment1) |
1401 _VAL2FLD(CANFD_CH_M_TTCAN_DBTP_DBRP, fastBitrate->prescaler) |
1402 _VAL2FLD(CANFD_CH_M_TTCAN_DBTP_DSJW, fastBitrate->syncJumpWidth);
1403
1404 CANFD_DBTP(base, chan) = regValue; /* Set Data Bit Timing and Prescaler Register */
1405 }
1406 }
1407
1408
1409 /*******************************************************************************
1410 * Function Name: Cy_CANFD_ConfigChangesEnable
1411 ****************************************************************************//**
1412 *
1413 * Enables the CPU write access to the protected configuration registers
1414 * of the CAN FD block and sets the CAN FD block into the initialization
1415 * state.
1416 *
1417 * \param *base
1418 * The pointer to a CAN FD instance.
1419 *
1420 * \param chan
1421 * The CAN FD channel number.
1422 *
1423 * \return
1424 * \ref cy_en_canfd_status_t
1425 *
1426 * \funcusage
1427 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_ConfigChangesEnable
1428 *
1429 *******************************************************************************/
Cy_CANFD_ConfigChangesEnable(CANFD_Type * base,uint32_t chan)1430 __STATIC_INLINE cy_en_canfd_status_t Cy_CANFD_ConfigChangesEnable(CANFD_Type *base, uint32_t chan)
1431 {
1432 cy_en_canfd_status_t ret = CY_CANFD_BAD_PARAM;
1433 uint32_t retry = CY_CANFD_RETRY_COUNT;
1434
1435 /* Set CCCR_INIT and wait until it is settled */
1436 CANFD_CCCR(base, chan) = CANFD_CH_M_TTCAN_CCCR_INIT_Msk;
1437
1438 while ((retry > 0UL) && !_FLD2BOOL(CANFD_CH_M_TTCAN_CCCR_INIT, CANFD_CCCR(base, chan)))
1439 {
1440 Cy_SysLib_DelayUs(CY_CANFD_INIT_TIMEOUT_US);
1441 retry--;
1442 }
1443
1444 if (retry > 0UL)
1445 {
1446 /* Enable configuration changes by setting the CCE bit */
1447 CANFD_CCCR(base, chan) |= CANFD_CH_M_TTCAN_CCCR_CCE_Msk;
1448
1449 ret = CY_CANFD_SUCCESS;
1450 }
1451
1452 return ret;
1453 }
1454
1455
1456 /*******************************************************************************
1457 * Function Name: Cy_CANFD_ConfigChangesDisable
1458 ****************************************************************************//**
1459 *
1460 * Disables the CPU write access to the protected configuration registers
1461 * of the CAN FD block and sets the CAN FD block into the Normal Operation.
1462 *
1463 * \param *base
1464 * The pointer to a CAN FD instance.
1465 *
1466 * \param chan
1467 * The CAN FD channel number.
1468 *
1469 * \return
1470 * \ref cy_en_canfd_status_t
1471 *
1472 * \funcusage
1473 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_ConfigChangesDisable
1474 *
1475 *******************************************************************************/
Cy_CANFD_ConfigChangesDisable(CANFD_Type * base,uint32_t chan)1476 __STATIC_INLINE cy_en_canfd_status_t Cy_CANFD_ConfigChangesDisable(CANFD_Type *base, uint32_t chan)
1477 {
1478 cy_en_canfd_status_t ret = CY_CANFD_BAD_PARAM;
1479 uint32_t retry = CY_CANFD_RETRY_COUNT;
1480
1481 /* Clear CCCR_INIT bit and wait until it is updated to finalize CAN FD initialization */
1482 CANFD_CCCR(base, chan) &= (uint32_t) ~CANFD_CH_M_TTCAN_CCCR_INIT_Msk;
1483
1484 while ((retry > 0UL) && _FLD2BOOL(CANFD_CH_M_TTCAN_CCCR_INIT, CANFD_CCCR(base, chan)))
1485 {
1486 Cy_SysLib_DelayUs(CY_CANFD_INIT_TIMEOUT_US);
1487 retry--;
1488 }
1489
1490 if (retry > 0UL)
1491 {
1492 ret = CY_CANFD_SUCCESS;
1493 }
1494
1495 return ret;
1496 }
1497
1498
1499 /*******************************************************************************
1500 * Function Name: Cy_CANFD_TestModeConfig
1501 ****************************************************************************//**
1502 *
1503 * Configures test mode.
1504 *
1505 * \note The \ref Cy_CANFD_ConfigChangesEnable must be called before calling
1506 * this function to enable the configuration changes.
1507 *
1508 * \param *base
1509 * The pointer to a CAN FD instance.
1510 *
1511 * \param chan
1512 * The CAN FD channel number.
1513 *
1514 * \param testMode \ref cy_stc_canfd_test_mode_t
1515 *
1516 * \funcusage
1517 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_TestModeConfig
1518 *
1519 *******************************************************************************/
Cy_CANFD_TestModeConfig(CANFD_Type * base,uint32_t chan,cy_stc_canfd_test_mode_t testMode)1520 __STATIC_INLINE void Cy_CANFD_TestModeConfig(CANFD_Type *base, uint32_t chan, cy_stc_canfd_test_mode_t testMode)
1521 {
1522 switch (testMode)
1523 {
1524 case CY_CANFD_TEST_MODE_DISABLE:
1525 CANFD_CCCR(base, chan) &= (uint32_t) ~(CANFD_CH_M_TTCAN_CCCR_TEST_Msk | /* Disable Test Mode */
1526 CANFD_CH_M_TTCAN_CCCR_MON__Msk); /* Disable Bus Monitoring Mode */
1527 CANFD_TEST(base, chan) &= (uint32_t) ~CANFD_CH_M_TTCAN_TEST_LBCK_Msk; /* Disable Loop Back Mode */
1528 break;
1529 case CY_CANFD_TEST_MODE_BUS_MONITORING:
1530 CANFD_CCCR(base, chan) |= (CANFD_CH_M_TTCAN_CCCR_MON__Msk); /* Enable Bus Monitoring Mode */
1531 break;
1532 case CY_CANFD_TEST_MODE_EXTERNAL_LOOP_BACK:
1533 CANFD_CCCR(base, chan) |= CANFD_CH_M_TTCAN_CCCR_TEST_Msk; /* Enable Test Mode */
1534 CANFD_TEST(base, chan) |= CANFD_CH_M_TTCAN_TEST_LBCK_Msk; /* Enable Loop Back Mode */
1535 break;
1536 case CY_CANFD_TEST_MODE_INTERNAL_LOOP_BACK:
1537 CANFD_CCCR(base, chan) |= (CANFD_CH_M_TTCAN_CCCR_TEST_Msk | /* Enable Test Mode */
1538 CANFD_CH_M_TTCAN_CCCR_MON__Msk); /* Enable Bus Monitoring Mode */
1539 CANFD_TEST(base, chan) |= CANFD_CH_M_TTCAN_TEST_LBCK_Msk; /* Enable Loop Back Mode */
1540 break;
1541 default:
1542 /* Unsupported test mode */
1543 break;
1544 }
1545 }
1546
1547
1548 /*******************************************************************************
1549 * Function Name: Cy_CANFD_SetTDC
1550 ****************************************************************************//**
1551 *
1552 * Sets the CAN FD transceiver delay compensation offset.
1553 *
1554 * \param *base
1555 * The pointer to a CAN FD instance.
1556 *
1557 * \param chan
1558 * The CAN FD channel number.
1559 *
1560 * \param *tdcConfig
1561 * The CAN FD transceiver delay compensation offset configuration.
1562 *
1563 *******************************************************************************/
Cy_CANFD_SetTDC(CANFD_Type * base,uint32_t chan,const cy_stc_canfd_transceiver_delay_compensation_t * tdcConfig)1564 __STATIC_INLINE void Cy_CANFD_SetTDC(CANFD_Type *base, uint32_t chan,
1565 const cy_stc_canfd_transceiver_delay_compensation_t *tdcConfig)
1566 {
1567 if (NULL != tdcConfig)
1568 {
1569 CY_ASSERT_L2(CY_CANFD_IS_TDCO_VALID(tdcConfig->tdcOffset));
1570 CY_ASSERT_L2(CY_CANFD_IS_TDCF_VALID(tdcConfig->tdcFilterWindow));
1571
1572 /* Transceiver Delay Compensation is enabled or disabled */
1573 CANFD_DBTP(base, chan) = _CLR_SET_FLD32U(CANFD_DBTP(base, chan),
1574 CANFD_CH_M_TTCAN_DBTP_TDC,
1575 ((tdcConfig->tdcEnabled) ? 1UL : 0UL));
1576
1577 /* Transmitter Delay Compensation Offset and Filter Window Length */
1578 CANFD_TDCR(base, chan) = _VAL2FLD(CANFD_CH_M_TTCAN_TDCR_TDCO, tdcConfig->tdcOffset) |
1579 _VAL2FLD(CANFD_CH_M_TTCAN_TDCR_TDCF, tdcConfig->tdcFilterWindow);
1580 }
1581 }
1582
1583 /** \} group_canfd_functions */
1584
1585 /**
1586 * \addtogroup group_canfd_functions
1587 * \{
1588 */
1589
1590 /*******************************************************************************
1591 * Function Name: Cy_CANFD_GetInterruptStatus
1592 ****************************************************************************//**
1593 *
1594 * Returns a status of CAN FD interrupt requests.
1595 *
1596 * \param *base
1597 * The pointer to a CAN FD instance.
1598 *
1599 * \param chan
1600 * The CAN FD channel number.
1601 *
1602 * \return uint32_t
1603 * The bit mask of the Interrupt Status.
1604 * Valid masks can be found in
1605 * \ref group_canfd_rx_interrupt_masks, \ref group_canfd_tx_interrupt_masks and
1606 * \ref group_canfd_error_interrupt_masks.
1607 *
1608 * \funcusage
1609 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_GetInterruptStatus
1610 *
1611 *******************************************************************************/
Cy_CANFD_GetInterruptStatus(CANFD_Type const * base,uint32_t chan)1612 __STATIC_INLINE uint32_t Cy_CANFD_GetInterruptStatus(CANFD_Type const *base, uint32_t chan)
1613 {
1614 return CANFD_IR(base, chan);
1615 }
1616
1617
1618 /*******************************************************************************
1619 * Function Name: Cy_CANFD_ClearInterrupt
1620 ****************************************************************************//**
1621 *
1622 * Clears CAN FD interrupts by setting each bit.
1623 *
1624 * \param *base
1625 * The pointer to a CAN FD instance.
1626 *
1627 * \param chan
1628 * The CAN FD channel number.
1629 *
1630 * \param status
1631 * The bitmask of statuses to clear.
1632 * Valid masks can be found in
1633 * \ref group_canfd_rx_interrupt_masks, \ref group_canfd_tx_interrupt_masks and
1634 * \ref group_canfd_error_interrupt_masks.
1635 *
1636 * \funcusage
1637 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_ClearInterrupt
1638 *
1639 *******************************************************************************/
Cy_CANFD_ClearInterrupt(CANFD_Type * base,uint32_t chan,uint32_t status)1640 __STATIC_INLINE void Cy_CANFD_ClearInterrupt(CANFD_Type *base, uint32_t chan, uint32_t status)
1641 {
1642 CANFD_IR(base, chan) = status;
1643 }
1644
1645
1646 /*******************************************************************************
1647 * Function Name: Cy_CANFD_GetInterruptMask
1648 ****************************************************************************//**
1649 *
1650 * Returns an interrupt mask.
1651 *
1652 * \param *base
1653 * The pointer to a CAN FD instance.
1654 *
1655 * \param chan
1656 * The CAN FD channel number.
1657 *
1658 * \return uint32_t
1659 * The bit field determines which status changes can cause an interrupt.
1660 * Valid masks can be found in
1661 * \ref group_canfd_rx_interrupt_masks, \ref group_canfd_tx_interrupt_masks and
1662 * \ref group_canfd_error_interrupt_masks.
1663 *
1664 * \funcusage
1665 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_GetInterruptMask
1666 *
1667 *******************************************************************************/
Cy_CANFD_GetInterruptMask(CANFD_Type const * base,uint32_t chan)1668 __STATIC_INLINE uint32_t Cy_CANFD_GetInterruptMask(CANFD_Type const *base, uint32_t chan)
1669 {
1670 return CANFD_IE(base, chan);
1671 }
1672
1673
1674 /*******************************************************************************
1675 * Function Name: Cy_CANFD_SetInterruptMask
1676 ****************************************************************************//**
1677 *
1678 * Configures which bits of the interrupt request register can trigger an
1679 * interrupt event.
1680 *
1681 * \param *base
1682 * The pointer to a CAN FD instance.
1683 *
1684 * \param chan
1685 * The CAN FD channel number.
1686 *
1687 * \param interrupt
1688 * The bit field determines which status changes can cause an interrupt.
1689 * Valid masks can be found in
1690 * \ref group_canfd_rx_interrupt_masks, \ref group_canfd_tx_interrupt_masks and
1691 * \ref group_canfd_error_interrupt_masks.
1692 *
1693 * \funcusage
1694 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_SetInterruptMask
1695 *
1696 *******************************************************************************/
Cy_CANFD_SetInterruptMask(CANFD_Type * base,uint32_t chan,uint32_t interrupt)1697 __STATIC_INLINE void Cy_CANFD_SetInterruptMask(CANFD_Type *base, uint32_t chan, uint32_t interrupt)
1698 {
1699 CANFD_IE(base, chan) = interrupt;
1700 }
1701
1702
1703 /*******************************************************************************
1704 * Function Name: Cy_CANFD_GetInterruptLine
1705 ****************************************************************************//**
1706 *
1707 * Returns the interrupt signals assigned to the line m_ttcan_int0
1708 * or m_ttcan_int1.
1709 *
1710 * \param *base
1711 * The pointer to a CAN FD instance.
1712 *
1713 * \param chan
1714 * The CAN FD channel number.
1715 *
1716 * \return uint32_t
1717 * The mask where 1 corresponds to the interrupt signals assigned
1718 * to the line m_ttcan_int1 and 0 corresponds to m_ttcan_int0.
1719 * Valid masks can be found in
1720 * \ref group_canfd_rx_interrupt_masks, \ref group_canfd_tx_interrupt_masks and
1721 * \ref group_canfd_error_interrupt_masks.
1722 *
1723 * \funcusage
1724 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_GetInterruptLine
1725 *
1726 *******************************************************************************/
Cy_CANFD_GetInterruptLine(CANFD_Type const * base,uint32_t chan)1727 __STATIC_INLINE uint32_t Cy_CANFD_GetInterruptLine(CANFD_Type const *base, uint32_t chan)
1728 {
1729 return CANFD_ILS(base, chan);
1730 }
1731
1732
1733 /*******************************************************************************
1734 * Function Name: Cy_CANFD_SetInterruptLine
1735 ****************************************************************************//**
1736 *
1737 * Configures the bits of the Interrupt Line Select Register to assign the
1738 * interrupt signal to the line m_ttcan_int0 or m_ttcan_int1.
1739 * Bit = 0: The interrupt assigned to the interrupt line m_ttcan_int0,
1740 * bit = 1: The interrupt assigned to the interrupt line m_ttcan_int1.
1741 *
1742 * \param *base
1743 * The pointer to a CAN FD instance.
1744 *
1745 * \param chan
1746 * The CAN FD channel number.
1747 *
1748 * \param interruptLineMask
1749 * The mask where 1 corresponds to the interrupt signals assigned
1750 * to the line m_ttcan_int1 and 0 corresponds to m_ttcan_int0.
1751 * Valid masks can be found in
1752 * \ref group_canfd_rx_interrupt_masks, \ref group_canfd_tx_interrupt_masks and
1753 * \ref group_canfd_error_interrupt_masks.
1754 *
1755 * \funcusage
1756 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_SetInterruptLine
1757 *
1758 *******************************************************************************/
Cy_CANFD_SetInterruptLine(CANFD_Type * base,uint32_t chan,uint32_t interruptLineMask)1759 __STATIC_INLINE void Cy_CANFD_SetInterruptLine(CANFD_Type *base, uint32_t chan, uint32_t interruptLineMask)
1760 {
1761 CANFD_ILS(base, chan) = interruptLineMask;
1762 }
1763
1764
1765 /*******************************************************************************
1766 * Function Name: Cy_CANFD_IsInterruptLineEnabled
1767 ****************************************************************************//**
1768 *
1769 * Checks whether Interrupt Line 0, Interrupt Line 1 or both are enabled.
1770 *
1771 * \param *base
1772 * The pointer to a CAN FD instance.
1773 *
1774 * \param chan
1775 * The CAN FD channel number.
1776 *
1777 * \param interruptLineMask
1778 * The bit mask to check which interrupt line is enabled.
1779 * Can be CY_CANFD_INTERRUPT_LINE_0_EN, CY_CANFD_INTERRUPT_LINE_1_EN or
1780 * (CY_CANFD_INTERRUPT_LINE_0_EN | CY_CANFD_INTERRUPT_LINE_1_EN)
1781 *
1782 * \return bool
1783 * The bit mask of the enabled interrupt lines.
1784 *
1785 * \funcusage
1786 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_IsInterruptLineEnabled
1787 *
1788 *******************************************************************************/
Cy_CANFD_IsInterruptLineEnabled(CANFD_Type const * base,uint32_t chan,uint32_t interruptLineMask)1789 __STATIC_INLINE bool Cy_CANFD_IsInterruptLineEnabled(CANFD_Type const *base, uint32_t chan,
1790 uint32_t interruptLineMask)
1791 {
1792 return (interruptLineMask == (CANFD_ILE(base, chan) & interruptLineMask));
1793 }
1794
1795
1796 /*******************************************************************************
1797 * Function Name: Cy_CANFD_EnableInterruptLine
1798 ****************************************************************************//**
1799 *
1800 * Configures which interrupt line is enabled (Interrupt Line 0, Interrupt Line 1 or both).
1801 *
1802 * \param *base
1803 * The pointer to a CAN FD instance.
1804 *
1805 * \param chan
1806 * The CAN FD channel number.
1807 *
1808 * \param interruptLineMask
1809 * The bit mask whose bits define interrupt lines to enable or disable.
1810 *
1811 * \funcusage
1812 * \snippet canfd/snippet/main.c snippet_Cy_CANFD_EnableInterruptLine
1813 *
1814 *******************************************************************************/
Cy_CANFD_EnableInterruptLine(CANFD_Type * base,uint32_t chan,uint32_t interruptLineMask)1815 __STATIC_INLINE void Cy_CANFD_EnableInterruptLine(CANFD_Type *base, uint32_t chan, uint32_t interruptLineMask)
1816 {
1817 CY_ASSERT_L2(CY_CANFD_IS_ILE_MASK_VALID(interruptLineMask));
1818
1819 CANFD_ILE(base, chan) = interruptLineMask;
1820 }
1821
1822 /** \} group_canfd_functions */
1823
1824 #if defined(__cplusplus)
1825 }
1826 #endif
1827
1828 #endif /* CY_IP_MXTTCANFD */
1829
1830 #endif /* CY_CANFD_H */
1831
1832 /** \} group_canfd */
1833
1834 /* [] END OF FILE */
1835