HPM SDK
HPMicro Software Development Kit
hpm_can_drv.h File Reference
#include "hpm_common.h"
#include "hpm_can_regs.h"
#include "hpm_soc_feature.h"

Go to the source code of this file.

Data Structures

struct  can_bit_timing_param_t
 CAN Bit timing parameters. More...
 
struct  can_filter_config_t
 CAN acceptance filter configuration. More...
 
struct  can_config_t
 CAN configuration. More...
 

Macros

#define CAN_EVENT_RECEIVE   (CAN_RTIF_RIF_MASK)
 CAN Event definitions. More...
 
#define CAN_EVENT_RX_BUF_OVERRUN   (CAN_RTIF_ROIF_MASK)
 
#define CAN_EVENT_RX_BUF_FULL   (CAN_RTIF_RFIF_MASK)
 
#define CAN_EVENT_RX_BUF_ALMOST_FULL   (CAN_RTIF_RAFIF_MASK)
 
#define CAN_EVENT_TX_PRIMARY_BUF   (CAN_RTIF_TPIF_MASK)
 
#define CAN_EVENT_TX_SECONDARY_BUF   (CAN_RTIF_TSIF_MASK)
 
#define CAN_EVENT_ERROR   (CAN_RTIF_EIF_MASK)
 
#define CAN_EVENT_ABORT   (CAN_RTIF_AIF_MASK)
 
#define CAN_STB_IS_EMPTY   (0U)
 CAN Secondary Transmit buffer Status. More...
 
#define CAN_STB_LESS_EQUAL_HALF_FULL   (1U)
 
#define CAN_STB_MORE_THAN_HALF_FULL   (2U)
 
#define CAN_STB_IS_FULL   (3U)
 
#define CAN_RXBUF_IS_EMPTY   (0U)
 CAN Receive Buffer States. More...
 
#define CAN_RXBUF_HAS_DATA   (1U)
 
#define CAN_RXBUF_ALMOST_FULL   (2U)
 
#define CAN_RXBUF_IS_FULL   (3U)
 
#define CAN_ERROR_WARNING_LIMIT_FLAG   (CAN_ERRINT_EWARN_MASK)
 CAN Error interrupts/flags. More...
 
#define CAN_ERROR_PASSIVE_MODE_ACTIVE_FLAG   (CAN_ERRINT_EPASS_MASK)
 
#define CAN_ERROR_PASSIVE_INT_ENABLE   (CAN_ERRINT_EPIE_MASK)
 
#define CAN_ERROR_PASSIVE_INT_FLAG   (CAN_ERRINT_EPIF_MASK)
 
#define CAN_ERROR_ARBITRATION_LOST_INT_ENABLE   (CAN_ERRINT_ALIE_MASK)
 
#define CAN_ERROR_ARBITRATION_LOST_INT_FLAG   (CAN_ERRINT_ALIE_MASK)
 
#define CAN_ERROR_BUS_ERROR_INT_ENABLE   (CAN_ERRINT_BEIE_MASK)
 
#define CAN_ERROR_BUS_ERROR_INT_FLAG   (CAN_ERRINT_BEIF_MASK)
 
#define CAN_KIND_OF_ERROR_NO_ERROR   (0U)
 CAN Error Kinds. More...
 
#define CAN_KIND_OF_ERROR_BIT_ERROR   (1U)
 
#define CAN_KIND_OF_ERROR_FORM_ERROR   (2U)
 
#define CAN_KIND_OF_ERROR_STUFF_ERROR   (3U)
 
#define CAN_KIND_OF_ERROR_ACK_ERROR   (4U)
 
#define CAN_KIND_OF_ERROR_CRC_ERROR   (5U)
 
#define CAN_KIND_OF_ERROR_OTHER_ERROR   (6U)
 
#define CAN_KIND_OF_ERROR_BUS_OFF   (7U)
 

Typedefs

typedef enum _can_mode can_node_mode_t
 CAN loopback types. More...
 
typedef enum _can_bit_timing_option can_bit_timing_option_t
 CAN bit timing options. More...
 
typedef union _can_rx_buf can_receive_buf_t
 CAN receive buffer data structure. More...
 
typedef union _can_tx_buf can_transmit_buf_t
 CAN transmit buffer data structure. More...
 
typedef enum _can_filter_id_mode can_filter_id_mode_t
 CAN acceptance filter modes. More...
 

Enumerations

enum  {
  status_can_bit_error = ((uint32_t)( status_group_can )*1000U + (uint32_t)( 0 )) , status_can_form_error = ((uint32_t)( status_group_can )*1000U + (uint32_t)( 1 )) , status_can_stuff_error = ((uint32_t)( status_group_can )*1000U + (uint32_t)( 2 )) , status_can_ack_error = ((uint32_t)( status_group_can )*1000U + (uint32_t)( 3 )) ,
  status_can_crc_error = ((uint32_t)( status_group_can )*1000U + (uint32_t)( 4 )) , status_can_other_error = ((uint32_t)( status_group_can )*1000U + (uint32_t)( 5 )) , status_can_tx_fifo_full = ((uint32_t)( status_group_can )*1000U + (uint32_t)( 6 )) , status_can_filter_index_invalid = ((uint32_t)( status_group_can )*1000U + (uint32_t)( 7 )) ,
  status_can_filter_num_invalid = ((uint32_t)( status_group_can )*1000U + (uint32_t)( 8 )) , status_can_invalid_bit_timing = ((uint32_t)( status_group_can )*1000U + (uint32_t)( 9 ))
}
 CAN error codes. More...
 
enum  {
  can_payload_size_0 = 0 , can_payload_size_1 , can_payload_size_2 , can_payload_size_3 ,
  can_payload_size_4 , can_payload_size_5 , can_payload_size_6 , can_payload_size_7 ,
  can_payload_size_8 , can_payload_size_12 , can_payload_size_16 , can_payload_size_20 ,
  can_payload_size_24 , can_payload_size_32 , can_payload_size_48 , can_payload_size_64 ,
  can_payload_size_max = can_payload_size_64
}
 CAN DLC definitions. More...
 

Functions

static void can_reset (CAN_Type *base, bool enable)
 Reset CAN controller. More...
 
static void can_force_bus_off (CAN_Type *base)
 Force CAN controller to Bus-off mode. More...
 
static void can_set_node_mode (CAN_Type *base, can_node_mode_t mode)
 Set CAN mode. More...
 
static void can_enable_listen_only_mode (CAN_Type *base, bool enable)
 Enable CAN listen-only mode. More...
 
static void can_enter_standby_mode (CAN_Type *base, bool enable)
 Enter CAN standby mode. More...
 
static void can_disable_ptb_retransmission (CAN_Type *base, bool enable)
 Disable the re-transmission for the primary transmission buffer. More...
 
static bool can_is_ptb_retransmission_disabled (CAN_Type *base)
 Check whether re-transmission is disabled for PTB or not. More...
 
static void can_disable_stb_retransmission (CAN_Type *base, bool enable)
 Disable the re-transmission for the secondary transmission buffer. More...
 
static bool can_is_stb_retransmission_disabled (CAN_Type *base)
 Check whether re-transmission is disabled for STB or not. More...
 
static void can_select_tx_buffer (CAN_Type *base, bool select_secondary_buffer)
 Select CAN TX buffer. More...
 
static void can_start_high_priority_message_transmit (CAN_Type *base)
 Start CAN high priority message transmit. More...
 
static void can_abort_high_priority_message_transmit (CAN_Type *base)
 Abort CAN high priority message transmit. More...
 
static void can_start_message_transmit (CAN_Type *base)
 Start CAN message transmit. More...
 
static void can_start_all_message_transmit (CAN_Type *base)
 Start CAN all messages transmit. More...
 
static void can_abort_message_transmit (CAN_Type *base)
 Abort CAN message transmit. More...
 
static void can_switch_to_next_tx_buffer (CAN_Type *base)
 Switch to next CAN tx buffer. More...
 
static void can_select_tx_buffer_priority_mode (CAN_Type *base, bool enable_priority_decision)
 Select CAN tx buffer priority mode. More...
 
static uint8_t can_get_secondary_transmit_buffer_status (CAN_Type *base)
 Get CAN secondary transmit buffer status. More...
 
static bool can_is_primary_transmit_buffer_full (CAN_Type *base)
 Check whether the primary transmit buffer is full. More...
 
static bool can_is_secondary_transmit_buffer_full (CAN_Type *base)
 Check whether the secondary transmit buffer is full. More...
 
static bool can_is_in_bus_off_mode (CAN_Type *base)
 Check whether the CAN is in BUS off mode. More...
 
static void can_enable_self_ack (CAN_Type *base, bool enable)
 Enable can self ack. More...
 
static void can_set_receive_buffer_overflow_mode (CAN_Type *base, bool override_enable)
 Set CAN receive buffer overflow mode. More...
 
static bool can_is_receive_buffer_overflow (CAN_Type *base)
 Check whether CAN receive buffer is overflow. More...
 
static void can_release_receive_buffer (CAN_Type *base)
 Release CAN receive buffer. More...
 
static void can_allow_store_all_data_in_receive_buffer (CAN_Type *base, bool allow)
 Allow can store all date in receive buffer. More...
 
static uint8_t can_get_receive_buffer_status (CAN_Type *base)
 Get CAN receive buffer status. More...
 
static bool can_is_data_available_in_receive_buffer (CAN_Type *base)
 Check whether there are data available in receive buffer. More...
 
static void can_enable_can_fd_iso_mode (CAN_Type *base, bool enable)
 Enable CAN FD ISO mode. More...
 
static void can_enable_tx_rx_irq (CAN_Type *base, uint8_t mask)
 Enable CAN TX/RX interrupt. More...
 
static void can_disable_tx_rx_irq (CAN_Type *base, uint8_t mask)
 Disable CAN TX/RX interrupt. More...
 
static void can_clear_tx_rx_flags (CAN_Type *base, uint8_t flags)
 Clear CAN TX/RX flags. More...
 
static uint8_t can_get_tx_rx_flags (CAN_Type *base)
 Get CAN TX/RX flags. More...
 
static void can_enable_error_irq (CAN_Type *base, uint8_t mask)
 Enable CAN error interrupt. More...
 
static void can_disable_error_irq (CAN_Type *base, uint8_t mask)
 Disable CAN error interrupt. More...
 
static uint8_t can_get_error_interrupt_flags (CAN_Type *base)
 Get CAN error interrupt flags. More...
 
static void can_clear_error_interrupt_flags (CAN_Type *base, uint8_t flags)
 Get CAN clear interrupt flags. More...
 
static uint8_t can_get_last_error_kind (CAN_Type *base)
 Get last CAN error kind. More...
 
static uint8_t can_get_last_arbitration_lost_position (CAN_Type *base)
 Get CAN last arbitrary lost position. More...
 
static void can_set_transmitter_delay_compensation (CAN_Type *base, uint8_t sample_point, bool enable)
 Set CAN transmitter delay compensation. More...
 
static void can_set_warning_limits (CAN_Type *base, uint8_t almost_full_limit, uint8_t error_warning_limit)
 Set CAN warning limits. More...
 
static uint8_t can_get_receive_error_count (CAN_Type *base)
 Get CAN receive error count. More...
 
static uint8_t can_get_transmit_error_count (CAN_Type *base)
 Get CAN transmit error count. More...
 
static void can_enable_filter (CAN_Type *base, uint32_t index)
 Enable a specified CAN filter. More...
 
static void can_disable_filter (CAN_Type *base, uint32_t index)
 Disable a specified CAN filter. More...
 
hpm_stat_t can_get_default_config (can_config_t *config)
 Get default CAN configuration parameters. More...
 
hpm_stat_t can_init (CAN_Type *base, can_config_t *config, uint32_t src_clk_freq)
 Initialize the CAN controller. More...
 
void can_deinit (CAN_Type *base)
 De-initialize the CAN controller. More...
 
static void can_set_slow_speed_timing (CAN_Type *base, const can_bit_timing_param_t *param)
 Configure the Slow Speed Bit timing using low-level interface. More...
 
static void can_set_fast_speed_timing (CAN_Type *base, const can_bit_timing_param_t *param)
 Configure the Fast Speed Bit timing using low-level interface. More...
 
hpm_stat_t can_set_bit_timing (CAN_Type *base, can_bit_timing_option_t option, uint32_t src_clk_freq, uint32_t baudrate, uint16_t samplepoint_min, uint16_t samplepoint_max)
 Configure the CAN bit timing for CAN BUS. More...
 
hpm_stat_t can_calculate_bit_timing (uint32_t src_clk_freq, can_bit_timing_option_t option, uint32_t baudrate, uint16_t samplepoint_min, uint16_t samplepoint_max, can_bit_timing_param_t *timing_param)
 Calculate the CAN bit timing for CAN BUS. More...
 
hpm_stat_t can_set_filter (CAN_Type *base, const can_filter_config_t *config)
 Configure the acceptable filter. More...
 
hpm_stat_t can_send_message_blocking (CAN_Type *base, const can_transmit_buf_t *message)
 Send CAN message using blocking transfer. More...
 
hpm_stat_t can_send_high_priority_message_blocking (CAN_Type *base, const can_transmit_buf_t *message)
 Send high-priority message using blocking transfer. More...
 
hpm_stat_t can_send_message_nonblocking (CAN_Type *base, const can_transmit_buf_t *message)
 Send CAN message using non-blocking transfer. More...
 
hpm_stat_t can_send_high_priority_message_nonblocking (CAN_Type *base, const can_transmit_buf_t *message)
 Send high-priority message using non-blocking transfer. More...
 
hpm_stat_t can_receive_message_blocking (CAN_Type *base, can_receive_buf_t *message)
 Receive CAN message using blocking transfer. More...
 
hpm_stat_t can_read_received_message (CAN_Type *base, can_receive_buf_t *message)
 Read Received CAN message. More...