This driver for AtmelĀ® | SMART SAM devices provides an low level interface for the configuration and management of the device's Control Area Network functionality.
For storage of Rx/Tx messages and for storage of the filter configuration, a message RAM is needed to the CAN module. In this driver, the message RAM is static allocated, the related setting is defined and can be changed in the module configuration file "conf_can.h".
The following peripherals are used by this module:
The following devices can use this module:
The outline of this documentation is as follows:
There are no prerequisites for this module.
This driver provides an interface for the Control Area Network Controller functions on the device.
There are no special considerations for this module.
For extra information see Extra Information for CAN Driver. This includes:
For a list of examples related to this driver, see Examples for CAN Driver.
Modules | |
Quick Start Guide(s) | |
In this section you can find a list of all Quick Start guides related to the SAM Control Area Network (CAN) Low Level Driver. | |
Data Structures | |
struct | can_config |
CAN configuration structure. More... | |
struct | can_module |
CAN software device instance structure. More... | |
Module Setting | |
enum | can_timeout_mode { CAN_TIMEOUT_CONTINUES = CAN_TOCC_TOS_CONT, CAN_TIMEOUT_TX_EVEN_FIFO = CAN_TOCC_TOS_TXEF, CAN_TIMEOUT_RX_FIFO_0 = CAN_TOCC_TOS_RXF0, CAN_TIMEOUT_RX_FIFO_1 = CAN_TOCC_TOS_RXF1 } |
Can time out modes. More... | |
enum | can_nonmatching_frames_action { CAN_NONMATCHING_FRAMES_FIFO_0, CAN_NONMATCHING_FRAMES_FIFO_1, CAN_NONMATCHING_FRAMES_REJECT } |
Can nonmatching frames action. More... | |
static void | can_get_config_defaults (struct can_config *const config) |
Initializes an CAN configuration structure to defaults. More... | |
void | can_init (struct can_module *const module_inst, Can *hw, struct can_config *config) |
Initializes CAN module. More... | |
void | can_set_baudrate (Can *hw, uint32_t baudrate) |
Set CAN baudrate. More... | |
void | can_fd_set_baudrate (Can *hw, uint32_t baudrate) |
Set CAN_FD baudrate. More... | |
void | can_start (struct can_module *const module_inst) |
Start CAN module communication. More... | |
void | can_stop (struct can_module *const module_inst) |
Stop CAN module communication. More... | |
void | can_enable_fd_mode (struct can_module *const module_inst) |
Enable CAN FD mode. More... | |
void | can_disable_fd_mode (struct can_module *const module_inst) |
Disable CAN FD mode. More... | |
void | can_enable_restricted_operation_mode (struct can_module *const module_inst) |
Enable CAN restricted operation mode. More... | |
void | can_disable_restricted_operation_mode (struct can_module *const module_inst) |
Disable CAN restricted operation mode. More... | |
void | can_enable_bus_monitor_mode (struct can_module *const module_inst) |
Enable CAN bus monitor mode. More... | |
void | can_disable_bus_monitor_mode (struct can_module *const module_inst) |
Disable CAN bus monitor mode. More... | |
void | can_enable_sleep_mode (struct can_module *const module_inst) |
Enable CAN sleep mode. More... | |
void | can_disable_sleep_mode (struct can_module *const module_inst) |
Disable CAN sleep mode. More... | |
void | can_enable_test_mode (struct can_module *const module_inst) |
Enable CAN test mode. More... | |
void | can_disable_test_mode (struct can_module *const module_inst) |
Disable CAN test mode. More... | |
static uint16_t | can_read_timestamp_count_value (struct can_module *const module_inst) |
Can read timestamp count value. More... | |
static uint16_t | can_read_timeout_count_value (struct can_module *const module_inst) |
Can read timeout count value. More... | |
static uint32_t | can_read_error_count (struct can_module *const module_inst) |
Can read error count. More... | |
static uint32_t | can_read_protocal_status (struct can_module *const module_inst) |
Can read protocol status. More... | |
Rx Handling | |
static uint32_t | can_read_high_priority_message_status (struct can_module *const module_inst) |
Read high priority message status. More... | |
static bool | can_rx_get_buffer_status (struct can_module *const module_inst, uint32_t index) |
Get Rx buffer status. More... | |
static void | can_rx_clear_buffer_status (struct can_module *const module_inst, uint32_t index) |
Clear Rx buffer status. More... | |
static uint32_t | can_rx_get_fifo_status (struct can_module *const module_inst, bool fifo_number) |
Get Rx FIFO status. More... | |
static void | can_rx_fifo_acknowledge (struct can_module *const module_inst, bool fifo_number, uint32_t index) |
Set Rx acknowledge. More... | |
static void | can_get_standard_message_filter_element_default (struct can_standard_message_filter_element *sd_filter) |
Get the standard message filter default value. More... | |
enum status_code | can_set_rx_standard_filter (struct can_module *const module_inst, struct can_standard_message_filter_element *sd_filter, uint32_t index) |
Set the standard message filter. More... | |
static void | can_get_extended_message_filter_element_default (struct can_extended_message_filter_element *et_filter) |
Get the extended message filter default value. More... | |
enum status_code | can_set_rx_extended_filter (struct can_module *const module_inst, struct can_extended_message_filter_element *et_filter, uint32_t index) |
Set the extended message filter. More... | |
enum status_code | can_get_rx_buffer_element (struct can_module *const module_inst, struct can_rx_element_buffer *rx_element, uint32_t index) |
Get the pointer to the receive buffer element. More... | |
enum status_code | can_get_rx_fifo_0_element (struct can_module *const module_inst, struct can_rx_element_fifo_0 *rx_element, uint32_t index) |
Get the pointer to the receive FIFO 0 element. More... | |
enum status_code | can_get_rx_fifo_1_element (struct can_module *const module_inst, struct can_rx_element_fifo_1 *rx_element, uint32_t index) |
Get the pointer to the receive FIFO 1 element. More... | |
Tx Handling | |
static uint32_t | can_tx_get_fifo_queue_status (struct can_module *const module_inst) |
Get Tx FIFO/Queue status. More... | |
static uint32_t | can_tx_get_pending_status (struct can_module *const module_inst) |
Get Tx buffer request pending status. More... | |
static enum status_code | can_tx_transfer_request (struct can_module *const module_inst, uint32_t trig_mask) |
Tx buffer add transfer request. More... | |
static enum status_code | can_tx_cancel_request (struct can_module *const module_inst, uint32_t trig_mask) |
Set Tx Queue operation. More... | |
static uint32_t | can_tx_get_transmission_status (struct can_module *const module_inst) |
Get Tx transmission status. More... | |
static uint32_t | can_tx_get_cancellation_status (struct can_module *const module_inst) |
Get Tx cancellation status. More... | |
static uint32_t | can_tx_get_event_fifo_status (struct can_module *const module_inst) |
Get Tx event FIFO status. More... | |
static void | can_tx_event_fifo_acknowledge (struct can_module *const module_inst, uint32_t index) |
Set Tx Queue operation. More... | |
static void | can_get_tx_buffer_element_defaults (struct can_tx_element *tx_element) |
Get the default transfer buffer element. More... | |
enum status_code | can_set_tx_buffer_element (struct can_module *const module_inst, struct can_tx_element *tx_element, uint32_t index) |
Set the transfer buffer element. More... | |
enum status_code | can_get_tx_event_fifo_element (struct can_module *const module_inst, struct can_tx_event_element *tx_event_element, uint32_t index) |
Get the pointer to the transfer event FIFO element. More... | |
enum can_interrupt_source |
Can module interrupt source.
Enum for the interrupt source.
enum can_timeout_mode |
|
inlinestatic |
Clear CAN interrupt status.
[in] | module_inst | Pointer to the CAN software instance struct |
[in] | source | Interrupt source type |
Referenced by CAN0_Handler().
void can_disable_bus_monitor_mode | ( | struct can_module *const | module_inst | ) |
Disable CAN bus monitor mode.
[in] | module_inst | Pointer to the CAN software instance struct |
void can_disable_fd_mode | ( | struct can_module *const | module_inst | ) |
Disable CAN FD mode.
[in] | module_inst | Pointer to the CAN software instance struct |
|
inlinestatic |
Disable CAN interrupt.
[in] | module_inst | Pointer to the CAN software instance struct |
[in] | source | Interrupt source type |
void can_disable_restricted_operation_mode | ( | struct can_module *const | module_inst | ) |
Disable CAN restricted operation mode.
[in] | module_inst | Pointer to the CAN software instance struct |
void can_disable_sleep_mode | ( | struct can_module *const | module_inst | ) |
Disable CAN sleep mode.
[in] | module_inst | Pointer to the CAN software instance struct |
References _can_enable_peripheral_clock(), gclk_chan_conf, system_gclk_chan_enable(), and system_gclk_chan_set_config().
void can_disable_test_mode | ( | struct can_module *const | module_inst | ) |
Disable CAN test mode.
[in] | module_inst | Pointer to the CAN software instance struct |
void can_enable_bus_monitor_mode | ( | struct can_module *const | module_inst | ) |
Enable CAN bus monitor mode.
[in] | module_inst | Pointer to the CAN software instance struct |
void can_enable_fd_mode | ( | struct can_module *const | module_inst | ) |
Enable CAN FD mode.
[in] | module_inst | Pointer to the CAN software instance struct |
Referenced by configure_can().
|
inlinestatic |
Enable CAN interrupt.
[in] | module_inst | Pointer to the CAN software instance struct |
[in] | source | Interrupt source type |
Referenced by can_set_extended_filter_0(), can_set_extended_filter_1(), can_set_standard_filter_0(), can_set_standard_filter_1(), and configure_can().
void can_enable_restricted_operation_mode | ( | struct can_module *const | module_inst | ) |
Enable CAN restricted operation mode.
[in] | module_inst | Pointer to the CAN software instance struct |
void can_enable_sleep_mode | ( | struct can_module *const | module_inst | ) |
Enable CAN sleep mode.
[in] | module_inst | Pointer to the CAN software instance struct |
void can_enable_test_mode | ( | struct can_module *const | module_inst | ) |
Enable CAN test mode.
[in] | module_inst | Pointer to the CAN software instance struct |
void can_fd_set_baudrate | ( | Can * | hw, |
uint32_t | baudrate | ||
) |
Set CAN_FD baudrate.
[in] | hw | Pointer to the CAN module instance |
[in] | baudrate | CAN_FD baudrate |
References system_gclk_chan_get_hz().
|
inlinestatic |
Initializes an CAN configuration structure to defaults.
Initializes a given CAN configuration struct to a set of known default values. This function should be called on any new instance of the configuration struct before being modified by the user application.
The default configuration is as follows:
[out] | config | Pointer to configuration struct to initialize to default values |
References Assert, can_config::automatic_retransmission, CAN_NONMATCHING_FRAMES_REJECT, CAN_TIMEOUT_CONTINUES, can_config::clock_source, can_config::clock_stop_acknowledge, can_config::clock_stop_request, can_config::delay_compensation_filter_window_length, can_config::delay_compensation_offset, can_config::edge_filtering, can_config::extended_id_mask, GCLK_GENERATOR_8, can_config::nonmatching_frames_action_extended, can_config::nonmatching_frames_action_standard, can_config::protocol_exception_handling, can_config::remote_frames_extended_reject, can_config::remote_frames_standard_reject, can_config::run_in_standby, can_config::rx_fifo_0_overwrite, can_config::rx_fifo_0_watermark, can_config::rx_fifo_1_overwrite, can_config::rx_fifo_1_watermark, can_config::tdc_enable, can_config::timeout_enable, can_config::timeout_mode, can_config::timeout_period, can_config::timestamp_prescaler, can_config::transmit_pause, can_config::tx_event_fifo_watermark, can_config::tx_queue_mode, and can_config::watchdog_configuration.
Referenced by configure_can().
|
inlinestatic |
Get the extended message filter default value.
The default configuration is as follows:
[out] | et_filter | Pointer to extended filter element struct to initialize to default values |
References CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFEC, CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFEC_STF1M_Val, CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_EFID1, CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFID2_Msk, CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_EFT_CLASSIC, can_extended_message_filter_element::F0, can_extended_message_filter_element::F1, CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_Type::reg, and CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_Type::reg.
Referenced by can_set_extended_filter_0(), and can_set_extended_filter_1().
enum status_code can_get_rx_buffer_element | ( | struct can_module *const | module_inst, |
struct can_rx_element_buffer * | rx_element, | ||
uint32_t | index | ||
) |
Get the pointer to the receive buffer element.
[in] | module_inst | Pointer to the CAN software instance struct |
[in] | rx_element | Pointer to receive buffer element |
[in] | index | Index offset in receive buffer |
STATUS_OK | Get the correct pointer to the receive buffer element. |
STATUS_ERR_INVALID_ARG | The parameter is not correct. |
References can0_rx_buffer, can1_rx_buffer, STATUS_ERR_INVALID_ARG, and STATUS_OK.
Referenced by CAN0_Handler().
enum status_code can_get_rx_fifo_0_element | ( | struct can_module *const | module_inst, |
struct can_rx_element_fifo_0 * | rx_element, | ||
uint32_t | index | ||
) |
Get the pointer to the receive FIFO 0 element.
[in] | module_inst | Pointer to the CAN software instance struct |
[in] | rx_element | Pointer to receive FIFO 0 |
[in] | index | Index offset in receive FIFO 0 |
STATUS_OK | Get the correct pointer to the receive FIFO 0 element. |
STATUS_ERR_INVALID_ARG | The parameter is not correct. |
References can0_rx_fifo_0, can1_rx_fifo_0, STATUS_ERR_INVALID_ARG, and STATUS_OK.
Referenced by CAN0_Handler().
enum status_code can_get_rx_fifo_1_element | ( | struct can_module *const | module_inst, |
struct can_rx_element_fifo_1 * | rx_element, | ||
uint32_t | index | ||
) |
Get the pointer to the receive FIFO 1 element.
[in] | module_inst | Pointer to the CAN software instance struct |
[in] | rx_element | Pointer to receive FIFO 1 |
[in] | index | Index offset in receive FIFO 1 |
STATUS_OK | Get the correct pointer to the receive FIFO 1 element. |
STATUS_ERR_INVALID_ARG | The parameter is not correct. |
References can0_rx_fifo_1, can1_rx_fifo_1, STATUS_ERR_INVALID_ARG, and STATUS_OK.
Referenced by CAN0_Handler().
|
inlinestatic |
Get the standard message filter default value.
The default configuration is as follows:
[out] | sd_filter | Pointer to standard filter element struct to initialize to default values |
References CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFEC, CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFEC_STF0M_Val, CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFID1, CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFID2_Msk, CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_SFT_CLASSIC, CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_Type::reg, and can_standard_message_filter_element::S0.
Referenced by can_set_standard_filter_0(), and can_set_standard_filter_1().
|
inlinestatic |
Get the default transfer buffer element.
The default configuration is as follows:
[out] | tx_element | Pointer to transfer element struct to initialize to default values |
References CAN_TX_ELEMENT_T1_DLC, CAN_TX_ELEMENT_T1_DLC_DATA8_Val, CAN_TX_ELEMENT_T1_EFC, CAN_TX_ELEMENT_T0_Type::reg, CAN_TX_ELEMENT_T1_Type::reg, can_tx_element::T0, and can_tx_element::T1.
Referenced by can_fd_send_extended_message(), can_fd_send_standard_message(), can_send_extended_message(), and can_send_standard_message().
enum status_code can_get_tx_event_fifo_element | ( | struct can_module *const | module_inst, |
struct can_tx_event_element * | tx_event_element, | ||
uint32_t | index | ||
) |
Get the pointer to the transfer event FIFO element.
[in] | module_inst | Pointer to the CAN software instance struct |
[in] | tx_event_element | Pointer to transfer event element |
[in] | index | Index offset in transfer event FIFO |
STATUS_OK | Get the correct pointer to the transfer event FIFO element. |
STATUS_ERR_INVALID_ARG | The parameter is not correct. |
References can0_tx_event_fifo, can1_tx_event_fifo, can_tx_event_element::E0, can_tx_event_element::E1, CAN_TX_EVENT_ELEMENT_E0_Type::reg, CAN_TX_EVENT_ELEMENT_E1_Type::reg, STATUS_ERR_INVALID_ARG, and STATUS_OK.
void can_init | ( | struct can_module *const | module_inst, |
Can * | hw, | ||
struct can_config * | config | ||
) |
Initializes CAN module.
[in] | module_inst | Pointer to the CAN software instance struct |
[in] | hw | Pointer to the CAN module instance |
[in] | config | Pointer to the configuration struct |
References _can_enable_peripheral_clock(), _can_message_memory_init(), _can_set_configuration(), Assert, can_config::clock_source, gclk_chan_conf, system_gclk_chan_config::source_generator, system_gclk_chan_enable(), system_gclk_chan_get_config_defaults(), and system_gclk_chan_set_config().
Referenced by configure_can().
|
inlinestatic |
Can read error count.
[in] | module_inst | Pointer to the CAN software instance struct |
|
inlinestatic |
Read high priority message status.
[in] | module_inst | Pointer to the CAN software instance struct |
|
inlinestatic |
Get CAN interrupt status.
[in] | module_inst | Pointer to the CAN software instance struct |
Referenced by CAN0_Handler().
|
inlinestatic |
Can read protocol status.
[in] | module_inst | Pointer to the CAN software instance struct |
|
inlinestatic |
Can read timeout count value.
[in] | module_inst | Pointer to the CAN software instance struct |
|
inlinestatic |
Can read timestamp count value.
[in] | module_inst | Pointer to the CAN software instance struct |
|
inlinestatic |
Clear Rx buffer status.
[in] | module_inst | Pointer to the CAN software instance struct |
[in] | index | Index offset in Rx buffer |
Referenced by CAN0_Handler().
|
inlinestatic |
Set Rx acknowledge.
[in] | module_inst | Pointer to the CAN software instance struct |
[in] | fifo_number | Rx FIFO 0 or 1 |
[in] | index | Index offset in FIFO |
Referenced by CAN0_Handler().
|
inlinestatic |
Get Rx buffer status.
[in] | module_inst | Pointer to the CAN software instance struct |
[in] | index | Index offset in Rx buffer |
true | Rx Buffer updated from new message. |
false | Rx Buffer not updated. |
Referenced by CAN0_Handler().
|
inlinestatic |
Get Rx FIFO status.
[in] | module_inst | Pointer to the CAN software instance struct |
[in] | fifo_number | Rx FIFO 0 or 1 |
void can_set_baudrate | ( | Can * | hw, |
uint32_t | baudrate | ||
) |
Set CAN baudrate.
[in] | hw | Pointer to the CAN module instance |
[in] | baudrate | CAN baudrate |
References system_gclk_chan_get_hz().
enum status_code can_set_rx_extended_filter | ( | struct can_module *const | module_inst, |
struct can_extended_message_filter_element * | et_filter, | ||
uint32_t | index | ||
) |
Set the extended message filter.
[in] | module_inst | Pointer to the CAN software instance struct |
[in] | et_filter | Pointer to extended filter element struct |
[in] | index | Index offset in extended filter element |
STATUS_OK | Set the correct extended message filter. |
STATUS_ERR_INVALID_ARG | The parameter is not correct. |
References can0_rx_extended_filter, can1_rx_extended_filter, can_extended_message_filter_element::F0, can_extended_message_filter_element::F1, CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F0_Type::reg, CAN_EXTENDED_MESSAGE_FILTER_ELEMENT_F1_Type::reg, STATUS_ERR_INVALID_ARG, and STATUS_OK.
Referenced by can_set_extended_filter_0(), and can_set_extended_filter_1().
enum status_code can_set_rx_standard_filter | ( | struct can_module *const | module_inst, |
struct can_standard_message_filter_element * | sd_filter, | ||
uint32_t | index | ||
) |
Set the standard message filter.
[in] | module_inst | Pointer to the CAN software instance struct |
[in] | sd_filter | Pointer to standard filter element struct |
[in] | index | Index offset in standard filter element |
STATUS_OK | Set the correct standard message filter. |
STATUS_ERR_INVALID_ARG | The parameter is not correct. |
References can0_rx_standard_filter, can1_rx_standard_filter, CAN_STANDARD_MESSAGE_FILTER_ELEMENT_S0_Type::reg, can_standard_message_filter_element::S0, STATUS_ERR_INVALID_ARG, and STATUS_OK.
Referenced by can_set_standard_filter_0(), and can_set_standard_filter_1().
enum status_code can_set_tx_buffer_element | ( | struct can_module *const | module_inst, |
struct can_tx_element * | tx_element, | ||
uint32_t | index | ||
) |
Set the transfer buffer element.
[in] | module_inst | Pointer to the CAN software instance struct |
[in] | tx_element | Pointer to transfer element struct |
[in] | index | Index for the transfer buffer |
STATUS_OK | Set the correct transfer buffer element. |
STATUS_ERR_INVALID_ARG | The parameter is not correct. |
References can0_tx_buffer, can1_tx_buffer, can_tx_element::data, i, CAN_TX_ELEMENT_T0_Type::reg, CAN_TX_ELEMENT_T1_Type::reg, STATUS_ERR_INVALID_ARG, STATUS_OK, can_tx_element::T0, and can_tx_element::T1.
Referenced by can_fd_send_extended_message(), can_fd_send_standard_message(), can_send_extended_message(), and can_send_standard_message().
void can_start | ( | struct can_module *const | module_inst | ) |
Start CAN module communication.
[in] | module_inst | Pointer to the CAN software instance struct |
Referenced by configure_can().
void can_stop | ( | struct can_module *const | module_inst | ) |
Stop CAN module communication.
[in] | module_inst | Pointer to the CAN software instance struct |
|
inlinestatic |
Set Tx Queue operation.
[in] | module_inst | Pointer to the CAN software instance struct |
[in] | trig_mask | The mask value to cancel transfer buffer |
STATUS_OK | Set the transfer request. |
STATUS_BUSY | The module is in configuration. |
References STATUS_BUSY, and STATUS_OK.
|
inlinestatic |
Set Tx Queue operation.
[in] | module_inst | Pointer to the CAN software instance struct |
[in] | index | Index for the transfer FIFO |
|
inlinestatic |
Get Tx cancellation status.
[in] | module_inst | Pointer to the CAN software instance struct |
|
inlinestatic |
Get Tx event FIFO status.
[in] | module_inst | Pointer to the CAN software instance struct |
|
inlinestatic |
Get Tx FIFO/Queue status.
[in] | module_inst | Pointer to the CAN software instance struct |
|
inlinestatic |
Get Tx buffer request pending status.
[in] | module_inst | Pointer to the CAN software instance struct |
|
inlinestatic |
Get Tx transmission status.
[in] | module_inst | Pointer to the CAN software instance struct |
|
inlinestatic |
Tx buffer add transfer request.
[in] | module_inst | Pointer to the CAN software instance struct |
[in] | trig_mask | The mask value to trigger transfer buffer |
STATUS_OK | Set the transfer request. |
STATUS_BUSY | The module is in configuration. |
References STATUS_BUSY, and STATUS_OK.
Referenced by can_fd_send_extended_message(), can_fd_send_standard_message(), can_send_extended_message(), and can_send_standard_message().