Microchip® Advanced Software Framework

can.c File Reference

SAM Control Area Network (CAN) Low Level Driver.

Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.

#include "can.h"
#include <string.h>

Functions

static void _can_enable_peripheral_clock (struct can_module *const module_inst)
 
static void _can_message_memory_init (Can *hw)
 
static void _can_set_configuration (Can *hw, struct can_config *config)
 
void can_disable_bus_monitor_mode (struct can_module *const module_inst)
 Disable CAN bus monitor mode. More...
 
void can_disable_fd_mode (struct can_module *const module_inst)
 Disable CAN FD mode. More...
 
void can_disable_restricted_operation_mode (struct can_module *const module_inst)
 Disable CAN restricted operation mode. More...
 
void can_disable_sleep_mode (struct can_module *const module_inst)
 Disable CAN sleep mode. More...
 
void can_disable_test_mode (struct can_module *const module_inst)
 Disable CAN test mode. More...
 
void can_enable_bus_monitor_mode (struct can_module *const module_inst)
 Enable CAN bus monitor mode. More...
 
void can_enable_fd_mode (struct can_module *const module_inst)
 Enable CAN FD mode. More...
 
void can_enable_restricted_operation_mode (struct can_module *const module_inst)
 Enable CAN restricted operation mode. More...
 
void can_enable_sleep_mode (struct can_module *const module_inst)
 Enable CAN sleep mode. More...
 
void can_enable_test_mode (struct can_module *const module_inst)
 Enable CAN test mode. More...
 
void can_fd_set_baudrate (Can *hw, uint32_t baudrate)
 Set CAN_FD baudrate. 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...
 
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...
 
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...
 
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_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...
 
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...
 
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...
 

Variables

static struct can_rx_element_buffer can0_rx_buffer [CONF_CAN0_RX_BUFFER_NUM]
 
static struct
can_extended_message_filter_element 
can0_rx_extended_filter [CONF_CAN0_RX_EXTENDED_ID_FILTER_NUM]
 
static struct can_rx_element_fifo_0 can0_rx_fifo_0 [CONF_CAN0_RX_FIFO_0_NUM]
 
static struct can_rx_element_fifo_1 can0_rx_fifo_1 [CONF_CAN0_RX_FIFO_1_NUM]
 
static struct
can_standard_message_filter_element 
can0_rx_standard_filter [CONF_CAN0_RX_STANDARD_ID_FILTER_NUM]
 
static struct can_tx_element can0_tx_buffer [CONF_CAN0_TX_BUFFER_NUM+CONF_CAN0_TX_FIFO_QUEUE_NUM]
 
static struct can_tx_event_element can0_tx_event_fifo [CONF_CAN0_TX_EVENT_FIFO]
 
static struct can_rx_element_buffer can1_rx_buffer [CONF_CAN1_RX_BUFFER_NUM]
 
static struct
can_extended_message_filter_element 
can1_rx_extended_filter [CONF_CAN1_RX_EXTENDED_ID_FILTER_NUM]
 
static struct can_rx_element_fifo_0 can1_rx_fifo_0 [CONF_CAN1_RX_FIFO_0_NUM]
 
static struct can_rx_element_fifo_1 can1_rx_fifo_1 [CONF_CAN1_RX_FIFO_1_NUM]
 
static struct
can_standard_message_filter_element 
can1_rx_standard_filter [CONF_CAN1_RX_STANDARD_ID_FILTER_NUM]
 
static struct can_tx_element can1_tx_buffer [CONF_CAN1_TX_BUFFER_NUM+CONF_CAN1_TX_FIFO_QUEUE_NUM]
 
static struct can_tx_event_element can1_tx_event_fifo [CONF_CAN1_TX_EVENT_FIFO]
 
struct system_gclk_chan_config gclk_chan_conf
 

static void _can_enable_peripheral_clock ( struct can_module *const  module_inst)
static
static void _can_message_memory_init ( Can *  hw)
static

The data size in conf_can.h should be 8/12/16/20/24/32/48/64, The corresponding setting value in register is 0/1//2/3/4/5/6/7. To simplify the calculation, seperate to two group 8/12/16/20/24 which increased with 4 and 32/48/64 which increased with 16.

References can0_rx_buffer, can0_rx_extended_filter, can0_rx_fifo_0, can0_rx_fifo_1, can0_rx_standard_filter, can0_tx_buffer, can0_tx_event_fifo, can1_rx_buffer, can1_rx_extended_filter, can1_rx_fifo_0, can1_rx_fifo_1, can1_rx_standard_filter, can1_tx_buffer, and can1_tx_event_fifo.

Referenced by can_init().

struct can_rx_element_buffer can0_rx_buffer[CONF_CAN0_RX_BUFFER_NUM]
static
struct can_extended_message_filter_element can0_rx_extended_filter[CONF_CAN0_RX_EXTENDED_ID_FILTER_NUM]
static
struct can_rx_element_fifo_0 can0_rx_fifo_0[CONF_CAN0_RX_FIFO_0_NUM]
static
struct can_rx_element_fifo_1 can0_rx_fifo_1[CONF_CAN0_RX_FIFO_1_NUM]
static
struct can_standard_message_filter_element can0_rx_standard_filter[CONF_CAN0_RX_STANDARD_ID_FILTER_NUM]
static
struct can_tx_element can0_tx_buffer[CONF_CAN0_TX_BUFFER_NUM+CONF_CAN0_TX_FIFO_QUEUE_NUM]
static
struct can_tx_event_element can0_tx_event_fifo[CONF_CAN0_TX_EVENT_FIFO]
static
struct can_rx_element_buffer can1_rx_buffer[CONF_CAN1_RX_BUFFER_NUM]
static
struct can_extended_message_filter_element can1_rx_extended_filter[CONF_CAN1_RX_EXTENDED_ID_FILTER_NUM]
static
struct can_rx_element_fifo_0 can1_rx_fifo_0[CONF_CAN1_RX_FIFO_0_NUM]
static
struct can_rx_element_fifo_1 can1_rx_fifo_1[CONF_CAN1_RX_FIFO_1_NUM]
static
struct can_standard_message_filter_element can1_rx_standard_filter[CONF_CAN1_RX_STANDARD_ID_FILTER_NUM]
static
struct can_tx_element can1_tx_buffer[CONF_CAN1_TX_BUFFER_NUM+CONF_CAN1_TX_FIFO_QUEUE_NUM]
static
struct can_tx_event_element can1_tx_event_fifo[CONF_CAN1_TX_EVENT_FIFO]
static
struct system_gclk_chan_config gclk_chan_conf

Referenced by can_disable_sleep_mode(), and can_init().