RA Flexible Software Package Documentation  Release v5.6.0

 
CAN Interface

Detailed Description

Interface for CAN peripheral.

Summary

The CAN interface provides common APIs for CAN HAL drivers. CAN interface supports following features.

Data Structures

struct  can_info_t
 
struct  can_bit_timing_cfg_t
 
struct  can_frame_t
 
struct  can_callback_args_t
 
struct  can_cfg_t
 
struct  can_api_t
 
struct  can_instance_t
 

Typedefs

typedef void can_ctrl_t
 

Enumerations

enum  can_event_t
 
enum  can_operation_mode_t
 
enum  can_test_mode_t
 
enum  can_id_mode_t
 
enum  can_frame_type_t
 

Data Structure Documentation

◆ can_info_t

struct can_info_t

CAN status info

Data Fields
uint32_t status Useful information from the CAN status register.
uint32_t rx_mb_status RX Message Buffer New Data flags.
uint32_t rx_fifo_status RX FIFO Empty flags.
uint8_t error_count_transmit Transmit error count.
uint8_t error_count_receive Receive error count.
uint32_t error_code Error code, cleared after reading.

◆ can_bit_timing_cfg_t

struct can_bit_timing_cfg_t

CAN bit rate configuration.

Data Fields
uint32_t baud_rate_prescaler Baud rate prescaler. Valid values: 1 - 1024.
uint32_t time_segment_1 Time segment 1 control.
uint32_t time_segment_2 Time segment 2 control.
uint32_t synchronization_jump_width Synchronization jump width.

◆ can_frame_t

struct can_frame_t

CAN data Frame

Data Fields
uint32_t id CAN ID.
can_id_mode_t id_mode Standard or Extended ID (IDE).
can_frame_type_t type Frame type (RTR).
uint8_t data_length_code CAN Data Length Code (DLC).
uint32_t options Implementation-specific options.
uint8_t data[CAN_DATA_BUFFER_LENGTH] CAN data.

◆ can_callback_args_t

struct can_callback_args_t

CAN callback parameter definition

Data Fields
uint32_t channel Device channel number.
can_event_t event Event code.
uint32_t error Error code.
union can_callback_args_t __unnamed__
void const * p_context Context provided to user during callback.
can_frame_t frame Received frame data.

◆ can_cfg_t

struct can_cfg_t

CAN Configuration

Data Fields

uint32_t channel
 CAN channel.
 
can_bit_timing_cfg_tp_bit_timing
 CAN bit timing.
 
void(* p_callback )(can_callback_args_t *p_args)
 Pointer to callback function.
 
void const * p_context
 User defined callback context.
 
void const * p_extend
 CAN hardware dependent configuration.
 
uint8_t ipl
 Error/Transmit/Receive interrupt priority.
 
IRQn_Type error_irq
 Error IRQ number.
 
IRQn_Type rx_irq
 Receive IRQ number.
 
IRQn_Type tx_irq
 Transmit IRQ number.
 

◆ can_api_t

struct can_api_t

Shared Interface definition for CAN

Data Fields

fsp_err_t(* open )(can_ctrl_t *const p_ctrl, can_cfg_t const *const p_cfg)
 
fsp_err_t(* write )(can_ctrl_t *const p_ctrl, uint32_t buffer_number, can_frame_t *const p_frame)
 
fsp_err_t(* read )(can_ctrl_t *const p_ctrl, uint32_t buffer_number, can_frame_t *const p_frame)
 
fsp_err_t(* close )(can_ctrl_t *const p_ctrl)
 
fsp_err_t(* modeTransition )(can_ctrl_t *const p_ctrl, can_operation_mode_t operation_mode, can_test_mode_t test_mode)
 
fsp_err_t(* infoGet )(can_ctrl_t *const p_ctrl, can_info_t *const p_info)
 
fsp_err_t(* callbackSet )(can_ctrl_t *const p_ctrl, void(*p_callback)(can_callback_args_t *), void const *const p_context, can_callback_args_t *const p_callback_memory)
 

Field Documentation

◆ open

fsp_err_t(* can_api_t::open) (can_ctrl_t *const p_ctrl, can_cfg_t const *const p_cfg)

Open function for CAN device

Parameters
[in,out]p_ctrlPointer to the CAN control block. Must be declared by user. Value set here.
[in]p_cfgPointer to CAN configuration structure. All elements of this structure must be set by user.

◆ write

fsp_err_t(* can_api_t::write) (can_ctrl_t *const p_ctrl, uint32_t buffer_number, can_frame_t *const p_frame)

Write function for CAN device

Parameters
[in]p_ctrlPointer to the CAN control block.
[in]bufferBuffer number (mailbox or message buffer) to write to.
[in]p_framePointer for frame of CAN ID, DLC, data and frame type to write.

◆ read

fsp_err_t(* can_api_t::read) (can_ctrl_t *const p_ctrl, uint32_t buffer_number, can_frame_t *const p_frame)

Read function for CAN device

Parameters
[in]p_ctrlPointer to the CAN control block.
[in]bufferMessage buffer (number) to read from.
[in]p_framePointer to store the CAN ID, DLC, data and frame type.

◆ close

fsp_err_t(* can_api_t::close) (can_ctrl_t *const p_ctrl)

Close function for CAN device

Parameters
[in]p_ctrlPointer to the CAN control block.

◆ modeTransition

fsp_err_t(* can_api_t::modeTransition) (can_ctrl_t *const p_ctrl, can_operation_mode_t operation_mode, can_test_mode_t test_mode)

Mode Transition function for CAN device

Parameters
[in]p_ctrlPointer to the CAN control block.
[in]operation_modeDestination CAN operation state.
[in]test_modeDestination CAN test state.

◆ infoGet

fsp_err_t(* can_api_t::infoGet) (can_ctrl_t *const p_ctrl, can_info_t *const p_info)

Get CAN channel info.

Parameters
[in]p_ctrlHandle for channel (pointer to channel control block)
[out]p_infoMemory address to return channel specific data to.

◆ callbackSet

fsp_err_t(* can_api_t::callbackSet) (can_ctrl_t *const p_ctrl, void(*p_callback)(can_callback_args_t *), void const *const p_context, can_callback_args_t *const p_callback_memory)

Specify callback function and optional context pointer and working memory pointer.

Parameters
[in]p_ctrlControl block set in can_api_t::open call.
[in]p_callbackCallback function to register
[in]p_contextPointer to send to callback function
[in]p_working_memoryPointer to volatile memory where callback structure can be allocated. Callback arguments allocated here are only valid during the callback.

◆ can_instance_t

struct can_instance_t

This structure encompasses everything that is needed to use an instance of this interface.

Data Fields
can_ctrl_t * p_ctrl Pointer to the control structure for this instance.
can_cfg_t const * p_cfg Pointer to the configuration structure for this instance.
can_api_t const * p_api Pointer to the API structure for this instance.

Typedef Documentation

◆ can_ctrl_t

typedef void can_ctrl_t

CAN control block. Allocate an instance specific control block to pass into the CAN API calls.

Enumeration Type Documentation

◆ can_event_t

CAN event codes

Enumerator
CAN_EVENT_ERR_WARNING 

Error Warning event.

CAN_EVENT_ERR_PASSIVE 

Error Passive event.

CAN_EVENT_ERR_BUS_OFF 

Bus Off event.

CAN_EVENT_BUS_RECOVERY 

Bus Off Recovery event.

CAN_EVENT_MAILBOX_MESSAGE_LOST 

Mailbox has been overrun.

CAN_EVENT_ERR_BUS_LOCK 

Bus lock detected (32 consecutive dominant bits).

CAN_EVENT_ERR_CHANNEL 

Channel error has occurred.

CAN_EVENT_TX_ABORTED 

Transmit abort event.

CAN_EVENT_RX_COMPLETE 

Receive complete event.

CAN_EVENT_TX_COMPLETE 

Transmit complete event.

CAN_EVENT_ERR_GLOBAL 

Global error has occurred.

CAN_EVENT_TX_FIFO_EMPTY 

Transmit FIFO is empty.

CAN_EVENT_FIFO_MESSAGE_LOST 

Receive FIFO overrun.

◆ can_operation_mode_t

CAN Operation modes

Enumerator
CAN_OPERATION_MODE_NORMAL 

CAN Normal Operation Mode.

CAN_OPERATION_MODE_RESET 

CAN Reset Operation Mode.

CAN_OPERATION_MODE_HALT 

CAN Halt Operation Mode.

CAN_OPERATION_MODE_SLEEP 

CAN Sleep Operation Mode.

◆ can_test_mode_t

CAN Test modes

Enumerator
CAN_TEST_MODE_DISABLED 

CAN Test Mode Disabled.

CAN_TEST_MODE_LISTEN 

CAN Test Listen Mode.

CAN_TEST_MODE_LOOPBACK_EXTERNAL 

CAN Test External Loopback Mode.

CAN_TEST_MODE_LOOPBACK_INTERNAL 

CAN Test Internal Loopback Mode.

CAN_TEST_MODE_INTERNAL_BUS 

CANFD Internal CAN Bus Communication Test Mode.

◆ can_id_mode_t

CAN ID modes

Enumerator
CAN_ID_MODE_STANDARD 

Standard IDs of 11 bits used.

CAN_ID_MODE_EXTENDED 

Extended IDs of 29 bits used.

◆ can_frame_type_t

CAN frame types

Enumerator
CAN_FRAME_TYPE_DATA 

Data frame.

CAN_FRAME_TYPE_REMOTE 

Remote frame.