1 /* 2 * Copyright (c) 2020 Nordic Semiconductor ASA 3 * SPDX-License-Identifier: Apache-2.0 4 */ 5 6 #ifndef ZEPHYR_INCLUDE_DEVICETREE_ORDINALS_H_ 7 #define ZEPHYR_INCLUDE_DEVICETREE_ORDINALS_H_ 8 9 /** 10 * @file 11 * @brief Devicetree node dependency ordinals 12 */ 13 14 /** 15 * @defgroup devicetree-dep-ord Dependency tracking 16 * @ingroup devicetree 17 * @{ 18 */ 19 20 /** 21 * @brief Get a node's dependency ordinal 22 * @param node_id Node identifier 23 * @return the node's dependency ordinal as an integer literal 24 */ 25 #define DT_DEP_ORD(node_id) DT_CAT(node_id, _ORD) 26 27 /** 28 * @brief Get a node's dependency ordinal in string sortable form 29 * @param node_id Node identifier 30 * @return the node's dependency ordinal as a zero-padded integer literal 31 */ 32 #define DT_DEP_ORD_STR_SORTABLE(node_id) DT_CAT(node_id, _ORD_STR_SORTABLE) 33 34 /** 35 * @brief Get a list of dependency ordinals of a node's direct dependencies 36 * 37 * There is a comma after each ordinal in the expansion, **including** 38 * the last one: 39 * 40 * DT_REQUIRES_DEP_ORDS(my_node) // required_ord_1, ..., required_ord_n, 41 * 42 * The one case DT_REQUIRES_DEP_ORDS() expands to nothing is when 43 * given the root node identifier @p DT_ROOT as argument. The root has 44 * no direct dependencies; every other node at least depends on its 45 * parent. 46 * 47 * @param node_id Node identifier 48 * @return a list of dependency ordinals, with each ordinal followed 49 * by a comma (<tt>,</tt>), or an empty expansion 50 */ 51 #define DT_REQUIRES_DEP_ORDS(node_id) DT_CAT(node_id, _REQUIRES_ORDS) 52 53 /** 54 * @brief Get a list of dependency ordinals of what depends directly on a node 55 * 56 * There is a comma after each ordinal in the expansion, **including** 57 * the last one: 58 * 59 * DT_SUPPORTS_DEP_ORDS(my_node) // supported_ord_1, ..., supported_ord_n, 60 * 61 * DT_SUPPORTS_DEP_ORDS() may expand to nothing. This happens when @p node_id 62 * refers to a leaf node that nothing else depends on. 63 * 64 * @param node_id Node identifier 65 * @return a list of dependency ordinals, with each ordinal followed 66 * by a comma (<tt>,</tt>), or an empty expansion 67 */ 68 #define DT_SUPPORTS_DEP_ORDS(node_id) DT_CAT(node_id, _SUPPORTS_ORDS) 69 70 /** 71 * @brief Get a DT_DRV_COMPAT instance's dependency ordinal 72 * 73 * Equivalent to DT_DEP_ORD(DT_DRV_INST(inst)). 74 * 75 * @param inst instance number 76 * @return The instance's dependency ordinal 77 */ 78 #define DT_INST_DEP_ORD(inst) DT_DEP_ORD(DT_DRV_INST(inst)) 79 80 /** 81 * @brief Get a list of dependency ordinals of a DT_DRV_COMPAT instance's 82 * direct dependencies 83 * 84 * Equivalent to DT_REQUIRES_DEP_ORDS(DT_DRV_INST(inst)). 85 * 86 * @param inst instance number 87 * @return a list of dependency ordinals for the nodes the instance depends 88 * on directly 89 */ 90 #define DT_INST_REQUIRES_DEP_ORDS(inst) DT_REQUIRES_DEP_ORDS(DT_DRV_INST(inst)) 91 92 /** 93 * @brief Get a list of dependency ordinals of what depends directly on a 94 * DT_DRV_COMPAT instance 95 * 96 * Equivalent to DT_SUPPORTS_DEP_ORDS(DT_DRV_INST(inst)). 97 * 98 * @param inst instance number 99 * @return a list of node identifiers for the nodes that depend directly 100 * on the instance 101 */ 102 #define DT_INST_SUPPORTS_DEP_ORDS(inst) DT_SUPPORTS_DEP_ORDS(DT_DRV_INST(inst)) 103 104 /** 105 * @} 106 */ 107 108 #endif /* ZEPHYR_INCLUDE_DEVICETREE_ORDINALS_H_ */ 109