Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
CAN Controller Driver Backend API

Data Structures

struct  can_driver_config
 Common CAN controller driver configuration. More...
struct  can_driver_data
 Common CAN controller driver data. More...
struct  can_driver_api
  Driver Operations CAN Controller driver operations More...

Macros

#define CAN_CALC_TDCO(_timing_data, _tdco_min, _tdco_max)
 Calculate Transmitter Delay Compensation Offset from data phase timing parameters.
#define CAN_DT_DRIVER_CONFIG_GET(node_id, _min_bitrate, _max_bitrate)
 Static initializer for can_driver_config struct.
#define CAN_DT_DRIVER_CONFIG_INST_GET(inst, _min_bitrate, _max_bitrate)
 Static initializer for can_driver_config struct from DT_DRV_COMPAT instance.

Typedefs

typedef int(* can_set_timing_t) (const struct device *dev, const struct can_timing *timing)
 Callback API upon setting CAN bus timing See can_set_timing() for argument description.
typedef int(* can_set_timing_data_t) (const struct device *dev, const struct can_timing *timing_data)
 Optional callback API upon setting CAN FD bus timing for the data phase.
typedef int(* can_get_capabilities_t) (const struct device *dev, can_mode_t *cap)
 Callback API upon getting CAN controller capabilities See can_get_capabilities() for argument description.
typedef int(* can_start_t) (const struct device *dev)
 Callback API upon starting CAN controller See can_start() for argument description.
typedef int(* can_stop_t) (const struct device *dev)
 Callback API upon stopping CAN controller See can_stop() for argument description.
typedef int(* can_set_mode_t) (const struct device *dev, can_mode_t mode)
 Callback API upon setting CAN controller mode See can_set_mode() for argument description.
typedef int(* can_send_t) (const struct device *dev, const struct can_frame *frame, k_timeout_t timeout, can_tx_callback_t callback, void *user_data)
 Callback API upon sending a CAN frame See can_send() for argument description.
typedef int(* can_add_rx_filter_t) (const struct device *dev, can_rx_callback_t callback, void *user_data, const struct can_filter *filter)
 Callback API upon adding an RX filter See can_add_rx_callback() for argument description.
typedef void(* can_remove_rx_filter_t) (const struct device *dev, int filter_id)
 Callback API upon removing an RX filter See can_remove_rx_filter() for argument description.
typedef int(* can_recover_t) (const struct device *dev, k_timeout_t timeout)
 Optional callback API upon manually recovering the CAN controller from bus-off state See can_recover() for argument description.
typedef int(* can_get_state_t) (const struct device *dev, enum can_state *state, struct can_bus_err_cnt *err_cnt)
 Callback API upon getting the CAN controller state See can_get_state() for argument description.
typedef void(* can_set_state_change_callback_t) (const struct device *dev, can_state_change_callback_t callback, void *user_data)
 Callback API upon setting a state change callback See can_set_state_change_callback() for argument description.
typedef int(* can_get_core_clock_t) (const struct device *dev, uint32_t *rate)
 Callback API upon getting the CAN core clock rate See can_get_core_clock() for argument description.
typedef int(* can_get_max_filters_t) (const struct device *dev, bool ide)
 Optional callback API upon getting the maximum number of concurrent CAN RX filters See can_get_max_filters() for argument description.

Detailed Description

This group contains the API type definitions, callback signatures, and other helpers required to implement a CAN Controller driver.

Macro Definition Documentation

◆ CAN_CALC_TDCO

#define CAN_CALC_TDCO ( _timing_data,
_tdco_min,
_tdco_max )

#include <zephyr/drivers/can.h>

Value:
CLAMP((1U + _timing_data->prop_seg + _timing_data->phase_seg1) * _timing_data->prescaler, \
_tdco_min, _tdco_max)
#define CLAMP(val, low, high)
Clamp a value to a given range.
Definition util.h:602

Calculate Transmitter Delay Compensation Offset from data phase timing parameters.

Calculates the TDC Offset in minimum time quanta (mtq) using the sample point and CAN core clock prescaler specified by a set of data phase timing parameters.

The result is clamped to the minimum/maximum supported TDC Offset values provided.

Parameters
_timing_dataPointer to data phase timing parameters.
_tdco_minMinimum supported TDC Offset value in mtq.
_tdco_maxMaximum supported TDC Offset value in mtq.
Returns
Calculated TDC Offset value in mtq.

◆ CAN_DT_DRIVER_CONFIG_GET

#define CAN_DT_DRIVER_CONFIG_GET ( node_id,
_min_bitrate,
_max_bitrate )

#include <zephyr/drivers/can.h>

Value:
{ \
.phy = DEVICE_DT_GET_OR_NULL(DT_PHANDLE(node_id, phys)), \
.min_bitrate = DT_CAN_TRANSCEIVER_MIN_BITRATE(node_id, _min_bitrate), \
.max_bitrate = DT_CAN_TRANSCEIVER_MAX_BITRATE(node_id, _max_bitrate), \
.bitrate = DT_PROP_OR(node_id, bitrate, \
DT_PROP_OR(node_id, bus_speed, CONFIG_CAN_DEFAULT_BITRATE)), \
.sample_point = DT_PROP_OR(node_id, sample_point, 0), \
IF_ENABLED(CONFIG_CAN_FD_MODE, \
(.bitrate_data = DT_PROP_OR(node_id, bitrate_data, \
DT_PROP_OR(node_id, bus_speed_data, CONFIG_CAN_DEFAULT_BITRATE_DATA)), \
.sample_point_data = DT_PROP_OR(node_id, sample_point_data, 0),)) \
}
#define DEVICE_DT_GET_OR_NULL(node_id)
Utility macro to obtain an optional reference to a device.
Definition device.h:382
#define DT_CAN_TRANSCEIVER_MIN_BITRATE(node_id, min)
Get the minimum transceiver bitrate for a CAN controller.
Definition can.h:75
#define DT_CAN_TRANSCEIVER_MAX_BITRATE(node_id, max)
Get the maximum transceiver bitrate for a CAN controller.
Definition can.h:118
#define DT_PROP_OR(node_id, prop, default_value)
Like DT_PROP(), but with a fallback to default_value.
Definition devicetree.h:971
#define DT_PHANDLE(node_id, prop)
Get a node identifier for a phandle property's value.
Definition devicetree.h:1847

Static initializer for can_driver_config struct.

Parameters
node_idDevicetree node identifier
_min_bitrateminimum bitrate supported by the CAN controller
_max_bitratemaximum bitrate supported by the CAN controller

◆ CAN_DT_DRIVER_CONFIG_INST_GET

#define CAN_DT_DRIVER_CONFIG_INST_GET ( inst,
_min_bitrate,
_max_bitrate )

#include <zephyr/drivers/can.h>

Value:
CAN_DT_DRIVER_CONFIG_GET(DT_DRV_INST(inst), _min_bitrate, _max_bitrate)
#define CAN_DT_DRIVER_CONFIG_GET(node_id, _min_bitrate, _max_bitrate)
Static initializer for can_driver_config struct.
Definition can.h:368
#define DT_DRV_INST(inst)
Node identifier for an instance of a DT_DRV_COMPAT compatible.
Definition devicetree.h:4085

Static initializer for can_driver_config struct from DT_DRV_COMPAT instance.

Parameters
instDT_DRV_COMPAT instance number
_min_bitrateminimum bitrate supported by the CAN controller
_max_bitratemaximum bitrate supported by the CAN controller
See also
CAN_DT_DRIVER_CONFIG_GET()

Typedef Documentation

◆ can_add_rx_filter_t

typedef int(* can_add_rx_filter_t) (const struct device *dev, can_rx_callback_t callback, void *user_data, const struct can_filter *filter)

#include <zephyr/drivers/can.h>

Callback API upon adding an RX filter See can_add_rx_callback() for argument description.

◆ can_get_capabilities_t

typedef int(* can_get_capabilities_t) (const struct device *dev, can_mode_t *cap)

#include <zephyr/drivers/can.h>

Callback API upon getting CAN controller capabilities See can_get_capabilities() for argument description.

◆ can_get_core_clock_t

typedef int(* can_get_core_clock_t) (const struct device *dev, uint32_t *rate)

#include <zephyr/drivers/can.h>

Callback API upon getting the CAN core clock rate See can_get_core_clock() for argument description.

◆ can_get_max_filters_t

typedef int(* can_get_max_filters_t) (const struct device *dev, bool ide)

#include <zephyr/drivers/can.h>

Optional callback API upon getting the maximum number of concurrent CAN RX filters See can_get_max_filters() for argument description.

◆ can_get_state_t

typedef int(* can_get_state_t) (const struct device *dev, enum can_state *state, struct can_bus_err_cnt *err_cnt)

#include <zephyr/drivers/can.h>

Callback API upon getting the CAN controller state See can_get_state() for argument description.

◆ can_recover_t

typedef int(* can_recover_t) (const struct device *dev, k_timeout_t timeout)

#include <zephyr/drivers/can.h>

Optional callback API upon manually recovering the CAN controller from bus-off state See can_recover() for argument description.

◆ can_remove_rx_filter_t

typedef void(* can_remove_rx_filter_t) (const struct device *dev, int filter_id)

#include <zephyr/drivers/can.h>

Callback API upon removing an RX filter See can_remove_rx_filter() for argument description.

◆ can_send_t

typedef int(* can_send_t) (const struct device *dev, const struct can_frame *frame, k_timeout_t timeout, can_tx_callback_t callback, void *user_data)

#include <zephyr/drivers/can.h>

Callback API upon sending a CAN frame See can_send() for argument description.

Note
From a driver perspective callback will never be NULL as a default callback will be provided if none is provided by the caller. This allows for simplifying the driver handling.

◆ can_set_mode_t

typedef int(* can_set_mode_t) (const struct device *dev, can_mode_t mode)

#include <zephyr/drivers/can.h>

Callback API upon setting CAN controller mode See can_set_mode() for argument description.

◆ can_set_state_change_callback_t

typedef void(* can_set_state_change_callback_t) (const struct device *dev, can_state_change_callback_t callback, void *user_data)

#include <zephyr/drivers/can.h>

Callback API upon setting a state change callback See can_set_state_change_callback() for argument description.

◆ can_set_timing_data_t

typedef int(* can_set_timing_data_t) (const struct device *dev, const struct can_timing *timing_data)

#include <zephyr/drivers/can.h>

Optional callback API upon setting CAN FD bus timing for the data phase.

See can_set_timing_data() for argument description

◆ can_set_timing_t

typedef int(* can_set_timing_t) (const struct device *dev, const struct can_timing *timing)

#include <zephyr/drivers/can.h>

Callback API upon setting CAN bus timing See can_set_timing() for argument description.

◆ can_start_t

typedef int(* can_start_t) (const struct device *dev)

#include <zephyr/drivers/can.h>

Callback API upon starting CAN controller See can_start() for argument description.

◆ can_stop_t

typedef int(* can_stop_t) (const struct device *dev)

#include <zephyr/drivers/can.h>

Callback API upon stopping CAN controller See can_stop() for argument description.