Zephyr API 3.6.99
Loading...
Searching...
No Matches
Existence checks

Macros

#define DT_NODE_EXISTS(node_id)
 Does a node identifier refer to a node?
 
#define DT_NODE_HAS_STATUS(node_id, status)
 Does a node identifier refer to a node with a status?
 
#define DT_NODE_HAS_STATUS_OKAY(node_id)
 Does a node identifier refer to a node with a status okay?
 
#define DT_HAS_COMPAT_STATUS_OKAY(compat)
 Does the devicetree have a status okay node with a compatible?
 
#define DT_NUM_INST_STATUS_OKAY(compat)
 Get the number of instances of a given compatible with status okay
 
#define DT_NODE_HAS_COMPAT(node_id, compat)
 Does a devicetree node match a compatible?
 
#define DT_NODE_HAS_COMPAT_STATUS(node_id, compat, status)
 Does a devicetree node have a compatible and status?
 
#define DT_NODE_HAS_PROP(node_id, prop)
 Does a devicetree node have a property?
 
#define DT_PHA_HAS_CELL_AT_IDX(node_id, pha, idx, cell)
 Does a phandle array have a named cell specifier at an index?
 
#define DT_PHA_HAS_CELL(node_id, pha, cell)
 Equivalent to DT_PHA_HAS_CELL_AT_IDX(node_id, pha, 0, cell)
 

Detailed Description

Macro Definition Documentation

◆ DT_HAS_COMPAT_STATUS_OKAY

#define DT_HAS_COMPAT_STATUS_OKAY ( compat)

#include <zephyr/devicetree.h>

Value:
IS_ENABLED(DT_CAT(DT_COMPAT_HAS_OKAY_, compat))
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition util_macro.h:124

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:3403
#define DT_NODE_HAS_COMPAT(node_id, compat)
Does a devicetree node match a compatible?
Definition devicetree.h:3487

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)

#include <zephyr/devicetree.h>

Value:
IS_ENABLED(DT_CAT(node_id, _EXISTS))

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 )

#include <zephyr/devicetree.h>

Value:
IS_ENABLED(DT_CAT3(node_id, _COMPAT_MATCHES_, compat))

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:200

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 )

#include <zephyr/devicetree.h>

Value:
UTIL_AND(DT_NODE_HAS_COMPAT(node_id, compat), DT_NODE_HAS_STATUS(node_id, status))
#define UTIL_AND(a, b)
Like a && b, but does evaluation and short-circuiting at C preprocessor time.
Definition util_macro.h:391

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 )

#include <zephyr/devicetree.h>

Value:
IS_ENABLED(DT_CAT4(node_id, _P_, prop, _EXISTS))

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 )

#include <zephyr/devicetree.h>

Value:
DT_NODE_HAS_STATUS_INTERNAL(node_id, status)

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:144

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_NODE_HAS_STATUS_OKAY

#define DT_NODE_HAS_STATUS_OKAY ( node_id)

#include <zephyr/devicetree.h>

Value:
DT_NODE_HAS_STATUS(node_id, okay)

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

Example uses:

DT_NODE_HAS_STATUS_OKAY(DT_PATH(soc, i2c_12340000))
#define DT_NODE_HAS_STATUS_OKAY(node_id)
Does a node identifier refer to a node with a status okay?
Definition devicetree.h:3426

Tests whether a node identifier refers to a node which:

  • exists in the devicetree, and
  • has a status property as okay

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

Parameters
node_ida node identifier
Returns
1 if the node has status as okay, 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:3447
#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 )

#include <zephyr/devicetree.h>

Value:
DT_PHA_HAS_CELL_AT_IDX(node_id, pha, 0, cell)
#define DT_PHA_HAS_CELL_AT_IDX(node_id, pha, idx, cell)
Does a phandle array have a named cell specifier at an index?
Definition devicetree.h:3540

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))

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.