libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
FDCAN peripheral API

libopencm3 STM32 FDCAN More...

Collaboration diagram for FDCAN peripheral API:

Functions

unsigned fdcan_get_fifo_element_size (uint32_t canport, unsigned fifo_id)
 Returns actual size of FIFO entry in FIFO for given CAN port and FIFO. More...
 
unsigned fdcan_get_txbuf_element_size (uint32_t canport)
 Returns actual size of transmit entry in transmit queue/FIFO for given CAN port. More...
 
void fdcan_init_std_filter_ram (uint32_t canport, uint32_t flssa, uint8_t lss)
 Initialize allocation of standard filter block in CAN message RAM. More...
 
void fdcan_init_ext_filter_ram (uint32_t canport, uint32_t flesa, uint8_t lse)
 Initialize allocation of extended filter block in CAN message RAM. More...
 
void fdcan_init_fifo_ram (uint32_t canport, unsigned fifo_id, uint32_t fxsa, uint8_t fxs)
 Initialize allocation of FIFO block in CAN message RAM. More...
 
void fdcan_init_tx_event_ram (uint32_t canport, uint32_t tesa, uint8_t tes)
 Initialize allocation of transmit event block in CAN message RAM. More...
 
void fdcan_init_tx_buffer_ram (uint32_t canport, uint32_t tbsa, uint8_t tbs)
 Initialize allocation of transmit queue block in CAN message RAM. More...
 
int fdcan_set_rx_element_size (uint32_t canport, uint8_t rxbuf, uint8_t rxfifo0, uint8_t rxfifo1)
 Initialize size of data fields in reception buffers. More...
 
int fdcan_set_tx_element_size (uint32_t canport, uint8_t txbuf)
 Initialize size of data fields in transmit buffers. More...
 
void fdcan_init_filter (uint32_t canport, uint8_t std_filt, uint8_t ext_filt)
 Configure amount of filters and initialize filtering block. More...
 
int fdcan_start (uint32_t canport, uint32_t timeout)
 Enable FDCAN operation after FDCAN block has been set up. More...
 
void fdcan_set_fifo_locked_mode (uint32_t canport, bool locked)
 Configure FDCAN FIFO lock mode. More...
 
int fdcan_init (uint32_t canport, uint32_t timeout)
 Put FDCAN block into INIT mode for setup. More...
 
void fdcan_set_can (uint32_t canport, bool auto_retry_disable, bool rx_fifo_locked, bool tx_queue_mode, bool silent, uint32_t n_sjw, uint32_t n_ts1, uint32_t n_ts2, uint32_t n_br_presc)
 Set essential FDCAN block parameters for plain CAN operation. More...
 
void fdcan_set_fdcan (uint32_t canport, bool brs_enable, bool fd_op_enable, uint32_t f_sjw, uint32_t f_ts1, uint32_t f_ts2, uint32_t f_br_presc)
 Set FDCAN block parameters for FDCAN transmission. More...
 
void fdcan_set_test (uint32_t canport, bool testing, bool loopback)
 Set FDCAN block testing features. More...
 
int fdcan_get_init_state (uint32_t canport)
 Return current FDCAN block operation state. More...
 
void fdcan_set_std_filter (uint32_t canport, uint32_t nr, uint8_t id_list_mode, uint32_t id1, uint32_t id2, uint8_t action)
 Configure filter rule for standard ID frames. More...
 
void fdcan_set_ext_filter (uint32_t canport, uint32_t nr, uint8_t id_list_mode, uint32_t id1, uint32_t id2, uint8_t action)
 Configure filter rule for extended ID frames. More...
 
int fdcan_transmit (uint32_t canport, uint32_t id, bool ext, bool rtr, bool fdcan_fmt, bool btr_switch, uint8_t length, const uint8_t *data)
 Transmit Message using FDCAN. More...
 
int fdcan_receive (uint32_t canport, uint8_t fifo_id, bool release, uint32_t *id, bool *ext, bool *rtr, uint8_t *fmi, uint8_t *length, uint8_t *data, uint16_t *timestamp)
 Receive Message from FDCAN FIFO. More...
 
void fdcan_release_fifo (uint32_t canport, uint8_t fifo_id)
 Release receive oldest FIFO entry. More...
 
void fdcan_enable_irq (uint32_t canport, uint32_t irq)
 Enable IRQ from FDCAN block. More...
 
void fdcan_disable_irq (uint32_t canport, uint32_t irq)
 Disable IRQ from FDCAN block. More...
 
bool fdcan_available_tx (uint32_t canport)
 Check if there is free transmit buffer. More...
 
bool fdcan_available_rx (uint32_t canport, uint8_t fifo)
 Tell if there is message waiting in receive FIFO. More...
 

Detailed Description

libopencm3 STM32 FDCAN

Version
1.0.0
Author
© 2021 Eduard Drusa <ventyl86 at netkosice dot sk>

Device is equipped with two FDCAN peripherals residing in one FDCAN block. The peripherals support both CAN 2.0 A and B standard and Bosch FDCAN standard. FDCAN frame format and bitrate switching is supported. The peripheral has several filters for incoming messages that can be distributed between two FIFOs and transmit buffer all of configurable amount of entries. For transmitted messages it is possible to opt for event notification once message is transmitted.

The FDCAN peripheral present in STM32 H7 is a superset of FDCAN peripheral found in other MCUs such as STM32 G4. It allows more fine-grade control over buffer and filter allocation and supports TTCAN on CAN1, etc. This driver provides source-level backwards compatible implementation of driver, which allows build of unmodified software originally written for STM32 G4 on STM32 H7.

LGPL License Terms libopencm3 License

Function Documentation

◆ fdcan_available_rx()

bool fdcan_available_rx ( uint32_t  canport,
uint8_t  fifo 
)

Tell if there is message waiting in receive FIFO.

Parameters
[in]canportFDCAN port. See FDCAN block base addresses.
[in]fifoRx FIFO number, 0 or 1
Returns
true if there is at least one message waiting in given receive FIFO, false otherwise.

Definition at line 687 of file fdcan_common.c.

References FDCAN_RXFIFO_FL_MASK, FDCAN_RXFIFO_FL_SHIFT, and FDCAN_RXFIS.

◆ fdcan_available_tx()

bool fdcan_available_tx ( uint32_t  canport)

Check if there is free transmit buffer.

Parameters
[in]canportFDCAN port. See FDCAN block base addresses.
Returns
true if there is at least one free transmit buffer for new message to be sent, false otherwise.

Definition at line 675 of file fdcan_common.c.

References FDCAN_E_BUSY, and fdcan_get_free_txbuf().

Here is the call graph for this function:

◆ fdcan_disable_irq()

void fdcan_disable_irq ( uint32_t  canport,
uint32_t  irq 
)

Disable IRQ from FDCAN block.

This routine configures FDCAN to disable certain IRQ. Each FDCAN block supports two IRQs.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]irqnumber of IRQ to be enabled (currently 0 or 1)

Definition at line 664 of file fdcan_common.c.

References FDCAN_ILE, FDCAN_ILE_INT0, and FDCAN_ILE_INT1.

◆ fdcan_enable_irq()

void fdcan_enable_irq ( uint32_t  canport,
uint32_t  irq 
)

Enable IRQ from FDCAN block.

This routine configures FDCAN to enable certain IRQ. Each FDCAN block supports two IRQs.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]irqnumber of IRQ to be enabled (currently 0 or 1)

Definition at line 651 of file fdcan_common.c.

References FDCAN_ILE, FDCAN_ILE_INT0, and FDCAN_ILE_INT1.

◆ fdcan_get_fifo_element_size()

unsigned fdcan_get_fifo_element_size ( uint32_t  canport,
unsigned  fifo_id 
)

Returns actual size of FIFO entry in FIFO for given CAN port and FIFO.

Obtains value of FIFO entry length. This value covers both fixed-size frame header block and payload buffer. User can configure payload buffer size individually for each FIFO and designated RX buffer.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]fifo_idID of FIFO whole length is queried.
Returns
Length of FIFO entry length covering frame header and frame payload.

Definition at line 72 of file fdcan.c.

References fdcan_dlc_to_length(), FDCAN_RXESC, FDCAN_RXESC_F0DS_MASK, FDCAN_RXESC_F0DS_SHIFT, and FDCAN_RXESC_F1DS_SHIFT.

Referenced by fdcan_get_rxfifo_addr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fdcan_get_init_state()

int fdcan_get_init_state ( uint32_t  canport)

Return current FDCAN block operation state.

This function effectively returns value of FDCAN_CCCR's INIT bit.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
Returns
1 if FDCAN block is in INIT mode, 0 if it is already started.

Definition at line 396 of file fdcan_common.c.

References FDCAN_CCCR, and FDCAN_CCCR_INIT.

◆ fdcan_get_txbuf_element_size()

unsigned fdcan_get_txbuf_element_size ( uint32_t  canport)

Returns actual size of transmit entry in transmit queue/FIFO for given CAN port.

Obtains value of entry length in transmit queue/FIFO. This value covers both fixed-sized frame header block and payload buffer. User can configure payload buffer size.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
Returns
Length of FIFO entry length covering frame header and frame payload.

Definition at line 94 of file fdcan.c.

References fdcan_dlc_to_length(), FDCAN_TXESC, FDCAN_TXESC_TBDS_MASK, and FDCAN_TXESC_TBDS_SHIFT.

Referenced by fdcan_get_txbuf_addr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fdcan_init()

int fdcan_init ( uint32_t  canport,
uint32_t  timeout 
)

Put FDCAN block into INIT mode for setup.

Initialize the selected CAN peripheral block. This function will switch CAN block into initialization mode. CAN block is then left in initialization mode in order to perform setup, which can't be adjusted once FDCAN block is started. It is mandatory to call at least fdcan_set_can function to configure basic timing values for CAN 2.0 operation. Functions which only have effect, if FDCAN block is in INIT mode are:

You can check if FDCAN block is in INIT mode or it is started using fdcan_get_init_state.

Parameters
[in]canportCAN register base address. See FDCAN block base addresses.
[in]timeoutAmount of empty busy loops, which routine should wait for FDCAN confirming that it entered INIT mode. If set to 0, function will return immediately.
Returns
Operation error status. See FDCAN error return values.

Definition at line 260 of file fdcan_common.c.

References FDCAN_CCCR, FDCAN_CCCR_CCE, fdcan_cccr_init_cfg(), FDCAN_E_OK, and FDCAN_E_TIMEOUT.

Here is the call graph for this function:

◆ fdcan_init_ext_filter_ram()

void fdcan_init_ext_filter_ram ( uint32_t  canport,
uint32_t  flesa,
uint8_t  lse 
)

Initialize allocation of extended filter block in CAN message RAM.

Allows specifying size of extended filtering block (in term of available filtering rules and filter base address within CAN message RAM. Note, that there are no limitations nor checking on address provided. It is possible to share whole filtering block or portion of it between multiple CAN interfaces.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]flesaextended filtering block start address offset in message RAM
[in]lseamount of extended filters

Definition at line 127 of file fdcan.c.

References FDCAN_XIDFC, FDCAN_XIDFC_FLESA_SHIFT, and FDCAN_XIDFC_LSE_SHIFT.

Referenced by fdcan_init_filter().

Here is the caller graph for this function:

◆ fdcan_init_fifo_ram()

void fdcan_init_fifo_ram ( uint32_t  canport,
unsigned  fifo_id,
uint32_t  fxsa,
uint8_t  fxs 
)

Initialize allocation of FIFO block in CAN message RAM.

Allows specifying size of FIFO block (in term of available messages in FIFO and FIFO base address within CAN message RAM. Note, that there are no limitations nor checking on address provided.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]fifo_idID of fifo being configured
[in]fxsaFIFO block start address offset in message RAM
[in]fxsnumber of elements to assign

Definition at line 143 of file fdcan.c.

References FDCAN_RXFIC, FDCAN_RXFIC_FIS_MASK, FDCAN_RXFIC_FIS_SHIFT, FDCAN_RXFIC_FISA_MASK, and FDCAN_RXFIC_FISA_SHIFT.

Referenced by fdcan_start().

Here is the caller graph for this function:

◆ fdcan_init_filter()

void fdcan_init_filter ( uint32_t  canport,
uint8_t  std_filt,
uint8_t  ext_filt 
)

Configure amount of filters and initialize filtering block.

This function allows to configure global amount of filters present. FDCAN block will only ever check as many filters as this function configures. Function will also clear all filter blocks to zero values. This function can be only called after fdcan_init has already been called and fdcan_start has not been called yet as registers holding filter count are write-protected unless FDCAN block is in INIT mode. It is possible to reconfigure filters (fdcan_set_std_filter and fdcan_set_ext_filter) after FDCAN block has already been started.

This function is provided for source level compatibility with code written for STM32G4. As an alternative, you can use fdcan_init_std_filter_ram() and fdcan_init_ext_filter_ram() to have more control over filtering configuration. Note that if you do so, your code won't be compatible with STM32G4 controllers.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]std_filtrequested amount of standard ID filter rules (0-28)
[in]ext_filtrequested amount of extended ID filter rules (0-8)

Definition at line 300 of file fdcan.c.

References CAN_MSG_BASE, CAN_MSG_SIZE, fdcan_extended_filter::conf_id1, FDCAN_BLOCK_ID, fdcan_get_flesa_addr(), fdcan_get_flssa_addr(), fdcan_init_ext_filter_ram(), fdcan_init_std_filter_ram(), fdcan_standard_filter::type_id1_conf_id2, and fdcan_extended_filter::type_id2.

Here is the call graph for this function:

◆ fdcan_init_std_filter_ram()

void fdcan_init_std_filter_ram ( uint32_t  canport,
uint32_t  flssa,
uint8_t  lss 
)

Initialize allocation of standard filter block in CAN message RAM.

Allows specifying size of standard filtering block (in term of available filtering rules and filter base address within CAN message RAM. Note, that there are no limitations nor checking on address provided. It is possible to share whole filtering block or portion of it between multiple CAN interfaces.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]flssastandard filtering block start address offset in message RAM
[in]lssamount of standard filters

Definition at line 111 of file fdcan.c.

References FDCAN_SIDFC, FDCAN_SIDFC_FLSSA_SHIFT, and FDCAN_SIDFC_LSS_SHIFT.

Referenced by fdcan_init_filter().

Here is the caller graph for this function:

◆ fdcan_init_tx_buffer_ram()

void fdcan_init_tx_buffer_ram ( uint32_t  canport,
uint32_t  tbsa,
uint8_t  tbs 
)

Initialize allocation of transmit queue block in CAN message RAM.

Allows specifying size of transmit queue block (in term of allocated buffers and block base address within CAN message RAM. Note, that there are no limitations nor checking on address provided.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]tbsablock start address offset in message RAM
[in]tbsnumber of elements to assign

Definition at line 183 of file fdcan.c.

References FDCAN_TXBC, FDCAN_TXBC_TBSA_MASK, FDCAN_TXBC_TBSA_SHIFT, FDCAN_TXBC_TFQS_MASK, and FDCAN_TXBC_TFQS_SHIFT.

Referenced by fdcan_start().

Here is the caller graph for this function:

◆ fdcan_init_tx_event_ram()

void fdcan_init_tx_event_ram ( uint32_t  canport,
uint32_t  tesa,
uint8_t  tes 
)

Initialize allocation of transmit event block in CAN message RAM.

Allows specifying size of transmit event block (in term of allocated events and block base address within CAN message RAM. Note, that there are no limitations nor checking on address provided.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]tesablock start address offset in message RAM
[in]tesnumber of elements to assign

Definition at line 163 of file fdcan.c.

References FDCAN_TXEFC, FDCAN_TXEFC_EFS_MASK, FDCAN_TXEFC_EFS_SHIFT, FDCAN_TXEFC_EFSA_MASK, and FDCAN_TXEFC_EFSA_SHIFT.

Referenced by fdcan_start().

Here is the caller graph for this function:

◆ fdcan_receive()

int fdcan_receive ( uint32_t  canport,
uint8_t  fifo_id,
bool  release,
uint32_t *  id,
bool *  ext,
bool *  rtr,
uint8_t *  fmi,
uint8_t *  length,
uint8_t *  data,
uint16_t *  timestamp 
)

Receive Message from FDCAN FIFO.

Reads one message from receive FIFO. Returns message ID, type of ID, message length and message payload. It is mandatory to provide valid pointers to suitably sized buffers for these outputs. Additionally, it is optinally possible to provide non-zero pointer to obtain filter identification, request of transmission flag and message timestamp. If pointers provided for optional outputs are NULL, then no information is returned for given pointer.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses
[in]fifo_idFIFO id.
[in]releaseRelease the FIFO automatically after copying data out
[out]idReturned message ID. Mandatory.
[out]extReturned type of the message ID (true if extended). Mandatory.
[out]rtrReturnes flag if request of transmission was requested. Optional.
[out]fmiReturned ID of the filter which matched this frame. Optional.
[out]lengthLength of message payload in bytes. Mandatory.
[out]dataBuffer for storage of message payload data. Mandatory.
[out]timestampReturned timestamp of received frame. Optional.
Returns
Operation error status. See FDCAN error return values.

Definition at line 562 of file fdcan_common.c.

References fdcan_rx_fifo_element::data, fdcan_dlc_to_length(), FDCAN_E_NOTAVAIL, FDCAN_E_OK, FDCAN_FIFO_DLC_MASK, FDCAN_FIFO_DLC_SHIFT, FDCAN_FIFO_EID_MASK, FDCAN_FIFO_EID_SHIFT, FDCAN_FIFO_MM_MASK, FDCAN_FIFO_MM_SHIFT, FDCAN_FIFO_RTR, FDCAN_FIFO_RXTS_MASK, FDCAN_FIFO_RXTS_SHIFT, FDCAN_FIFO_SID_MASK, FDCAN_FIFO_SID_SHIFT, FDCAN_FIFO_XTD, fdcan_get_fill_rxfifo(), fdcan_get_rxfifo_addr(), FDCAN_RXFIA, FDCAN_RXFIFO_AI_SHIFT, fdcan_rx_fifo_element::filt_fmt_dlc_ts, and fdcan_rx_fifo_element::identifier_flags.

Here is the call graph for this function:

◆ fdcan_release_fifo()

void fdcan_release_fifo ( uint32_t  canport,
uint8_t  fifo_id 
)

Release receive oldest FIFO entry.

This function will mask oldest entry in FIFO as released making space for another received frame. This function can be used if fdcan_receive was called using release = false. If used in other case, then messages can get lost.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]fifo_idID of FIFO where release should be performed (0 or 1)

Definition at line 628 of file fdcan_common.c.

References FDCAN_RXFIA, FDCAN_RXFIFO_AI_SHIFT, FDCAN_RXFIFO_FL_SHIFT, FDCAN_RXFIFO_GI_SHIFT, and FDCAN_RXFIS.

◆ fdcan_set_can()

void fdcan_set_can ( uint32_t  canport,
bool  auto_retry_disable,
bool  rx_fifo_locked,
bool  tx_queue_mode,
bool  silent,
uint32_t  n_sjw,
uint32_t  n_ts1,
uint32_t  n_ts2,
uint32_t  n_br_presc 
)

Set essential FDCAN block parameters for plain CAN operation.

Allows configuration of prescalers and essential transmit and FIFO behavior used during transmission in plain CAN 2.0 mode. In this mode FDCAN frame format is not available nor is possible to use fast bitrates. This function does neither enable FD-CAN mode after reset nor disable it after re-entering INIT mode of previously configured block. Timing values set here are valid for both arbitration phase of all frames and for data phase of both CAN and FDCAN frames, which don't use bitrate switching. This function can only be called after FDCAN block has been switched into INIT mode. It is possible to receive FDCAN frames even if FDCAN block is configured only using this function as long as bitrate switching is not used.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]auto_retry_disableDisable automatic frame retransmission on error
[in]rx_fifo_lockedEnable FIFO locked mode. Upon FIFO overflow all received messages are discarded.
[in]tx_queue_modeEnable transmission queue mode. Otherwise transmission works in FIFO mode.
[in]silentEnable silent mode. Transmitter stays recessive all the time.
[in]n_sjwResynchronization time quanta jump width
[in]n_ts1Time segment 1 time quanta
[in]n_ts2Time segment 2 time quanta
[in]n_br_prescArbitration phase / CAN mode bitrate prescaler

Definition at line 296 of file fdcan_common.c.

References FDCAN_CCCR, FDCAN_CCCR_DAR, FDCAN_CCCR_MON, FDCAN_NBTP, FDCAN_NBTP_NBRP_SHIFT, FDCAN_NBTP_NSJW_SHIFT, FDCAN_NBTP_NTSEG1_SHIFT, FDCAN_NBTP_NTSEG2_SHIFT, fdcan_set_fifo_locked_mode(), FDCAN_TXBC, and FDCAN_TXBC_TFQM.

Here is the call graph for this function:

◆ fdcan_set_ext_filter()

void fdcan_set_ext_filter ( uint32_t  canport,
uint32_t  nr,
uint8_t  id_list_mode,
uint32_t  id1,
uint32_t  id2,
uint8_t  action 
)

Configure filter rule for extended ID frames.

Sets up filter rule for frames having extended ID. Each FDCAN block can have its own set of filtering rules. It is only possible to configure as many filters as was configured previously using fdcan_init_filter.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]nrnumber of filter to be configured
[in]id_list_modemode in which id1 and id2 are used to match the rule. See Extended ID filter match type.
[in]id1extended ID for matching. Used as exact value, lower bound or bit pattern depending on matching mode selected
[in]id2extended ID or bitmask. Used as exact value, upper bound or bit mask depending on matching mode selected
[in]actionAction performed if filtering rule matches frame ID. See Extended ID filter action.

Definition at line 458 of file fdcan_common.c.

References fdcan_extended_filter::conf_id1, FDCAN_EFEC_SHIFT, FDCAN_EFID1_MASK, FDCAN_EFID1_SHIFT, FDCAN_EFID2_MASK, FDCAN_EFID2_SHIFT, FDCAN_EFT_SHIFT, fdcan_get_flesa_addr(), and fdcan_extended_filter::type_id2.

Here is the call graph for this function:

◆ fdcan_set_fdcan()

void fdcan_set_fdcan ( uint32_t  canport,
bool  brs_enable,
bool  fd_op_enable,
uint32_t  f_sjw,
uint32_t  f_ts1,
uint32_t  f_ts2,
uint32_t  f_br_presc 
)

Set FDCAN block parameters for FDCAN transmission.

Enables and configures parameters related to FDCAN transmission. This function allows configuration of bitrate switching, FDCAN frame format and fast mode timing. This function can only be called if FDCAN block is in INIT mode. It is safe to call this function on previously configured block in order to enable/disable/change FDCAN mode parameters. Non-FDCAN parameters won't be affected.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]brs_enableEnable FDCAN bitrate switching for fast mode operation
[in]fd_op_enableEnable transmission of FDCAN-formatted frames
[in]f_sjwResynchronization time quanta jump width in fast mode
[in]f_ts1Time segment 1 time quanta in fast mode
[in]f_ts2Time segment 2 time quanta in fast mode
[in]f_br_prescFast mode operation bitrate prescaler

Definition at line 343 of file fdcan_common.c.

References FDCAN_CCCR, FDCAN_CCCR_BRSE, FDCAN_CCCR_FDOE, FDCAN_DBTP, FDCAN_DBTP_DBRP_SHIFT, FDCAN_DBTP_DSJW_SHIFT, FDCAN_DBTP_DTSEG1_SHIFT, and FDCAN_DBTP_DTSEG2_SHIFT.

◆ fdcan_set_fifo_locked_mode()

void fdcan_set_fifo_locked_mode ( uint32_t  canport,
bool  locked 
)

Configure FDCAN FIFO lock mode.

This function allows to choose between locked and overewrite mode of FIFOs. In locked mode, whenever FIFO is full and new frame arrives, which would normally been stored into given FIFO, then frame is dropped. If overwrite mode is active, then most recent message in FIFO is rewritten by frame just received.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]lockedtrue activates locked mode, false activates overwrite mode

Definition at line 460 of file fdcan.c.

References FDCAN_RXF0C, FDCAN_RXF0C_F0OM, FDCAN_RXF1C, and FDCAN_RXF1C_F1OM.

Referenced by fdcan_set_can().

Here is the caller graph for this function:

◆ fdcan_set_rx_element_size()

int fdcan_set_rx_element_size ( uint32_t  canport,
uint8_t  rxbuf,
uint8_t  rxfifo0,
uint8_t  rxfifo1 
)

Initialize size of data fields in reception buffers.

Configures maximum size of message payload, which can be stored in different reception buffers. Each buffer can have maximum payload size configured independently. Buffers can only be configured to sizes which are valid sizes of FDCAN payload. Sizes smaller than 8 are automatically padded to 8.

Note
If you change these values, then content of reception buffers is invalidated. You may also want to recalculate base addresses of objects in message RAM as their size might have changed.
Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]rxbufmaximum storable payload size of dedicated RX buffer
[in]rxfifo0maximum storable payload size of RX FIFO 0
[in]rxfifo1maximum storable payload size of RX FIFO 1
Returns
operation return status. See FDCAN error return values.

Definition at line 209 of file fdcan.c.

References FDCAN_E_INVALID, FDCAN_E_OK, fdcan_length_to_dlc(), FDCAN_RXESC, FDCAN_RXESC_F0DS_SHIFT, FDCAN_RXESC_F1DS_SHIFT, and FDCAN_RXESC_RBDS_SHIFT.

Referenced by fdcan_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fdcan_set_std_filter()

void fdcan_set_std_filter ( uint32_t  canport,
uint32_t  nr,
uint8_t  id_list_mode,
uint32_t  id1,
uint32_t  id2,
uint8_t  action 
)

Configure filter rule for standard ID frames.

Sets up filter rule for frames having standard ID. Each FDCAN block can have its own set of filtering rules. It is only possible to configure as many filters as was configured previously using fdcan_init_filter.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]nrnumber of filter to be configured
[in]id_list_modeMode in which id1 and id2 are used to match the rule. See Standard ID filter match type.
[in]id1standard ID for matching. Used as exact value, lower bound or bit pattern depending on matching mode selected
[in]id2standard ID or bitmask. Used as exact value, upper bound or bit mask depending on matching mode selected
[in]actionAction performed if filtering rule matches frame ID. See Standard ID filter action.

Definition at line 418 of file fdcan_common.c.

References fdcan_get_flssa_addr(), FDCAN_SFEC_SHIFT, FDCAN_SFID1_MASK, FDCAN_SFID1_SHIFT, FDCAN_SFID2_MASK, FDCAN_SFID2_SHIFT, FDCAN_SFT_SHIFT, and fdcan_standard_filter::type_id1_conf_id2.

Here is the call graph for this function:

◆ fdcan_set_test()

void fdcan_set_test ( uint32_t  canport,
bool  testing,
bool  loopback 
)

Set FDCAN block testing features.

Configures self-test functions of FDCAN block. It is safe to call this function on fully configured interface. This function can only be called after FDCAN block is put into INIT mode.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]testingEnables testing mode of FDCAN block
[in]loopbackEnables transmission loopback

Definition at line 374 of file fdcan_common.c.

References FDCAN_CCCR, FDCAN_CCCR_TEST, FDCAN_TEST, and FDCAN_TEST_LBCK.

◆ fdcan_set_tx_element_size()

int fdcan_set_tx_element_size ( uint32_t  canport,
uint8_t  txbuf 
)

Initialize size of data fields in transmit buffers.

Configures maximum size of message payload, which can be stored either in dedicated transmit buffer or into transmit queue/FIFO. One size is applied both to transmit buffer and transmit queue / FIFO. Buffers can only be configured to sizes which are valid sizes of FDCAN payload. Sizes smaller than 8 are automatically padded to 8 bytes.

Note
If you change these values, then content of transmission buffers is invalidated. You may also want to recalculate base addresses of objects in message RAM as their size might have changed.
Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]txbufmaximum storable payload size of TX buffer / FIFO / queue
Returns
operation return status. See FDCAN error return values.

Definition at line 261 of file fdcan.c.

References FDCAN_E_INVALID, FDCAN_E_OK, fdcan_length_to_dlc(), FDCAN_TXESC, and FDCAN_TXESC_TBDS_SHIFT.

Referenced by fdcan_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fdcan_start()

int fdcan_start ( uint32_t  canport,
uint32_t  timeout 
)

Enable FDCAN operation after FDCAN block has been set up.

This function will disable FDCAN configuration effectively allowing FDCAN to sync up with the bus. After calling this function it is not possible to reconfigure amount of filter rules, yet it is possible to configure rules themselves. FDCAN block operation state can be checked using fdcan_get_init_state.

Parameters
[in]canportFDCAN block base address. See FDCAN block base addresses.
[in]timeoutAmount of empty busy loops, which routine should wait for FDCAN confirming that it left INIT mode. If set to 0, function will return immediately.
Returns
Operation error status. See FDCAN error return values.
Note
If this function returns with timeout, it usually means that FDCAN_clk is not set up properly.

Definition at line 359 of file fdcan.c.

References CAN_MSG_SIZE, FDCAN_BLOCK_ID, fdcan_cccr_init_cfg(), FDCAN_E_OK, FDCAN_E_TIMEOUT, fdcan_init_fifo_ram(), fdcan_init_tx_buffer_ram(), fdcan_init_tx_event_ram(), FDCAN_LFESA_OFFSET, FDCAN_LSE_COUNT, FDCAN_RXESC, FDCAN_RXFIFO_OFFSET, fdcan_set_rx_element_size(), fdcan_set_tx_element_size(), FDCAN_TXBUF_OFFSET, FDCAN_TXESC, and FDCAN_TXEVT_OFFSET.

Here is the call graph for this function:

◆ fdcan_transmit()

int fdcan_transmit ( uint32_t  canport,
uint32_t  id,
bool  ext,
bool  rtr,
bool  fdcan_fmt,
bool  btr_switch,
uint8_t  length,
const uint8_t *  data 
)

Transmit Message using FDCAN.

Parameters
[in]canportCAN block register base. See FDCAN block base addresses.
[in]idMessage ID
[in]extExtended message ID
[in]rtrRequest transmit
[in]fdcan_fmtUse FDCAN format
[in]btr_switchSwitch bitrate for data portion of frame
[in]lengthMessage payload length. Must be valid CAN or FDCAN frame length
[in]dataMessage payload data
Returns
int 0, 1 or 2 on success and depending on which outgoing mailbox got selected. Otherwise returns error code. For error codes, see FDCAN error return values.

Definition at line 486 of file fdcan_common.c.

References fdcan_tx_buffer_element::data, fdcan_tx_buffer_element::evt_fmt_dlc_res, FDCAN_E_BUSY, FDCAN_E_INVALID, FDCAN_FIFO_BRS, FDCAN_FIFO_DLC_SHIFT, FDCAN_FIFO_EID_MASK, FDCAN_FIFO_EID_SHIFT, FDCAN_FIFO_FDF, FDCAN_FIFO_RTR, FDCAN_FIFO_SID_MASK, FDCAN_FIFO_SID_SHIFT, FDCAN_FIFO_XTD, fdcan_get_free_txbuf(), fdcan_get_txbuf_addr(), fdcan_length_to_dlc(), FDCAN_TXBAR, and fdcan_tx_buffer_element::identifier_flags.

Here is the call graph for this function: