PebbleOS v4.47.0-1075-g013613c8a
Loading...
Searching...
No Matches

CAN controller class, for CAN and CAN FD. More...

Data Structures

struct  pbl_can_frame
 A CAN or CAN FD frame. More...
 
struct  pbl_can_config
 Bus configuration. More...
 
struct  pbl_can_filter
 Acceptance filter: frames whose identifier matches id in the bits of mask. More...
 
struct  pbl_can_timing
 Bit timing of one phase, in time quanta. More...
 
struct  pbl_can_timing_limits
 Bit timing limits of one phase. More...
 
struct  pbl_can_err_cnt
 Error counters. More...
 
struct  pbl_can_stats
 Counts of errors and bus off events, since the controller was initialized. More...
 
struct  pbl_can_ops
 Controller driver operations. More...
 
struct  pbl_can
 A CAN controller. More...
 
union  pbl_can_frame.__unnamed6__
 Data. More...
 

Macros

#define PBL_CAN_STD_ID_MASK   0x7ffU
 Largest standard (11-bit) identifier.
 
#define PBL_CAN_EXT_ID_MASK   0x1fffffffU
 Largest extended (29-bit) identifier.
 
#define PBL_CAN_MAX_LEN   8U
 Most data bytes of a CAN frame.
 
#define PBL_CAN_FD_MAX_LEN   64U
 Most data bytes of a CAN FD frame.
 
#define PBL_CAN_STATE_DEFINE(sym, _tx_slots)
 Define the class state of controller sym, for the PBL_CAN_*_DEFINE() macro of a driver.
 
#define PBL_CAN_INIT(sym, _name, _parent, _ops, _limits, _data_limits, _modes, _num_filters)
 Initializer for the struct pbl_can of controller sym.
 

Typedefs

typedef void(* pbl_can_rx_callback_t) (const struct pbl_can *can, const struct pbl_can_frame *frame, void *arg)
 Receive callback, called from the controller's interrupt for each frame accepted.
 
typedef void(* pbl_can_tx_callback_t) (const struct pbl_can *can, int status, void *arg)
 Transmit callback, called from the controller's interrupt once a frame is done.
 
typedef void(* pbl_can_state_callback_t) (const struct pbl_can *can, enum pbl_can_bus_state state, struct pbl_can_err_cnt cnt, void *arg)
 State callback, called from the controller's interrupt when its state changes.
 

Enumerations

enum  pbl_can_bus_state {
  PBL_CAN_STATE_STOPPED , PBL_CAN_STATE_ERROR_ACTIVE , PBL_CAN_STATE_ERROR_WARNING , PBL_CAN_STATE_ERROR_PASSIVE ,
  PBL_CAN_STATE_BUS_OFF
}
 Fault confinement state. More...
 
enum  pbl_can_error {
  PBL_CAN_ERROR_BIT , PBL_CAN_ERROR_STUFF , PBL_CAN_ERROR_FORM , PBL_CAN_ERROR_ACK ,
  PBL_CAN_ERROR_CRC , PBL_CAN_ERROR_ARBITRATION_LOST , PBL_CAN_ERROR_RX_OVERRUN , PBL_CAN_ERROR_COUNT
}
 Kinds of errors the controller counts. More...
 

Functions

int pbl_can_dev_init (const struct pbl_device *dev)
 Device init of every controller: calls the driver's init.
 
void pbl_can_receive (const struct pbl_can *can, const struct pbl_can_frame *frame)
 Hand a received frame to the receive callback.
 
void pbl_can_tx_done (const struct pbl_can *can, pbl_can_tx_callback_t cb, void *arg, int status)
 Complete a frame given to the driver's send().
 
void pbl_can_report_state (const struct pbl_can *can, enum pbl_can_bus_state state, struct pbl_can_err_cnt cnt)
 Report a state change.
 
void pbl_can_report_error (const struct pbl_can *can, enum pbl_can_error error)
 Count an error.
 
int pbl_can_calc_timing (const struct pbl_can_timing_limits *limits, uint32_t clock, uint32_t bitrate, uint16_t sample_point, struct pbl_can_timing *timing)
 Compute the bit timing of one phase.
 
uint8_t pbl_can_dlc_to_len (uint8_t dlc)
 Get the bytes of a frame of a data length code.
 
uint8_t pbl_can_len_to_dlc (uint8_t len)
 Get the data length code of a frame of len bytes.
 
int pbl_can_configure (const struct pbl_can *can, const struct pbl_can_config *cfg)
 Set the bit rates and mode, while stopped.
 
int pbl_can_config_get (const struct pbl_can *can, struct pbl_can_config *cfg)
 Get the configuration.
 
int pbl_can_add_filter (const struct pbl_can *can, const struct pbl_can_filter *filter)
 Add an acceptance filter, while stopped.
 
int pbl_can_remove_filter (const struct pbl_can *can, int idx)
 Remove an acceptance filter, while stopped.
 
void pbl_can_set_rx_callback (const struct pbl_can *can, pbl_can_rx_callback_t cb, void *arg)
 Set the receive callback.
 
void pbl_can_set_state_callback (const struct pbl_can *can, pbl_can_state_callback_t cb, void *arg)
 Set the state callback.
 
int pbl_can_start (const struct pbl_can *can)
 Join the bus, with the configuration and filters given while stopped.
 
int pbl_can_stop (const struct pbl_can *can)
 Leave the bus.
 
int pbl_can_send (const struct pbl_can *can, const struct pbl_can_frame *frame, pbl_timeout_t timeout, pbl_can_tx_callback_t cb, void *arg)
 Send a frame.
 
int pbl_can_get_state (const struct pbl_can *can, enum pbl_can_bus_state *state, struct pbl_can_err_cnt *cnt)
 Get the state and error counters.
 
int pbl_can_recover (const struct pbl_can *can)
 Start the recovery from bus off, with PBL_CAN_MODE_MANUAL_RECOVERY.
 
int pbl_can_get_stats (const struct pbl_can *can, struct pbl_can_stats *stats)
 Get the error counts.
 

Variables

const struct pbl_device_class pbl_can_class
 Class of the CAN controllers.
 
const struct pbl_can *const CAN_BUS
 The controller of the board's CAN bus connector.
 

Frame flags

#define PBL_CAN_FRAME_IDE   PBL_BIT(0)
 Extended (29-bit) identifier.
 
#define PBL_CAN_FRAME_RTR   PBL_BIT(1)
 Remote frame, CAN only.
 
#define PBL_CAN_FRAME_FDF   PBL_BIT(2)
 CAN FD frame.
 
#define PBL_CAN_FRAME_BRS   PBL_BIT(3)
 CAN FD frame whose data phase goes at the data bit rate.
 
#define PBL_CAN_FRAME_ESI   PBL_BIT(4)
 CAN FD frame from an error passive node, on reception.
 

Modes

#define PBL_CAN_MODE_LOOPBACK   PBL_BIT(0)
 Receive the frames sent, without driving the bus.
 
#define PBL_CAN_MODE_LISTEN_ONLY   PBL_BIT(1)
 Receive only, without acknowledging frames or signalling errors; sending is refused.
 
#define PBL_CAN_MODE_FD   PBL_BIT(2)
 Send and receive CAN FD frames, as ISO 11898-1:2015 specifies them.
 
#define PBL_CAN_MODE_FD_NON_ISO   PBL_BIT(3)
 With PBL_CAN_MODE_FD, CAN FD frames as first specified, without the stuff count.
 
#define PBL_CAN_MODE_ONE_SHOT   PBL_BIT(4)
 Send each frame once, without retransmitting it after an error or a lost arbitration.
 
#define PBL_CAN_MODE_MANUAL_RECOVERY   PBL_BIT(5)
 Stay bus off until pbl_can_recover(), instead of recovering on its own.
 

Detailed Description

CAN controller class, for CAN and CAN FD.

A CAN controller is a struct pbl_can device. It starts stopped: it is given its bit rates and mode with pbl_can_configure(), and its acceptance filters with pbl_can_add_filter(), while stopped, then joins the bus with pbl_can_start(). Received frames are handed to a callback from the controller's interrupt, and frames are sent with pbl_can_send(), either waiting for the transmission or with a callback for its outcome:

static void prv_rx(const struct pbl_can *can, const struct pbl_can_frame *frame, void *arg) {
// interrupt context
}
const struct pbl_can_config cfg = {.bitrate = 500000U};
const struct pbl_can_frame frame = {.id = 0x123, .len = 2, .data = {0xbe, 0xef}};
ret = pbl_can_configure(can, &cfg);
pbl_can_set_rx_callback(can, prv_rx, nullptr);
ret = pbl_can_start(can);
ret = pbl_can_send(can, &frame, PBL_MSEC(100), nullptr, nullptr);
uint32_t bitrate
Nominal bit rate, in bits per second.
Definition can.h:114
uint32_t id
Identifier, standard or extended as PBL_CAN_FRAME_IDE says.
Definition can.h:99
Bus configuration.
Definition can.h:112
A CAN or CAN FD frame.
Definition can.h:97
A CAN controller.
Definition can.h:318
void pbl_can_set_rx_callback(const struct pbl_can *can, pbl_can_rx_callback_t cb, void *arg)
Set the receive callback.
int pbl_can_configure(const struct pbl_can *can, const struct pbl_can_config *cfg)
Set the bit rates and mode, while stopped.
int pbl_can_start(const struct pbl_can *can)
Join the bus, with the configuration and filters given while stopped.
int pbl_can_send(const struct pbl_can *can, const struct pbl_can_frame *frame, pbl_timeout_t timeout, pbl_can_tx_callback_t cb, void *arg)
Send a frame.
#define PBL_MSEC(ms)
Timeout in milliseconds, rounded down to whole ticks.
Definition types.h:63

The class computes the bit timing from the bit rates, sample points and the controller's clock, within the limits the driver gives, and only accepts bit rates the clock divides exactly. Without filters, the controller accepts every frame.

Calls return 0 or a negative errno: -ENODEV if the controller is not ready, -ENOTSUP for a mode it does not support, -EBUSY for a call that needs it stopped and -ENETDOWN for one that needs it started.


Data Structure Documentation

◆ pbl_can_frame

struct pbl_can_frame

A CAN or CAN FD frame.

Data Fields
union pbl_can_frame.__unnamed6__ __unnamed__ Data.
uint8_t flags Frame flags, PBL_CAN_FRAME_*.
uint32_t id Identifier, standard or extended as PBL_CAN_FRAME_IDE says.
uint8_t len Data bytes: up to 8, or for CAN FD 12, 16, 20, 24, 32, 48 or 64.

◆ pbl_can_config

struct pbl_can_config

Bus configuration.

Data Fields
uint32_t bitrate Nominal bit rate, in bits per second.
uint32_t data_bitrate Data phase bit rate of CAN FD frames, in bits per second, with PBL_CAN_MODE_FD.
uint16_t data_sample_point Data phase sample point, in tenths of a percent, or 0 for the class default.
uint32_t mode Mode, PBL_CAN_MODE_* flags.
uint16_t sample_point Nominal sample point, in tenths of a percent, or 0 for the class default.

◆ pbl_can_filter

struct pbl_can_filter

Acceptance filter: frames whose identifier matches id in the bits of mask.

Data Fields
uint8_t flags Frame flags: PBL_CAN_FRAME_IDE for extended identifiers, or none for standard ones.
uint32_t id Identifier.
uint32_t mask Bits of the identifier that have to match.

◆ pbl_can_timing

struct pbl_can_timing

Bit timing of one phase, in time quanta.

Data Fields
uint16_t prescaler Clock periods per time quantum.
uint16_t sjw Synchronization jump width.
uint16_t tseg1 Propagation and phase segment 1.
uint16_t tseg2 Phase segment 2.

◆ pbl_can_timing_limits

struct pbl_can_timing_limits

Bit timing limits of one phase.

Data Fields
uint16_t prescaler_max Largest prescaler.
uint16_t prescaler_min Smallest prescaler.
uint16_t sjw_max Largest synchronization jump width.
uint16_t tseg1_max Longest propagation and phase segment 1.
uint16_t tseg1_min Shortest propagation and phase segment 1.
uint16_t tseg2_max Longest phase segment 2.
uint16_t tseg2_min Shortest phase segment 2.

◆ pbl_can_err_cnt

struct pbl_can_err_cnt

Error counters.

Data Fields
uint8_t rx Receive error counter.
uint8_t tx Transmit error counter.

◆ pbl_can_stats

struct pbl_can_stats

Counts of errors and bus off events, since the controller was initialized.

Data Fields
uint32_t bus_off Times the controller went bus off.
uint32_t errors[PBL_CAN_ERROR_COUNT] Errors, by pbl_can_error.

◆ pbl_can

struct pbl_can

A CAN controller.

Data Fields
const struct pbl_can_timing_limits * data_limits Data phase bit timing limits, or NULL without CAN FD.
struct pbl_device dev Device.
const struct pbl_can_timing_limits * limits Nominal bit timing limits.
uint32_t modes Supported modes, PBL_CAN_MODE_* flags.
uint8_t num_filters Acceptance filters.
const struct pbl_can_ops * ops Driver operations.
struct pbl_can_state * state Runtime state.

◆ pbl_can_frame.__unnamed6__

union pbl_can_frame.__unnamed6__

Data.

Data Fields
uint8_t data[PBL_CAN_FD_MAX_LEN]
uint32_t data32[PBL_CAN_FD_MAX_LEN/4U]

Macro Definition Documentation

◆ PBL_CAN_EXT_ID_MASK

#define PBL_CAN_EXT_ID_MASK   0x1fffffffU

Largest extended (29-bit) identifier.

◆ PBL_CAN_FD_MAX_LEN

#define PBL_CAN_FD_MAX_LEN   64U

Most data bytes of a CAN FD frame.

◆ PBL_CAN_FRAME_BRS

#define PBL_CAN_FRAME_BRS   PBL_BIT(3)

CAN FD frame whose data phase goes at the data bit rate.

◆ PBL_CAN_FRAME_ESI

#define PBL_CAN_FRAME_ESI   PBL_BIT(4)

CAN FD frame from an error passive node, on reception.

◆ PBL_CAN_FRAME_FDF

#define PBL_CAN_FRAME_FDF   PBL_BIT(2)

CAN FD frame.

◆ PBL_CAN_FRAME_IDE

#define PBL_CAN_FRAME_IDE   PBL_BIT(0)

Extended (29-bit) identifier.

◆ PBL_CAN_FRAME_RTR

#define PBL_CAN_FRAME_RTR   PBL_BIT(1)

Remote frame, CAN only.

◆ PBL_CAN_INIT

#define PBL_CAN_INIT (   sym,
  _name,
  _parent,
  _ops,
  _limits,
  _data_limits,
  _modes,
  _num_filters 
)
Value:
{ \
.dev = PBL_DEVICE_INIT_CLASS(sym, _name, pbl_can_dev_init, _parent, &pbl_can_class), \
.ops = (_ops), \
.state = &sym##_can_state, \
.limits = (_limits), \
.data_limits = (_data_limits), \
.modes = (_modes), \
.num_filters = (_num_filters), \
}
int pbl_can_dev_init(const struct pbl_device *dev)
Device init of every controller: calls the driver's init.
const struct pbl_device_class pbl_can_class
Class of the CAN controllers.
#define PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, _cls)
Initializer for the struct pbl_device of device instance sym, in class _cls.
Definition device.h:153

Initializer for the struct pbl_can of controller sym.

Parameters
symSymbol of the controller instance, with its state defined by PBL_CAN_STATE_DEFINE().
_nameName.
_parentParent device, or NULL.
_opsDriver operations.
_limitsNominal bit timing limits.
_data_limitsData phase bit timing limits, or NULL without CAN FD.
_modesSupported modes.
_num_filtersAcceptance filters.

◆ PBL_CAN_MAX_LEN

#define PBL_CAN_MAX_LEN   8U

Most data bytes of a CAN frame.

◆ PBL_CAN_MODE_FD

#define PBL_CAN_MODE_FD   PBL_BIT(2)

Send and receive CAN FD frames, as ISO 11898-1:2015 specifies them.

◆ PBL_CAN_MODE_FD_NON_ISO

#define PBL_CAN_MODE_FD_NON_ISO   PBL_BIT(3)

With PBL_CAN_MODE_FD, CAN FD frames as first specified, without the stuff count.

◆ PBL_CAN_MODE_LISTEN_ONLY

#define PBL_CAN_MODE_LISTEN_ONLY   PBL_BIT(1)

Receive only, without acknowledging frames or signalling errors; sending is refused.

◆ PBL_CAN_MODE_LOOPBACK

#define PBL_CAN_MODE_LOOPBACK   PBL_BIT(0)

Receive the frames sent, without driving the bus.

◆ PBL_CAN_MODE_MANUAL_RECOVERY

#define PBL_CAN_MODE_MANUAL_RECOVERY   PBL_BIT(5)

Stay bus off until pbl_can_recover(), instead of recovering on its own.

◆ PBL_CAN_MODE_ONE_SHOT

#define PBL_CAN_MODE_ONE_SHOT   PBL_BIT(4)

Send each frame once, without retransmitting it after an error or a lost arbitration.

◆ PBL_CAN_STATE_DEFINE

#define PBL_CAN_STATE_DEFINE (   sym,
  _tx_slots 
)
Value:
static struct pbl_can_state sym##_can_state = { \
.tx_slots = PBL_SEM_INITIALIZER((_tx_slots), (_tx_slots)), \
}
#define PBL_DEVICE_STATE_DEFINE(sym)
Define the runtime state of device instance sym.
Definition device.h:132
#define PBL_MUTEX_INITIALIZER
Static initializer for an unlocked mutex.
Definition mutex.h:50
#define PBL_SEM_INITIALIZER(init, lim)
Static initializer for a semaphore.
Definition sem.h:56

Define the class state of controller sym, for the PBL_CAN_*_DEFINE() macro of a driver.

Parameters
symSymbol of the controller instance.
_tx_slotsFrames the controller can have in flight.

◆ PBL_CAN_STD_ID_MASK

#define PBL_CAN_STD_ID_MASK   0x7ffU

Largest standard (11-bit) identifier.

Typedef Documentation

◆ pbl_can_rx_callback_t

typedef void(* pbl_can_rx_callback_t) (const struct pbl_can *can, const struct pbl_can_frame *frame, void *arg)

Receive callback, called from the controller's interrupt for each frame accepted.

Parameters
canController.
frameFrame, valid during the call.
argCallback argument.

◆ pbl_can_state_callback_t

typedef void(* pbl_can_state_callback_t) (const struct pbl_can *can, enum pbl_can_bus_state state, struct pbl_can_err_cnt cnt, void *arg)

State callback, called from the controller's interrupt when its state changes.

Parameters
canController.
stateNew state.
cntError counters.
argCallback argument.

◆ pbl_can_tx_callback_t

typedef void(* pbl_can_tx_callback_t) (const struct pbl_can *can, int status, void *arg)

Transmit callback, called from the controller's interrupt once a frame is done.

Parameters
canController.
status0 if the frame was sent, -ECANCELED if it was aborted, -ENETDOWN if the controller stopped or went bus off first, -EIO if it failed with PBL_CAN_MODE_ONE_SHOT.
argCallback argument.

Enumeration Type Documentation

◆ pbl_can_bus_state

Fault confinement state.

Enumerator
PBL_CAN_STATE_STOPPED 

Stopped, off the bus.

PBL_CAN_STATE_ERROR_ACTIVE 

Error active: both error counters below 96.

PBL_CAN_STATE_ERROR_WARNING 

Error warning: an error counter at 96 or more.

PBL_CAN_STATE_ERROR_PASSIVE 

Error passive: an error counter above 127.

PBL_CAN_STATE_BUS_OFF 

Bus off: the transmit error counter went past 255.

◆ pbl_can_error

Kinds of errors the controller counts.

Enumerator
PBL_CAN_ERROR_BIT 

Bit error: the node sent a bit and read back another.

PBL_CAN_ERROR_STUFF 

Stuff error: six equal bits in a row.

PBL_CAN_ERROR_FORM 

Form error: a fixed-form field with a wrong bit.

PBL_CAN_ERROR_ACK 

Acknowledgment error: no node acknowledged a frame sent.

PBL_CAN_ERROR_CRC 

CRC error.

PBL_CAN_ERROR_ARBITRATION_LOST 

Arbitration lost to another node, not an error on the bus.

PBL_CAN_ERROR_RX_OVERRUN 

Frames received with no room left for them, dropped.

PBL_CAN_ERROR_COUNT 

Number of kinds of errors.

Function Documentation

◆ pbl_can_add_filter()

int pbl_can_add_filter ( const struct pbl_can *  can,
const struct pbl_can_filter *  filter 
)

Add an acceptance filter, while stopped.

Once a filter is added, the controller only accepts the frames some filter matches.

Parameters
canController.
filterFilter.
Returns
Filter index, to remove it with, -ENOSPC if every filter is in use, or another negative errno.

◆ pbl_can_calc_timing()

int pbl_can_calc_timing ( const struct pbl_can_timing_limits *  limits,
uint32_t  clock,
uint32_t  bitrate,
uint16_t  sample_point,
struct pbl_can_timing *  timing 
)

Compute the bit timing of one phase.

Picks the smallest prescaler that gives the bit rate exactly and the sample point closest to the one asked, with the synchronization jump width as long as both phase segments allow.

Parameters
limitsBit timing limits.
clockClock the time quanta are counted in, in Hz.
bitrateBit rate, in bits per second.
sample_pointSample point, in tenths of a percent.
[out]timingBit timing.
Returns
0, or -EINVAL if no timing within limits gives the bit rate.

◆ pbl_can_config_get()

int pbl_can_config_get ( const struct pbl_can *  can,
struct pbl_can_config *  cfg 
)

Get the configuration.

Parameters
canController.
[out]cfgConfiguration.
Returns
0, -EINVAL if the controller was never configured, or another negative errno.

◆ pbl_can_configure()

int pbl_can_configure ( const struct pbl_can *  can,
const struct pbl_can_config *  cfg 
)

Set the bit rates and mode, while stopped.

Parameters
canController.
cfgConfiguration.
Returns
0, -EINVAL if the controller's clock cannot give a bit rate, or another negative errno.

◆ pbl_can_dev_init()

int pbl_can_dev_init ( const struct pbl_device *  dev)

Device init of every controller: calls the driver's init.

Parameters
devController device.
Returns
0 or a negative errno.

◆ pbl_can_dlc_to_len()

uint8_t pbl_can_dlc_to_len ( uint8_t  dlc)

Get the bytes of a frame of a data length code.

Parameters
dlcData length code, 0 to 15.
Returns
Data bytes, as a CAN FD frame has them.

◆ pbl_can_get_state()

int pbl_can_get_state ( const struct pbl_can *  can,
enum pbl_can_bus_state *  state,
struct pbl_can_err_cnt *  cnt 
)

Get the state and error counters.

Parameters
canController.
[out]stateState.
[out]cntError counters, or NULL.
Returns
0 or a negative errno.

◆ pbl_can_get_stats()

int pbl_can_get_stats ( const struct pbl_can *  can,
struct pbl_can_stats *  stats 
)

Get the error counts.

Parameters
canController.
[out]statsError counts.
Returns
0 or a negative errno.

◆ pbl_can_len_to_dlc()

uint8_t pbl_can_len_to_dlc ( uint8_t  len)

Get the data length code of a frame of len bytes.

Parameters
lenData bytes, one a CAN FD frame can have.
Returns
Data length code.

◆ pbl_can_receive()

void pbl_can_receive ( const struct pbl_can *  can,
const struct pbl_can_frame *  frame 
)

Hand a received frame to the receive callback.

Called by the controller driver from its interrupt.

Parameters
canController.
frameFrame.

◆ pbl_can_recover()

int pbl_can_recover ( const struct pbl_can *  can)

Start the recovery from bus off, with PBL_CAN_MODE_MANUAL_RECOVERY.

The controller rejoins the bus once it has seen 128 sequences of 11 recessive bits, and the state callback reports it. Does nothing if the controller is not bus off.

Parameters
canController.
Returns
0, -ENOTSUP without PBL_CAN_MODE_MANUAL_RECOVERY, or another negative errno.

◆ pbl_can_remove_filter()

int pbl_can_remove_filter ( const struct pbl_can *  can,
int  idx 
)

Remove an acceptance filter, while stopped.

Parameters
canController.
idxFilter index, from pbl_can_add_filter().
Returns
0 or a negative errno.

◆ pbl_can_report_error()

void pbl_can_report_error ( const struct pbl_can *  can,
enum pbl_can_error  error 
)

Count an error.

Called by the controller driver from its interrupt.

Parameters
canController.
errorKind of error.

◆ pbl_can_report_state()

void pbl_can_report_state ( const struct pbl_can *  can,
enum pbl_can_bus_state  state,
struct pbl_can_err_cnt  cnt 
)

Report a state change.

Called by the controller driver from its interrupt.

Parameters
canController.
stateNew state.
cntError counters.

◆ pbl_can_send()

int pbl_can_send ( const struct pbl_can *  can,
const struct pbl_can_frame *  frame,
pbl_timeout_t  timeout,
pbl_can_tx_callback_t  cb,
void *  arg 
)

Send a frame.

Waits up to timeout for room in the controller. With a callback, returns once the frame is queued, and the callback gets its outcome. Without one, also waits up to timeout for the frame to go, aborting it past then, and returns its outcome.

Parameters
canController.
frameFrame.
timeoutHow long to wait, PBL_NO_WAIT from interrupt context.
cbTransmit callback, or NULL to wait for the frame to go. Required from interrupt context.
argCallback argument.
Returns
0, -EPERM with PBL_CAN_MODE_LISTEN_ONLY, -EINVAL for a frame the configuration does not allow, -EAGAIN if the controller had no room in time, -ETIMEDOUT if the frame did not go in time, or the outcome of the frame as given to pbl_can_tx_callback_t.

◆ pbl_can_set_rx_callback()

void pbl_can_set_rx_callback ( const struct pbl_can *  can,
pbl_can_rx_callback_t  cb,
void *  arg 
)

Set the receive callback.

Parameters
canController.
cbReceive callback, or NULL to drop the frames received.
argCallback argument.

◆ pbl_can_set_state_callback()

void pbl_can_set_state_callback ( const struct pbl_can *  can,
pbl_can_state_callback_t  cb,
void *  arg 
)

Set the state callback.

Parameters
canController.
cbState callback, or NULL.
argCallback argument.

◆ pbl_can_start()

int pbl_can_start ( const struct pbl_can *  can)

Join the bus, with the configuration and filters given while stopped.

Parameters
canController.
Returns
0, -EINVAL if the controller was never configured, or another negative errno.

◆ pbl_can_stop()

int pbl_can_stop ( const struct pbl_can *  can)

Leave the bus.

The frames in flight complete with -ENETDOWN.

Parameters
canController.
Returns
0 or a negative errno.

◆ pbl_can_tx_done()

void pbl_can_tx_done ( const struct pbl_can *  can,
pbl_can_tx_callback_t  cb,
void *  arg,
int  status 
)

Complete a frame given to the driver's send().

Called by the controller driver from its interrupt, or from its stop().

Parameters
canController.
cbTransmit callback given to send().
argCallback argument given to send().
status0, -ECANCELED or -ENETDOWN, as for pbl_can_tx_callback_t.

Variable Documentation

◆ CAN_BUS

const struct pbl_can* const CAN_BUS
extern

The controller of the board's CAN bus connector.

◆ pbl_can_class

const struct pbl_device_class pbl_can_class
extern

Class of the CAN controllers.