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 * @{ 23 */ 24 25 /** 26 * @brief Get the maximum transceiver bitrate for a CAN controller 27 * 28 * The bitrate will be limited to the maximum bitrate supported by the CAN 29 * controller. If no CAN transceiver is present in the devicetree, the maximum 30 * bitrate will be that of the CAN controller. 31 * 32 * Example devicetree fragment: 33 * 34 * transceiver0: can-phy0 { 35 * compatible = "vnd,can-transceiver"; 36 * max-bitrate = <1000000>; 37 * #phy-cells = <0>; 38 * }; 39 * 40 * can0: can@... { 41 * compatible = "vnd,can-controller"; 42 * phys = <&transceiver0>; 43 * }; 44 * 45 * can1: can@... { 46 * compatible = "vnd,can-controller"; 47 * 48 * can-transceiver { 49 * max-bitrate = <2000000>; 50 * }; 51 * }; 52 * 53 * Example usage: 54 * 55 * DT_CAN_TRANSCEIVER_MAX_BITRATE(DT_NODELABEL(can0), 5000000) // 1000000 56 * DT_CAN_TRANSCEIVER_MAX_BITRATE(DT_NODELABEL(can1), 5000000) // 2000000 57 * DT_CAN_TRANSCEIVER_MAX_BITRATE(DT_NODELABEL(can1), 1000000) // 1000000 58 * 59 * @param node_id node identifier 60 * @param max maximum bitrate supported by the CAN controller 61 * @return the maximum bitrate supported by the CAN controller/transceiver combination 62 */ 63 #define DT_CAN_TRANSCEIVER_MAX_BITRATE(node_id, max) \ 64 COND_CODE_1(DT_NODE_HAS_PROP(node_id, phys), \ 65 MIN(DT_PROP(DT_PHANDLE(node_id, phys), max_bitrate), max), \ 66 MIN(DT_PROP_OR(DT_CHILD(node_id, can_transceiver), max_bitrate, max), max)) 67 68 /** 69 * @brief Get the maximum transceiver bitrate for a DT_DRV_COMPAT CAN controller 70 * @param inst DT_DRV_COMPAT instance number 71 * @param max maximum bitrate supported by the CAN controller 72 * @return the maximum bitrate supported by the CAN controller/transceiver combination 73 * @see DT_CAN_TRANSCEIVER_MAX_BITRATE() 74 */ 75 #define DT_INST_CAN_TRANSCEIVER_MAX_BITRATE(inst, max) \ 76 DT_CAN_TRANSCEIVER_MAX_BITRATE(DT_DRV_INST(inst), max) 77 78 /** 79 * @} 80 */ 81 82 #ifdef __cplusplus 83 } 84 #endif 85 86 #endif /* ZEPHYR_INCLUDE_DEVICETREE_CAN_H_ */ 87