Detailed Description

How to use the FlexCAN driver in your application

In order to be able to use the FlexCAN in your application, the first thing to do is initializing it with the desired configuration. This is done by calling the FLEXCAN_DRV_Init function. One of the arguments passed to this function is the configuration which will be used for the FlexCAN module, specified by the flexcan_user_config_t structure.

The flexcan_user_config_t structure allows you to configure the following:

The bitrate is represented by a flexcan_time_segment_t structure, with the following fields:

Details about these fields can be found in the reference manual.

In order to use a mailbox for transmission/reception, it should be initialized using either FLEXCAN_DRV_ConfigRxMb, FLEXCAN_DRV_ConfigRxFifo or FLEXCAN_DRV_ConfigTxMb.

After having the mailbox configured, you can start sending/receiving data using the specified mailbox, by calling one of the following functions:

A default FlexCAN configuration can be accesed by calling the FLEXCAN_DRV_GetDefaultConfig function. This function takes as argument a flexcan_user_config_t structure and fills it according to the following settings:

FlexCAN Rx FIFO configuration

The Rx FIFO is receive-only and 6-message deep. The user can read the received messages sequentially, in the order they were received, by repeatedly reading Message Buffer 0 (zero). The Rx FIFO ID filter table (configurable from 8 to 128 table elements) specifies filtering criteria for accepting frames into the FIFO. This table is represented through a structure of flexcan_id_table_t type, which specifies if specifies if Remote Frames are accepted into the FIFO if they match the target ID, whether extended or standard frames are accepted into the FIFO if they match the target ID and the target ID.

/* ID Filter table */
const flexcan_id_table_t filterTable[] = {
{
.isExtendedFrame = false,
.isRemoteFrame = false,
.id = 1U
},
...
};

The number of elements in the ID filter table is defined by the following formula:

Each element in the ID filter table specifies an ID to be used as acceptance criteria for the FIFO, as follows:

When Rx FIFO feature is enabled, buffer 0 (zero) cannot be used for transmission.

Important Notes

Example:

#define INST_CANCOM1 (0U)
#define RX_MAILBOX (1U)
#define MSG_ID (2U)
flexcan_state_t canCom1_State;
const flexcan_user_config_t canCom1_InitConfig0 = {
.fd_enable = true,
.max_num_mb = 16,
.num_id_filters = FLEXCAN_RX_FIFO_ID_FILTERS_8,
.is_rx_fifo_needed = false,
.flexcanMode = FLEXCAN_NORMAL_MODE,
.bitrate = {
.propSeg = 7,
.phaseSeg1 = 4,
.phaseSeg2 = 1,
.preDivider = 0,
.rJumpwidth = 1
},
.bitrate_cbt = {
.propSeg = 11,
.phaseSeg1 = 1,
.phaseSeg2 = 1,
.preDivider = 0,
.rJumpwidth = 1
},
.rxFifoDMAChannel = 0U
};
/* Initialize FlexCAN driver */
FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0);
/* Set information about the data to be received */
{
.data_length = 1U,
.msg_id_type = FLEXCAN_MSG_ID_STD,
.enable_brs = true,
.fd_enable = true,
.fd_padding = 0U
};
/* Configure Rx message buffer with index 1 to receive frames with ID 2 */
FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, RX_MAILBOX, &dataInfo, MSG_ID);
/* Receive a frame in the recvBuff variable */
FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MAILBOX, &recvBuff);
/* Wait for the message to be received */
while (FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, RX_MAILBOX) == STATUS_BUSY);
/* De-initialize driver */
FLEXCAN_DRV_Deinit(INST_CANCOM1);

Data Structures

struct  flexcan_msgbuff_t
 FlexCAN message buffer structure Implements : flexcan_msgbuff_t_Class. More...
 
struct  flexcan_mb_handle_t
 Information needed for internal handling of a given MB. Implements : flexcan_mb_handle_t_Class. More...
 
struct  FlexCANState
 Internal driver state information. More...
 
struct  flexcan_data_info_t
 FlexCAN data info from user Implements : flexcan_data_info_t_Class. More...
 
struct  flexcan_id_table_t
 FlexCAN Rx FIFO ID filter table structure Implements : flexcan_id_table_t_Class. More...
 
struct  flexcan_time_segment_t
 FlexCAN bitrate related structures Implements : flexcan_time_segment_t_Class. More...
 
struct  flexcan_user_config_t
 FlexCAN configuration. More...
 
struct  flexcan_pn_id_filter_t
 Pretended Networking ID filter. More...
 
struct  flexcan_pn_payload_filter_t
 Pretended Networking payload filter. More...
 
struct  flexcan_pn_config_t
 Pretended Networking configuration structure Implements : flexcan_pn_config_t_Class. More...
 

Typedefs

typedef struct FlexCANState flexcan_state_t
 Internal driver state information. More...
 
typedef void(* flexcan_callback_t) (uint8_t instance, flexcan_event_type_t eventType, uint32_t buffIdx, flexcan_state_t *flexcanState)
 FlexCAN Driver callback function type Implements : flexcan_callback_t_Class. More...
 
typedef void(* flexcan_error_callback_t) (uint8_t instance, flexcan_event_type_t eventType, flexcan_state_t *flexcanState)
 FlexCAN Driver error callback function type Implements : flexcan_error_callback_t_Class. More...
 

Enumerations

enum  flexcan_rxfifo_transfer_type_t { FLEXCAN_RXFIFO_USING_INTERRUPTS, FLEXCAN_RXFIFO_USING_DMA }
 The type of the RxFIFO transfer (interrupts/DMA). Implements : flexcan_rxfifo_transfer_type_t_Class. More...
 
enum  flexcan_event_type_t {
  FLEXCAN_EVENT_RX_COMPLETE, FLEXCAN_EVENT_RXFIFO_COMPLETE, FLEXCAN_EVENT_RXFIFO_WARNING, FLEXCAN_EVENT_RXFIFO_OVERFLOW,
  FLEXCAN_EVENT_TX_COMPLETE, FLEXCAN_EVENT_WAKEUP_TIMEOUT, FLEXCAN_EVENT_WAKEUP_MATCH, FLEXCAN_EVENT_SELF_WAKEUP,
  FLEXCAN_EVENT_ERROR
}
 The type of the event which occurred when the callback was invoked. Implements : flexcan_event_type_t_Class. More...
 
enum  flexcan_mb_state_t { FLEXCAN_MB_IDLE, FLEXCAN_MB_RX_BUSY, FLEXCAN_MB_TX_BUSY }
 The state of a given MB (idle/Rx busy/Tx busy). Implements : flexcan_mb_state_t_Class. More...
 
enum  flexcan_msgbuff_id_type_t { FLEXCAN_MSG_ID_STD, FLEXCAN_MSG_ID_EXT }
 FlexCAN Message Buffer ID type Implements : flexcan_msgbuff_id_type_t_Class. More...
 
enum  flexcan_clk_source_t { FLEXCAN_CLK_SOURCE_OSC = 0U, FLEXCAN_CLK_SOURCE_PERIPH = 1U }
 FlexCAN PE clock sources Implements : flexcan_clk_source_t_Class. More...
 
enum  flexcan_rx_fifo_id_filter_num_t {
  FLEXCAN_RX_FIFO_ID_FILTERS_8 = 0x0, FLEXCAN_RX_FIFO_ID_FILTERS_16 = 0x1, FLEXCAN_RX_FIFO_ID_FILTERS_24 = 0x2, FLEXCAN_RX_FIFO_ID_FILTERS_32 = 0x3,
  FLEXCAN_RX_FIFO_ID_FILTERS_40 = 0x4, FLEXCAN_RX_FIFO_ID_FILTERS_48 = 0x5, FLEXCAN_RX_FIFO_ID_FILTERS_56 = 0x6, FLEXCAN_RX_FIFO_ID_FILTERS_64 = 0x7,
  FLEXCAN_RX_FIFO_ID_FILTERS_72 = 0x8, FLEXCAN_RX_FIFO_ID_FILTERS_80 = 0x9, FLEXCAN_RX_FIFO_ID_FILTERS_88 = 0xA, FLEXCAN_RX_FIFO_ID_FILTERS_96 = 0xB,
  FLEXCAN_RX_FIFO_ID_FILTERS_104 = 0xC, FLEXCAN_RX_FIFO_ID_FILTERS_112 = 0xD, FLEXCAN_RX_FIFO_ID_FILTERS_120 = 0xE, FLEXCAN_RX_FIFO_ID_FILTERS_128 = 0xF
}
 FlexCAN Rx FIFO filters number Implements : flexcan_rx_fifo_id_filter_num_t_Class. More...
 
enum  flexcan_rx_mask_type_t { FLEXCAN_RX_MASK_GLOBAL, FLEXCAN_RX_MASK_INDIVIDUAL }
 FlexCAN Rx mask type. Implements : flexcan_rx_mask_type_t_Class. More...
 
enum  flexcan_rx_fifo_id_element_format_t { FLEXCAN_RX_FIFO_ID_FORMAT_A, FLEXCAN_RX_FIFO_ID_FORMAT_B, FLEXCAN_RX_FIFO_ID_FORMAT_C, FLEXCAN_RX_FIFO_ID_FORMAT_D }
 ID formats for Rx FIFO Implements : flexcan_rx_fifo_id_element_format_t_Class. More...
 
enum  flexcan_operation_modes_t {
  FLEXCAN_NORMAL_MODE, FLEXCAN_LISTEN_ONLY_MODE, FLEXCAN_LOOPBACK_MODE, FLEXCAN_FREEZE_MODE,
  FLEXCAN_DISABLE_MODE
}
 FlexCAN operation modes Implements : flexcan_operation_modes_t_Class. More...
 
enum  flexcan_fd_payload_size_t { FLEXCAN_PAYLOAD_SIZE_8 = 0, FLEXCAN_PAYLOAD_SIZE_16, FLEXCAN_PAYLOAD_SIZE_32, FLEXCAN_PAYLOAD_SIZE_64 }
 FlexCAN payload sizes Implements : flexcan_fd_payload_size_t_Class. More...
 
enum  flexcan_pn_filter_combination_t { FLEXCAN_FILTER_ID, FLEXCAN_FILTER_ID_PAYLOAD, FLEXCAN_FILTER_ID_NTIMES, FLEXCAN_FILTER_ID_PAYLOAD_NTIMES }
 Pretended Networking filtering combinations. More...
 
enum  flexcan_pn_filter_selection_t { FLEXCAN_FILTER_MATCH_EXACT, FLEXCAN_FILTER_MATCH_GEQ, FLEXCAN_FILTER_MATCH_LEQ, FLEXCAN_FILTER_MATCH_RANGE }
 Pretended Networking matching schemes. More...
 

Bit rate

void FLEXCAN_DRV_SetBitrate (uint8_t instance, const flexcan_time_segment_t *bitrate)
 Sets the FlexCAN bit rate for standard frames or the arbitration phase of FD frames. More...
 
void FLEXCAN_DRV_SetBitrateCbt (uint8_t instance, const flexcan_time_segment_t *bitrate)
 Sets the FlexCAN bit rate for the data phase of FD frames (BRS enabled). More...
 
void FLEXCAN_DRV_GetBitrate (uint8_t instance, flexcan_time_segment_t *bitrate)
 Gets the FlexCAN bit rate for standard frames or the arbitration phase of FD frames. More...
 
void FLEXCAN_DRV_GetBitrateFD (uint8_t instance, flexcan_time_segment_t *bitrate)
 Gets the FlexCAN bit rate for the data phase of FD frames (BRS enabled). More...
 

Rx MB and Rx FIFO masks

void FLEXCAN_DRV_SetRxMaskType (uint8_t instance, flexcan_rx_mask_type_t type)
 Sets the Rx masking type. More...
 
void FLEXCAN_DRV_SetRxFifoGlobalMask (uint8_t instance, flexcan_msgbuff_id_type_t id_type, uint32_t mask)
 Sets the FlexCAN Rx FIFO global mask (standard or extended). More...
 
void FLEXCAN_DRV_SetRxMbGlobalMask (uint8_t instance, flexcan_msgbuff_id_type_t id_type, uint32_t mask)
 Sets the FlexCAN Rx MB global mask (standard or extended). More...
 
void FLEXCAN_DRV_SetRxMb14Mask (uint8_t instance, flexcan_msgbuff_id_type_t id_type, uint32_t mask)
 Sets the FlexCAN Rx MB 14 mask (standard or extended). More...
 
void FLEXCAN_DRV_SetRxMb15Mask (uint8_t instance, flexcan_msgbuff_id_type_t id_type, uint32_t mask)
 Sets the FlexCAN Rx MB 15 mask (standard or extended). More...
 
status_t FLEXCAN_DRV_SetRxIndividualMask (uint8_t instance, flexcan_msgbuff_id_type_t id_type, uint8_t mb_idx, uint32_t mask)
 Sets the FlexCAN Rx individual mask (standard or extended). More...
 

Initialization and Shutdown

void FLEXCAN_DRV_GetDefaultConfig (flexcan_user_config_t *config)
 Gets the default configuration structure. More...
 
status_t FLEXCAN_DRV_Init (uint8_t instance, flexcan_state_t *state, const flexcan_user_config_t *data)
 Initializes the FlexCAN peripheral. More...
 
status_t FLEXCAN_DRV_Deinit (uint8_t instance)
 Shuts down a FlexCAN instance. More...
 
void FLEXCAN_DRV_SetTDCOffset (uint8_t instance, bool enable, uint8_t offset)
 Enables/Disables the Transceiver Delay Compensation feature and sets the Transceiver Delay Compensation Offset (offset value to be added to the measured transceiver's loop delay in order to define the position of the delayed comparison point when bit rate switching is active). More...
 
uint8_t FLEXCAN_DRV_GetTDCValue (uint8_t instance)
 Gets the value of the Transceiver Delay Compensation. More...
 
bool FLEXCAN_DRV_GetTDCFail (uint8_t instance)
 Gets the value of the TDC Fail flag. More...
 
void FLEXCAN_DRV_ClearTDCFail (uint8_t instance)
 Clears the TDC Fail flag. More...
 

Send configuration

status_t FLEXCAN_DRV_ConfigTxMb (uint8_t instance, uint8_t mb_idx, const flexcan_data_info_t *tx_info, uint32_t msg_id)
 FlexCAN transmit message buffer field configuration. More...
 
status_t FLEXCAN_DRV_ConfigRemoteResponseMb (uint8_t instance, uint8_t mb_idx, const flexcan_data_info_t *tx_info, uint32_t msg_id, const uint8_t *mb_data)
 Configures a transmit message buffer for remote frame response. More...
 
status_t FLEXCAN_DRV_SendBlocking (uint8_t instance, uint8_t mb_idx, const flexcan_data_info_t *tx_info, uint32_t msg_id, const uint8_t *mb_data, uint32_t timeout_ms)
 Sends a CAN frame using the specified message buffer, in a blocking manner. More...
 
status_t FLEXCAN_DRV_Send (uint8_t instance, uint8_t mb_idx, const flexcan_data_info_t *tx_info, uint32_t msg_id, const uint8_t *mb_data)
 Sends a CAN frame using the specified message buffer. More...
 

Receive configuration

status_t FLEXCAN_DRV_ConfigRxMb (uint8_t instance, uint8_t mb_idx, const flexcan_data_info_t *rx_info, uint32_t msg_id)
 FlexCAN receive message buffer field configuration. More...
 
void FLEXCAN_DRV_ConfigRxFifo (uint8_t instance, flexcan_rx_fifo_id_element_format_t id_format, const flexcan_id_table_t *id_filter_table)
 FlexCAN Rx FIFO field configuration. More...
 
status_t FLEXCAN_DRV_ReceiveBlocking (uint8_t instance, uint8_t mb_idx, flexcan_msgbuff_t *data, uint32_t timeout_ms)
 Receives a CAN frame using the specified message buffer, in a blocking manner. More...
 
status_t FLEXCAN_DRV_Receive (uint8_t instance, uint8_t mb_idx, flexcan_msgbuff_t *data)
 Receives a CAN frame using the specified message buffer. More...
 
status_t FLEXCAN_DRV_RxFifoBlocking (uint8_t instance, flexcan_msgbuff_t *data, uint32_t timeout_ms)
 Receives a CAN frame using the message FIFO, in a blocking manner. More...
 
status_t FLEXCAN_DRV_RxFifo (uint8_t instance, flexcan_msgbuff_t *data)
 Receives a CAN frame using the message FIFO. More...
 

Transfer status

status_t FLEXCAN_DRV_AbortTransfer (uint8_t instance, uint8_t mb_idx)
 Ends a non-blocking FlexCAN transfer early. More...
 
status_t FLEXCAN_DRV_GetTransferStatus (uint8_t instance, uint8_t mb_idx)
 Returns whether the previous FlexCAN transfer has finished. More...
 
uint32_t FLEXCAN_DRV_GetErrorStatus (uint8_t instance)
 Returns reported error conditions. More...
 

IRQ handler callback

void FLEXCAN_DRV_InstallEventCallback (uint8_t instance, flexcan_callback_t callback, void *callbackParam)
 Installs a callback function for the IRQ handler. More...
 
void FLEXCAN_DRV_InstallErrorCallback (uint8_t instance, flexcan_error_callback_t callback, void *callbackParam)
 Installs an error callback function for the IRQ handler and enables error interrupts. More...
 

Pretended Networking

void FLEXCAN_DRV_ConfigPN (uint8_t instance, bool enable, const flexcan_pn_config_t *pnConfig)
 Configures Pretended Networking settings. More...
 
void FLEXCAN_DRV_GetWMB (uint8_t instance, uint8_t wmbIndex, flexcan_msgbuff_t *wmb)
 Extracts one of the frames which triggered the wake up event. More...
 

Typedef Documentation

typedef void(* flexcan_callback_t) (uint8_t instance, flexcan_event_type_t eventType, uint32_t buffIdx, flexcan_state_t *flexcanState)

FlexCAN Driver callback function type Implements : flexcan_callback_t_Class.

Definition at line 331 of file flexcan_driver.h.

typedef void(* flexcan_error_callback_t) (uint8_t instance, flexcan_event_type_t eventType, flexcan_state_t *flexcanState)

FlexCAN Driver error callback function type Implements : flexcan_error_callback_t_Class.

Definition at line 337 of file flexcan_driver.h.

typedef struct FlexCANState flexcan_state_t

Internal driver state information.

Note
The contents of this structure are internal to the driver and should not be modified by users. Also, contents of the structure are subject to change in future releases. Implements : flexcan_state_t_Class

Enumeration Type Documentation

FlexCAN PE clock sources Implements : flexcan_clk_source_t_Class.

Enumerator
FLEXCAN_CLK_SOURCE_OSC 

The CAN engine clock source is the oscillator clock.

FLEXCAN_CLK_SOURCE_PERIPH 

The CAN engine clock source is the peripheral clock.

Definition at line 87 of file flexcan_driver.h.

The type of the event which occurred when the callback was invoked. Implements : flexcan_event_type_t_Class.

Enumerator
FLEXCAN_EVENT_RX_COMPLETE 

A frame was received in the configured Rx MB.

FLEXCAN_EVENT_RXFIFO_COMPLETE 

A frame was received in the Rx FIFO.

FLEXCAN_EVENT_RXFIFO_WARNING 

Rx FIFO is almost full (5 frames).

FLEXCAN_EVENT_RXFIFO_OVERFLOW 

Rx FIFO is full (incoming message was lost).

FLEXCAN_EVENT_TX_COMPLETE 

A frame was sent from the configured Tx MB.

FLEXCAN_EVENT_WAKEUP_TIMEOUT 

An wake up event occurred due to timeout.

FLEXCAN_EVENT_WAKEUP_MATCH 

An wake up event occurred due to matching.

FLEXCAN_EVENT_SELF_WAKEUP 

A self wake up event occurred.

FLEXCAN_EVENT_ERROR 

Definition at line 52 of file flexcan_driver.h.

FlexCAN payload sizes Implements : flexcan_fd_payload_size_t_Class.

Enumerator
FLEXCAN_PAYLOAD_SIZE_8 

FlexCAN message buffer payload size in bytes

FLEXCAN_PAYLOAD_SIZE_16 

FlexCAN message buffer payload size in bytes

FLEXCAN_PAYLOAD_SIZE_32 

FlexCAN message buffer payload size in bytes

FLEXCAN_PAYLOAD_SIZE_64 

FlexCAN message buffer payload size in bytes

Definition at line 226 of file flexcan_driver.h.

The state of a given MB (idle/Rx busy/Tx busy). Implements : flexcan_mb_state_t_Class.

Enumerator
FLEXCAN_MB_IDLE 

The MB is not used by any transfer.

FLEXCAN_MB_RX_BUSY 

The MB is used for a reception.

FLEXCAN_MB_TX_BUSY 

The MB is used for a transmission.

Definition at line 69 of file flexcan_driver.h.

FlexCAN Message Buffer ID type Implements : flexcan_msgbuff_id_type_t_Class.

Enumerator
FLEXCAN_MSG_ID_STD 

Standard ID

FLEXCAN_MSG_ID_EXT 

Extended ID

Definition at line 78 of file flexcan_driver.h.

FlexCAN operation modes Implements : flexcan_operation_modes_t_Class.

Enumerator
FLEXCAN_NORMAL_MODE 

Normal mode or user mode

FLEXCAN_LISTEN_ONLY_MODE 

Listen-only mode

FLEXCAN_LOOPBACK_MODE 

Loop-back mode

FLEXCAN_FREEZE_MODE 

Freeze mode

FLEXCAN_DISABLE_MODE 

Module disable mode

Definition at line 214 of file flexcan_driver.h.

Pretended Networking filtering combinations.

Enumerator
FLEXCAN_FILTER_ID 

Message ID filtering only

FLEXCAN_FILTER_ID_PAYLOAD 

Message ID and payload filtering

FLEXCAN_FILTER_ID_NTIMES 

Message ID filtering occurring a specified number of times

FLEXCAN_FILTER_ID_PAYLOAD_NTIMES 

Message ID and payload filtering occurring a specified number of times

Definition at line 294 of file flexcan_driver.h.

Pretended Networking matching schemes.

Enumerator
FLEXCAN_FILTER_MATCH_EXACT 

Match an exact target value.

FLEXCAN_FILTER_MATCH_GEQ 

Match greater than or equal to a specified target value.

FLEXCAN_FILTER_MATCH_LEQ 

Match less than or equal to a specified target value.

FLEXCAN_FILTER_MATCH_RANGE 

Match inside a range, greater than or equal to a specified lower limit and smaller than or equal to a specified upper limit.

Definition at line 302 of file flexcan_driver.h.

ID formats for Rx FIFO Implements : flexcan_rx_fifo_id_element_format_t_Class.

Enumerator
FLEXCAN_RX_FIFO_ID_FORMAT_A 

One full ID (standard and extended) per ID Filter Table element.

FLEXCAN_RX_FIFO_ID_FORMAT_B 

Two full standard IDs or two partial 14-bit (standard and extended) IDs per ID Filter Table element.

FLEXCAN_RX_FIFO_ID_FORMAT_C 

Four partial 8-bit Standard IDs per ID Filter Table element.

FLEXCAN_RX_FIFO_ID_FORMAT_D 

All frames rejected.

Definition at line 194 of file flexcan_driver.h.

FlexCAN Rx FIFO filters number Implements : flexcan_rx_fifo_id_filter_num_t_Class.

Enumerator
FLEXCAN_RX_FIFO_ID_FILTERS_8 

8 Rx FIFO Filters.

FLEXCAN_RX_FIFO_ID_FILTERS_16 

16 Rx FIFO Filters.

FLEXCAN_RX_FIFO_ID_FILTERS_24 

24 Rx FIFO Filters.

FLEXCAN_RX_FIFO_ID_FILTERS_32 

32 Rx FIFO Filters.

FLEXCAN_RX_FIFO_ID_FILTERS_40 

40 Rx FIFO Filters.

FLEXCAN_RX_FIFO_ID_FILTERS_48 

48 Rx FIFO Filters.

FLEXCAN_RX_FIFO_ID_FILTERS_56 

56 Rx FIFO Filters.

FLEXCAN_RX_FIFO_ID_FILTERS_64 

64 Rx FIFO Filters.

FLEXCAN_RX_FIFO_ID_FILTERS_72 

72 Rx FIFO Filters.

FLEXCAN_RX_FIFO_ID_FILTERS_80 

80 Rx FIFO Filters.

FLEXCAN_RX_FIFO_ID_FILTERS_88 

88 Rx FIFO Filters.

FLEXCAN_RX_FIFO_ID_FILTERS_96 

96 Rx FIFO Filters.

FLEXCAN_RX_FIFO_ID_FILTERS_104 

104 Rx FIFO Filters.

FLEXCAN_RX_FIFO_ID_FILTERS_112 

112 Rx FIFO Filters.

FLEXCAN_RX_FIFO_ID_FILTERS_120 

120 Rx FIFO Filters.

FLEXCAN_RX_FIFO_ID_FILTERS_128 

128 Rx FIFO Filters.

Definition at line 164 of file flexcan_driver.h.

FlexCAN Rx mask type. Implements : flexcan_rx_mask_type_t_Class.

Enumerator
FLEXCAN_RX_MASK_GLOBAL 

Rx global mask

FLEXCAN_RX_MASK_INDIVIDUAL 

Rx individual mask

Definition at line 186 of file flexcan_driver.h.

The type of the RxFIFO transfer (interrupts/DMA). Implements : flexcan_rxfifo_transfer_type_t_Class.

Enumerator
FLEXCAN_RXFIFO_USING_INTERRUPTS 

Use interrupts for RxFIFO.

FLEXCAN_RXFIFO_USING_DMA 

Use DMA for RxFIFO.

Definition at line 42 of file flexcan_driver.h.

Function Documentation

status_t FLEXCAN_DRV_AbortTransfer ( uint8_t  instance,
uint8_t  mb_idx 
)

Ends a non-blocking FlexCAN transfer early.

Parameters
instanceA FlexCAN instance number
mb_idxThe index of the message buffer
Returns
STATUS_SUCCESS if successful; STATUS_FLEXCAN_NO_TRANSFER_IN_PROGRESS if no transfer was running

Definition at line 1484 of file flexcan_driver.c.

void FLEXCAN_DRV_ClearTDCFail ( uint8_t  instance)

Clears the TDC Fail flag.

Parameters
baseThe FlexCAN base address

Definition at line 1168 of file flexcan_driver.c.

void FLEXCAN_DRV_ConfigPN ( uint8_t  instance,
bool  enable,
const flexcan_pn_config_t pnConfig 
)

Configures Pretended Networking settings.

Parameters
instanceThe FlexCAN instance number.
enableEnable/Disable Pretended Networking mode.
pnConfigPointer to the Pretended Networking configuration structure.

Definition at line 1855 of file flexcan_driver.c.

status_t FLEXCAN_DRV_ConfigRemoteResponseMb ( uint8_t  instance,
uint8_t  mb_idx,
const flexcan_data_info_t tx_info,
uint32_t  msg_id,
const uint8_t *  mb_data 
)

Configures a transmit message buffer for remote frame response.

Parameters
instanceA FlexCAN instance number
mb_idxIndex of the message buffer
tx_infoData info
msg_idID of the message to transmit
mb_dataBytes of the FlexCAN message
Returns
STATUS_SUCCESS if successful; STATUS_FLEXCAN_MB_OUT_OF_RANGE if the index of the message buffer is invalid

Definition at line 725 of file flexcan_driver.c.

void FLEXCAN_DRV_ConfigRxFifo ( uint8_t  instance,
flexcan_rx_fifo_id_element_format_t  id_format,
const flexcan_id_table_t id_filter_table 
)

FlexCAN Rx FIFO field configuration.

Note
The number of elements in the ID filter table is defined by the following formula:
  • for format A: the number of Rx FIFO ID filters
  • for format B: twice the number of Rx FIFO ID filters
  • for format C: four times the number of Rx FIFO ID filters The user must provide the exact number of elements in order to avoid any misconfiguration.

Each element in the ID filter table specifies an ID to be used as acceptance criteria for the FIFO as follows:

  • for format A: In the standard frame format, bits 10 to 0 of the ID are used for frame identification. In the extended frame format, bits 28 to 0 are used.
  • for format B: In the standard frame format, bits 10 to 0 of the ID are used for frame identification. In the extended frame format, only the 14 most significant bits (28 to 15) of the ID are compared to the 14 most significant bits (28 to 15) of the received ID.
  • for format C: In both standard and extended frame formats, only the 8 most significant bits (7 to 0 for standard, 28 to 21 for extended) of the ID are compared to the 8 most significant bits (7 to 0 for standard, 28 to 21 for extended) of the received ID.
Parameters
instanceA FlexCAN instance number
id_formatThe format of the Rx FIFO ID Filter Table Elements
id_filter_tableThe ID filter table elements which contain RTR bit, IDE bit, and Rx message ID

Definition at line 894 of file flexcan_driver.c.

status_t FLEXCAN_DRV_ConfigRxMb ( uint8_t  instance,
uint8_t  mb_idx,
const flexcan_data_info_t rx_info,
uint32_t  msg_id 
)

FlexCAN receive message buffer field configuration.

Parameters
instanceA FlexCAN instance number
mb_idxIndex of the message buffer
rx_infoData info
msg_idID of the message to transmit
Returns
STATUS_SUCCESS if successful; STATUS_FLEXCAN_MB_OUT_OF_RANGE if the index of a message buffer is invalid;

Definition at line 846 of file flexcan_driver.c.

status_t FLEXCAN_DRV_ConfigTxMb ( uint8_t  instance,
uint8_t  mb_idx,
const flexcan_data_info_t tx_info,
uint32_t  msg_id 
)

FlexCAN transmit message buffer field configuration.

Parameters
instanceA FlexCAN instance number
mb_idxIndex of the message buffer
tx_infoData info
msg_idID of the message to transmit
Returns
STATUS_SUCCESS if successful; STATUS_FLEXCAN_MB_OUT_OF_RANGE if the index of the message buffer is invalid

Definition at line 687 of file flexcan_driver.c.

status_t FLEXCAN_DRV_Deinit ( uint8_t  instance)

Shuts down a FlexCAN instance.

Parameters
instanceA FlexCAN instance number
Returns
STATUS_SUCCESS if successful; STATUS_ERROR if failed

Definition at line 1055 of file flexcan_driver.c.

void FLEXCAN_DRV_GetBitrate ( uint8_t  instance,
flexcan_time_segment_t bitrate 
)

Gets the FlexCAN bit rate for standard frames or the arbitration phase of FD frames.

Parameters
instanceA FlexCAN instance number
bitrateA pointer to a variable for returning the FlexCAN bit rate settings

Definition at line 218 of file flexcan_driver.c.

void FLEXCAN_DRV_GetBitrateFD ( uint8_t  instance,
flexcan_time_segment_t bitrate 
)

Gets the FlexCAN bit rate for the data phase of FD frames (BRS enabled).

Parameters
instanceA FlexCAN instance number
bitrateA pointer to a variable for returning the FlexCAN bit rate settings

Definition at line 243 of file flexcan_driver.c.

void FLEXCAN_DRV_GetDefaultConfig ( flexcan_user_config_t config)

Gets the default configuration structure.

This function gets the default configuration structure, with the following settings:

  • 16 message buffers
  • flexible data rate disabled
  • Rx FIFO disabled
  • normal operation mode
  • 8 byte payload size
  • Protocol Engine clock = Oscillator clock
  • bitrate of 500 Kbit/s (computed for sample point = 87.5)
Parameters
[out]configThe configuration structure

Definition at line 2060 of file flexcan_driver.c.

uint32_t FLEXCAN_DRV_GetErrorStatus ( uint8_t  instance)

Returns reported error conditions.

Reports various error conditions detected in the reception and transmission of a CAN frame and some general status of the device.

Parameters
instanceThe FlexCAN instance number.
Returns
value of the Error and Status 1 register;

Definition at line 1465 of file flexcan_driver.c.

bool FLEXCAN_DRV_GetTDCFail ( uint8_t  instance)

Gets the value of the TDC Fail flag.

Parameters
baseThe FlexCAN base address
Returns
If true, indicates that the TDC mechanism is out of range, unable to compensate the transceiver's loop delay and successfully compare the delayed received bits to the transmitted ones.

Definition at line 1152 of file flexcan_driver.c.

uint8_t FLEXCAN_DRV_GetTDCValue ( uint8_t  instance)

Gets the value of the Transceiver Delay Compensation.

Parameters
baseThe FlexCAN base address
Returns
The value of the transceiver loop delay measured from the transmitted EDL to R0 transition edge to the respective received one added to the TDCOFF value specified by FLEXCAN_HAL_SetTDCOffset.

Definition at line 1136 of file flexcan_driver.c.

status_t FLEXCAN_DRV_GetTransferStatus ( uint8_t  instance,
uint8_t  mb_idx 
)

Returns whether the previous FlexCAN transfer has finished.

When performing an async transfer, call this function to ascertain the state of the current transfer: in progress (or busy) or complete (success).

Parameters
instanceThe FlexCAN instance number.
mb_idxThe index of the message buffer.
Returns
STATUS_SUCCESS if successful; STATUS_BUSY if a resource is busy;

Definition at line 1438 of file flexcan_driver.c.

void FLEXCAN_DRV_GetWMB ( uint8_t  instance,
uint8_t  wmbIndex,
flexcan_msgbuff_t wmb 
)

Extracts one of the frames which triggered the wake up event.

Parameters
instanceThe FlexCAN instance number.
wmbIndexThe index of the message buffer to be extracted.
wmbPointer to the message buffer structure where the frame will be saved.

Definition at line 1883 of file flexcan_driver.c.

status_t FLEXCAN_DRV_Init ( uint8_t  instance,
flexcan_state_t state,
const flexcan_user_config_t data 
)

Initializes the FlexCAN peripheral.

This function initializes

Parameters
instanceA FlexCAN instance number
statePointer to the FlexCAN driver state structure.
dataThe FlexCAN platform data
Returns
STATUS_SUCCESS if successful; STATUS_FLEXCAN_MB_OUT_OF_RANGE if the index of a message buffer is invalid; STATUS_ERROR if other error occurred

Definition at line 481 of file flexcan_driver.c.

void FLEXCAN_DRV_InstallErrorCallback ( uint8_t  instance,
flexcan_error_callback_t  callback,
void *  callbackParam 
)

Installs an error callback function for the IRQ handler and enables error interrupts.

Parameters
instanceThe FlexCAN instance number.
callbackThe error callback function.
callbackParamUser parameter passed to the error callback function through the state parameter.

Definition at line 1818 of file flexcan_driver.c.

void FLEXCAN_DRV_InstallEventCallback ( uint8_t  instance,
flexcan_callback_t  callback,
void *  callbackParam 
)

Installs a callback function for the IRQ handler.

Parameters
instanceThe FlexCAN instance number.
callbackThe callback function.
callbackParamUser parameter passed to the callback function through the state parameter.

Definition at line 1798 of file flexcan_driver.c.

status_t FLEXCAN_DRV_Receive ( uint8_t  instance,
uint8_t  mb_idx,
flexcan_msgbuff_t data 
)

Receives a CAN frame using the specified message buffer.

This function receives a CAN frame using a configured message buffer. The function returns immediately. If a callback is installed, it will be invoked after the frame was received and read into the specified buffer.

Parameters
instanceA FlexCAN instance number
mb_idxIndex of the message buffer
dataThe FlexCAN receive message buffer data.
Returns
STATUS_SUCCESS if successful; STATUS_FLEXCAN_MB_OUT_OF_RANGE if the index of a message buffer is invalid; STATUS_BUSY if a resource is busy

Definition at line 966 of file flexcan_driver.c.

status_t FLEXCAN_DRV_ReceiveBlocking ( uint8_t  instance,
uint8_t  mb_idx,
flexcan_msgbuff_t data,
uint32_t  timeout_ms 
)

Receives a CAN frame using the specified message buffer, in a blocking manner.

This function receives a CAN frame using a configured message buffer. The function blocks until either a frame was received, or the specified timeout expired.

Parameters
instanceA FlexCAN instance number
mb_idxIndex of the message buffer
dataThe FlexCAN receive message buffer data.
timeout_msA timeout for the transfer in milliseconds.
Returns
STATUS_SUCCESS if successful; STATUS_FLEXCAN_MB_OUT_OF_RANGE if the index of a message buffer is invalid; STATUS_BUSY if a resource is busy; STATUS_TIMEOUT if the timeout is reached

Definition at line 920 of file flexcan_driver.c.

status_t FLEXCAN_DRV_RxFifo ( uint8_t  instance,
flexcan_msgbuff_t data 
)

Receives a CAN frame using the message FIFO.

This function receives a CAN frame using the Rx FIFO. The function returns immediately. If a callback is installed, it will be invoked after the frame was received and read into the specified buffer.

Parameters
instanceA FlexCAN instance number
dataThe FlexCAN receive message buffer data.
Returns
STATUS_SUCCESS if successful; STATUS_BUSY if a resource is busy; STATUS_ERROR if other error occurred

Definition at line 1034 of file flexcan_driver.c.

status_t FLEXCAN_DRV_RxFifoBlocking ( uint8_t  instance,
flexcan_msgbuff_t data,
uint32_t  timeout_ms 
)

Receives a CAN frame using the message FIFO, in a blocking manner.

This function receives a CAN frame using the Rx FIFO. The function blocks until either a frame was received, or the specified timeout expired.

Parameters
instanceA FlexCAN instance number
dataThe FlexCAN receive message buffer data.
timeout_msA timeout for the transfer in milliseconds.
Returns
STATUS_SUCCESS if successful; STATUS_BUSY if a resource is busy; STATUS_TIMEOUT if the timeout is reached; STATUS_ERROR if other error occurred

Definition at line 989 of file flexcan_driver.c.

status_t FLEXCAN_DRV_Send ( uint8_t  instance,
uint8_t  mb_idx,
const flexcan_data_info_t tx_info,
uint32_t  msg_id,
const uint8_t *  mb_data 
)

Sends a CAN frame using the specified message buffer.

This function sends a CAN frame using a configured message buffer. The function returns immediately. If a callback is installed, it will be invoked after the frame was sent.

Parameters
instanceA FlexCAN instance number
mb_idxIndex of the message buffer
tx_infoData info
msg_idID of the message to transmit
mb_dataBytes of the FlexCAN message.
Returns
STATUS_SUCCESS if successful; STATUS_FLEXCAN_MB_OUT_OF_RANGE if the index of a message buffer is invalid; STATUS_BUSY if a resource is busy

Definition at line 809 of file flexcan_driver.c.

status_t FLEXCAN_DRV_SendBlocking ( uint8_t  instance,
uint8_t  mb_idx,
const flexcan_data_info_t tx_info,
uint32_t  msg_id,
const uint8_t *  mb_data,
uint32_t  timeout_ms 
)

Sends a CAN frame using the specified message buffer, in a blocking manner.

This function sends a CAN frame using a configured message buffer. The function blocks until either the frame was sent, or the specified timeout expired.

Parameters
instanceA FlexCAN instance number
mb_idxIndex of the message buffer
tx_infoData info
msg_idID of the message to transmit
mb_dataBytes of the FlexCAN message
timeout_msA timeout for the transfer in milliseconds.
Returns
STATUS_SUCCESS if successful; STATUS_FLEXCAN_MB_OUT_OF_RANGE if the index of a message buffer is invalid; STATUS_BUSY if a resource is busy; STATUS_TIMEOUT if the timeout is reached

Definition at line 757 of file flexcan_driver.c.

void FLEXCAN_DRV_SetBitrate ( uint8_t  instance,
const flexcan_time_segment_t bitrate 
)

Sets the FlexCAN bit rate for standard frames or the arbitration phase of FD frames.

Parameters
instanceA FlexCAN instance number
bitrateA pointer to the FlexCAN bit rate settings.

Definition at line 154 of file flexcan_driver.c.

void FLEXCAN_DRV_SetBitrateCbt ( uint8_t  instance,
const flexcan_time_segment_t bitrate 
)

Sets the FlexCAN bit rate for the data phase of FD frames (BRS enabled).

Parameters
instanceA FlexCAN instance number
bitrateA pointer to the FlexCAN bit rate settings.

Definition at line 193 of file flexcan_driver.c.

void FLEXCAN_DRV_SetRxFifoGlobalMask ( uint8_t  instance,
flexcan_msgbuff_id_type_t  id_type,
uint32_t  mask 
)

Sets the FlexCAN Rx FIFO global mask (standard or extended).

Parameters
instanceA FlexCAN instance number
id_typeStandard ID or extended ID
maskMask value

Definition at line 289 of file flexcan_driver.c.

status_t FLEXCAN_DRV_SetRxIndividualMask ( uint8_t  instance,
flexcan_msgbuff_id_type_t  id_type,
uint8_t  mb_idx,
uint32_t  mask 
)

Sets the FlexCAN Rx individual mask (standard or extended).

Parameters
instanceA FlexCAN instance number
id_typeA standard ID or an extended ID
mb_idxIndex of the message buffer
maskMask value
Returns
STATUS_SUCCESS if successful; STATUS_FLEXCAN_MB_OUT_OF_RANGE if the index of the message buffer is invalid

Definition at line 433 of file flexcan_driver.c.

void FLEXCAN_DRV_SetRxMaskType ( uint8_t  instance,
flexcan_rx_mask_type_t  type 
)

Sets the Rx masking type.

Parameters
instanceA FlexCAN instance number
typeThe FlexCAN RX mask type

Definition at line 268 of file flexcan_driver.c.

void FLEXCAN_DRV_SetRxMb14Mask ( uint8_t  instance,
flexcan_msgbuff_id_type_t  id_type,
uint32_t  mask 
)

Sets the FlexCAN Rx MB 14 mask (standard or extended).

Parameters
instanceA FlexCAN instance number
id_typeStandard ID or extended ID
maskMask value

Definition at line 361 of file flexcan_driver.c.

void FLEXCAN_DRV_SetRxMb15Mask ( uint8_t  instance,
flexcan_msgbuff_id_type_t  id_type,
uint32_t  mask 
)

Sets the FlexCAN Rx MB 15 mask (standard or extended).

Parameters
instanceA FlexCAN instance number
id_typeStandard ID or extended ID
maskMask value

Definition at line 397 of file flexcan_driver.c.

void FLEXCAN_DRV_SetRxMbGlobalMask ( uint8_t  instance,
flexcan_msgbuff_id_type_t  id_type,
uint32_t  mask 
)

Sets the FlexCAN Rx MB global mask (standard or extended).

Parameters
instanceA FlexCAN instance number
id_typeStandard ID or extended ID
maskMask value

Definition at line 325 of file flexcan_driver.c.

void FLEXCAN_DRV_SetTDCOffset ( uint8_t  instance,
bool  enable,
uint8_t  offset 
)

Enables/Disables the Transceiver Delay Compensation feature and sets the Transceiver Delay Compensation Offset (offset value to be added to the measured transceiver's loop delay in order to define the position of the delayed comparison point when bit rate switching is active).

Parameters
instanceA FlexCAN instance number
enableEnable/Disable Transceiver Delay Compensation
offsetTransceiver Delay Compensation Offset

Definition at line 1115 of file flexcan_driver.c.