Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SAM Control Area Network (CAN) Low Level Driver

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.

Note
Since "The Control Area Network (CAN) performs communication according to ISO 11898-1 (Bosch CAN specification 2.0 part A,B) and to Bosch CAN FD specification V1.0", the driver is focus on the MAC layer and try to offer the APIs which can be used by upper application layer.

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:

Prerequisites

There are no prerequisites for this module.

Module Overview

This driver provides an interface for the Control Area Network Controller functions on the device.

Special Considerations

There are no special considerations for this module.

Extra Information

For extra information see Extra Information for CAN Driver. This includes:

Examples

For a list of examples related to this driver, see Examples for CAN Driver.

API Overview

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...
 

Interrupt Handling

enum  can_interrupt_source {
  CAN_RX_FIFO_0_NEW_MESSAGE = CAN_IE_RF0NE,
  CAN_RX_FIFO_0_WATERMARK = CAN_IE_RF0WE,
  CAN_RX_FIFO_0_FULL = CAN_IE_RF0FE,
  CAN_RX_FIFO_0_LOST_MESSAGE = CAN_IE_RF0LE,
  CAN_RX_FIFO_1_NEW_MESSAGE = CAN_IE_RF1NE,
  CAN_RX_FIFO_1_WATERMARK = CAN_IE_RF1WE,
  CAN_RX_FIFO_1_FULL = CAN_IE_RF1FE,
  CAN_RX_FIFO_1_MESSAGE_LOST = CAN_IE_RF1LE,
  CAN_RX_HIGH_PRIORITY_MESSAGE = CAN_IE_HPME,
  CAN_TIMESTAMP_COMPLETE = CAN_IE_TCE,
  CAN_TX_CANCELLATION_FINISH = CAN_IE_TCFE,
  CAN_TX_FIFO_EMPTY = CAN_IE_TFEE,
  CAN_TX_EVENT_FIFO_NEW_ENTRY = CAN_IE_TEFNE,
  CAN_TX_EVENT_FIFO_WATERMARK = CAN_IE_TEFWE,
  CAN_TX_EVENT_FIFO_FULL = CAN_IE_TEFFE,
  CAN_TX_EVENT_FIFO_ELEMENT_LOST = CAN_IE_TEFLE,
  CAN_TIMESTAMP_WRAPAROUND = CAN_IE_TSWE,
  CAN_MESSAGE_RAM_ACCESS_FAILURE = CAN_IE_MRAFE,
  CAN_TIMEOUT_OCCURRED = CAN_IE_TOOE,
  CAN_RX_BUFFER_NEW_MESSAGE = CAN_IE_DRXE,
  CAN_BIT_ERROR_CORRECTED = CAN_IE_BECE,
  CAN_BIT_ERROR_UNCORRECTED = CAN_IE_BEUE,
  CAN_ERROR_LOGGING_OVERFLOW = CAN_IE_ELOE,
  CAN_ERROR_PASSIVE = CAN_IE_EPE,
  CAN_WARNING_STATUS = CAN_IE_EWE,
  CAN_BUS_OFF = CAN_IE_BOE,
  CAN_WATCHDOG = CAN_IE_WDIE,
  CAN_PROTOCOL_ERROR_ARBITRATION = CAN_IE_PEAE,
  CAN_PROTOCOL_ERROR_DATA = CAN_IE_PEDE,
  CAN_ACCESS_RESERVED_ADDRESS = CAN_IE_ARAE
}
 Can module interrupt source. More...
 
static void can_enable_interrupt (struct can_module *const module_inst, const enum can_interrupt_source source)
 Enable CAN interrupt. More...
 
static void can_disable_interrupt (struct can_module *const module_inst, const enum can_interrupt_source source)
 Disable CAN interrupt. More...
 
static uint32_t can_read_interrupt_status (struct can_module *const module_inst)
 Get CAN interrupt status. More...
 
static void can_clear_interrupt_status (struct can_module *const module_inst, const enum can_interrupt_source source)
 Clear CAN interrupt status. More...
 

Can module interrupt source.

Enum for the interrupt source.

Enumerator
CAN_RX_FIFO_0_NEW_MESSAGE 

Rx FIFO 0 New Message Interrupt Enable.

CAN_RX_FIFO_0_WATERMARK 

Rx FIFO 0 Watermark Reached Interrupt Enable.

CAN_RX_FIFO_0_FULL 

Rx FIFO 0 Full Interrupt Enable.

CAN_RX_FIFO_0_LOST_MESSAGE 

Rx FIFO 0 Message Lost Interrupt Enable.

CAN_RX_FIFO_1_NEW_MESSAGE 

Rx FIFO 1 New Message Interrupt Enable.

CAN_RX_FIFO_1_WATERMARK 

Rx FIFO 1 Watermark Reached Interrupt Enable.

CAN_RX_FIFO_1_FULL 

Rx FIFO 1 Full Interrupt Enable.

CAN_RX_FIFO_1_MESSAGE_LOST 

Rx FIFO 1 Message Lost Interrupt Enable.

CAN_RX_HIGH_PRIORITY_MESSAGE 

High Priority Message Interrupt Enable.

CAN_TIMESTAMP_COMPLETE 

Timestamp Completed Interrupt Enable.

CAN_TX_CANCELLATION_FINISH 

Transmission Cancellation Finished Interrupt Enable.

CAN_TX_FIFO_EMPTY 

Tx FIFO Empty Interrupt Enable.

CAN_TX_EVENT_FIFO_NEW_ENTRY 

Tx Event FIFO New Entry Interrupt Enable.

CAN_TX_EVENT_FIFO_WATERMARK 

Tx Event FIFO Watermark Reached Interrupt Enable.

CAN_TX_EVENT_FIFO_FULL 

Tx Event FIFO Full Interrupt Enable.

CAN_TX_EVENT_FIFO_ELEMENT_LOST 

Tx Event FIFO Element Lost Interrupt Enable.

CAN_TIMESTAMP_WRAPAROUND 

Timestamp Wraparound Interrupt Enable.

CAN_MESSAGE_RAM_ACCESS_FAILURE 

Message RAM Access Failure Interrupt Enable.

CAN_TIMEOUT_OCCURRED 

Timeout Occurred Interrupt Enable.

CAN_RX_BUFFER_NEW_MESSAGE 

Message stored to Dedicated Rx Buffer Interrupt Enable.

CAN_BIT_ERROR_CORRECTED 

Bit Error Corrected Interrupt Enable.

CAN_BIT_ERROR_UNCORRECTED 

Bit Error Uncorrected Interrupt Enable.

CAN_ERROR_LOGGING_OVERFLOW 

Error Logging Overflow Interrupt Enable.

CAN_ERROR_PASSIVE 

Error Passive Interrupt Enable.

CAN_WARNING_STATUS 

Warning Status Interrupt Enable.

CAN_BUS_OFF 

Bus_Off Status Interrupt Enable.

CAN_WATCHDOG 

Watchdog Interrupt Interrupt Enable.

CAN_PROTOCOL_ERROR_ARBITRATION 

Protocol Error in Arbitration Phase Enable.

CAN_PROTOCOL_ERROR_DATA 

Protocol Error in Data Phase Enable.

CAN_ACCESS_RESERVED_ADDRESS 

Access to Reserved Address Enable.

Can nonmatching frames action.

Enumerator
CAN_NONMATCHING_FRAMES_FIFO_0 

Accept in Rx FIFO 0.

CAN_NONMATCHING_FRAMES_FIFO_1 

Accept in Rx FIFO 1.

CAN_NONMATCHING_FRAMES_REJECT 

Reject.

Can time out modes.

Enumerator
CAN_TIMEOUT_CONTINUES 

Continuous operation.

CAN_TIMEOUT_TX_EVEN_FIFO 

Timeout controlled by TX Event FIFO.

CAN_TIMEOUT_RX_FIFO_0 

Timeout controlled by Rx FIFO 0.

CAN_TIMEOUT_RX_FIFO_1 

Timeout controlled by Rx FIFO 1.

static void can_clear_interrupt_status ( struct can_module *const  module_inst,
const enum can_interrupt_source  source 
)
inlinestatic

Clear CAN interrupt status.

Parameters
[in]module_instPointer to the CAN software instance struct
[in]sourceInterrupt source type
Returns
Bit mask of interrupt status value.

Referenced by CAN0_Handler().

void can_disable_bus_monitor_mode ( struct can_module *const  module_inst)

Disable CAN bus monitor mode.

Parameters
[in]module_instPointer to the CAN software instance struct
void can_disable_fd_mode ( struct can_module *const  module_inst)

Disable CAN FD mode.

Parameters
[in]module_instPointer to the CAN software instance struct
static void can_disable_interrupt ( struct can_module *const  module_inst,
const enum can_interrupt_source  source 
)
inlinestatic

Disable CAN interrupt.

Parameters
[in]module_instPointer to the CAN software instance struct
[in]sourceInterrupt source type
void can_disable_restricted_operation_mode ( struct can_module *const  module_inst)

Disable CAN restricted operation mode.

Parameters
[in]module_instPointer to the CAN software instance struct
void can_disable_sleep_mode ( struct can_module *const  module_inst)

Disable CAN sleep mode.

Parameters
[in]module_instPointer 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.

Parameters
[in]module_instPointer to the CAN software instance struct
void can_enable_bus_monitor_mode ( struct can_module *const  module_inst)

Enable CAN bus monitor mode.

Note
This function will set the CCCR.INIT bit, can_start() is needed to restart the communication.
Parameters
[in]module_instPointer to the CAN software instance struct
void can_enable_fd_mode ( struct can_module *const  module_inst)

Enable CAN FD mode.

Note
This function will set the CCCR.INIT bit, can_start() is needed to restart the communication.
Parameters
[in]module_instPointer to the CAN software instance struct

Referenced by configure_can().

static void can_enable_interrupt ( struct can_module *const  module_inst,
const enum can_interrupt_source  source 
)
inlinestatic

Enable CAN interrupt.

Parameters
[in]module_instPointer to the CAN software instance struct
[in]sourceInterrupt 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.

Note
This function will set the CCCR.INIT bit, can_start() is needed to restart the communication.
Parameters
[in]module_instPointer to the CAN software instance struct
void can_enable_sleep_mode ( struct can_module *const  module_inst)

Enable CAN sleep mode.

Parameters
[in]module_instPointer to the CAN software instance struct
void can_enable_test_mode ( struct can_module *const  module_inst)

Enable CAN test mode.

Note
This function will set the CCCR.INIT bit, can_start() is needed to restart the communication.
Parameters
[in]module_instPointer to the CAN software instance struct
void can_fd_set_baudrate ( Can *  hw,
uint32_t  baudrate 
)

Set CAN_FD baudrate.

Parameters
[in]hwPointer to the CAN module instance
[in]baudrateCAN_FD baudrate

References system_gclk_chan_get_hz().

static void can_get_config_defaults ( struct can_config *const  config)
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:

  • GCLK generator 8 (GCLK main) clock source
  • Not run in standby mode
  • Disable Watchdog
  • Transmit pause enabled
  • Edge filtering during bus integration enabled
  • Protocol exception handling enabled
  • Automatic retransmission enabled
  • Clock stop request disabled
  • Clock stop acknowledge disabled
  • Timestamp Counter Prescaler 1
  • Timeout Period with 0xFFFF
  • Timeout Mode: Continuous operation
  • Disable Timeout
  • Transmitter Delay Compensation Offset is 0
  • Transmitter Delay Compensation Filter Window Length is 0
  • Reject nonmatching standard frames
  • Reject nonmatching extended frames
  • Reject remote standard frames
  • Reject remote extended frames
  • Extended ID Mask is 0x1FFFFFFF
  • Rx FIFO 0 Operation Mode: overwrite
  • Disable Rx FIFO 0 Watermark
  • Rx FIFO 1 Operation Mode: overwrite
  • Disable Rx FIFO 1 Watermark
  • Tx FIFO/Queue Mode: FIFO
  • Disable Tx Event FIFO Watermark
Parameters
[out]configPointer 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().

static void can_get_extended_message_filter_element_default ( struct can_extended_message_filter_element et_filter)
inlinestatic

Get the extended message filter default value.

The default configuration is as follows:

  • Classic filter: SFID1 = filter, SFID2 = mask
  • Store in Rx FIFO 1 if filter matches
  • SFID2 = 0x1FFFFFFFul
  • SFID1 = 0x0ul
Parameters
[out]et_filterPointer 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.

Parameters
[in]module_instPointer to the CAN software instance struct
[in]rx_elementPointer to receive buffer element
[in]indexIndex offset in receive buffer
Returns
Status of the result.
Return values
STATUS_OKGet the correct pointer to the receive buffer element.
STATUS_ERR_INVALID_ARGThe 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.

Parameters
[in]module_instPointer to the CAN software instance struct
[in]rx_elementPointer to receive FIFO 0
[in]indexIndex offset in receive FIFO 0
Returns
Status of the result.
Return values
STATUS_OKGet the correct pointer to the receive FIFO 0 element.
STATUS_ERR_INVALID_ARGThe 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.

Parameters
[in]module_instPointer to the CAN software instance struct
[in]rx_elementPointer to receive FIFO 1
[in]indexIndex offset in receive FIFO 1
Returns
Status of the result.
Return values
STATUS_OKGet the correct pointer to the receive FIFO 1 element.
STATUS_ERR_INVALID_ARGThe parameter is not correct.

References can0_rx_fifo_1, can1_rx_fifo_1, STATUS_ERR_INVALID_ARG, and STATUS_OK.

Referenced by CAN0_Handler().

static void can_get_standard_message_filter_element_default ( struct can_standard_message_filter_element sd_filter)
inlinestatic

Get the standard message filter default value.

The default configuration is as follows:

  • Classic filter: SFID1 = filter, SFID2 = mask
  • Store in Rx FIFO 0 if filter matches
  • SFID2 = 0x7FFul
  • SFID1 = 0x0ul
Parameters
[out]sd_filterPointer 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().

static void can_get_tx_buffer_element_defaults ( struct can_tx_element tx_element)
inlinestatic

Get the default transfer buffer element.

The default configuration is as follows:

  • 11-bit standard identifier
  • Transmit data frame
  • ID = 0x0ul
  • Store Tx events
  • Frame transmitted in Classic CAN format
  • Data Length Code is 8
Parameters
[out]tx_elementPointer 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.

Parameters
[in]module_instPointer to the CAN software instance struct
[in]tx_event_elementPointer to transfer event element
[in]indexIndex offset in transfer event FIFO
Returns
Status of the result.
Return values
STATUS_OKGet the correct pointer to the transfer event FIFO element.
STATUS_ERR_INVALID_ARGThe 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.

Parameters
[in]module_instPointer to the CAN software instance struct
[in]hwPointer to the CAN module instance
[in]configPointer 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().

static uint32_t can_read_error_count ( struct can_module *const  module_inst)
inlinestatic

Can read error count.

Parameters
[in]module_instPointer to the CAN software instance struct
Returns
Error count value.
static uint32_t can_read_high_priority_message_status ( struct can_module *const  module_inst)
inlinestatic

Read high priority message status.

Parameters
[in]module_instPointer to the CAN software instance struct
Returns
High priority message status value.
static uint32_t can_read_interrupt_status ( struct can_module *const  module_inst)
inlinestatic

Get CAN interrupt status.

Parameters
[in]module_instPointer to the CAN software instance struct

Referenced by CAN0_Handler().

static uint32_t can_read_protocal_status ( struct can_module *const  module_inst)
inlinestatic

Can read protocol status.

Parameters
[in]module_instPointer to the CAN software instance struct
Returns
protocol status value.
static uint16_t can_read_timeout_count_value ( struct can_module *const  module_inst)
inlinestatic

Can read timeout count value.

Parameters
[in]module_instPointer to the CAN software instance struct
Returns
Timeout count value.
static uint16_t can_read_timestamp_count_value ( struct can_module *const  module_inst)
inlinestatic

Can read timestamp count value.

Parameters
[in]module_instPointer to the CAN software instance struct
Returns
Timestamp count value.
static void can_rx_clear_buffer_status ( struct can_module *const  module_inst,
uint32_t  index 
)
inlinestatic

Clear Rx buffer status.

Parameters
[in]module_instPointer to the CAN software instance struct
[in]indexIndex offset in Rx buffer

Referenced by CAN0_Handler().

static void can_rx_fifo_acknowledge ( struct can_module *const  module_inst,
bool  fifo_number,
uint32_t  index 
)
inlinestatic

Set Rx acknowledge.

Parameters
[in]module_instPointer to the CAN software instance struct
[in]fifo_numberRx FIFO 0 or 1
[in]indexIndex offset in FIFO

Referenced by CAN0_Handler().

static bool can_rx_get_buffer_status ( struct can_module *const  module_inst,
uint32_t  index 
)
inlinestatic

Get Rx buffer status.

Parameters
[in]module_instPointer to the CAN software instance struct
[in]indexIndex offset in Rx buffer
Returns
Rx buffer status value.
Return values
trueRx Buffer updated from new message.
falseRx Buffer not updated.

Referenced by CAN0_Handler().

static uint32_t can_rx_get_fifo_status ( struct can_module *const  module_inst,
bool  fifo_number 
)
inlinestatic

Get Rx FIFO status.

Parameters
[in]module_instPointer to the CAN software instance struct
[in]fifo_numberRx FIFO 0 or 1
Returns
Rx FIFO status value.
void can_set_baudrate ( Can *  hw,
uint32_t  baudrate 
)

Set CAN baudrate.

Parameters
[in]hwPointer to the CAN module instance
[in]baudrateCAN 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.

Parameters
[in]module_instPointer to the CAN software instance struct
[in]et_filterPointer to extended filter element struct
[in]indexIndex offset in extended filter element
Returns
Status of the result.
Return values
STATUS_OKSet the correct extended message filter.
STATUS_ERR_INVALID_ARGThe 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.

Parameters
[in]module_instPointer to the CAN software instance struct
[in]sd_filterPointer to standard filter element struct
[in]indexIndex offset in standard filter element
Returns
Status of the result.
Return values
STATUS_OKSet the correct standard message filter.
STATUS_ERR_INVALID_ARGThe 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.

Parameters
[in]module_instPointer to the CAN software instance struct
[in]tx_elementPointer to transfer element struct
[in]indexIndex for the transfer buffer
Returns
Status of the result.
Return values
STATUS_OKSet the correct transfer buffer element.
STATUS_ERR_INVALID_ARGThe 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.

Parameters
[in]module_instPointer to the CAN software instance struct

Referenced by configure_can().

void can_stop ( struct can_module *const  module_inst)

Stop CAN module communication.

Parameters
[in]module_instPointer to the CAN software instance struct
static enum status_code can_tx_cancel_request ( struct can_module *const  module_inst,
uint32_t  trig_mask 
)
inlinestatic

Set Tx Queue operation.

Parameters
[in]module_instPointer to the CAN software instance struct
[in]trig_maskThe mask value to cancel transfer buffer
Returns
Status of the result.
Return values
STATUS_OKSet the transfer request.
STATUS_BUSYThe module is in configuration.

References STATUS_BUSY, and STATUS_OK.

static void can_tx_event_fifo_acknowledge ( struct can_module *const  module_inst,
uint32_t  index 
)
inlinestatic

Set Tx Queue operation.

Parameters
[in]module_instPointer to the CAN software instance struct
[in]indexIndex for the transfer FIFO
static uint32_t can_tx_get_cancellation_status ( struct can_module *const  module_inst)
inlinestatic

Get Tx cancellation status.

Parameters
[in]module_instPointer to the CAN software instance struct
Returns
Bit mask of Tx cancellation status value.
static uint32_t can_tx_get_event_fifo_status ( struct can_module *const  module_inst)
inlinestatic

Get Tx event FIFO status.

Parameters
[in]module_instPointer to the CAN software instance struct
Returns
Tx event FIFO status value.
static uint32_t can_tx_get_fifo_queue_status ( struct can_module *const  module_inst)
inlinestatic

Get Tx FIFO/Queue status.

Parameters
[in]module_instPointer to the CAN software instance struct
Returns
Tx FIFO/Queue status value.
static uint32_t can_tx_get_pending_status ( struct can_module *const  module_inst)
inlinestatic

Get Tx buffer request pending status.

Parameters
[in]module_instPointer to the CAN software instance struct
Returns
Bit mask of Tx buffer request pending status value.
static uint32_t can_tx_get_transmission_status ( struct can_module *const  module_inst)
inlinestatic

Get Tx transmission status.

Parameters
[in]module_instPointer to the CAN software instance struct
Returns
Bit mask of Tx transmission status value.
static enum status_code can_tx_transfer_request ( struct can_module *const  module_inst,
uint32_t  trig_mask 
)
inlinestatic

Tx buffer add transfer request.

Parameters
[in]module_instPointer to the CAN software instance struct
[in]trig_maskThe mask value to trigger transfer buffer
Returns
Status of the result.
Return values
STATUS_OKSet the transfer request.
STATUS_BUSYThe 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().