Zephyr Project API 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Devicetree CAN API

Macros

#define DT_CAN_TRANSCEIVER_MIN_BITRATE(node_id, min)
 Get the minimum transceiver bitrate for a CAN controller.
 
#define DT_CAN_TRANSCEIVER_MAX_BITRATE(node_id, max)
 Get the maximum transceiver bitrate for a CAN controller.
 
#define DT_INST_CAN_TRANSCEIVER_MIN_BITRATE(inst, min)    DT_CAN_TRANSCEIVER_MIN_BITRATE(DT_DRV_INST(inst), min)
 Get the minimum transceiver bitrate for a DT_DRV_COMPAT CAN controller.
 
#define DT_INST_CAN_TRANSCEIVER_MAX_BITRATE(inst, max)    DT_CAN_TRANSCEIVER_MAX_BITRATE(DT_DRV_INST(inst), max)
 Get the maximum transceiver bitrate for a DT_DRV_COMPAT CAN controller.
 

Detailed Description

Macro Definition Documentation

◆ DT_CAN_TRANSCEIVER_MAX_BITRATE

#define DT_CAN_TRANSCEIVER_MAX_BITRATE (   node_id,
  max 
)

#include <include/zephyr/devicetree/can.h>

Value:
COND_CODE_1(DT_NODE_HAS_PROP(node_id, phys), \
MIN(DT_PROP(DT_PHANDLE(node_id, phys), max_bitrate), max), \
MIN(DT_PROP_OR(DT_CHILD(node_id, can_transceiver), max_bitrate, max), max))
#define DT_NODE_HAS_PROP(node_id, prop)
Does a devicetree node have a property?
Definition devicetree.h:3677
#define DT_CHILD(node_id, child)
Get a node identifier for a child node.
Definition devicetree.h:419
#define DT_PROP_OR(node_id, prop, default_value)
Like DT_PROP(), but with a fallback to default_value.
Definition devicetree.h:907
#define DT_PHANDLE(node_id, prop)
Get a node identifier for a phandle property's value.
Definition devicetree.h:1771
#define DT_PROP(node_id, prop)
Get a devicetree property value.
Definition devicetree.h:745
#define COND_CODE_1(_flag, _if_1_code, _else_code)
Insert code depending on whether _flag expands to 1 or not.
Definition util_macro.h:195
#define MIN(a, b)
Obtain the minimum of two values.
Definition util.h:400

Get the maximum transceiver bitrate for a CAN controller.

The bitrate will be limited to the maximum bitrate supported by the CAN controller. If no CAN transceiver is present in the devicetree, the maximum bitrate will be that of the CAN controller.

Example devicetree fragment:

transceiver0: can-phy0 {
        compatible = "vnd,can-transceiver";
        max-bitrate = <1000000>;
        #phy-cells = <0>;
};

can0: can@... {
        compatible = "vnd,can-controller";
        phys = <&transceiver0>;
};

can1: can@... {
        compatible = "vnd,can-controller";

        can-transceiver {
                max-bitrate = <2000000>;
        };
};

Example usage:

DT_CAN_TRANSCEIVER_MAX_BITRATE(DT_NODELABEL(can0), 5000000) // 1000000
DT_CAN_TRANSCEIVER_MAX_BITRATE(DT_NODELABEL(can1), 5000000) // 2000000
DT_CAN_TRANSCEIVER_MAX_BITRATE(DT_NODELABEL(can1), 1000000) // 1000000
Parameters
node_idnode identifier
maxmaximum bitrate supported by the CAN controller
Returns
the maximum bitrate supported by the CAN controller/transceiver combination

◆ DT_CAN_TRANSCEIVER_MIN_BITRATE

#define DT_CAN_TRANSCEIVER_MIN_BITRATE (   node_id,
  min 
)

#include <include/zephyr/devicetree/can.h>

Value:
COND_CODE_1(DT_NODE_HAS_PROP(node_id, phys), \
MAX(DT_PROP_OR(DT_PHANDLE(node_id, phys), min_bitrate, 0), min), \
MAX(DT_PROP_OR(DT_CHILD(node_id, can_transceiver), min_bitrate, min), min))
#define MAX(a, b)
Obtain the maximum of two values.
Definition util.h:385

Get the minimum transceiver bitrate for a CAN controller.

The bitrate will be limited to the minimum bitrate supported by the CAN controller. If no CAN transceiver is present in the devicetree, the minimum bitrate will be that of the CAN controller.

Example devicetree fragment:

transceiver0: can-phy0 {
        compatible = "vnd,can-transceiver";
        min-bitrate = <15000>;
        max-bitrate = <1000000>;
        #phy-cells = <0>;
};

can0: can@... {
        compatible = "vnd,can-controller";
        phys = <&transceiver0>;
};

can1: can@... {
        compatible = "vnd,can-controller";

        can-transceiver {
                min-bitrate = <25000>;
                max-bitrate = <2000000>;
        };
};

can2: can@... {
        compatible = "vnd,can-controller";

        can-transceiver {
                max-bitrate = <2000000>;
        };
};

Example usage:

DT_CAN_TRANSCEIVER_MIN_BITRATE(DT_NODELABEL(can0), 10000) // 15000
DT_CAN_TRANSCEIVER_MIN_BITRATE(DT_NODELABEL(can1), 0)     // 250000
DT_CAN_TRANSCEIVER_MIN_BITRATE(DT_NODELABEL(can1), 50000) // 500000
DT_CAN_TRANSCEIVER_MIN_BITRATE(DT_NODELABEL(can2), 0)     // 0
Parameters
node_idnode identifier
minminimum bitrate supported by the CAN controller
Returns
the minimum bitrate supported by the CAN controller/transceiver combination

◆ DT_INST_CAN_TRANSCEIVER_MAX_BITRATE

#define DT_INST_CAN_TRANSCEIVER_MAX_BITRATE (   inst,
  max 
)     DT_CAN_TRANSCEIVER_MAX_BITRATE(DT_DRV_INST(inst), max)

#include <include/zephyr/devicetree/can.h>

Get the maximum transceiver bitrate for a DT_DRV_COMPAT CAN controller.

Parameters
instDT_DRV_COMPAT instance number
maxmaximum bitrate supported by the CAN controller
Returns
the maximum bitrate supported by the CAN controller/transceiver combination
See also
DT_CAN_TRANSCEIVER_MAX_BITRATE()

◆ DT_INST_CAN_TRANSCEIVER_MIN_BITRATE

#define DT_INST_CAN_TRANSCEIVER_MIN_BITRATE (   inst,
  min 
)     DT_CAN_TRANSCEIVER_MIN_BITRATE(DT_DRV_INST(inst), min)

#include <include/zephyr/devicetree/can.h>

Get the minimum transceiver bitrate for a DT_DRV_COMPAT CAN controller.

Parameters
instDT_DRV_COMPAT instance number
minminimum bitrate supported by the CAN controller
Returns
the minimum bitrate supported by the CAN controller/transceiver combination
See also
DT_CAN_TRANSCEIVER_MIN_BITRATE()