Microchip® Advanced Software Framework

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CAN software stack

CAN software stack for 32-bit AVR that supports initializing the CAN bus and sending/receiving data.

Modules

 

Data Structures

struct  can_mob_t
 

Macros

#define CAN_CMD_ACCEPTED   0x00
 This constant is used as return value for "can_cmd" function. More...
 
#define CAN_CMD_REFUSED   0xFF
 This constant is used as return value for "can_cmd" function. More...
 
#define CAN_DATA_FRAME   0
 This constant is used for MOB Initialization request. More...
 
#define CAN_MOB_NOT_ALLOCATED   0xFF
 This constant is used for MOB Allocation status. More...
 
#define CAN_REMOTE_FRAME   1
 This constant is used for MOB Initialization request. More...
 
#define CAN_STATUS_BUSOFF   0x04
 This constant is used as return value for "can_get_status" function. More...
 
#define CAN_STATUS_COMPLETED   0x00
 This constant is used as return value for "can_get_status" function. More...
 
#define CAN_STATUS_ERROR   0x02
 This constant is used as return value for "can_get_status" function. More...
 
#define CAN_STATUS_NOT_COMPLETED   0x01
 This constant is used as return value for "can_get_status" function. More...
 
#define CAN_STATUS_WAKEUP   0x03
 This constant is used as return value for "can_get_status" function. More...
 

Functions

void can_clear_status (U8 ch, U8 mob)
 Clear All Status on CAN Channel for a selected MOB. More...
 
U8 can_enable_interrupt (U8 ch)
 Enable interrupt on CAN Channel. More...
 
Union64 can_get_mob_data (U8 ch, U8 handle)
 Get Mob data from a selected MOB. More...
 
U8 can_get_mob_dlc (U8 ch, U8 handle)
 Get Mob dlc from a selected MOB. More...
 
U32 can_get_mob_id (U8 ch, U8 handle)
 Get Mob ID from a selected MOB. More...
 
U8 can_init (U8 ch, U32 can_msg_ram_add, U8 operating_mode, void(*can_msg_callback)(U8, U8))
 Initialize CAN channel. More...
 
U8 can_mob_alloc (U8 ch)
 Allocate one MOB in a specific CAN Channel. More...
 
U8 can_mob_free (U8 ch, U8 handle)
 Free one specific MOB in a specific CAN Channel. More...
 
U8 can_mob_get_status (U8 ch, U8 handle)
 Get Mob status from a selected MOB. More...
 
U8 can_rx (U8 ch, U8 handle, U8 req_type, const can_msg_t *can_msg)
 Start Reception. More...
 
U8 can_tx (U8 ch, U8 handle, U8 dlc, U8 req_type, const can_msg_t *can_msg)
 Start Transmission. More...
 

#define CAN_CMD_ACCEPTED   0x00

This constant is used as return value for "can_cmd" function.

Referenced by can_enable_interrupt(), can_init(), can_mob_free(), can_rx(), and can_tx().

#define CAN_CMD_REFUSED   0xFF
#define CAN_DATA_FRAME   0

This constant is used for MOB Initialization request.

#define CAN_MOB_NOT_ALLOCATED   0xFF

This constant is used for MOB Allocation status.

#define CAN_REMOTE_FRAME   1

This constant is used for MOB Initialization request.

Referenced by can_rx(), and can_tx().

#define CAN_STATUS_BUSOFF   0x04

This constant is used as return value for "can_get_status" function.

Referenced by can0_int_busoff_handler(), can1_int_busoff_handler(), and main().

#define CAN_STATUS_COMPLETED   0x00

This constant is used as return value for "can_get_status" function.

Referenced by can0_int_rx_handler(), can0_int_tx_handler(), can1_int_rx_handler(), can1_int_tx_handler(), can_mob_get_status(), and main().

#define CAN_STATUS_ERROR   0x02

This constant is used as return value for "can_get_status" function.

Referenced by can0_int_cerr_handler(), can1_int_cerr_handler(), can_mob_get_status(), and main().

#define CAN_STATUS_NOT_COMPLETED   0x01

This constant is used as return value for "can_get_status" function.

Referenced by can_mob_get_status().

#define CAN_STATUS_WAKEUP   0x03

This constant is used as return value for "can_get_status" function.

Referenced by can0_int_wakeup_handler(), and can1_int_wakeup_handler().

void can_clear_status ( U8  ch,
U8  mob 
)

Clear All Status on CAN Channel for a selected MOB.

Parameters
chCAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
mobCAN MOB number

References CANIF_mob_clear_status.

Union64 can_get_mob_data ( U8  ch,
U8  handle 
)

Get Mob data from a selected MOB.

Parameters
chCAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
handleCAN MOB number
Returns
Union64 See compiler.h file for type return definition

References CANIF_mob_get_ptr_data, and data.

Referenced by can_out_callback_channel0().

U8 can_get_mob_dlc ( U8  ch,
U8  handle 
)

Get Mob dlc from a selected MOB.

Parameters
chCAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
handleCAN MOB number
Returns
U8 Return the DLC

References CANIF_mob_get_dlc.

Referenced by can_out_callback_channel0().

U32 can_get_mob_id ( U8  ch,
U8  handle 
)

Get Mob ID from a selected MOB.

Parameters
chCAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
handleCAN MOB number
Returns
U32 Return the ID

References CANIF_get_ext_id.

Referenced by can_out_callback_channel0().

U8 can_init ( U8  ch,
U32  can_msg_ram_add,
U8  operating_mode,
void(*)(U8, U8 can_msg_callback 
)

Initialize CAN channel.

Parameters
chCAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
can_msg_ram_addAddress of the location of MOB Ram Buffer
operating_modeSelection between CAN_CHANNEL_MODE_NORMAL or CAN_CHANNEL_MODE_LISTENING or CAN_CHANNEL_MODE_LOOPBACK
can_msg_callbackCallback for hardware interrupt
Returns
U8 CAN_CMD_REFUSED or CAN_CMD_ACCEPTED
U8 can_mob_alloc ( U8  ch)

Allocate one MOB in a specific CAN Channel.

Parameters
chCAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
Returns
U8 CAN_CMD_REFUSED or the number of the MOB selected

References CAN_CMD_REFUSED, can_mob_alloc_vector0, can_mob_alloc_vector1, CANIF_clr_mob, i, and NB_MOB_CHANNEL.

Referenced by can_example_prepare_data(), can_example_prepare_data_to_receive(), can_example_prepare_data_to_send(), and main().

U8 can_mob_free ( U8  ch,
U8  handle 
)

Free one specific MOB in a specific CAN Channel.

Parameters
chCAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
handleCAN MOB number
Returns
U8 CAN_CMD_REFUSED or CAN_CMD_ACCEPTED

References CAN_CMD_ACCEPTED, CAN_CMD_REFUSED, can_mob_alloc_vector0, can_mob_alloc_vector1, and NB_MOB_CHANNEL.

Referenced by can_out_callback_channel0(), and can_out_callback_channel1().

U8 can_mob_get_status ( U8  ch,
U8  handle 
)

Get Mob status from a selected MOB.

Parameters
chCAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
handleCAN MOB number
Returns
U8 CAN_CMD_REFUSED or CAN_STATUS_ERROR or CAN_STATUS_COMPLETED or CAN_STATUS_NOT_COMPLETED

References CAN_CMD_REFUSED, CAN_STATUS_COMPLETED, CAN_STATUS_ERROR, CAN_STATUS_NOT_COMPLETED, CANIF_get_interrupt_error_status, CANIF_mob_get_status, MOB_RX_COMPLETED, MOB_RX_COMPLETED_DLCW, MOB_TX_COMPLETED, NB_MOB_CHANNEL, and status.

U8 can_rx ( U8  ch,
U8  handle,
U8  req_type,
const can_msg_t can_msg 
)

Start Reception.

Parameters
chCAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
handleCAN MOB number
req_typeCAN_DATA_FRAME or CAN_REMOTE_FRAME
can_msgCAN Message
Returns
U8 CAN_CMD_REFUSED or CAN_CMD_ACCEPTED

References CAN_CMD_ACCEPTED, CAN_CMD_REFUSED, CAN_REMOTE_FRAME, CANIF_config_rx, CANIF_mob_enable, CANIF_mob_enable_interrupt, CANIF_mob_set_automode, CANIF_set_data, CANIF_set_ext_id, CANIF_set_ext_idmask, CANIF_set_rtr, CANIF_set_rtrmask, CANIF_set_std_id, CANIF_set_std_idmask, data, can_msg_t::id, can_msg_t::id_mask, can_msg_t::ide_bit, and NB_MOB_CHANNEL.

Referenced by can_example_prepare_data(), can_example_prepare_data_to_receive(), and main().

U8 can_tx ( U8  ch,
U8  handle,
U8  dlc,
U8  req_type,
const can_msg_t can_msg 
)

Start Transmission.

Parameters
chCAN channel selected 0 (CAN Channel 0) 1 (CAN Channel 1)
handleCAN MOB number
dlcDatalength
req_typeCAN_DATA_FRAME or CAN_REMOTE_FRAME
can_msgCAN Message
Returns
U8 CAN_CMD_REFUSED or CAN_CMD_ACCEPTED

References CAN_CMD_ACCEPTED, CAN_CMD_REFUSED, CAN_REMOTE_FRAME, CANIF_config_tx, CANIF_mob_clr_dlc, CANIF_mob_enable, CANIF_mob_enable_interrupt, CANIF_mob_set_automode, CANIF_mob_set_dlc, CANIF_set_data, CANIF_set_ext_id, CANIF_set_ext_idmask, CANIF_set_rtr, CANIF_set_rtrmask, CANIF_set_std_id, CANIF_set_std_idmask, data, can_msg_t::id, can_msg_t::id_mask, can_msg_t::ide_bit, and NB_MOB_CHANNEL.

Referenced by can_example_prepare_data(), and can_example_prepare_data_to_send().