Skip to content

Commit

Permalink
devicetree: memory-attr: Introduce DT_MEMORY_ATTR_FOREACH_STATUS_OKAY…
Browse files Browse the repository at this point in the history
…_NODE

Introduce a new DT_MEMORY_ATTR_FOREACH_STATUS_OKAY_NODE() macro and make
the DT_MEMORY_ATTR_FOREACH_NODE() macro visiting disabled nodes as well.

Signed-off-by: Carlo Caione <[email protected]>
  • Loading branch information
carlocaione committed Jul 27, 2023
1 parent 0751fbe commit ab59087
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
20 changes: 18 additions & 2 deletions include/zephyr/devicetree/memory-attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@

/** @endcond */

/**
* @brief Invokes @p fn for every status `okay` node in the tree with property
* `zephyr,memory-attr`
*
* The macro @p fn must take one parameter, which will be a node identifier
* with the `zephyr,memory-attr` property. The macro is expanded once for each
* node in the tree with status `okay`. The order that nodes are visited in is
* not specified.
*
* @param fn macro to invoke
*/
#define DT_MEMORY_ATTR_FOREACH_STATUS_OKAY_NODE(fn) \
DT_FOREACH_STATUS_OKAY_NODE_VARGS(_FILTER, fn)


/**
* @brief Invokes @p fn for every node in the tree with property
* `zephyr,memory-attr`
Expand All @@ -59,14 +74,15 @@
* @param fn macro to invoke
*/
#define DT_MEMORY_ATTR_FOREACH_NODE(fn) \
DT_FOREACH_STATUS_OKAY_NODE_VARGS(_FILTER, fn)
DT_FOREACH_NODE_VARGS(_FILTER, fn)

/**
* @brief Invokes @p fn for MPU/MMU regions generation from the device tree
* nodes with `zephyr,memory-attr` property.
*
* Helper macro to invoke a @p fn macro on all the memory regions declared
* using the `zephyr,memory-attr` property
* using the `zephyr,memory-attr` property. The macro is expanded once for each
* node in the tree with status `okay`.
*
* The macro @p fn must take the form:
*
Expand Down
7 changes: 7 additions & 0 deletions tests/lib/devicetree/api/app.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,13 @@
zephyr,memory-attr = "RAM_NOCACHE";
};

test_mem_disabled: memory@11223344 {
compatible = "vnd,memory-attr";
reg = < 0x11223344 0x1000 >;
zephyr,memory-attr = "FLASH";
status = "disabled";
};

};

test_64 {
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/devicetree/api/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2753,6 +2753,16 @@ ZTEST(devicetree_api, test_memory_attr)
zassert_equal(val_filt[0], 0x44332211, "");

#undef TEST_FUNC

#define TEST_FUNC(node_id) DT_REG_SIZE(node_id),

size_t val_status_ok[] = {
DT_MEMORY_ATTR_FOREACH_STATUS_OKAY_NODE(TEST_FUNC)
};

zassert_equal(ARRAY_SIZE(val_status_ok), 2, "");

#undef TEST_FUNC
}

ZTEST(devicetree_api, test_string_token)
Expand Down

0 comments on commit ab59087

Please sign in to comment.