LCOV - code coverage report
Current view: top level - zephyr/devicetree - can.h Coverage Total Hit
Test: new.info Lines: 100.0 % 5 5
Test Date: 2025-09-05 16:43:28

            Line data    Source code
       1            1 : /**
       2              :  * @file
       3              :  * @brief CAN devicetree macro public API header file.
       4              :  */
       5              : 
       6              : /*
       7              :  * Copyright (c) 2022 Vestas Wind Systems A/S
       8              :  *
       9              :  * SPDX-License-Identifier: Apache-2.0
      10              :  */
      11              : 
      12              : #ifndef ZEPHYR_INCLUDE_DEVICETREE_CAN_H_
      13              : #define ZEPHYR_INCLUDE_DEVICETREE_CAN_H_
      14              : 
      15              : #ifdef __cplusplus
      16              : extern "C" {
      17              : #endif
      18              : 
      19              : /**
      20              :  * @defgroup devicetree-can Devicetree CAN API
      21              :  * @ingroup devicetree
      22              :  * @ingroup can_interface
      23              :  * @{
      24              :  */
      25              : 
      26              : /**
      27              :  * @brief Get the minimum transceiver bitrate for a CAN controller
      28              :  *
      29              :  * The bitrate will be limited to the minimum bitrate supported by the CAN
      30              :  * controller. If no CAN transceiver is present in the devicetree, the minimum
      31              :  * bitrate will be that of the CAN controller.
      32              :  *
      33              :  * Example devicetree fragment:
      34              :  *
      35              :  *     transceiver0: can-phy0 {
      36              :  *             compatible = "vnd,can-transceiver";
      37              :  *             min-bitrate = <15000>;
      38              :  *             max-bitrate = <1000000>;
      39              :  *             #phy-cells = <0>;
      40              :  *     };
      41              :  *
      42              :  *     can0: can@... {
      43              :  *             compatible = "vnd,can-controller";
      44              :  *             phys = <&transceiver0>;
      45              :  *     };
      46              :  *
      47              :  *     can1: can@... {
      48              :  *             compatible = "vnd,can-controller";
      49              :  *
      50              :  *             can-transceiver {
      51              :  *                     min-bitrate = <25000>;
      52              :  *                     max-bitrate = <2000000>;
      53              :  *             };
      54              :  *     };
      55              :  *
      56              :  *     can2: can@... {
      57              :  *             compatible = "vnd,can-controller";
      58              :  *
      59              :  *             can-transceiver {
      60              :  *                     max-bitrate = <2000000>;
      61              :  *             };
      62              :  *     };
      63              :  *
      64              :  * Example usage:
      65              :  *
      66              :  *     DT_CAN_TRANSCEIVER_MIN_BITRATE(DT_NODELABEL(can0), 10000) // 15000
      67              :  *     DT_CAN_TRANSCEIVER_MIN_BITRATE(DT_NODELABEL(can1), 0)     // 250000
      68              :  *     DT_CAN_TRANSCEIVER_MIN_BITRATE(DT_NODELABEL(can1), 50000) // 500000
      69              :  *     DT_CAN_TRANSCEIVER_MIN_BITRATE(DT_NODELABEL(can2), 0)     // 0
      70              :  *
      71              :  * @param node_id node identifier
      72              :  * @param min minimum bitrate supported by the CAN controller
      73              :  * @return the minimum bitrate supported by the CAN controller/transceiver combination
      74              :  */
      75            1 : #define DT_CAN_TRANSCEIVER_MIN_BITRATE(node_id, min)                                    \
      76              :         COND_CODE_1(DT_NODE_HAS_PROP(node_id, phys),                                    \
      77              :                     MAX(DT_PROP_OR(DT_PHANDLE(node_id, phys), min_bitrate, 0), min),    \
      78              :                     MAX(DT_PROP_OR(DT_CHILD(node_id, can_transceiver), min_bitrate, min), min))
      79              : 
      80              : /**
      81              :  * @brief Get the maximum transceiver bitrate for a CAN controller
      82              :  *
      83              :  * The bitrate will be limited to the maximum bitrate supported by the CAN
      84              :  * controller. If no CAN transceiver is present in the devicetree, the maximum
      85              :  * bitrate will be that of the CAN controller.
      86              :  *
      87              :  * Example devicetree fragment:
      88              :  *
      89              :  *     transceiver0: can-phy0 {
      90              :  *             compatible = "vnd,can-transceiver";
      91              :  *             max-bitrate = <1000000>;
      92              :  *             #phy-cells = <0>;
      93              :  *     };
      94              :  *
      95              :  *     can0: can@... {
      96              :  *             compatible = "vnd,can-controller";
      97              :  *             phys = <&transceiver0>;
      98              :  *     };
      99              :  *
     100              :  *     can1: can@... {
     101              :  *             compatible = "vnd,can-controller";
     102              :  *
     103              :  *             can-transceiver {
     104              :  *                     max-bitrate = <2000000>;
     105              :  *             };
     106              :  *     };
     107              :  *
     108              :  * Example usage:
     109              :  *
     110              :  *     DT_CAN_TRANSCEIVER_MAX_BITRATE(DT_NODELABEL(can0), 5000000) // 1000000
     111              :  *     DT_CAN_TRANSCEIVER_MAX_BITRATE(DT_NODELABEL(can1), 5000000) // 2000000
     112              :  *     DT_CAN_TRANSCEIVER_MAX_BITRATE(DT_NODELABEL(can1), 1000000) // 1000000
     113              :  *
     114              :  * @param node_id node identifier
     115              :  * @param max maximum bitrate supported by the CAN controller
     116              :  * @return the maximum bitrate supported by the CAN controller/transceiver combination
     117              :  */
     118            1 : #define DT_CAN_TRANSCEIVER_MAX_BITRATE(node_id, max)                                    \
     119              :         COND_CODE_1(DT_NODE_HAS_PROP(node_id, phys),                                    \
     120              :                     MIN(DT_PROP(DT_PHANDLE(node_id, phys), max_bitrate), max),          \
     121              :                     MIN(DT_PROP_OR(DT_CHILD(node_id, can_transceiver), max_bitrate, max), max))
     122              : 
     123              : /**
     124              :  * @brief Get the minimum transceiver bitrate for a DT_DRV_COMPAT CAN controller
     125              :  * @param inst DT_DRV_COMPAT instance number
     126              :  * @param min minimum bitrate supported by the CAN controller
     127              :  * @return the minimum bitrate supported by the CAN controller/transceiver combination
     128              :  * @see DT_CAN_TRANSCEIVER_MIN_BITRATE()
     129              :  */
     130            1 : #define DT_INST_CAN_TRANSCEIVER_MIN_BITRATE(inst, min) \
     131              :         DT_CAN_TRANSCEIVER_MIN_BITRATE(DT_DRV_INST(inst), min)
     132              : 
     133              : /**
     134              :  * @brief Get the maximum transceiver bitrate for a DT_DRV_COMPAT CAN controller
     135              :  * @param inst DT_DRV_COMPAT instance number
     136              :  * @param max maximum bitrate supported by the CAN controller
     137              :  * @return the maximum bitrate supported by the CAN controller/transceiver combination
     138              :  * @see DT_CAN_TRANSCEIVER_MAX_BITRATE()
     139              :  */
     140            1 : #define DT_INST_CAN_TRANSCEIVER_MAX_BITRATE(inst, max) \
     141              :         DT_CAN_TRANSCEIVER_MAX_BITRATE(DT_DRV_INST(inst), max)
     142              : 
     143              : /**
     144              :  * @}
     145              :  */
     146              : 
     147              : #ifdef __cplusplus
     148              : }
     149              : #endif
     150              : 
     151              : #endif /* ZEPHYR_INCLUDE_DEVICETREE_CAN_H_ */
        

Generated by: LCOV version 2.0-1