Zephyr Project API 3.7.0
A Scalable Open Source RTOS
|
Macros | |
#define | DT_INVALID_NODE _ |
Name for an invalid node identifier. | |
#define | DT_ROOT DT_N |
Node identifier for the root node in the devicetree. | |
#define | DT_PATH(...) DT_PATH_INTERNAL(__VA_ARGS__) |
Get a node identifier for a devicetree path. | |
#define | DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label) |
Get a node identifier for a node label. | |
#define | DT_ALIAS(alias) DT_CAT(DT_N_ALIAS_, alias) |
Get a node identifier from /aliases. | |
#define | DT_INST(inst, compat) UTIL_CAT(DT_N_INST, DT_DASH(inst, compat)) |
Get a node identifier for an instance of a compatible. | |
#define | DT_PARENT(node_id) DT_CAT(node_id, _PARENT) |
Get a node identifier for a parent node. | |
#define | DT_GPARENT(node_id) DT_PARENT(DT_PARENT(node_id)) |
Get a node identifier for a grandparent node. | |
#define | DT_CHILD(node_id, child) UTIL_CAT(node_id, DT_S_PREFIX(child)) |
Get a node identifier for a child node. | |
#define | DT_COMPAT_GET_ANY_STATUS_OKAY(compat) |
Get a node identifier for a status okay node with a compatible. | |
#define | DT_NODE_PATH(node_id) DT_CAT(node_id, _PATH) |
Get a devicetree node's full path as a string literal. | |
#define | DT_NODE_FULL_NAME(node_id) DT_CAT(node_id, _FULL_NAME) |
Get a devicetree node's name with unit-address as a string literal. | |
#define | DT_NODE_CHILD_IDX(node_id) DT_CAT(node_id, _CHILD_IDX) |
Get a devicetree node's index into its parent's list of children. | |
#define | DT_CHILD_NUM(node_id) DT_CAT(node_id, _CHILD_NUM) |
Get the number of child nodes of a given node. | |
#define | DT_CHILD_NUM_STATUS_OKAY(node_id) DT_CAT(node_id, _CHILD_NUM_STATUS_OKAY) |
Get the number of child nodes of a given node which child nodes' status are okay. | |
#define | DT_SAME_NODE(node_id1, node_id2) (DT_DEP_ORD(node_id1) == (DT_DEP_ORD(node_id2))) |
Do node_id1 and node_id2 refer to the same node? | |
#define | DT_NODELABEL_STRING_ARRAY(node_id) { DT_FOREACH_NODELABEL(node_id, DT_NODELABEL_STRING_ARRAY_ENTRY_INTERNAL) } |
Get a devicetree node's node labels as an array of strings. | |
#define DT_ALIAS | ( | alias | ) | DT_CAT(DT_N_ALIAS_, alias) |
#include <include/zephyr/devicetree.h>
Get a node identifier from /aliases.
This macro's argument is a property of the /aliases
node. It returns a node identifier for the node which is aliased. Convert non-alphanumeric characters in the alias property to underscores to form valid C tokens, and lowercase all letters.
Example devicetree fragment:
You can use DT_ALIAS(my_serial) to get a node identifier for the serial@40001000
node. Notice how my-serial
in the devicetree becomes my_serial
in the DT_ALIAS() argument. Example usage with DT_PROP() to get the current-speed property:
alias | lowercase-and-underscores alias name. |
#define DT_CHILD | ( | node_id, | |
child | |||
) | UTIL_CAT(node_id, DT_S_PREFIX(child)) |
#include <include/zephyr/devicetree.h>
Get a node identifier for a child node.
Example devicetree fragment:
Example usage with DT_PROP() to get the status of the serial@40001000
node:
Node labels like serial1
cannot be used as the child
argument to this macro. Use DT_NODELABEL() for that instead.
You can also use DT_FOREACH_CHILD() to iterate over node identifiers for all of a node's children.
node_id | node identifier |
child | lowercase-and-underscores child node name |
#define DT_CHILD_NUM | ( | node_id | ) | DT_CAT(node_id, _CHILD_NUM) |
#include <include/zephyr/devicetree.h>
Get the number of child nodes of a given node.
node_id | a node identifier |
#define DT_CHILD_NUM_STATUS_OKAY | ( | node_id | ) | DT_CAT(node_id, _CHILD_NUM_STATUS_OKAY) |
#include <include/zephyr/devicetree.h>
Get the number of child nodes of a given node which child nodes' status are okay.
node_id | a node identifier |
#define DT_COMPAT_GET_ANY_STATUS_OKAY | ( | compat | ) |
#include <include/zephyr/devicetree.h>
Get a node identifier for a status okay
node with a compatible.
Use this if you want to get an arbitrary enabled node with a given compatible, and you do not care which one you get. If any enabled nodes with the given compatible exist, a node identifier for one of them is returned. Otherwise, DT_INVALID_NODE is returned.
Example devicetree fragment:
Example usage:
This expands to a node identifier for either node-a
or node-b
. It will not expand to a node identifier for node-c
, because that node does not have status okay
.
compat | lowercase-and-underscores compatible, without quotes |
#include <include/zephyr/devicetree.h>
Get a node identifier for a grandparent node.
Example devicetree fragment:
The following are equivalent ways to get the same node identifier:
node_id | node identifier |
#define DT_INST | ( | inst, | |
compat | |||
) | UTIL_CAT(DT_N_INST, DT_DASH(inst, compat)) |
#include <include/zephyr/devicetree.h>
Get a node identifier for an instance of a compatible.
All nodes with a particular compatible property value are assigned instance numbers, which are zero-based indexes specific to that compatible. You can get a node identifier for these nodes by passing DT_INST() an instance number, inst
, along with the lowercase-and-underscores version of the compatible, compat
.
Instance numbers have the following properties:
okay
or missing) are assigned the instance numbers starting from 0, and disabled nodes have instance numbers which are greater than those of any enabled nodeNo other guarantees are made. In particular:
Example devicetree fragment:
Assuming no other nodes in the devicetree have compatible "vnd,soc-serial"
, that compatible has nodes with instance numbers 0, 1, and 2.
The nodes serial@40002000
and serial@40003000
are both enabled, so their instance numbers are 0 and 1, but no guarantees are made regarding which node has which instance number.
Since serial@40001000
is the only disabled node, it has instance number 2, since disabled nodes are assigned the largest instance numbers. Therefore:
Notice how "vnd,soc-serial"
in the devicetree becomes vnd_soc_serial
(without quotes) in the DT_INST() arguments. (As usual, current-speed
in the devicetree becomes current_speed
as well.)
Nodes whose compatible
property has multiple values are assigned independent instance numbers for each compatible.
inst | instance number for compatible compat |
compat | lowercase-and-underscores compatible, without quotes |
#define DT_INVALID_NODE _ |
#include <include/zephyr/devicetree.h>
Name for an invalid node identifier.
This supports cases where factored macros can be invoked from paths where devicetree data may or may not be available. It is a preprocessor identifier that does not match any valid devicetree node identifier.
#define DT_NODE_CHILD_IDX | ( | node_id | ) | DT_CAT(node_id, _CHILD_IDX) |
#include <include/zephyr/devicetree.h>
Get a devicetree node's index into its parent's list of children.
Indexes are zero-based.
It is an error to use this macro with the root node.
Example devicetree fragment:
Example usage:
node_id | node identifier |
#define DT_NODE_FULL_NAME | ( | node_id | ) | DT_CAT(node_id, _FULL_NAME) |
#include <include/zephyr/devicetree.h>
Get a devicetree node's name with unit-address as a string literal.
This returns the node name and unit-address from a node identifier.
Example devicetree fragment:
Example usage:
node_id | node identifier |
#define DT_NODE_PATH | ( | node_id | ) | DT_CAT(node_id, _PATH) |
#include <include/zephyr/devicetree.h>
Get a devicetree node's full path as a string literal.
This returns the path to a node from a node identifier. To get a node identifier from path components instead, use DT_PATH().
Example devicetree fragment:
Example usage:
node_id | node identifier |
#define DT_NODELABEL | ( | label | ) | DT_CAT(DT_N_NODELABEL_, label) |
#include <include/zephyr/devicetree.h>
Get a node identifier for a node label.
Convert non-alphanumeric characters in the node label to underscores to form valid C tokens, and lowercase all letters. Note that node labels are not the same thing as label properties.
Example devicetree fragment:
The only node label in this example is serial1
.
The string UART_0
is not a node label; it's the value of a property named label.
You can use DT_NODELABEL(serial1)
to get a node identifier for the serial@40001000
node. Example usage with DT_PROP() to get the current-speed property:
Another example devicetree fragment:
Example usage to get the cache-level property:
Notice how L2_0
in the devicetree is lowercased to l2_0
in the DT_NODELABEL() argument.
label | lowercase-and-underscores node label name |
#define DT_NODELABEL_STRING_ARRAY | ( | node_id | ) | { DT_FOREACH_NODELABEL(node_id, DT_NODELABEL_STRING_ARRAY_ENTRY_INTERNAL) } |
#include <include/zephyr/devicetree.h>
Get a devicetree node's node labels as an array of strings.
Example devicetree fragment:
Example usage:
This expands to:
node_id | node identifier |
#define DT_PARENT | ( | node_id | ) | DT_CAT(node_id, _PARENT) |
#include <include/zephyr/devicetree.h>
Get a node identifier for a parent node.
Example devicetree fragment:
The following are equivalent ways to get the same node identifier:
node_id | node identifier |
#define DT_PATH | ( | ... | ) | DT_PATH_INTERNAL(__VA_ARGS__) |
#include <include/zephyr/devicetree.h>
Get a node identifier for a devicetree path.
The arguments to this macro are the names of non-root nodes in the tree required to reach the desired node, starting from the root. Non-alphanumeric characters in each name must be converted to underscores to form valid C tokens, and letters must be lowercased.
Example devicetree fragment:
You can use DT_PATH(soc, serial_40001000)
to get a node identifier for the serial@40001000
node. Node labels like serial1
cannot be used as DT_PATH() arguments; use DT_NODELABEL() for those instead.
Example usage with DT_PROP() to get the current-speed
property:
(The current-speed
property is also in lowercase-and-underscores
form when used with this API.)
When determining arguments to DT_PATH():
soc
above)serial_40001000
above, from the node name serial@40001000
after lowercasing and changing @
to _
)... | lowercase-and-underscores node names along the node's path, with each name given as a separate argument |
#define DT_ROOT DT_N |
#include <include/zephyr/devicetree.h>
Node identifier for the root node in the devicetree.
#define DT_SAME_NODE | ( | node_id1, | |
node_id2 | |||
) | (DT_DEP_ORD(node_id1) == (DT_DEP_ORD(node_id2))) |
#include <include/zephyr/devicetree.h>
Do node_id1
and node_id2
refer to the same node?
Both node_id1
and node_id2
must be node identifiers for nodes that exist in the devicetree (if unsure, you can check with DT_NODE_EXISTS()).
The expansion evaluates to 0 or 1, but may not be a literal integer 0 or 1.
node_id1 | first node identifier |
node_id2 | second node identifier |