From ec4584348ec2a993228f7e72f38f1cb5be0ca027 Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Wed, 25 Mar 2020 16:36:57 -0500 Subject: [PATCH] devicetree: Add DT_INST version of some DT_*_HAS_* macros Add DT_INST implementations of DT_PROP_HAS_IDX, DT_PHA_HAS_CELL_AT_IDX, and DT_INST_PHA_HAS_CELL. Signed-off-by: Kumar Gala --- include/devicetree.h | 37 +++++++++++++++++++++++++++++++++ tests/lib/devicetree/src/main.c | 6 ++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/include/devicetree.h b/include/devicetree.h index 3f6d0fca844..05d343a1f36 100644 --- a/include/devicetree.h +++ b/include/devicetree.h @@ -1071,6 +1071,18 @@ #define DT_INST_PROP_BY_IDX(inst, prop, idx) \ DT_PROP_BY_IDX(DT_DRV_INST(inst), prop, idx) +/** + * @brief Is index "idx" valid for an array type property + * on a DT_DRV_COMPAT instance? + * @param inst instance number + * @param prop lowercase-and-underscores property name + * @param idx index to check + * @return 1 if "idx" is a valid index into the given property, + * 0 otherwise. + */ +#define DT_INST_PROP_HAS_IDX(inst, prop, idx) \ + DT_PROP_HAS_IDX(DT_DRV_INST(inst), prop, idx) + /** * @brief Get a DT_DRV_COMPAT property length * @param inst instance number @@ -1329,6 +1341,31 @@ #define DT_INST_NODE_HAS_PROP(inst, prop) \ DT_NODE_HAS_PROP(DT_DRV_INST(inst), prop) +/** + * @brief Does a phandle array have a named cell specifier at an index? + * for a DT_DRV_COMPAT instance + * @param inst instance number + * @param pha lowercase-and-underscores property with type "phandle-array" + * @param idx index to check + * @param cell named cell value whose existence to check + * @return 1 if the named cell exists in the specifier at index idx, + * 0 otherwise. + */ +#define DT_INST_PHA_HAS_CELL_AT_IDX(inst, pha, idx, cell) \ + DT_PHA_HAS_CELL_AT_IDX(DT_DRV_INST(inst), pha, idx, cell) + +/** + * @brief Does a phandle array have a named cell specifier at index 0 + * for a DT_DRV_COMPAT instance? + * @param inst instance number + * @param pha lowercase-and-underscores property with type "phandle-array" + * @param cell named cell value whose existence to check + * @return 1 if the named cell exists in the specifier at index 0, + * 0 otherwise. + */ +#define DT_INST_PHA_HAS_CELL(inst, pha, cell) \ + DT_INST_PHA_HAS_CELL_AT_IDX(inst, pha, 0, cell) + /** * @brief is index valid for interrupt property on a DT_DRV_COMPAT instance? * Equivalent to DT_IRQ_HAS_IDX(DT_DRV_INST(inst), idx). diff --git a/tests/lib/devicetree/src/main.c b/tests/lib/devicetree/src/main.c index fcc48f0e699..216ed495c42 100644 --- a/tests/lib/devicetree/src/main.c +++ b/tests/lib/devicetree/src/main.c @@ -581,7 +581,7 @@ static void test_phandles(void) zassert_equal(ARRAY_SIZE(gps), 2, "gpios size"); zassert_equal(DT_PROP_LEN(TEST_PH, gpios), 2, "pha len"); - /* DT_PHA_HAS_IDX */ + /* DT_PROP_HAS_IDX */ zassert_true(DT_PROP_HAS_IDX(TEST_PH, gpios, 0), "has idx 0"); zassert_true(DT_PROP_HAS_IDX(TEST_PH, gpios, 1), "has idx 1"); zassert_false(DT_PROP_HAS_IDX(TEST_PH, gpios, 2), "!has idx 2"); @@ -686,8 +686,7 @@ static void test_phandles(void) "TEST_GPIO_2"), "gpios[1].label"); -#if 0 - /* DT_INST_PHA_HAS_IDX */ + /* DT_INST_PROP_HAS_IDX */ zassert_true(DT_INST_PROP_HAS_IDX(0, gpios, 0), "has idx 0"); zassert_true(DT_INST_PROP_HAS_IDX(0, gpios, 1), "has idx 1"); zassert_false(DT_INST_PROP_HAS_IDX(0, gpios, 2), "!has idx 2"); @@ -710,7 +709,6 @@ static void test_phandles(void) /* DT_INST_PHA_HAS_CELL */ zassert_true(DT_INST_PHA_HAS_CELL(0, gpios, flags), "has gpio flags"); zassert_false(DT_INST_PHA_HAS_CELL(0, gpios, bar), "no gpio bar"); -#endif /* DT_INST_PHANDLE_BY_IDX */ zassert_true(!strcmp(DT_LABEL(DT_INST_PHANDLE_BY_IDX(0, gpios, 0)),