Zephyr API Documentation  3.2.99
A Scalable Open Source RTOS
Existence checks

Macros

#define DT_NODE_EXISTS(node_id)   IS_ENABLED(DT_CAT(node_id, _EXISTS))
 Does a node identifier refer to a node? More...
 
#define DT_NODE_HAS_STATUS(node_id, status)    DT_NODE_HAS_STATUS_INTERNAL(node_id, status)
 Does a node identifier refer to a node with a status? More...
 
#define DT_HAS_COMPAT_STATUS_OKAY(compat)    IS_ENABLED(DT_CAT(DT_COMPAT_HAS_OKAY_, compat))
 Does the devicetree have a status okay node with a compatible? More...
 
#define DT_NUM_INST_STATUS_OKAY(compat)
 Get the number of instances of a given compatible with status okay More...
 
#define DT_NODE_HAS_COMPAT(node_id, compat)    IS_ENABLED(DT_CAT3(node_id, _COMPAT_MATCHES_, compat))
 Does a devicetree node match a compatible? More...
 
#define DT_NODE_HAS_COMPAT_STATUS(node_id, compat, status)    DT_NODE_HAS_COMPAT(node_id, compat) && DT_NODE_HAS_STATUS(node_id, status)
 Does a devicetree node have a compatible and status? More...
 
#define DT_NODE_HAS_PROP(node_id, prop)    IS_ENABLED(DT_CAT4(node_id, _P_, prop, _EXISTS))
 Does a devicetree node have a property? More...
 
#define DT_PHA_HAS_CELL_AT_IDX(node_id, pha, idx, cell)
 Does a phandle array have a named cell specifier at an index? More...
 
#define DT_PHA_HAS_CELL(node_id, pha, cell)    DT_PHA_HAS_CELL_AT_IDX(node_id, pha, 0, cell)
 Equivalent to DT_PHA_HAS_CELL_AT_IDX(node_id, pha, 0, cell) More...
 

Detailed Description

Macro Definition Documentation

◆ DT_HAS_COMPAT_STATUS_OKAY

#define DT_HAS_COMPAT_STATUS_OKAY (   compat)     IS_ENABLED(DT_CAT(DT_COMPAT_HAS_OKAY_, compat))

#include <zephyr/devicetree.h>

Does the devicetree have a status okay node with a compatible?

Test for whether the devicetree has any nodes with status okay and the given compatible. That is, this returns 1 if and only if there is at least one node_id for which both of these expressions return 1:

DT_NODE_HAS_STATUS(node_id, okay)
DT_NODE_HAS_COMPAT(node_id, compat)
#define DT_NODE_HAS_STATUS(node_id, status)
Does a node identifier refer to a node with a status?
Definition: devicetree.h:2685
#define DT_NODE_HAS_COMPAT(node_id, compat)
Does a devicetree node match a compatible?
Definition: devicetree.h:2747

As usual, both a missing status and an ok status are treated as okay.

Parameters
compatlowercase-and-underscores compatible, without quotes
Returns
1 if both of the above conditions are met, 0 otherwise

◆ DT_NODE_EXISTS

#define DT_NODE_EXISTS (   node_id)    IS_ENABLED(DT_CAT(node_id, _EXISTS))

#include <zephyr/devicetree.h>

Does a node identifier refer to a node?

Tests whether a node identifier refers to a node which exists, i.e. is defined in the devicetree.

It doesn't matter whether or not the node has a matching binding, or what the node's status value is. This is purely a check of whether the node exists at all.

Parameters
node_ida node identifier
Returns
1 if the node identifier refers to a node, 0 otherwise.

◆ DT_NODE_HAS_COMPAT

#define DT_NODE_HAS_COMPAT (   node_id,
  compat 
)     IS_ENABLED(DT_CAT3(node_id, _COMPAT_MATCHES_, compat))

#include <zephyr/devicetree.h>

Does a devicetree node match a compatible?

Example devicetree fragment:

n: node {
compatible = "vnd,specific-device", "generic-device";
}

Example usages which evaluate to 1:

DT_NODE_HAS_COMPAT(DT_NODELABEL(n), vnd_specific_device)
DT_NODE_HAS_COMPAT(DT_NODELABEL(n), generic_device)
#define DT_NODELABEL(label)
Get a node identifier for a node label.
Definition: devicetree.h:190

This macro only uses the value of the compatible property. Whether or not a particular compatible has a matching binding has no effect on its value, nor does the node's status.

Parameters
node_idnode identifier
compatlowercase-and-underscores compatible, without quotes
Returns
1 if the node's compatible property contains compat, 0 otherwise.

◆ DT_NODE_HAS_COMPAT_STATUS

#define DT_NODE_HAS_COMPAT_STATUS (   node_id,
  compat,
  status 
)     DT_NODE_HAS_COMPAT(node_id, compat) && DT_NODE_HAS_STATUS(node_id, status)

#include <zephyr/devicetree.h>

Does a devicetree node have a compatible and status?

This is equivalent to:

(DT_NODE_HAS_COMPAT(node_id, compat) &&
DT_NODE_HAS_STATUS(node_id, status))
Parameters
node_idnode identifier
compatlowercase-and-underscores compatible, without quotes
statusokay or disabled as a token, not a string

◆ DT_NODE_HAS_PROP

#define DT_NODE_HAS_PROP (   node_id,
  prop 
)     IS_ENABLED(DT_CAT4(node_id, _P_, prop, _EXISTS))

#include <zephyr/devicetree.h>

Does a devicetree node have a property?

Tests whether a devicetree node has a property defined.

This tests whether the property is defined at all, not whether a boolean property is true or false. To get a boolean property's truth value, use DT_PROP(node_id, prop) instead.

Parameters
node_idnode identifier
proplowercase-and-underscores property name
Returns
1 if the node has the property, 0 otherwise.

◆ DT_NODE_HAS_STATUS

#define DT_NODE_HAS_STATUS (   node_id,
  status 
)     DT_NODE_HAS_STATUS_INTERNAL(node_id, status)

#include <zephyr/devicetree.h>

Does a node identifier refer to a node with a status?

Example uses:

DT_NODE_HAS_STATUS(DT_PATH(soc, i2c_12340000), okay)
DT_NODE_HAS_STATUS(DT_PATH(soc, i2c_12340000), disabled)
#define DT_PATH(...)
Get a node identifier for a devicetree path.
Definition: devicetree.h:134

Tests whether a node identifier refers to a node which:

  • exists in the devicetree, and
  • has a status property matching the second argument (except that either a missing status or an ok status in the devicetree is treated as if it were okay instead)
Parameters
node_ida node identifier
statusa status as one of the tokens okay or disabled, not a string
Returns
1 if the node has the given status, 0 otherwise.

◆ DT_NUM_INST_STATUS_OKAY

#define DT_NUM_INST_STATUS_OKAY (   compat)

#include <zephyr/devicetree.h>

Value:
UTIL_CAT(DT_N_INST, DT_DASH(compat, NUM_OKAY)))
#define DT_HAS_COMPAT_STATUS_OKAY(compat)
Does the devicetree have a status okay node with a compatible?
Definition: devicetree.h:2707
#define UTIL_AND(a, b)
Like a && b, but does evaluation and short-circuiting at C preprocessor time.
Definition: util_macro.h:344
#define UTIL_CAT(a,...)
Definition: util_internal.h:104

Get the number of instances of a given compatible with status okay

Parameters
compatlowercase-and-underscores compatible, without quotes
Returns
Number of instances with status okay

◆ DT_PHA_HAS_CELL

#define DT_PHA_HAS_CELL (   node_id,
  pha,
  cell 
)     DT_PHA_HAS_CELL_AT_IDX(node_id, pha, 0, cell)

#include <zephyr/devicetree.h>

Equivalent to DT_PHA_HAS_CELL_AT_IDX(node_id, pha, 0, cell)

Parameters
node_idnode identifier
phalowercase-and-underscores property with type phandle-array
celllowercase-and-underscores cell name whose existence to check at index idx
Returns
1 if the named cell exists in the specifier at index 0, 0 otherwise.

◆ DT_PHA_HAS_CELL_AT_IDX

#define DT_PHA_HAS_CELL_AT_IDX (   node_id,
  pha,
  idx,
  cell 
)

#include <zephyr/devicetree.h>

Value:
IS_ENABLED(DT_CAT8(node_id, _P_, pha, \
_IDX_, idx, _VAL_, cell, _EXISTS))
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition: util_macro.h:101

Does a phandle array have a named cell specifier at an index?

If this returns 1, then the phandle-array property pha has a cell named cell at index idx, and therefore DT_PHA_BY_IDX(node_id, pha, idx, cell) is valid. If it returns 0, it's an error to use DT_PHA_BY_IDX() with the same arguments.

Parameters
node_idnode identifier
phalowercase-and-underscores property with type phandle-array
idxindex to check within pha
celllowercase-and-underscores cell name whose existence to check at index idx
Returns
1 if the named cell exists in the specifier at index idx, 0 otherwise.