![]() |
S32 SDK
|
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 using it 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:
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... | |
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, flexcan_state_t *flexcanState) |
FlexCAN Driver callback function type Implements : flexcan_callback_t_Class. 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_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... | |
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... | |
typedef void(* flexcan_callback_t) (uint8_t instance, flexcan_event_type_t eventType, flexcan_state_t *flexcanState) |
FlexCAN Driver callback function type Implements : flexcan_callback_t_Class.
Definition at line 293 of file flexcan_driver.h.
typedef struct FlexCANState flexcan_state_t |
Internal driver state information.
enum flexcan_event_type_t |
The type of the event which occurred when the callback was invoked. Implements : flexcan_event_type_t_Class.
Definition at line 50 of file flexcan_driver.h.
FlexCAN payload sizes Implements : flexcan_fd_payload_size_t_Class.
Definition at line 195 of file flexcan_driver.h.
enum flexcan_mb_state_t |
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 64 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 73 of file flexcan_driver.h.
FlexCAN operation modes Implements : flexcan_operation_modes_t_Class.
Definition at line 184 of file flexcan_driver.h.
ID formats for Rx FIFO Implements : flexcan_rx_fifo_id_element_format_t_Class.
Definition at line 164 of file flexcan_driver.h.
FlexCAN Rx FIFO filters number Implements : flexcan_rx_fifo_id_filter_num_t_Class.
Definition at line 134 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 156 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.
status_t FLEXCAN_DRV_AbortTransfer | ( | uint8_t | instance, |
uint8_t | mb_idx | ||
) |
Ends a non-blocking FlexCAN transfer early.
instance | A FlexCAN instance number |
mb_idx | The index of the message buffer |
Definition at line 1266 of file flexcan_driver.c.
void FLEXCAN_DRV_ClearTDCFail | ( | uint8_t | instance | ) |
Clears the TDC Fail flag.
base | The FlexCAN base address |
Definition at line 1055 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.
instance | A FlexCAN instance number |
id_format | The format of the Rx FIFO ID Filter Table Elements |
id_filter_table | The ID filter table elements which contain RTR bit, IDE bit, and Rx message ID |
Definition at line 789 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.
instance | A FlexCAN instance number |
mb_idx | Index of the message buffer |
rx_info | Data info |
msg_id | ID of the message to transmit |
Definition at line 743 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.
instance | A FlexCAN instance number |
mb_idx | Index of the message buffer |
tx_info | Data info |
msg_id | ID of the message to transmit |
Definition at line 616 of file flexcan_driver.c.
status_t FLEXCAN_DRV_Deinit | ( | uint8_t | instance | ) |
Shuts down a FlexCAN instance.
instance | A FlexCAN instance number |
Definition at line 953 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.
instance | A FlexCAN instance number |
bitrate | A pointer to a variable for returning the FlexCAN bit rate settings |
Definition at line 197 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).
instance | A FlexCAN instance number |
bitrate | A pointer to a variable for returning the FlexCAN bit rate settings |
Definition at line 221 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:
[out] | config | The configuration structure |
Definition at line 1702 of file flexcan_driver.c.
bool FLEXCAN_DRV_GetTDCFail | ( | uint8_t | instance | ) |
Gets the value of the TDC Fail flag.
base | The FlexCAN base address |
Definition at line 1039 of file flexcan_driver.c.
uint8_t FLEXCAN_DRV_GetTDCValue | ( | uint8_t | instance | ) |
Gets the value of the Transceiver Delay Compensation.
base | The FlexCAN base address |
Definition at line 1023 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).
instance | The FlexCAN instance number. |
mb_idx | The index of the message buffer. |
Definition at line 1237 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
instance | A FlexCAN instance number |
state | Pointer to the FlexCAN driver state structure. |
data | The FlexCAN platform data |
Definition at line 458 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.
instance | The FlexCAN instance number. |
callback | The callback function. |
callbackParam | User parameter passed to the callback function through the state parameter. |
Definition at line 1581 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.
instance | A FlexCAN instance number |
mb_idx | Index of the message buffer |
data | The FlexCAN receive message buffer data. |
Definition at line 864 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.
instance | A FlexCAN instance number |
mb_idx | Index of the message buffer |
data | The FlexCAN receive message buffer data. |
timeout_ms | A timeout for the transfer in milliseconds. |
Definition at line 815 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.
instance | A FlexCAN instance number |
data | The FlexCAN receive message buffer data. |
Definition at line 932 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.
instance | A FlexCAN instance number |
data | The FlexCAN receive message buffer data. |
timeout_ms | A timeout for the transfer in milliseconds. |
Definition at line 887 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.
instance | A FlexCAN instance number |
mb_idx | Index of the message buffer |
tx_info | Data info |
msg_id | ID of the message to transmit |
mb_data | Bytes of the FlexCAN message. |
Definition at line 704 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.
instance | A FlexCAN instance number |
mb_idx | Index of the message buffer |
tx_info | Data info |
msg_id | ID of the message to transmit |
mb_data | Bytes of the FlexCAN message |
timeout_ms | A timeout for the transfer in milliseconds. |
Definition at line 651 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.
instance | A FlexCAN instance number |
bitrate | A pointer to the FlexCAN bit rate settings. |
Definition at line 139 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).
instance | A FlexCAN instance number |
bitrate | A pointer to the FlexCAN bit rate settings. |
Definition at line 173 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).
instance | A FlexCAN instance number |
id_type | Standard ID or extended ID |
mask | Mask value |
Definition at line 266 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).
instance | A FlexCAN instance number |
id_type | A standard ID or an extended ID |
mb_idx | Index of the message buffer |
mask | Mask value |
Definition at line 410 of file flexcan_driver.c.
void FLEXCAN_DRV_SetRxMaskType | ( | uint8_t | instance, |
flexcan_rx_mask_type_t | type | ||
) |
Sets the Rx masking type.
instance | A FlexCAN instance number |
type | The FlexCAN RX mask type |
Definition at line 245 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).
instance | A FlexCAN instance number |
id_type | Standard ID or extended ID |
mask | Mask value |
Definition at line 338 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).
instance | A FlexCAN instance number |
id_type | Standard ID or extended ID |
mask | Mask value |
Definition at line 374 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).
instance | A FlexCAN instance number |
id_type | Standard ID or extended ID |
mask | Mask value |
Definition at line 302 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).
instance | A FlexCAN instance number |
enable | Enable/Disable Transceiver Delay Compensation |
offset | Transceiver Delay Compensation Offset |
Definition at line 1002 of file flexcan_driver.c.