MTB CAT1 Peripheral driver library

General Description

Functions

__STATIC_INLINE void Cy_CANFD_Enable (CANFD_Type *base, uint32_t channelMask)
 Enables the CAN FD channels. More...
 
__STATIC_INLINE cy_en_canfd_status_t Cy_CANFD_Disable (CANFD_Type *base, uint32_t channelMask)
 Disables the CAN FD channels to stop providing clocks to un-used CAN channels for power saving with this functionality. More...
 
__STATIC_INLINE void Cy_CANFD_EnableMRAM (CANFD_Type *base, uint32_t channelMask, uint16_t delay)
 Switches MRAM on and enables the channels. More...
 
__STATIC_INLINE cy_en_canfd_status_t Cy_CANFD_DisableMRAM (CANFD_Type *base)
 Disables the channels and switches MRAM off. More...
 
__STATIC_INLINE void Cy_CANFD_SetBitrate (CANFD_Type *base, uint32_t chan, const cy_stc_canfd_bitrate_t *bitrate)
 Sets Nominal Bit Timing and Prescaler Register parameters: -Nominal Time segment after sample point; -Nominal Time segment before sample point; -Nominal Baud Rate Prescaler; -Nominal Synchronization Jump Width. More...
 
__STATIC_INLINE void Cy_CANFD_SetFastBitrate (CANFD_Type *base, uint32_t chan, const cy_stc_canfd_bitrate_t *fastBitrate)
 Sets Data Bit Timing and Prescaler Register parameters for data: -Data Time segment after sample point; -Data Time segment before sample point; -Data Baud Rate Prescaler; -Data Synchronization Jump Width. More...
 
void Cy_CANFD_SidFilterSetup (CANFD_Type const *base, uint32_t chan, const cy_stc_id_filter_t *filter, uint32_t index, cy_stc_canfd_context_t const *context)
 Updates the Standard Message ID Filter Element configuration in Message RAM. More...
 
void Cy_CANFD_SidFiltersSetup (CANFD_Type const *base, uint32_t chan, const cy_stc_canfd_sid_filter_config_t *filterConfig, cy_stc_canfd_context_t const *context)
 Updates the Standard Message ID Filters configuration in Message RAM. More...
 
void Cy_CANFD_XidFilterSetup (CANFD_Type const *base, uint32_t chan, const cy_stc_extid_filter_t *filter, uint32_t index, cy_stc_canfd_context_t const *context)
 Updates the Extended Message ID Filter Element configuration in Message RAM. More...
 
void Cy_CANFD_XidFiltersSetup (CANFD_Type const *base, uint32_t chan, const cy_stc_canfd_extid_filter_config_t *filterConfig, cy_stc_canfd_context_t const *context)
 Updates the Extended Message ID Filters configuration in Message RAM. More...
 
cy_en_canfd_status_t Cy_CANFD_TxBufferConfig (CANFD_Type const *base, uint32_t chan, const cy_stc_canfd_tx_buffer_t *txBuffer, uint8_t index, cy_stc_canfd_context_t const *context)
 Updates the T0 and T1 Tx buffer element parameters in Message RAM and copies data from cy_stc_canfd_tx_buffer_t structure to Message RAM. More...
 
uint32_t Cy_CANFD_CalcRxBufAdrs (CANFD_Type const *base, uint32_t chan, uint32_t index, cy_stc_canfd_context_t const *context)
 Calculates the address of the RX buffer element. More...
 
uint32_t Cy_CANFD_CalcRxFifoAdrs (CANFD_Type const *base, uint32_t chan, uint32_t fifoNumber, uint32_t index, cy_stc_canfd_context_t const *context)
 Calculates the address of the RX FIFO element. More...
 
cy_en_canfd_status_t Cy_CANFD_GetRxBuffer (CANFD_Type const *base, uint32_t chan, const uint32_t bufferAddress, cy_stc_canfd_rx_buffer_t const *rxBuffer)
 Extracts the RX Buffer from Message RAM. More...
 
cy_en_canfd_status_t Cy_CANFD_GetFIFOTop (CANFD_Type const *base, uint32_t chan, const uint8_t FIFONumber, cy_stc_canfd_rx_buffer_t const *rxBuffer)
 Extracts one RX FIFO Buffer element using the FIFO TOP register logic. More...
 
cy_en_canfd_status_t Cy_CANFD_ExtractMsgFromRXBuffer (CANFD_Type *base, uint32_t chan, bool rxFIFOMsg, uint8_t msgBufOrRxFIFONum, cy_stc_canfd_rx_buffer_t const *rxBuffer, cy_stc_canfd_context_t const *context)
 Extracts one RX buffer or one FIFO buffer element. More...
 
void Cy_CANFD_AckRxBuf (CANFD_Type *base, uint32_t chan, uint32_t bufNum)
 Acknowledges the data reading and makes the buffer element available for a next message. More...
 
void Cy_CANFD_AckRxFifo (CANFD_Type *base, uint32_t chan, uint32_t FIFOnumber)
 Acknowledges the data reading and makes the buffer element available for a next message. More...
 
__STATIC_INLINE cy_en_canfd_status_t Cy_CANFD_ConfigChangesEnable (CANFD_Type *base, uint32_t chan)
 Enables the CPU write access to the protected configuration registers of the CAN FD block and sets the CAN FD block into the initialization state. More...
 
__STATIC_INLINE cy_en_canfd_status_t Cy_CANFD_ConfigChangesDisable (CANFD_Type *base, uint32_t chan)
 Disables the CPU write access to the protected configuration registers of the CAN FD block and sets the CAN FD block into the Normal Operation. More...
 
__STATIC_INLINE void Cy_CANFD_TestModeConfig (CANFD_Type *base, uint32_t chan, cy_stc_canfd_test_mode_t testMode)
 Configures test mode. More...
 
__STATIC_INLINE void Cy_CANFD_SetTDC (CANFD_Type *base, uint32_t chan, const cy_stc_canfd_transceiver_delay_compensation_t *tdcConfig)
 Sets the CAN FD transceiver delay compensation offset. More...
 
uint32_t Cy_CANFD_GetLastError (CANFD_Type const *base, uint32_t chan)
 Returns the value of Protocol Status Register (PSR). More...
 
void Cy_CANFD_IrqHandler (CANFD_Type *base, uint32_t chan, cy_stc_canfd_context_t const *context)
 CAN FD (Status/Error/Rx/Tx) interrupt ISR. More...
 
cy_en_canfd_status_t Cy_CANFD_Init (CANFD_Type *base, uint32_t chan, const cy_stc_canfd_config_t *config, cy_stc_canfd_context_t *context)
 Initializes the CAN FD module. More...
 
cy_en_canfd_status_t Cy_CANFD_DeInit (CANFD_Type *base, uint32_t chan, cy_stc_canfd_context_t *context)
 De-initializes the CAN FD block, returns registers values to default. More...
 
cy_en_canfd_status_t Cy_CANFD_TransmitTxBuffer (CANFD_Type *base, uint32_t chan, uint8_t index)
 Starts transmission of the message prepared with Cy_CANFD_TxBufferConfig(). More...
 
cy_en_canfd_status_t Cy_CANFD_UpdateAndTransmitMsgBuffer (CANFD_Type *base, uint32_t chan, const cy_stc_canfd_tx_buffer_t *txBuffer, uint8_t index, cy_stc_canfd_context_t const *context)
 Updates the T0 and T1 Tx buffer element parameters in Message RAM and copies data from cy_stc_canfd_tx_buffer_t structure to Message RAM. More...
 
cy_en_canfd_tx_buffer_status_t Cy_CANFD_GetTxBufferStatus (CANFD_Type const *base, uint32_t chan, uint8_t index)
 Gets the status of the CAN FD Tx buffer. More...
 
__STATIC_INLINE uint32_t Cy_CANFD_GetInterruptStatus (CANFD_Type const *base, uint32_t chan)
 Returns a status of CAN FD interrupt requests. More...
 
__STATIC_INLINE void Cy_CANFD_ClearInterrupt (CANFD_Type *base, uint32_t chan, uint32_t status)
 Clears CAN FD interrupts by setting each bit. More...
 
__STATIC_INLINE uint32_t Cy_CANFD_GetInterruptMask (CANFD_Type const *base, uint32_t chan)
 Returns an interrupt mask. More...
 
__STATIC_INLINE void Cy_CANFD_SetInterruptMask (CANFD_Type *base, uint32_t chan, uint32_t interrupt)
 Configures which bits of the interrupt request register can trigger an interrupt event. More...
 
__STATIC_INLINE uint32_t Cy_CANFD_GetInterruptLine (CANFD_Type const *base, uint32_t chan)
 Returns the interrupt signals assigned to the line m_ttcan_int0 or m_ttcan_int1. More...
 
__STATIC_INLINE void Cy_CANFD_SetInterruptLine (CANFD_Type *base, uint32_t chan, uint32_t interruptLineMask)
 Configures the bits of the Interrupt Line Select Register to assign the interrupt signal to the line m_ttcan_int0 or m_ttcan_int1. More...
 
__STATIC_INLINE bool Cy_CANFD_IsInterruptLineEnabled (CANFD_Type const *base, uint32_t chan, uint32_t interruptLineMask)
 Checks whether Interrupt Line 0, Interrupt Line 1 or both are enabled. More...
 
__STATIC_INLINE void Cy_CANFD_EnableInterruptLine (CANFD_Type *base, uint32_t chan, uint32_t interruptLineMask)
 Configures which interrupt line is enabled (Interrupt Line 0, Interrupt Line 1 or both). More...
 

Function Documentation

◆ Cy_CANFD_Enable()

__STATIC_INLINE void Cy_CANFD_Enable ( CANFD_Type *  base,
uint32_t  channelMask 
)

Enables the CAN FD channels.

Note
Call Cy_CANFD_Enable before Cy_CANFD_Init.
Parameters
*baseThe CAN FD registers structure pointer.
channelMaskThe channel mask (0-0xFF).
Function Usage
/* Scenario: The CAN FD block and channel must be enabled. */
uint32_t channelMask = 0x00000001UL; /* Enable the first channel */
Cy_CANFD_Enable(CANFD0, channelMask);

◆ Cy_CANFD_Disable()

__STATIC_INLINE cy_en_canfd_status_t Cy_CANFD_Disable ( CANFD_Type *  base,
uint32_t  channelMask 
)

Disables the CAN FD channels to stop providing clocks to un-used CAN channels for power saving with this functionality.

Note
Call Cy_CANFD_Disable only after Cy_CANFD_DeInit. Do not access the CAN FD registers until calling Cy_CANFD_Enable again.
Parameters
*baseThe CAN FD registers structure pointer.
channelMaskThe channel mask (0-0xFF).
Function Usage
/* Scenario: CAN FD no longer in use, a channel or channels must be switched off */
uint32_t channelMask = 0x00000001UL; /* Disable first channel */
if(CY_CANFD_SUCCESS != Cy_CANFD_Disable(CANFD0, channelMask))
{
/* Insert error handling */
}

◆ Cy_CANFD_EnableMRAM()

__STATIC_INLINE void Cy_CANFD_EnableMRAM ( CANFD_Type *  base,
uint32_t  channelMask,
uint16_t  delay 
)

Switches MRAM on and enables the channels.

Parameters
*baseThe CAN FD registers structure pointer.
channelMaskThe channel mask (0-0xFF).
delayThe delay in usec to wait power up time before MRAM can be used. Recommended value is 150 CPU cycles or 6 usec for the 25 MHz CPU clock.
Function Usage
/* Scenario: Switches MRAM on and enables specified channels. */
uint32_t channelMask = 0x00000001UL; /* Enables the first channel */
uint16_t delay = 0x0006U; /* A delay in usec before the MRAM can be used */
Cy_CANFD_EnableMRAM(CANFD0, channelMask, delay);

◆ Cy_CANFD_DisableMRAM()

__STATIC_INLINE cy_en_canfd_status_t Cy_CANFD_DisableMRAM ( CANFD_Type *  base)

Disables the channels and switches MRAM off.

Parameters
*baseThe CAN FD registers structure pointer.
Function Usage
/* Scenario: Disables all the channels and switches off the MRAM to save power. */

◆ Cy_CANFD_SetBitrate()

__STATIC_INLINE void Cy_CANFD_SetBitrate ( CANFD_Type *  base,
uint32_t  chan,
const cy_stc_canfd_bitrate_t bitrate 
)

Sets Nominal Bit Timing and Prescaler Register parameters: -Nominal Time segment after sample point; -Nominal Time segment before sample point; -Nominal Baud Rate Prescaler; -Nominal Synchronization Jump Width.

Note
Before calling the Cy_CANFD_SetBitrate() function, the Cy_CANFD_ConfigChangesEnable() function must be called to set bits CCCR.CCE and CCCR.INIT. It is recommended to call Cy_CANFD_ConfigChangesDisable() after updating Bitrate.
Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
*bitratecy_stc_canfd_bitrate_t
Function Usage
/* Scenario: Changes the Nominal Bit Timing or Prescaler Register parameters after the CAN FD block is initialized. */
cy_stc_canfd_bitrate_t bitrateConfig =
{
/* .prescaler */ 10u - 1u,
/* .timeSegment1 */ 5u - 1u,
/* .timeSegment2 */ 2u - 1u,
/* .syncJumpWidth */ 2u - 1u
};
Cy_CANFD_SetBitrate(CANFD0, 0UL, &bitrateConfig);

◆ Cy_CANFD_SetFastBitrate()

__STATIC_INLINE void Cy_CANFD_SetFastBitrate ( CANFD_Type *  base,
uint32_t  chan,
const cy_stc_canfd_bitrate_t fastBitrate 
)

Sets Data Bit Timing and Prescaler Register parameters for data: -Data Time segment after sample point; -Data Time segment before sample point; -Data Baud Rate Prescaler; -Data Synchronization Jump Width.

Note
Before calling the Cy_CANFD_SetFastBitrate() function, the Cy_CANFD_ConfigChangesEnable() function must be called to set bits CCCR.CCE and CCCR.INIT. It is recommended to call Cy_CANFD_ConfigChangesDisable() after updating Bitrate.
Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
*fastBitratecy_stc_canfd_bitrate_t
Function Usage
/* Scenario: Changes the Data Bit Timing or Prescaler Register parameters after the CAN FD block is initialized. */
cy_stc_canfd_bitrate_t bitrateConfig =
{
/* .prescaler */ 5u - 1u,
/* .timeSegment1 */ 5u - 1u,
/* .timeSegment2 */ 2u - 1u,
/* .syncJumpWidth */ 2u - 1u
};
Cy_CANFD_SetFastBitrate(CANFD0, 0UL, &bitrateConfig);

◆ Cy_CANFD_SidFilterSetup()

void Cy_CANFD_SidFilterSetup ( CANFD_Type const *  base,
uint32_t  chan,
const cy_stc_id_filter_t filter,
uint32_t  index,
cy_stc_canfd_context_t const *  context 
)

Updates the Standard Message ID Filter Element configuration in Message RAM.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
*filterThe SID Filter register element structure.
indexThe SID filter index.
*contextThe pointer to the context structure cy_stc_canfd_context_t allocated by the user. The structure is used during the CAN FD operation for internal configuration and data retention. The user must not modify anything in this structure.
Function Usage
/* Scenario: Updates the Standard Message ID Filter Element configuration in the Message RAM. */
static const cy_stc_id_filter_t filter =
{
/* .sfid2 */ 0x00000010UL,
/* .sfid1 */ 0x00000020UL,
};
cy_stc_canfd_context_t context = {0}; /* This is a shared context buffer, unique for each channel */
Cy_CANFD_SidFilterSetup(CANFD0, 0UL, &filter, 0UL, &context);

◆ Cy_CANFD_SidFiltersSetup()

void Cy_CANFD_SidFiltersSetup ( CANFD_Type const *  base,
uint32_t  chan,
const cy_stc_canfd_sid_filter_config_t filterConfig,
cy_stc_canfd_context_t const *  context 
)

Updates the Standard Message ID Filters configuration in Message RAM.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
filterConfigThe Standard ID filter configuration structure.
contextThe pointer to the context structure cy_stc_canfd_context_t allocated by the user. The structure is used during the CAN FD operation for internal configuration and data retention. The user must not modify anything in this structure.

◆ Cy_CANFD_XidFilterSetup()

void Cy_CANFD_XidFilterSetup ( CANFD_Type const *  base,
uint32_t  chan,
const cy_stc_extid_filter_t filter,
uint32_t  index,
cy_stc_canfd_context_t const *  context 
)

Updates the Extended Message ID Filter Element configuration in Message RAM.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
filterThe XID Filter register element structure.
indexThe XID filter index.
contextThe pointer to the context structure cy_stc_canfd_context_t allocated by the user. The structure is used during the CAN FD operation for internal configuration and data retention. The user must not modify anything in this structure.
Function Usage
/* Scenario: Updates the Extended Message ID Filter Element configuration in the Message RAM. */
cy_stc_canfd_context_t context = {0};
cy_stc_canfd_f0_t filterF0Config =
{
/* .efid1 */ 0x00010010UL,
};
cy_stc_canfd_f1_t filterF1Config =
{
/* .efid2 */ 0x00010020UL,
};
/* extIdFilter */
{
/* .f0_f */ &filterF0Config,
/* .f1_f */ &filterF1Config
};
Cy_CANFD_XidFilterSetup(CANFD0, 0UL, &filter, 0UL, &context);

◆ Cy_CANFD_XidFiltersSetup()

void Cy_CANFD_XidFiltersSetup ( CANFD_Type const *  base,
uint32_t  chan,
const cy_stc_canfd_extid_filter_config_t filterConfig,
cy_stc_canfd_context_t const *  context 
)

Updates the Extended Message ID Filters configuration in Message RAM.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
filterConfigThe Extended ID filter configuration structure.
contextThe pointer to the context structure cy_stc_canfd_context_t allocated by the user. The structure is used during the CAN FD operation for internal configuration and data retention. The user must not modify anything in this structure.

◆ Cy_CANFD_TxBufferConfig()

cy_en_canfd_status_t Cy_CANFD_TxBufferConfig ( CANFD_Type const *  base,
uint32_t  chan,
const cy_stc_canfd_tx_buffer_t txBuffer,
uint8_t  index,
cy_stc_canfd_context_t const *  context 
)

Updates the T0 and T1 Tx buffer element parameters in Message RAM and copies data from cy_stc_canfd_tx_buffer_t structure to Message RAM.

Note
Function Cy_CANFD_Init() must be called before setting up an identifier and enabling this message buffer.
Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
*txBufferThe Tx Buffer configuration structure.
indexthe message buffer index (0-31).
contextThe pointer to the context structure cy_stc_canfd_context_t allocated by the user. The structure is used during the CAN FD operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
cy_en_canfd_status_t
Function Usage
/* Scenario: Configure a transmit buffer for the CAN FD transmit operation */
cy_stc_canfd_context_t context = {0}; /* This is a shared context structure, it is unique for each channel.
* It must be global
*/
uint8_t index = 0U; /* Tx Buffer Element number */
cy_stc_canfd_t0_t t0fConfig =
{
/* .id */ 0x00000055UL,
};
cy_stc_canfd_t1_t t1fConfig =
{
/* .dlc */ 15U,
/* .brs */ true,
/* .efc */ false,
/* .mm */ 0UL
};
uint32_t data[16] =
{
0x00000000, 0x11111111, 0x22222222, 0x33333333,
0x44444444, 0x55555555, 0x66666666, 0x77777777,
0x88888888, 0x99999999, 0xAAAAAAAA, 0xBBBBBBBB,
0xCCCCCCCC, 0xDDDDDDDD, 0xEEEEEEEE, 0xFFFFFFFF
};
const cy_stc_canfd_tx_buffer_t txBufferConfig =
{
/* .t0_f */ &t0fConfig,
/* .t1_f */ &t1fConfig,
/* data_area_f */ data
};
if(CY_CANFD_SUCCESS != Cy_CANFD_TxBufferConfig(CANFD0, 0UL, &txBufferConfig, index, &context))
{
/* Insert error handling */
}

◆ Cy_CANFD_CalcRxBufAdrs()

uint32_t Cy_CANFD_CalcRxBufAdrs ( CANFD_Type const *  base,
uint32_t  chan,
uint32_t  index,
cy_stc_canfd_context_t const *  context 
)

Calculates the address of the RX buffer element.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
indexThe message buffer index for reception (0-63).
contextThe pointer to the context structure cy_stc_canfd_context_t allocated by the user. The structure is used during the CAN FD operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
The message buffer address corresponding to the index. Can be 0 if the index is invalid.
Function Usage
/* Scenario: Reads one RX buffer element. */
uint32_t index = 0UL; /* RX buffer element index */
bool useFIFO = false; /* true - uses FIFO buffer, false - uses RX buffer */
uint32_t FIFOnumber = CY_CANFD_RX_FIFO0; /* FIFO number (0 or 1), if used */
cy_stc_canfd_context_t context = {0}; /* This is a shared context structure unique for each channel
* It must be global, initialized with Cy_CANFD_Init()
*/
uint32_t address ; /* The address of the RX buffer in Message RAM */
/* The members of the rxBuffer structure */
cy_stc_canfd_r0_t r0RxBuffer; /* The R0 register structure of the RX buffer element */
cy_stc_canfd_r1_t r1RxBuffer; /* The R1 register structure of the RX buffer element */
uint32_t rxData[CY_CANFD_DATA_ELEMENTS_MAX]; /* The array to store RX data */
{
/* .r0_f */ &r0RxBuffer,
/* .r1_f */ &r1RxBuffer,
/* .data_area_f */ rxData
};
if (useFIFO)
{
address = Cy_CANFD_CalcRxFifoAdrs(CANFD0, 0UL, FIFOnumber, index, &context);
}
else
{
address = Cy_CANFD_CalcRxBufAdrs(CANFD0, 0UL, index, &context);
}
if(CY_CANFD_SUCCESS == (Cy_CANFD_GetRxBuffer(CANFD0, 0UL, address, &rxBuffer)))
{
if (useFIFO)
{
Cy_CANFD_AckRxFifo(CANFD0, 0UL, FIFOnumber);
}
else
{
Cy_CANFD_AckRxBuf(CANFD0, 0UL, index);
}
}
else
{
/* Insert error handling */
}

◆ Cy_CANFD_CalcRxFifoAdrs()

uint32_t Cy_CANFD_CalcRxFifoAdrs ( CANFD_Type const *  base,
uint32_t  chan,
uint32_t  fifoNumber,
uint32_t  index,
cy_stc_canfd_context_t const *  context 
)

Calculates the address of the RX FIFO element.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
fifoNumberThe FIFO number (0 or 1).
indexThe Message buffer index for the reception (0-63).
contextThe pointer to the context structure cy_stc_canfd_context_t allocated by the user. The structure is used during the CAN FD operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
The Message buffer address corresponding to the index. Can be 0 if the index is invalid.
Function Usage
/* Scenario: Reads one RX buffer element. */
uint32_t index = 0UL; /* RX buffer element index */
bool useFIFO = false; /* true - uses FIFO buffer, false - uses RX buffer */
uint32_t FIFOnumber = CY_CANFD_RX_FIFO0; /* FIFO number (0 or 1), if used */
cy_stc_canfd_context_t context = {0}; /* This is a shared context structure unique for each channel
* It must be global, initialized with Cy_CANFD_Init()
*/
uint32_t address ; /* The address of the RX buffer in Message RAM */
/* The members of the rxBuffer structure */
cy_stc_canfd_r0_t r0RxBuffer; /* The R0 register structure of the RX buffer element */
cy_stc_canfd_r1_t r1RxBuffer; /* The R1 register structure of the RX buffer element */
uint32_t rxData[CY_CANFD_DATA_ELEMENTS_MAX]; /* The array to store RX data */
{
/* .r0_f */ &r0RxBuffer,
/* .r1_f */ &r1RxBuffer,
/* .data_area_f */ rxData
};
if (useFIFO)
{
address = Cy_CANFD_CalcRxFifoAdrs(CANFD0, 0UL, FIFOnumber, index, &context);
}
else
{
address = Cy_CANFD_CalcRxBufAdrs(CANFD0, 0UL, index, &context);
}
if(CY_CANFD_SUCCESS == (Cy_CANFD_GetRxBuffer(CANFD0, 0UL, address, &rxBuffer)))
{
if (useFIFO)
{
Cy_CANFD_AckRxFifo(CANFD0, 0UL, FIFOnumber);
}
else
{
Cy_CANFD_AckRxBuf(CANFD0, 0UL, index);
}
}
else
{
/* Insert error handling */
}

◆ Cy_CANFD_GetRxBuffer()

cy_en_canfd_status_t Cy_CANFD_GetRxBuffer ( CANFD_Type const *  base,
uint32_t  chan,
const uint32_t  bufferAddress,
cy_stc_canfd_rx_buffer_t const *  rxBuffer 
)

Extracts the RX Buffer from Message RAM.

Note
Remember to clear the NDAT register bits after the RX buffer is read.
Remember to acknowledge the FIFO buffer after reading one FIFO element.
Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
bufferAddressThe Rx, FIFO 0 or FIFO 1 Buffer element address in CAN Message RAM.
*rxBufferThe Rx Buffer structure in RAM.
Returns
cy_en_canfd_status_t
Function Usage
/* Scenario: Reads one RX buffer element. */
uint32_t index = 0UL; /* RX buffer element index */
bool useFIFO = false; /* true - uses FIFO buffer, false - uses RX buffer */
uint32_t FIFOnumber = CY_CANFD_RX_FIFO0; /* FIFO number (0 or 1), if used */
cy_stc_canfd_context_t context = {0}; /* This is a shared context structure unique for each channel
* It must be global, initialized with Cy_CANFD_Init()
*/
uint32_t address ; /* The address of the RX buffer in Message RAM */
/* The members of the rxBuffer structure */
cy_stc_canfd_r0_t r0RxBuffer; /* The R0 register structure of the RX buffer element */
cy_stc_canfd_r1_t r1RxBuffer; /* The R1 register structure of the RX buffer element */
uint32_t rxData[CY_CANFD_DATA_ELEMENTS_MAX]; /* The array to store RX data */
{
/* .r0_f */ &r0RxBuffer,
/* .r1_f */ &r1RxBuffer,
/* .data_area_f */ rxData
};
if (useFIFO)
{
address = Cy_CANFD_CalcRxFifoAdrs(CANFD0, 0UL, FIFOnumber, index, &context);
}
else
{
address = Cy_CANFD_CalcRxBufAdrs(CANFD0, 0UL, index, &context);
}
if(CY_CANFD_SUCCESS == (Cy_CANFD_GetRxBuffer(CANFD0, 0UL, address, &rxBuffer)))
{
if (useFIFO)
{
Cy_CANFD_AckRxFifo(CANFD0, 0UL, FIFOnumber);
}
else
{
Cy_CANFD_AckRxBuf(CANFD0, 0UL, index);
}
}
else
{
/* Insert error handling */
}

◆ Cy_CANFD_GetFIFOTop()

cy_en_canfd_status_t Cy_CANFD_GetFIFOTop ( CANFD_Type const *  base,
uint32_t  chan,
const uint8_t  FIFONumber,
cy_stc_canfd_rx_buffer_t const *  rxBuffer 
)

Extracts one RX FIFO Buffer element using the FIFO TOP register logic.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
FIFONumberThe CY_CANFD_RX_FIFO0 or CY_CANFD_RX_FIFO1, FIFO Buffer number.
*rxBufferThe Rx Buffer structure in RAM.
Returns
cy_en_canfd_status_t
Function Usage
/* Scenario: Reads one RX FIFO0 element using the FIFO TOP register logic. */
uint32_t FIFONumber = 0; /* 0 - read FIFO0, 1 - read FIFO1 */
/* The members of the rxBuffer structure */
cy_stc_canfd_r0_t r0RxBuffer; /* The R0 register structure of the RX buffer element */
cy_stc_canfd_r1_t r1RxBuffer; /* The R1 register structure of the RX buffer element */
uint32_t rxData[CY_CANFD_DATA_ELEMENTS_MAX]; /* The array to store RX data */
{
/* .r0_f */ &r0RxBuffer,
/* .r1_f */ &r1RxBuffer,
/* .data_area_f */ rxData
};
if(CY_CANFD_SUCCESS != (Cy_CANFD_GetFIFOTop(CANFD0, 0UL, FIFONumber, &rxBuffer)))
{
/* Insert error handling */
}

◆ Cy_CANFD_ExtractMsgFromRXBuffer()

cy_en_canfd_status_t Cy_CANFD_ExtractMsgFromRXBuffer ( CANFD_Type *  base,
uint32_t  chan,
bool  rxFIFOMsg,
uint8_t  msgBufOrRxFIFONum,
cy_stc_canfd_rx_buffer_t const *  rxBuffer,
cy_stc_canfd_context_t const *  context 
)

Extracts one RX buffer or one FIFO buffer element.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
rxFIFOMsgThe buffer to read: True for FIFO buffers and False for RX buffers.
msgBufOrRxFIFONumThe RX buffer element index or FIFO buffer number.
*rxBufferThe Rx buffer structure in RAM.
contextThe pointer to the context structure cy_stc_canfd_context_t allocated by the user. The structure is used during the CAN FD operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
cy_en_canfd_status_t
Function Usage
/* Scenario: Reads one RX buffer element. */
cy_stc_canfd_context_t context = {0}; /* This is a shared context structure unique for each channel
* It must be global, initialized with Cy_CANFD_Init()
*/
uint8_t msgBufOrRxFIFONum = 0; /* RX buffer element index or FIFO number*/
bool rxFIFOMsg = false; /* True for FIFO buffers anf False for RX buffers */
/* The members of the rxBuffer structure */
cy_stc_canfd_r0_t r0RxBuffer; /* The R0 register structure of the RX buffer element */
cy_stc_canfd_r1_t r1RxBuffer; /* The R1 register structure of the RX buffer element */
uint32_t rxData[CY_CANFD_DATA_ELEMENTS_MAX]; /* The array to store RX data */
{
/* .r0_f */ &r0RxBuffer,
/* .r1_f */ &r1RxBuffer,
/* .data_area_f */ rxData
};
rxFIFOMsg, msgBufOrRxFIFONum,
&rxBuffer, &context)))
{
/* Insert error handling */
}

◆ Cy_CANFD_AckRxBuf()

void Cy_CANFD_AckRxBuf ( CANFD_Type *  base,
uint32_t  chan,
uint32_t  bufNum 
)

Acknowledges the data reading and makes the buffer element available for a next message.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
bufNumThe RX buffer element index.
Function Usage
/* Scenario: Reads one RX buffer element. */
uint32_t index = 0UL; /* RX buffer element index */
bool useFIFO = false; /* true - uses FIFO buffer, false - uses RX buffer */
uint32_t FIFOnumber = CY_CANFD_RX_FIFO0; /* FIFO number (0 or 1), if used */
cy_stc_canfd_context_t context = {0}; /* This is a shared context structure unique for each channel
* It must be global, initialized with Cy_CANFD_Init()
*/
uint32_t address ; /* The address of the RX buffer in Message RAM */
/* The members of the rxBuffer structure */
cy_stc_canfd_r0_t r0RxBuffer; /* The R0 register structure of the RX buffer element */
cy_stc_canfd_r1_t r1RxBuffer; /* The R1 register structure of the RX buffer element */
uint32_t rxData[CY_CANFD_DATA_ELEMENTS_MAX]; /* The array to store RX data */
{
/* .r0_f */ &r0RxBuffer,
/* .r1_f */ &r1RxBuffer,
/* .data_area_f */ rxData
};
if (useFIFO)
{
address = Cy_CANFD_CalcRxFifoAdrs(CANFD0, 0UL, FIFOnumber, index, &context);
}
else
{
address = Cy_CANFD_CalcRxBufAdrs(CANFD0, 0UL, index, &context);
}
if(CY_CANFD_SUCCESS == (Cy_CANFD_GetRxBuffer(CANFD0, 0UL, address, &rxBuffer)))
{
if (useFIFO)
{
Cy_CANFD_AckRxFifo(CANFD0, 0UL, FIFOnumber);
}
else
{
Cy_CANFD_AckRxBuf(CANFD0, 0UL, index);
}
}
else
{
/* Insert error handling */
}

◆ Cy_CANFD_AckRxFifo()

void Cy_CANFD_AckRxFifo ( CANFD_Type *  base,
uint32_t  chan,
uint32_t  FIFOnumber 
)

Acknowledges the data reading and makes the buffer element available for a next message.

Note
Do not use this function with Cy_CANFD_GetFIFOTop(). FIFO top logic takes care on updating the FIFO read pointer buffer with hardware.
Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
FIFOnumberThe RX buffer element index.
Function Usage
/* Scenario: Reads one RX buffer element. */
uint32_t index = 0UL; /* RX buffer element index */
bool useFIFO = false; /* true - uses FIFO buffer, false - uses RX buffer */
uint32_t FIFOnumber = CY_CANFD_RX_FIFO0; /* FIFO number (0 or 1), if used */
cy_stc_canfd_context_t context = {0}; /* This is a shared context structure unique for each channel
* It must be global, initialized with Cy_CANFD_Init()
*/
uint32_t address ; /* The address of the RX buffer in Message RAM */
/* The members of the rxBuffer structure */
cy_stc_canfd_r0_t r0RxBuffer; /* The R0 register structure of the RX buffer element */
cy_stc_canfd_r1_t r1RxBuffer; /* The R1 register structure of the RX buffer element */
uint32_t rxData[CY_CANFD_DATA_ELEMENTS_MAX]; /* The array to store RX data */
{
/* .r0_f */ &r0RxBuffer,
/* .r1_f */ &r1RxBuffer,
/* .data_area_f */ rxData
};
if (useFIFO)
{
address = Cy_CANFD_CalcRxFifoAdrs(CANFD0, 0UL, FIFOnumber, index, &context);
}
else
{
address = Cy_CANFD_CalcRxBufAdrs(CANFD0, 0UL, index, &context);
}
if(CY_CANFD_SUCCESS == (Cy_CANFD_GetRxBuffer(CANFD0, 0UL, address, &rxBuffer)))
{
if (useFIFO)
{
Cy_CANFD_AckRxFifo(CANFD0, 0UL, FIFOnumber);
}
else
{
Cy_CANFD_AckRxBuf(CANFD0, 0UL, index);
}
}
else
{
/* Insert error handling */
}

◆ Cy_CANFD_ConfigChangesEnable()

__STATIC_INLINE cy_en_canfd_status_t Cy_CANFD_ConfigChangesEnable ( CANFD_Type *  base,
uint32_t  chan 
)

Enables the CPU write access to the protected configuration registers of the CAN FD block and sets the CAN FD block into the initialization state.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
Returns
cy_en_canfd_status_t
Function Usage
/* Scenario: Enable the CPU Write access to the protected configuration registers */
{
/* Insert error handling */
}

◆ Cy_CANFD_ConfigChangesDisable()

__STATIC_INLINE cy_en_canfd_status_t Cy_CANFD_ConfigChangesDisable ( CANFD_Type *  base,
uint32_t  chan 
)

Disables the CPU write access to the protected configuration registers of the CAN FD block and sets the CAN FD block into the Normal Operation.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
Returns
cy_en_canfd_status_t
Function Usage
/* Scenario: Disables the CPU Write access to the protected configuration
* registers of the CAN FD block.
*/
{
/* Insert error handling */
}

◆ Cy_CANFD_TestModeConfig()

__STATIC_INLINE void Cy_CANFD_TestModeConfig ( CANFD_Type *  base,
uint32_t  chan,
cy_stc_canfd_test_mode_t  testMode 
)

Configures test mode.

Note
The Cy_CANFD_ConfigChangesEnable must be called before calling this function to enable the configuration changes.
Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
testModecy_stc_canfd_test_mode_t
Function Usage
/* Scenario: Configures Test mode to use the external loop back to receive
* the sent data back.
*/

◆ Cy_CANFD_SetTDC()

__STATIC_INLINE void Cy_CANFD_SetTDC ( CANFD_Type *  base,
uint32_t  chan,
const cy_stc_canfd_transceiver_delay_compensation_t tdcConfig 
)

Sets the CAN FD transceiver delay compensation offset.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
*tdcConfigThe CAN FD transceiver delay compensation offset configuration.

◆ Cy_CANFD_GetLastError()

uint32_t Cy_CANFD_GetLastError ( CANFD_Type const *  base,
uint32_t  chan 
)

Returns the value of Protocol Status Register (PSR).


Use the Protocol Status Register (PSR) masks to extract necessary fields from the register.
Use the cy_en_canfd_LEC_t enumeration to interpret LEC and DLEC fields.
Use the cy_en_canfd_PSR_ACT_t enumeration to interpret the ACT field.

Note
Protocol Status Register has reset on read fields. Reading the register will clear the bits PXE, RFDF, RBRS and RESI, and set DLEC[2:0] and LEC[2:0].
Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
Returns
Content of the Protocol Status Register (PSR).

◆ Cy_CANFD_IrqHandler()

void Cy_CANFD_IrqHandler ( CANFD_Type *  base,
uint32_t  chan,
cy_stc_canfd_context_t const *  context 
)

CAN FD (Status/Error/Rx/Tx) interrupt ISR.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
contextThe pointer to the context structure cy_stc_canfd_context_t allocated by the user. The structure is used during the CAN FD operation for internal configuration and data retention. The user must not modify anything in this structure.

◆ Cy_CANFD_Init()

cy_en_canfd_status_t Cy_CANFD_Init ( CANFD_Type *  base,
uint32_t  chan,
const cy_stc_canfd_config_t config,
cy_stc_canfd_context_t context 
)

Initializes the CAN FD module.

Note
The function does not enable the Tx Event FIFO but reserves 10 Tx Event FIFO elements in Message RAM.
The function enables the "Message stored to Rx Buffer", "Rx FIFO 1 New Message" and "Rx FIFO 0 New Message" interrupt events only. Other interrupts can be configured with the Cy_CANFD_SetInterruptMask() function.
If the channel was disabled, call Cy_CANFD_Enable before calling Cy_CANFD_Init.
Call this function only after all debug messages reception is completed.
Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
*configThe pointer to the CAN FD configuration structure.
*contextThe pointer to the context structure cy_stc_canfd_context_t allocated by the user. The structure is used during the CAN FD operation for internal configuration and data retention. User must not modify anything in this structure.
Returns
cy_en_canfd_status_t
Function Usage
/* Scenario: Initialize the CAN FD block with predefined settings to:
- Receive the frames with ID = 0x10 into RX buffer element #0 in Massage RAM;
- Receive the frames with ID = 0x20 into RX buffer element #1 in Massage RAM;
- Receive the frames with ID = 0x10010 into RX buffer element #2 in Massage RAM;
- Receive the frames with ID = 0x10020 into RX buffer element #3 in Massage RAM;
- Receive the frames with non-Matching Standard IDs into RX FIFO#0 in Massage RAM;
- Receive the frames with non-Matching Extended IDs into RX FIFO#1 in Massage RAM;
- Transmit two TX buffers.
*/
#define MESSAGE_ID0 (0x00000001UL)
#define MESSAGE_ID1 (0x00000010UL)
#define MESSAGE_ID2 (0x00000020UL)
#define RX_BUFFER_ELEMENT_1 (0x0UL)
#define RX_BUFFER_ELEMENT_2 (0x1UL)
#define MESSAGE_ID3 (0x00010010UL)
#define MESSAGE_ID4 (0x00010020UL)
#define RX_BUFFER_ELEMENT_3 (0x2UL)
#define RX_BUFFER_ELEMENT_4 (0x3UL)
cy_stc_canfd_context_t context = {0}; /* This is a shared context structure, it is unique for each channel.
* It must be global
*/
cy_stc_canfd_bitrate_t bitrateConfig =
{
/* .prescaler */ 10u - 1u,
/* .timeSegment1 */ 5u - 1u,
/* .timeSegment2 */ 2u - 1u,
/* .syncJumpWidth */ 2u - 1u
};
cy_stc_canfd_bitrate_t fastBitrateConfig =
{
/* .prescaler */ 5u - 1u,
/* .timeSegment1 */ 5u - 1u,
/* .timeSegment2 */ 2u - 1u,
/* .syncJumpWidth */ 2u - 1u
};
{
/* .tdcEnabled */ false,
/* .tdcOffset */ 0,
/* .tdcFilterWindow */ 0
};
static const cy_stc_id_filter_t stdIdFilters[] =
{
/* stdIdFilter[0] */
{
/* .sfid2 */ RX_BUFFER_ELEMENT_1,
/* .sfid1 */ MESSAGE_ID1,
/* .sft */ CY_CANFD_SFT_CLASSIC_FILTER
},
/* stdIdFilter[1] */
{
/* .sfid2 */ RX_BUFFER_ELEMENT_2,
/* .sfid1 */ MESSAGE_ID2,
/* .sft */ CY_CANFD_SFT_CLASSIC_FILTER
}
};
cy_stc_canfd_f0_t filter0F0Config =
{
/* .efid1 */ MESSAGE_ID3,
/* .efec */ CY_CANFD_EFEC_STORE_RX_BUFFER
};
cy_stc_canfd_f1_t filter0F1Config =
{
/* .efid2 */ RX_BUFFER_ELEMENT_3,
/* .eft */ CY_CANFD_EFT_CLASSIC_FILTER
};
cy_stc_canfd_f0_t filter1F0Config =
{
/* .efid1 */ MESSAGE_ID4,
/* .efec */ CY_CANFD_EFEC_STORE_RX_BUFFER
};
cy_stc_canfd_f1_t filter1F1Config =
{
/* .efid2 */ RX_BUFFER_ELEMENT_4,
/* .eft */ CY_CANFD_EFT_CLASSIC_FILTER
};
const cy_stc_extid_filter_t extIdFilters[] =
{
/* extIdFilter[0] */
{
/* .f0_f */ &filter0F0Config,
/* .f1_f */ &filter0F1Config
},
/* extIdFilter[1] */
{
/* .f0_f */ &filter1F0Config,
/* .f1_f */ &filter1F1Config
}
};
{
/* .numberOfSIDFilters */ sizeof(stdIdFilters) / sizeof(stdIdFilters[0]),
/* .sidFilter */ stdIdFilters,
};
{
/* numberOfEXTIDFilters */ sizeof(extIdFilters) / sizeof(extIdFilters[0]),
/* extidFilter */ extIdFilters,
/* extIDANDMask */ 0x1fffffffUL
};
{
/* .nonMatchingFramesStandard */ CY_CANFD_ACCEPT_IN_RXFIFO_0,
/* .nonMatchingFramesExtended */ CY_CANFD_ACCEPT_IN_RXFIFO_1,
/* .rejectRemoteFramesStandard */ true,
/* .rejectRemoteFramesExtended */ true
};
cy_en_canfd_fifo_config_t rxFifo0Config =
{
/* watermark */ 1U,
/* numberOfFifoElements */ 2U,
/* topPointerLogicEnabled */ false
};
cy_en_canfd_fifo_config_t rxFifo1Config =
{
/* watermark */ 4U,
/* numberOfFifoElements */ 5U,
/* topPointerLogicEnabled */ false
};
const cy_stc_canfd_config_t config =
{
/* .txCallback */ NULL,
/* .rxCallback */ NULL,
/* .errorCallback */ NULL,
/* .canFDMode */ true,
/* .bitrate */ &bitrateConfig,
/* .fastBitrate */ &fastBitrateConfig,
/* .tdcConfig */ &tdcConfig,
/* .sidFilterConfig */ &sidFiltersConfig,
/* .extidFilterConfig */ &extidFiltersConfig,
/* .globalFilterConfig */ &globalFilterConfig,
/* .rxBufferDataSize */ CY_CANFD_BUFFER_DATA_SIZE_64,
/* .rxFIFO1DataSize */ CY_CANFD_BUFFER_DATA_SIZE_64,
/* .rxFIFO0DataSize */ CY_CANFD_BUFFER_DATA_SIZE_64,
/* .txBufferDataSize */ CY_CANFD_BUFFER_DATA_SIZE_64,
/* .rxFIFO0Config */ &rxFifo0Config,
/* .rxFIFO1Config */ &rxFifo1Config,
/* .noOfRxBuffers */ 0x4U,
/* .noOfTxBuffers */ 0x2U,
/* .messageRAMaddress */ CY_CAN0MRAM_BASE,
/* .messageRAMsize */ 8192U
};
if(CY_CANFD_SUCCESS != Cy_CANFD_Init (CANFD0, 0U, &config, &context))
{
/* Insert error handling */
}

◆ Cy_CANFD_DeInit()

cy_en_canfd_status_t Cy_CANFD_DeInit ( CANFD_Type *  base,
uint32_t  chan,
cy_stc_canfd_context_t context 
)

De-initializes the CAN FD block, returns registers values to default.

Note
Do not call Cy_CANFD_Disable before Cy_CANFD_DeInit.
Call this function only after all debug messages reception is completed.
Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
*contextThe pointer to the context structure cy_stc_canfd_context_t allocated by the user. The structure is used during the CAN FD operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
cy_en_canfd_status_t
Function Usage
/* Scenario: The CAN FD block is initialized/working and then no longer used or needs to be reset. */
cy_stc_canfd_context_t context = {0}; /* This is a shared context structure, it is unique for each channel.
* It must be global
*/
if(CY_CANFD_SUCCESS != Cy_CANFD_DeInit (CANFD0, 0UL, &context))
{
/* Insert error handling */
}

◆ Cy_CANFD_TransmitTxBuffer()

cy_en_canfd_status_t Cy_CANFD_TransmitTxBuffer ( CANFD_Type *  base,
uint32_t  chan,
uint8_t  index 
)

Starts transmission of the message prepared with Cy_CANFD_TxBufferConfig().

Transmits the message immediately. Function CanFD_Init() must be called before setting up the identifier and enabling this message buffer.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
indexMessage buffer index (0-31).
Returns
cy_en_canfd_status_t
Function Usage
/* Scenario: The TX buffer is configured with Cy_CANFD_TxBufferConfig()
* and a message is ready to be sent.
*/
uint8_t index = 0u; /* TX buffer index (max 31u) */
if(CY_CANFD_SUCCESS != Cy_CANFD_TransmitTxBuffer(CANFD0, 0UL, index))
{
/* Insert error handling */
}

◆ Cy_CANFD_UpdateAndTransmitMsgBuffer()

cy_en_canfd_status_t Cy_CANFD_UpdateAndTransmitMsgBuffer ( CANFD_Type *  base,
uint32_t  chan,
const cy_stc_canfd_tx_buffer_t txBuffer,
uint8_t  index,
cy_stc_canfd_context_t const *  context 
)

Updates the T0 and T1 Tx buffer element parameters in Message RAM and copies data from cy_stc_canfd_tx_buffer_t structure to Message RAM.

Transmits the message immediately. Function CanFD_Init() must be called before setting up the identifier and enabling this message buffer.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
*txBufferThe Tx Buffer configuration structure.
indexthe message buffer index (0-31).
contextThe pointer to the context structure cy_stc_canfd_context_t allocated by the user. The structure is used during the CAN FD operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
cy_en_canfd_status_t
Function Usage
/* Scenario: Configure a transmit buffer for the CAN FD transmit operation */
cy_stc_canfd_context_t context = {0}; /* This is a shared context structure, it is unique for each channel.
* It must be global
*/
uint8_t index = 0U; /* Tx Buffer Element number */
cy_stc_canfd_t0_t t0fConfig =
{
/* .id */ 0x00000055UL,
/* .esi */ CY_CANFD_ESI_ERROR_PASSIVE
};
cy_stc_canfd_t1_t t1fConfig =
{
/* .dlc */ 15U,
/* .brs */ true,
/* .efc */ false,
/* .mm */ 0UL
};
uint32_t data[16] =
{
0x00000000UL, 0x11111111UL, 0x22222222UL, 0x33333333UL,
0x44444444UL, 0x55555555UL, 0x66666666UL, 0x77777777UL,
0x88888888UL, 0x99999999UL, 0xAAAAAAAAUL, 0xBBBBBBBBUL,
0xCCCCCCCCUL, 0xDDDDDDDDUL, 0xEEEEEEEEUL, 0xFFFFFFFFUL
};
const cy_stc_canfd_tx_buffer_t txBufferConfig =
{
/* .t0_f */ &t0fConfig,
/* .t1_f */ &t1fConfig,
/* data_area_f */ data
};
if(CY_CANFD_SUCCESS != Cy_CANFD_UpdateAndTransmitMsgBuffer(CANFD0, 0UL, &txBufferConfig, index, &context))
{
/* Insert error handling */
}

◆ Cy_CANFD_GetTxBufferStatus()

cy_en_canfd_tx_buffer_status_t Cy_CANFD_GetTxBufferStatus ( CANFD_Type const *  base,
uint32_t  chan,
uint8_t  index 
)

Gets the status of the CAN FD Tx buffer.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
indexMessage buffer index (0-31).
Returns
cy_en_canfd_status_t
Function Usage
/* Scenario: Checks if the buffer was transmitted. */
uint8_t index = 0u; /* TX buffer index (max 31u) */
{
/* The buffer with index 0 was transmitted */
}

◆ Cy_CANFD_GetInterruptStatus()

__STATIC_INLINE uint32_t Cy_CANFD_GetInterruptStatus ( CANFD_Type const *  base,
uint32_t  chan 
)

Returns a status of CAN FD interrupt requests.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
Returns
uint32_t The bit mask of the Interrupt Status. Valid masks can be found in RX Interrupt masks, TX Interrupt masks and Error Interrupt masks.
Function Usage
/* Scenario: Checks for a new message in the RX buffer. */
uint32_t status;
status = Cy_CANFD_GetInterruptStatus(CANFD0, 0UL);
if (0 != (status & CY_CANFD_RX_BUFFER_NEW_MESSAGE))
{
/* Process the received message */
}

◆ Cy_CANFD_ClearInterrupt()

__STATIC_INLINE void Cy_CANFD_ClearInterrupt ( CANFD_Type *  base,
uint32_t  chan,
uint32_t  status 
)

Clears CAN FD interrupts by setting each bit.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
statusThe bitmask of statuses to clear. Valid masks can be found in RX Interrupt masks, TX Interrupt masks and Error Interrupt masks.
Function Usage
/* Scenario: Clears all RX interrupts by setting corresponding bits to 1. */
uint32_t status = (CY_CANFD_RX_BUFFER_NEW_MESSAGE | /* Message stored to Rx Buffer */
CY_CANFD_RX_FIFO_1_NEW_MESSAGE | /* Rx FIFO 1 New Message */
CY_CANFD_RX_FIFO_0_NEW_MESSAGE); /* Rx FIFO 0 New Message */
Cy_CANFD_ClearInterrupt(CANFD0, 0UL, status);

◆ Cy_CANFD_GetInterruptMask()

__STATIC_INLINE uint32_t Cy_CANFD_GetInterruptMask ( CANFD_Type const *  base,
uint32_t  chan 
)

Returns an interrupt mask.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
Returns
uint32_t The bit field determines which status changes can cause an interrupt. Valid masks can be found in RX Interrupt masks, TX Interrupt masks and Error Interrupt masks.
Function Usage
/* Scenario: Checks if the RX buffer interrupt is enabled. */
if (0 != (Cy_CANFD_GetInterruptMask(CANFD0, 0UL) & CY_CANFD_RX_BUFFER_NEW_MESSAGE))
{
/* The RX buffer interrupt is enabled */
}

◆ Cy_CANFD_SetInterruptMask()

__STATIC_INLINE void Cy_CANFD_SetInterruptMask ( CANFD_Type *  base,
uint32_t  chan,
uint32_t  interrupt 
)

Configures which bits of the interrupt request register can trigger an interrupt event.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
interruptThe bit field determines which status changes can cause an interrupt. Valid masks can be found in RX Interrupt masks, TX Interrupt masks and Error Interrupt masks.
Function Usage
/* Scenario: Enables the interrupts from the RX buffer, RX FIFO 0 and RX FIFO 1. */
uint32_t status = (CY_CANFD_RX_BUFFER_NEW_MESSAGE | /* Message stored to Rx Buffer */
CY_CANFD_RX_FIFO_1_NEW_MESSAGE | /* Rx FIFO 1 New Message */
CY_CANFD_RX_FIFO_0_NEW_MESSAGE); /* Rx FIFO 0 New Message */
Cy_CANFD_SetInterruptMask(CANFD0, 0UL, status);

◆ Cy_CANFD_GetInterruptLine()

__STATIC_INLINE uint32_t Cy_CANFD_GetInterruptLine ( CANFD_Type const *  base,
uint32_t  chan 
)

Returns the interrupt signals assigned to the line m_ttcan_int0 or m_ttcan_int1.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
Returns
uint32_t The mask where 1 corresponds to the interrupt signals assigned to the line m_ttcan_int1 and 0 corresponds to m_ttcan_int0. Valid masks can be found in RX Interrupt masks, TX Interrupt masks and Error Interrupt masks.
Function Usage
/* Scenario: Checks if Transmission Completed Interrupt uses the line m_ttcan_int1. */
uint32_t interruptLine;
interruptLine = Cy_CANFD_GetInterruptLine(CANFD0, 0UL);
if (0 != (interruptLine & CY_CANFD_TRANSMISSION_COMPLETE))
{
/* Transmission Completed Interrupt uses the line m_ttcan_int1 */
}

◆ Cy_CANFD_SetInterruptLine()

__STATIC_INLINE void Cy_CANFD_SetInterruptLine ( CANFD_Type *  base,
uint32_t  chan,
uint32_t  interruptLineMask 
)

Configures the bits of the Interrupt Line Select Register to assign the interrupt signal to the line m_ttcan_int0 or m_ttcan_int1.

Bit = 0: The interrupt assigned to the interrupt line m_ttcan_int0, bit = 1: The interrupt assigned to the interrupt line m_ttcan_int1.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
interruptLineMaskThe mask where 1 corresponds to the interrupt signals assigned to the line m_ttcan_int1 and 0 corresponds to m_ttcan_int0. Valid masks can be found in RX Interrupt masks, TX Interrupt masks and Error Interrupt masks.
Function Usage
/* Scenario: Sets Transmission Completed Interrupt to the interrupt
* line m_ttcan_int1.
*/
CY_CANFD_TRANSMISSION_COMPLETE);

◆ Cy_CANFD_IsInterruptLineEnabled()

__STATIC_INLINE bool Cy_CANFD_IsInterruptLineEnabled ( CANFD_Type const *  base,
uint32_t  chan,
uint32_t  interruptLineMask 
)

Checks whether Interrupt Line 0, Interrupt Line 1 or both are enabled.

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
interruptLineMaskThe bit mask to check which interrupt line is enabled. Can be CY_CANFD_INTERRUPT_LINE_0_EN, CY_CANFD_INTERRUPT_LINE_1_EN or (CY_CANFD_INTERRUPT_LINE_0_EN | CY_CANFD_INTERRUPT_LINE_1_EN)
Returns
bool The bit mask of the enabled interrupt lines.
Function Usage
/* Scenario: Checks if the interrupt line m_ttcan_int0 is enabled. */
#define INT_LINE_MASK CY_CANFD_INTERRUPT_LINE_0_EN
if (Cy_CANFD_IsInterruptLineEnabled(CANFD0, 0UL, INT_LINE_MASK))
{
/* The interrupt line m_ttcan_int0 is enabled */
}

◆ Cy_CANFD_EnableInterruptLine()

__STATIC_INLINE void Cy_CANFD_EnableInterruptLine ( CANFD_Type *  base,
uint32_t  chan,
uint32_t  interruptLineMask 
)

Configures which interrupt line is enabled (Interrupt Line 0, Interrupt Line 1 or both).

Parameters
*baseThe pointer to a CAN FD instance.
chanThe CAN FD channel number.
interruptLineMaskThe bit mask whose bits define interrupt lines to enable or disable.
Function Usage
/* Scenario: Enables the interrupt line m_ttcan_int0. */