PebbleOS v4.47.0-1362-gd278268fe
Loading...
Searching...
No Matches
CAN controller drivers

Interface for CAN controller drivers. More...

Data Structures

struct  pbl_can_ops
 Controller driver operations. More...
 
struct  pbl_can
 A CAN controller. More...
 

Macros

#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.
 

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.
 

Detailed Description

Interface for CAN controller drivers.

A driver embeds a struct pbl_can in its instance, sets it up with PBL_CAN_STATE_DEFINE() and PBL_CAN_INIT(), and implements the struct pbl_can_ops the class calls.


Data Structure Documentation

◆ 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.

Macro Definition Documentation

◆ 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.
#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_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.

Function Documentation

◆ 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_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_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_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.