File tree Expand file tree Collapse file tree 3 files changed +11
-0
lines changed
tests/lib/devicetree/api/src Expand file tree Collapse file tree 3 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,8 @@ By alias
5050 :zephyr:code-sample: `blinky `, which uses the ``led0 `` alias) that need to
5151 refer to *some * device of a particular type ("the board's user LED") but
5252 don't care which one is used.
53+ You may also use :c:macro: `DT_HAS_ALIAS() ` to verify whether an alias
54+ node exists.
5355
5456By instance number
5557 This is done primarily by device drivers, as instance numbers are a way to
Original file line number Diff line number Diff line change 239239 */
240240#define DT_ALIAS (alias ) DT_CAT(DT_N_ALIAS_, alias)
241241
242+ /**
243+ * @brief Test if the devicetree has a given alias
244+ * @param alias_name lowercase-and-underscores devicetree alias name
245+ * @return 1 if the alias exists and refers to a node, 0 otherwise
246+ */
247+ #define DT_HAS_ALIAS (alias_name ) DT_NODE_EXISTS(DT_ALIAS(alias_name))
248+
242249/**
243250 * @brief Get a node identifier for an instance of a compatible
244251 *
Original file line number Diff line number Diff line change @@ -127,6 +127,8 @@ ZTEST(devicetree_api, test_path_props)
127127
128128ZTEST (devicetree_api , test_alias_props )
129129{
130+ zassert_equal (DT_HAS_ALIAS (test_alias ), 1 , "" );
131+ zassert_equal (DT_HAS_ALIAS (test_alias_none ), 0 , "" );
130132 zassert_equal (DT_NUM_REGS (TEST_ALIAS ), 1 , "" );
131133 zassert_equal (DT_REG_ADDR (TEST_ALIAS ), 0xdeadbeef , "" );
132134 zassert_equal (DT_REG_SIZE (TEST_ALIAS ), 0x1000 , "" );
You can’t perform that action at this time.
0 commit comments