libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
|
libopencm3 STM32 FDCAN More...
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... | |
libopencm3 STM32 FDCAN
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
bool fdcan_available_rx | ( | uint32_t | canport, |
uint8_t | fifo | ||
) |
Tell if there is message waiting in receive FIFO.
[in] | canport | FDCAN port. See FDCAN block base addresses. |
[in] | fifo | Rx FIFO number, 0 or 1 |
Definition at line 687 of file fdcan_common.c.
References FDCAN_RXFIFO_FL_MASK, FDCAN_RXFIFO_FL_SHIFT, and FDCAN_RXFIS.
bool fdcan_available_tx | ( | uint32_t | canport | ) |
Check if there is free transmit buffer.
[in] | canport | FDCAN port. See FDCAN block base addresses. |
Definition at line 675 of file fdcan_common.c.
References FDCAN_E_BUSY, and fdcan_get_free_txbuf().
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | irq | number 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.
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | irq | number 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.
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | fifo_id | ID of FIFO whole length is queried. |
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().
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
Definition at line 396 of file fdcan_common.c.
References FDCAN_CCCR, and FDCAN_CCCR_INIT.
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
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().
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.
[in] | canport | CAN register base address. See FDCAN block base addresses. |
[in] | timeout | Amount of empty busy loops, which routine should wait for FDCAN confirming that it entered INIT mode. If set to 0, function will return immediately. |
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.
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | flesa | extended filtering block start address offset in message RAM |
[in] | lse | amount 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().
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | fifo_id | ID of fifo being configured |
[in] | fxsa | FIFO block start address offset in message RAM |
[in] | fxs | number 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().
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | std_filt | requested amount of standard ID filter rules (0-28) |
[in] | ext_filt | requested 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.
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | flssa | standard filtering block start address offset in message RAM |
[in] | lss | amount 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().
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | tbsa | block start address offset in message RAM |
[in] | tbs | number 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().
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | tesa | block start address offset in message RAM |
[in] | tes | number 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().
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses |
[in] | fifo_id | FIFO id. |
[in] | release | Release the FIFO automatically after copying data out |
[out] | id | Returned message ID. Mandatory. |
[out] | ext | Returned type of the message ID (true if extended). Mandatory. |
[out] | rtr | Returnes flag if request of transmission was requested. Optional. |
[out] | fmi | Returned ID of the filter which matched this frame. Optional. |
[out] | length | Length of message payload in bytes. Mandatory. |
[out] | data | Buffer for storage of message payload data. Mandatory. |
[out] | timestamp | Returned timestamp of received frame. Optional. |
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.
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | fifo_id | ID 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.
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | auto_retry_disable | Disable automatic frame retransmission on error |
[in] | rx_fifo_locked | Enable FIFO locked mode. Upon FIFO overflow all received messages are discarded. |
[in] | tx_queue_mode | Enable transmission queue mode. Otherwise transmission works in FIFO mode. |
[in] | silent | Enable silent mode. Transmitter stays recessive all the time. |
[in] | n_sjw | Resynchronization time quanta jump width |
[in] | n_ts1 | Time segment 1 time quanta |
[in] | n_ts2 | Time segment 2 time quanta |
[in] | n_br_presc | Arbitration 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.
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | nr | number of filter to be configured |
[in] | id_list_mode | mode in which id1 and id2 are used to match the rule. See Extended ID filter match type. |
[in] | id1 | extended ID for matching. Used as exact value, lower bound or bit pattern depending on matching mode selected |
[in] | id2 | extended ID or bitmask. Used as exact value, upper bound or bit mask depending on matching mode selected |
[in] | action | Action 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.
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | brs_enable | Enable FDCAN bitrate switching for fast mode operation |
[in] | fd_op_enable | Enable transmission of FDCAN-formatted frames |
[in] | f_sjw | Resynchronization time quanta jump width in fast mode |
[in] | f_ts1 | Time segment 1 time quanta in fast mode |
[in] | f_ts2 | Time segment 2 time quanta in fast mode |
[in] | f_br_presc | Fast 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.
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | locked | true 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().
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | rxbuf | maximum storable payload size of dedicated RX buffer |
[in] | rxfifo0 | maximum storable payload size of RX FIFO 0 |
[in] | rxfifo1 | maximum storable payload size of RX FIFO 1 |
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().
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | nr | number of filter to be configured |
[in] | id_list_mode | Mode in which id1 and id2 are used to match the rule. See Standard ID filter match type. |
[in] | id1 | standard ID for matching. Used as exact value, lower bound or bit pattern depending on matching mode selected |
[in] | id2 | standard ID or bitmask. Used as exact value, upper bound or bit mask depending on matching mode selected |
[in] | action | Action 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.
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | testing | Enables testing mode of FDCAN block |
[in] | loopback | Enables transmission loopback |
Definition at line 374 of file fdcan_common.c.
References FDCAN_CCCR, FDCAN_CCCR_TEST, FDCAN_TEST, and FDCAN_TEST_LBCK.
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | txbuf | maximum storable payload size of TX buffer / FIFO / queue |
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().
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.
[in] | canport | FDCAN block base address. See FDCAN block base addresses. |
[in] | timeout | Amount of empty busy loops, which routine should wait for FDCAN confirming that it left INIT mode. If set to 0, function will return immediately. |
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.
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.
[in] | canport | CAN block register base. See FDCAN block base addresses. |
[in] | id | Message ID |
[in] | ext | Extended message ID |
[in] | rtr | Request transmit |
[in] | fdcan_fmt | Use FDCAN format |
[in] | btr_switch | Switch bitrate for data portion of frame |
[in] | length | Message payload length. Must be valid CAN or FDCAN frame length |
[in] | data | Message payload data |
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.