devicetree: Add DT/DT_INST_CHILD_NUM and DT/DT_INST_CHILD_NUM_STATUS_OKAY
Add a generated macro for the number of child nodes of a given node.
Add a generated macro for the number of child nodes of a given node which
children's status are "okay".
Signed-off-by: Swift Tian <swift.tian@ambiq.com>
diff --git a/scripts/dts/gen_defines.py b/scripts/dts/gen_defines.py
index b23a4cb..eb350b0 100755
--- a/scripts/dts/gen_defines.py
+++ b/scripts/dts/gen_defines.py
@@ -524,6 +524,15 @@
out_comment("Helper macros for child nodes of this node.")
+ out_dt_define(f"{node.z_path_id}_CHILD_NUM", len(node.children))
+
+ ok_nodes_num = 0
+ for child in node.children.values():
+ if child.status == "okay":
+ ok_nodes_num = ok_nodes_num + 1
+
+ out_dt_define(f"{node.z_path_id}_CHILD_NUM_STATUS_OKAY", ok_nodes_num)
+
out_dt_define(f"{node.z_path_id}_FOREACH_CHILD(fn)",
" ".join(f"fn(DT_{child.z_path_id})" for child in
node.children.values()))