File tree Expand file tree Collapse file tree 3 files changed +34
-4
lines changed
tests/lib/devicetree/api/src Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -20,8 +20,8 @@ Generic APIs
2020The APIs in this section can be used anywhere and do not require
2121``DT_DRV_COMPAT `` to be defined.
2222
23- Node identifiers
24- ================
23+ Node identifiers and helpers
24+ ============================
2525
2626A *node identifier * is a way to refer to a devicetree node at C preprocessor
2727time. While node identifiers are not C values, you can use them to access
@@ -36,6 +36,8 @@ There are also :c:func:`DT_PARENT` and :c:func:`DT_CHILD` macros which can be
3636used to create node identifiers for a given node's parent node or a particular
3737child node, respectively.
3838
39+ The following macros create or operate on node identifiers.
40+
3941.. doxygengroup :: devicetree-generic-id
4042 :project: Zephyr
4143
Original file line number Diff line number Diff line change 6565 */
6666
6767/**
68- * @defgroup devicetree-generic-id Node identifiers
68+ * @defgroup devicetree-generic-id Node identifiers and helpers
6969 * @ingroup devicetree
7070 * @{
7171 */
399399 */
400400#define DT_NODE_PATH (node_id ) DT_CAT(node_id, _PATH)
401401
402+ /**
403+ * @brief Do node_id1 and node_id2 refer to the same node?
404+ *
405+ * Both "node_id1" and "node_id2" must be node identifiers for nodes
406+ * that exist in the devicetree (if unsure, you can check with
407+ * DT_NODE_EXISTS()).
408+ *
409+ * The expansion evaluates to 0 or 1, but may not be a literal integer
410+ * 0 or 1.
411+ *
412+ * @param node_id1 first node identifer
413+ * @param node_id2 second node identifier
414+ * @return an expression that evaluates to 1 if the node identifiers
415+ * refer to the same node, and evaluates to 0 otherwise
416+ */
417+ #define DT_SAME_NODE (node_id1 , node_id2 ) \
418+ (DT_DEP_ORD(node_id1) == (DT_DEP_ORD(node_id2)))
419+
420+ /* Implementation note: distinct nodes have distinct node identifiers.
421+ * See include/devicetree/ordinals.h. */
422+
402423/**
403424 * @}
404425 */
Original file line number Diff line number Diff line change @@ -1545,6 +1545,12 @@ static void test_path(void)
15451545 "/test/gpio@deadbeef" ), "" );
15461546}
15471547
1548+ static void test_same_node (void )
1549+ {
1550+ zassert_true (DT_SAME_NODE (TEST_DEADBEEF , TEST_DEADBEEF ), "" );
1551+ zassert_false (DT_SAME_NODE (TEST_DEADBEEF , TEST_ABCD1234 ), "" );
1552+ }
1553+
15481554void test_main (void )
15491555{
15501556 ztest_test_suite (devicetree_api ,
@@ -1579,7 +1585,8 @@ void test_main(void)
15791585 ztest_unit_test (test_child_nodes_list ),
15801586 ztest_unit_test (test_great_grandchild ),
15811587 ztest_unit_test (test_dep_ord ),
1582- ztest_unit_test (test_path )
1588+ ztest_unit_test (test_path ),
1589+ ztest_unit_test (test_same_node )
15831590 );
15841591 ztest_run_test_suite (devicetree_api );
15851592}
You can’t perform that action at this time.
0 commit comments