Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Controller Area Network (CAN) Driver

See Quickstart guide for SAM CAN module..

Purpose

The CAN controller provides all the features required to implement the serial communication protocol CAN defined by Robert Bosch GmbH, the CAN specification. This is a driver for configuration, enabling, disabling and use of the CAN peripheral.

Modules

 
 Quick Start Guide(s)
 In this section you can find a list of all Quick Start guides related to the Controller Area Network (CAN) Driver.
 

Functions

void can_disable (Can *p_can)
 Disable CAN Controller. More...
 
void can_disable_autobaud_listen_mode (Can *p_can)
 Disable CAN Controller autobaud/listen mode. More...
 
void can_disable_interrupt (Can *p_can, uint32_t dw_mask)
 Disable CAN interrupt. More...
 
void can_disable_low_power_mode (Can *p_can)
 Disable CAN Controller low power mode. More...
 
void can_disable_overload_frame (Can *p_can)
 CAN Controller won't generate overload frame. More...
 
void can_disable_time_triggered_mode (Can *p_can)
 Disable CAN Controller time triggered mode. More...
 
void can_disable_timer_freeze (Can *p_can)
 Disable CAN Controller timer freeze. More...
 
void can_disable_tx_repeat (Can *p_can)
 Disable CAN Controller transmit repeat function. More...
 
void can_enable (Can *p_can)
 Enable CAN Controller. More...
 
void can_enable_autobaud_listen_mode (Can *p_can)
 Enable CAN Controller autobaud/listen mode. More...
 
void can_enable_interrupt (Can *p_can, uint32_t dw_mask)
 Enable CAN interrupt. More...
 
void can_enable_low_power_mode (Can *p_can)
 Enable CAN Controller low power mode. More...
 
void can_enable_overload_frame (Can *p_can)
 CAN Controller will generate an overload frame after each successful reception for mailboxes configured in Receive mode, Producer and Consumer. More...
 
void can_enable_time_triggered_mode (Can *p_can)
 Enable CAN Controller time triggered mode. More...
 
void can_enable_timer_freeze (Can *p_can)
 Enable CAN Controller timer freeze. More...
 
void can_enable_tx_repeat (Can *p_can)
 Enable CAN Controller transmit repeat function. More...
 
uint32_t can_get_internal_timer_value (Can *p_can)
 Get the 16-bit free-running internal timer count. More...
 
uint32_t can_get_interrupt_mask (Can *p_can)
 Get CAN Interrupt Mask. More...
 
uint8_t can_get_rx_error_cnt (Can *p_can)
 Get CAN receive error counter. More...
 
uint32_t can_get_status (Can *p_can)
 Get CAN status. More...
 
uint32_t can_get_timestamp_value (Can *p_can)
 Get CAN timestamp register value. More...
 
uint8_t can_get_tx_error_cnt (Can *p_can)
 Get CAN transmit error counter. More...
 
void can_global_send_abort_cmd (Can *p_can, uint8_t uc_mask)
 Send global abort request. More...
 
void can_global_send_transfer_cmd (Can *p_can, uint8_t uc_mask)
 Send global transfer request. More...
 
uint32_t can_init (Can *p_can, uint32_t ul_mck, uint32_t ul_baudrate)
 Initialize CAN controller. More...
 
uint32_t can_mailbox_get_status (Can *p_can, uint8_t uc_index)
 Get status of the mailbox. More...
 
void can_mailbox_init (Can *p_can, can_mb_conf_t *p_mailbox)
 Initialize the mailbox in different mode and set up related configuration. More...
 
uint32_t can_mailbox_read (Can *p_can, can_mb_conf_t *p_mailbox)
 Read receive information for the mailbox. More...
 
void can_mailbox_send_abort_cmd (Can *p_can, can_mb_conf_t *p_mailbox)
 Send single mailbox abort request. More...
 
void can_mailbox_send_transfer_cmd (Can *p_can, can_mb_conf_t *p_mailbox)
 Send single mailbox transfer request. More...
 
void can_mailbox_set_timemark (Can *p_can, uint8_t uc_index, uint16_t us_cnt)
 Configure the timemark for the mailbox. More...
 
uint32_t can_mailbox_tx_remote_frame (Can *p_can, can_mb_conf_t *p_mailbox)
 Require to send out a remote frame. More...
 
uint32_t can_mailbox_write (Can *p_can, can_mb_conf_t *p_mailbox)
 Prepare transmit information and write them into the mailbox. More...
 
void can_reset_all_mailbox (Can *p_can)
 Reset the eight mailboxes. More...
 
void can_reset_internal_timer (Can *p_can)
 Reset the internal free-running 16-bit timer. More...
 
void can_set_rx_sync_stage (Can *p_can, uint32_t ul_stage)
 Configure CAN Controller reception synchronization stage. More...
 
void can_set_timestamp_capture_point (Can *p_can, uint32_t ul_flag)
 Configure the timestamp capture point, at the start or the end of frame. More...
 

void can_disable ( Can *  p_can)

Disable CAN Controller.

Parameters
p_canPointer to a CAN peripheral instance.

Referenced by can_set_baudrate(), main(), and run_can_test().

void can_disable_autobaud_listen_mode ( Can *  p_can)

Disable CAN Controller autobaud/listen mode.

Parameters
p_canPointer to a CAN peripheral instance.
void can_disable_interrupt ( Can *  p_can,
uint32_t  dw_mask 
)

Disable CAN interrupt.

Parameters
p_canPointer to a CAN peripheral instance.
dw_maskInterrupt to be disabled.

Referenced by main(), run_can_test(), test_1(), test_2(), test_3(), and test_4().

void can_disable_low_power_mode ( Can *  p_can)

Disable CAN Controller low power mode.

Parameters
p_canPointer to a CAN peripheral instance.
void can_disable_overload_frame ( Can *  p_can)

CAN Controller won't generate overload frame.

Parameters
p_canPointer to a CAN peripheral instance.
void can_disable_time_triggered_mode ( Can *  p_can)

Disable CAN Controller time triggered mode.

Parameters
p_canPointer to a CAN peripheral instance.
void can_disable_timer_freeze ( Can *  p_can)

Disable CAN Controller timer freeze.

Parameters
p_canPointer to a CAN peripheral instance.
void can_disable_tx_repeat ( Can *  p_can)

Disable CAN Controller transmit repeat function.

Parameters
p_canPointer to a CAN peripheral instance.
void can_enable ( Can *  p_can)

Enable CAN Controller.

Parameters
p_canPointer to a CAN peripheral instance.

Referenced by can_init().

void can_enable_autobaud_listen_mode ( Can *  p_can)

Enable CAN Controller autobaud/listen mode.

Parameters
p_canPointer to a CAN peripheral instance.
void can_enable_interrupt ( Can *  p_can,
uint32_t  dw_mask 
)

Enable CAN interrupt.

Parameters
p_canPointer to a CAN peripheral instance.
dw_maskInterrupt to be enabled.

Referenced by run_can_test(), test_1(), test_2(), test_3(), and test_4().

void can_enable_low_power_mode ( Can *  p_can)

Enable CAN Controller low power mode.

Parameters
p_canPointer to a CAN peripheral instance.
void can_enable_overload_frame ( Can *  p_can)

CAN Controller will generate an overload frame after each successful reception for mailboxes configured in Receive mode, Producer and Consumer.

Parameters
p_canPointer to a CAN peripheral instance.
void can_enable_time_triggered_mode ( Can *  p_can)

Enable CAN Controller time triggered mode.

Parameters
p_canPointer to a CAN peripheral instance.
void can_enable_timer_freeze ( Can *  p_can)

Enable CAN Controller timer freeze.

Parameters
p_canPointer to a CAN peripheral instance.
void can_enable_tx_repeat ( Can *  p_can)

Enable CAN Controller transmit repeat function.

Parameters
p_canPointer to a CAN peripheral instance.
uint32_t can_get_internal_timer_value ( Can *  p_can)

Get the 16-bit free-running internal timer count.

Parameters
p_canPointer to a CAN peripheral instance.
Return values
Theinternal CAN free-running timer counter.
uint32_t can_get_interrupt_mask ( Can *  p_can)

Get CAN Interrupt Mask.

Parameters
p_canPointer to a CAN peripheral instance.
Return values
CANinterrupt mask.
uint8_t can_get_rx_error_cnt ( Can *  p_can)

Get CAN receive error counter.

Parameters
p_canPointer to a CAN peripheral instance.
Return values
Receiveerror counter.
uint32_t can_get_status ( Can *  p_can)

Get CAN status.

Parameters
p_canPointer to a CAN peripheral instance.
Return values
CANstatus.

Referenced by CAN0_Handler(), CAN1_Handler(), and can_init().

uint32_t can_get_timestamp_value ( Can *  p_can)

Get CAN timestamp register value.

Parameters
p_canPointer to a CAN peripheral instance.
Return values
Thetimestamp value.
uint8_t can_get_tx_error_cnt ( Can *  p_can)

Get CAN transmit error counter.

Parameters
p_canPointer to a CAN peripheral instance.
Return values
Transmiterror counter.
void can_global_send_abort_cmd ( Can *  p_can,
uint8_t  uc_mask 
)

Send global abort request.

Parameters
p_canPointer to a CAN peripheral instance.
uc_maskMask for mailboxes that are requested to abort.

References GLOBAL_MAILBOX_MASK.

void can_global_send_transfer_cmd ( Can *  p_can,
uint8_t  uc_mask 
)

Send global transfer request.

Parameters
p_canPointer to a CAN peripheral instance.
uc_maskMask for mailboxes that are requested to transfer.

References GLOBAL_MAILBOX_MASK.

Referenced by can_mailbox_tx_remote_frame(), run_can_test(), test_1(), test_2(), test_3(), and test_4().

uint32_t can_init ( Can *  p_can,
uint32_t  ul_mck,
uint32_t  ul_baudrate 
)

Initialize CAN controller.

Parameters
p_canPointer to a CAN peripheral instance.
ul_mckCAN module input clock.
ul_baudrateCAN communication baudrate in kbs.
Return values
0If failed to initialize the CAN module; otherwise successful.
Note
PMC clock for CAN peripheral should be enabled before calling this function.

References can_enable(), can_get_status(), can_reset_all_mailbox(), can_set_baudrate(), and CAN_TIMEOUT.

Referenced by main(), and run_can_test().

uint32_t can_mailbox_get_status ( Can *  p_can,
uint8_t  uc_index 
)

Get status of the mailbox.

Parameters
p_canPointer to a CAN peripheral instance.
uc_indexIndicate which mailbox is to be read.
Return values
Themailbox status.

Referenced by CAN0_Handler(), CAN1_Handler(), and can_mailbox_write().

void can_mailbox_init ( Can *  p_can,
can_mb_conf_t p_mailbox 
)

Initialize the mailbox in different mode and set up related configuration.

Parameters
p_canPointer to a CAN peripheral instance.
p_mailboxPointer to a CAN mailbox instance.

References if(), can_mb_conf_t::uc_id_ver, can_mb_conf_t::uc_obj_type, can_mb_conf_t::uc_tx_prio, can_mb_conf_t::ul_id, can_mb_conf_t::ul_id_msk, and can_mb_conf_t::ul_mb_idx.

Referenced by can_reset_all_mailbox(), run_can_test(), test_1(), test_2(), test_3(), and test_4().

uint32_t can_mailbox_read ( Can *  p_can,
can_mb_conf_t p_mailbox 
)

Read receive information for the mailbox.

Parameters
p_canPointer to a CAN peripheral instance.
p_mailboxPointer to a CAN mailbox instance.
Return values
DifferentCAN mailbox transfer status.
Note
Read the mailbox status before calling this function.

References CAN_MAILBOX_RX_NEED_RD_AGAIN, CAN_MAILBOX_RX_OVER, can_mailbox_send_transfer_cmd(), CAN_MAILBOX_TRANSFER_OK, if(), can_mb_conf_t::uc_length, can_mb_conf_t::ul_datah, can_mb_conf_t::ul_datal, can_mb_conf_t::ul_fid, can_mb_conf_t::ul_mb_idx, and can_mb_conf_t::ul_status.

Referenced by CAN0_Handler(), and CAN1_Handler().

void can_mailbox_send_abort_cmd ( Can *  p_can,
can_mb_conf_t p_mailbox 
)

Send single mailbox abort request.

Parameters
p_canPointer to a CAN peripheral instance.
p_mailboxPointer to a CAN mailbox instance.

References can_mb_conf_t::uc_length, and can_mb_conf_t::ul_mb_idx.

void can_mailbox_send_transfer_cmd ( Can *  p_can,
can_mb_conf_t p_mailbox 
)

Send single mailbox transfer request.

Parameters
p_canPointer to a CAN peripheral instance.
p_mailboxPointer to a CAN mailbox instance.

References can_mb_conf_t::uc_length, and can_mb_conf_t::ul_mb_idx.

Referenced by can_mailbox_read().

void can_mailbox_set_timemark ( Can *  p_can,
uint8_t  uc_index,
uint16_t  us_cnt 
)

Configure the timemark for the mailbox.

Parameters
p_canPointer to a CAN peripheral instance.
uc_indexIndicate which mailbox is to be configured.
us_cntThe timemark to be set.
Note
The timemark is active in Time Triggered mode only.

References TIMEMARK_MASK.

uint32_t can_mailbox_tx_remote_frame ( Can *  p_can,
can_mb_conf_t p_mailbox 
)

Require to send out a remote frame.

Parameters
p_canPointer to a CAN peripheral instance.
p_mailboxPointer to a CAN mailbox instance.
Return values
CAN_MAILBOX_NOT_READY,:Failed because mailbox isn't ready for transmitting message. CAN_MAILBOX_TRANSFER_OK: Successfully send out a remote frame.

References can_global_send_transfer_cmd(), CAN_MAILBOX_NOT_READY, CAN_MAILBOX_TRANSFER_OK, if(), can_mb_conf_t::uc_id_ver, can_mb_conf_t::uc_length, can_mb_conf_t::ul_id, can_mb_conf_t::ul_mb_idx, and can_mb_conf_t::ul_status.

Referenced by run_can_test().

uint32_t can_mailbox_write ( Can *  p_can,
can_mb_conf_t p_mailbox 
)

Prepare transmit information and write them into the mailbox.

Parameters
p_canPointer to a CAN peripheral instance.
p_mailboxPointer to a CAN mailbox instance.
Return values
CAN_MAILBOX_NOT_READY,:Failed because mailbox isn't ready. CAN_MAILBOX_TRANSFER_OK: Successfully write message into mailbox.
Note
After calling this function, the mailbox message won't be sent out until can_mailbox_send_transfer_cmd() is called.

References can_mailbox_get_status(), CAN_MAILBOX_NOT_READY, CAN_MAILBOX_TRANSFER_OK, can_mb_conf_t::uc_id_ver, can_mb_conf_t::uc_length, can_mb_conf_t::ul_datah, can_mb_conf_t::ul_datal, can_mb_conf_t::ul_id, can_mb_conf_t::ul_mb_idx, and can_mb_conf_t::ul_status.

Referenced by run_can_test(), test_1(), test_2(), test_3(), and test_4().

void can_reset_all_mailbox ( Can *  p_can)

Reset the eight mailboxes.

Parameters
p_canPointer to a CAN peripheral instance.

References can_mailbox_init(), CAN_MB_DISABLE_MODE, can_mb_conf_t::uc_obj_type, and can_mb_conf_t::ul_mb_idx.

Referenced by can_init(), run_can_test(), test_1(), test_2(), test_3(), and test_4().

void can_reset_internal_timer ( Can *  p_can)

Reset the internal free-running 16-bit timer.

Parameters
p_canPointer to a CAN peripheral instance.
Note
If the internal timer counter is frozen, this function automatically re-enables it.
void can_set_rx_sync_stage ( Can *  p_can,
uint32_t  ul_stage 
)

Configure CAN Controller reception synchronization stage.

Parameters
p_canPointer to a CAN peripheral instance.
ul_stageThe reception stage to be configured.
Note
This is just for debug purpose only.
void can_set_timestamp_capture_point ( Can *  p_can,
uint32_t  ul_flag 
)

Configure the timestamp capture point, at the start or the end of frame.

Parameters
p_canPointer to a CAN peripheral instance.
ul_flag0: Timestamp is captured at each start of frame; 1: Timestamp is captured at each end of frame.