|
3817 | 3817 | #define DT_PHA_HAS_CELL(node_id, pha, cell) \ |
3818 | 3818 | DT_PHA_HAS_CELL_AT_IDX(node_id, pha, 0, cell) |
3819 | 3819 |
|
| 3820 | +/** |
| 3821 | + * @brief Iterate over all cells in a phandle array element by index |
| 3822 | + * |
| 3823 | + * This macro calls @p fn(cell_value) for each cell value in the |
| 3824 | + * phandle array element at index @p idx. |
| 3825 | + * |
| 3826 | + * In general, this macro expands to: |
| 3827 | + * |
| 3828 | + * fn(node_id, pha, idx, cell[0]) fn(node_id, pha, idx, cell[1]) [...] |
| 3829 | + * fn(node_id, pha, idx, cell[n-1]) |
| 3830 | + * |
| 3831 | + * where `n` is the number of cells in @p pha, as it would be |
| 3832 | + * returned by `DT_PHA_NUM_CELLS_BY_IDX(node_id, pha, idx)`, and cell[x] is the NAME of the cell |
| 3833 | + * in the specifier. |
| 3834 | + * |
| 3835 | + * @param node_id node identifier |
| 3836 | + * @param pha lowercase-and-underscores property with type `phandle-array` |
| 3837 | + * @param idx index of the phandle array element |
| 3838 | + * @param fn macro to call for each cell value |
| 3839 | + */ |
| 3840 | +#define DT_FOREACH_PHA_CELL_BY_IDX(node_id, pha, idx, fn) \ |
| 3841 | + DT_CAT6(node_id, _P_, pha, _IDX_, idx, _FOREACH_CELL)(fn) |
| 3842 | + |
| 3843 | +/** |
| 3844 | + * @brief Iterate over all cells in a phandle array element by index with separator |
| 3845 | + * |
| 3846 | + * This is like DT_FOREACH_PHA_CELL_BY_IDX(), but @p sep is placed between |
| 3847 | + * each invocation of @p fn. |
| 3848 | + * |
| 3849 | + * @param node_id node identifier |
| 3850 | + * @param pha lowercase-and-underscores property with type `phandle-array` |
| 3851 | + * @param idx index of the phandle array element |
| 3852 | + * @param fn macro to call for each cell value |
| 3853 | + * @param sep separator (e.g. comma or semicolon) |
| 3854 | + */ |
| 3855 | +#define DT_FOREACH_PHA_CELL_BY_IDX_SEP(node_id, pha, idx, fn, sep) \ |
| 3856 | + DT_CAT6(node_id, _P_, pha, _IDX_, idx, _FOREACH_CELL_SEP)(fn, sep) |
| 3857 | + |
| 3858 | +/** |
| 3859 | + * @brief Get the number of cells in a phandle array element by index |
| 3860 | + * |
| 3861 | + * @param node_id node identifier |
| 3862 | + * @param pha lowercase-and-underscores property with type `phandle-array` |
| 3863 | + * @param idx index of the phandle array element |
| 3864 | + * @return number of cells in the element at index @p idx |
| 3865 | + */ |
| 3866 | +#define DT_PHA_NUM_CELLS_BY_IDX(node_id, pha, idx) \ |
| 3867 | + DT_CAT6(node_id, _P_, pha, _IDX_, idx, _NUM_CELLS) |
| 3868 | + |
| 3869 | +/** |
| 3870 | + * @brief Get the name of a phandle array element by index |
| 3871 | + * |
| 3872 | + * This returns the name in the *-names property of the node |
| 3873 | + * corresponding to the index @p idx of @p pha |
| 3874 | + * |
| 3875 | + * @param node_id node identifier |
| 3876 | + * @param pha lowercase-and-underscores property with type `phandle-array` |
| 3877 | + * @param idx index of the phandle array element |
| 3878 | + * @return name of the element at index @p idx |
| 3879 | + */ |
| 3880 | +#define DT_PHA_ELEM_NAME_BY_IDX(node_id, pha, idx) \ |
| 3881 | + DT_CAT6(node_id, _P_, pha, _IDX_, idx, _NAME) |
| 3882 | + |
| 3883 | +/** |
| 3884 | + * @brief Iterate over all cells in a phandle array element by name |
| 3885 | + * |
| 3886 | + * This macro calls @p fn(cell_value) for each cell value in the |
| 3887 | + * phandle array @p pha element with the given @p name in the *-names property. |
| 3888 | + * |
| 3889 | + * In general, this macro expands to: |
| 3890 | + * |
| 3891 | + * fn(node_id, pha, name, cell[0]) fn(node_id, pha, idx, cell[1]) [...] |
| 3892 | + * fn(node_id, pha, idx, cell[n-1]) |
| 3893 | + * |
| 3894 | + * where `n` is the number of cells in @p pha, as it would be |
| 3895 | + * returned by `DT_PHA_NUM_CELLS_BY_NAME(node_id, pha, name)`, and cell[x] is the NAME of the cell |
| 3896 | + * in the specifier. |
| 3897 | + * |
| 3898 | + * |
| 3899 | + * @param node_id node identifier |
| 3900 | + * @param pha lowercase-and-underscores property with type `phandle-array` |
| 3901 | + * @param name lowercase-and-underscores name of the phandle array element |
| 3902 | + * @param fn macro to call for each cell value |
| 3903 | + */ |
| 3904 | +#define DT_FOREACH_PHA_CELL_BY_NAME(node_id, pha, name, fn) \ |
| 3905 | + DT_CAT6(node_id, _P_, pha, _NAME_, name, _FOREACH_CELL)(fn) |
| 3906 | + |
| 3907 | +/** |
| 3908 | + * @brief Iterate over all cells in a phandle array element by name with separator |
| 3909 | + * |
| 3910 | + * This is like DT_FOREACH_PHA_CELL_BY_NAME(), but @p sep is placed between |
| 3911 | + * each invocation of @p fn. |
| 3912 | + * |
| 3913 | + * @param node_id node identifier |
| 3914 | + * @param pha lowercase-and-underscores property with type `phandle-array` |
| 3915 | + * @param name lowercase-and-underscores name of the phandle array element |
| 3916 | + * @param fn macro to call for each cell value |
| 3917 | + * @param sep separator (e.g. comma or semicolon) |
| 3918 | + */ |
| 3919 | +#define DT_FOREACH_PHA_CELL_BY_NAME_SEP(node_id, pha, name, fn, sep) \ |
| 3920 | + DT_CAT6(node_id, _P_, pha, _NAME_, name, _FOREACH_CELL_SEP)(fn, sep) |
| 3921 | + |
| 3922 | +/** |
| 3923 | + * @brief Get the number of cells in a phandle array element by name |
| 3924 | + * |
| 3925 | + * @param node_id node identifier |
| 3926 | + * @param pha lowercase-and-underscores property with type `phandle-array` |
| 3927 | + * @param name lowercase-and-underscores name of the phandle array element |
| 3928 | + * @return number of cells in the element with the given @p name |
| 3929 | + */ |
| 3930 | +#define DT_PHA_NUM_CELLS_BY_NAME(node_id, pha, name) \ |
| 3931 | + DT_CAT6(node_id, _P_, pha, _NAME_, name, _NUM_CELLS) |
| 3932 | + |
| 3933 | +/** |
| 3934 | + * @brief Get the index of a phandle array element by name |
| 3935 | + * |
| 3936 | + * This returns the index of the @p pha which has the name @p name in the corresponding |
| 3937 | + * *-names property. |
| 3938 | + * |
| 3939 | + * @param node_id node identifier |
| 3940 | + * @param pha lowercase-and-underscores property with type `phandle-array` |
| 3941 | + * @param name lowercase-and-underscores name of the phandle array element |
| 3942 | + * @return index of the element with the given @p name |
| 3943 | + */ |
| 3944 | +#define DT_PHA_ELEM_IDX_BY_NAME(node_id, pha, name) \ |
| 3945 | + DT_CAT6(node_id, _P_, pha, _NAME_, name, _IDX) |
| 3946 | + |
| 3947 | + |
3820 | 3948 | /** |
3821 | 3949 | * @} |
3822 | 3950 | */ |
|
0 commit comments