modules: hal_nordic: Use common nrfx_config section for GRTC

Move code that prepares `NRFX_CONFIG_GRTC_*` definitions based on
information from devicetree from the nRF54L15 nrfx_config header
to the global one, so that the code can be used by nRF54H20, too.

The checks that validate owned-channels and child-owned-channels
DT properties are moved to the nrf_grtc_timer driver so that
the global nrfx_config is not polluted unnecessarily.

The default values in nrfx_config_nrf54l15_enga_application.h
are restored to those from the corresponding template file.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
This commit is contained in:
Andrzej Głąbek 2024-02-01 09:40:57 +01:00 committed by Carles Cufí
parent 2efd34bda3
commit 139b97a64a
3 changed files with 43 additions and 28 deletions

View file

@ -13,6 +13,18 @@
#include <nrfx_grtc.h>
#include <zephyr/sys/math_extras.h>
#define GRTC_NODE DT_NODELABEL(grtc)
/* Ensure that GRTC properties in devicetree are defined correctly. */
#if !DT_NODE_HAS_PROP(GRTC_NODE, owned_channels)
#error GRTC owned-channels DT property is not defined
#endif
#define OWNED_CHANNELS_MASK NRFX_CONFIG_GRTC_MASK_DT(owned_channels)
#define CHILD_OWNED_CHANNELS_MASK NRFX_CONFIG_GRTC_MASK_DT(child_owned_channels)
#if ((OWNED_CHANNELS_MASK | CHILD_OWNED_CHANNELS_MASK) != OWNED_CHANNELS_MASK)
#error GRTC child-owned-channels DT property must be a subset of owned-channels
#endif
#define CHAN_COUNT NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS
#define EXT_CHAN_COUNT (CHAN_COUNT - 1)
/* The reset value of waketime is 1, which doesn't seem to work.
@ -22,8 +34,6 @@
#define WAKETIME (4)
#define TIMEOUT (WAKETIME + 1)
#define GRTC_NODE DT_NODELABEL(grtc)
#ifndef GRTC_SYSCOUNTERL_VALUE_Msk
#define GRTC_SYSCOUNTERL_VALUE_Msk GRTC_SYSCOUNTER_SYSCOUNTERL_VALUE_Msk
#endif

View file

@ -675,6 +675,27 @@
#define NRF_PERIPH(P) P##_S
#endif
/* If the GRTC system timer driver is to be used, prepare definitions required
* by the nrfx_grtc driver (NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK and
* NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS) based on information from devicetree.
*/
#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_grtc)
#define NRFX_CONFIG_BIT_DT(node_id, prop, idx) \
BIT(DT_PROP_BY_IDX(node_id, prop, idx))
#define NRFX_CONFIG_GRTC_MASK_DT(prop) \
(COND_CODE_1(DT_NODE_HAS_PROP(DT_INST(0, nordic_nrf_grtc), prop), \
(DT_FOREACH_PROP_ELEM_SEP(DT_INST(0, nordic_nrf_grtc), prop, \
NRFX_CONFIG_BIT_DT, (|))), \
(0)))
#define NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK \
(NRFX_CONFIG_GRTC_MASK_DT(owned_channels) & \
~NRFX_CONFIG_GRTC_MASK_DT(child_owned_channels))
#define NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS \
(DT_PROP_LEN_OR(DT_INST(0, nordic_nrf_grtc), owned_channels, 0) - \
DT_PROP_LEN_OR(DT_INST(0, nordic_nrf_grtc), child_owned_channels, 0))
#endif /* DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_grtc) */
#include <nrfx_config_common.h>
#if defined(NRF51)
#include <nrfx_config_nrf51.h>

View file

@ -249,37 +249,21 @@
#define NRFX_GRTC_ENABLED 0
#endif
/**
* @brief NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS
*
* Integer value.
*/
#ifndef NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS
#define NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS 11
#endif
/**
* @brief GRTC CC channels ownership mask.
*/
#ifndef NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK
#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_grtc)
#if DT_NODE_HAS_PROP(DT_INST(0, nordic_nrf_grtc), owned_channels)
#define NRFX_CONFIG_BIT_DT(node_id, prop, idx) \
BIT(DT_PROP_BY_IDX(node_id, prop, idx))
#define NRFX_CONFIG_GRTC_MASK_DT(prop) \
(COND_CODE_1(DT_NODE_HAS_PROP(DT_INST(0, nordic_nrf_grtc), prop), \
(DT_FOREACH_PROP_ELEM_SEP(DT_INST(0, nordic_nrf_grtc), prop, \
NRFX_CONFIG_BIT_DT, (|))), \
(0)))
#define NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK \
(NRFX_CONFIG_GRTC_MASK_DT(owned_channels) & \
~NRFX_CONFIG_GRTC_MASK_DT(child_owned_channels))
#define NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS \
(DT_PROP_LEN_OR(DT_INST(0, nordic_nrf_grtc), owned_channels, 0) - \
DT_PROP_LEN_OR(DT_INST(0, nordic_nrf_grtc), child_owned_channels, 0))
#if ((NRFX_CONFIG_GRTC_MASK_DT(owned_channels) | \
NRFX_CONFIG_GRTC_MASK_DT(child_owned_channels)) != NRFX_CONFIG_GRTC_MASK_DT(owned_channels))
#error "`child-owned-channels` property must be a subset of `owned-channels` property"
#define NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK 0x000007ff
#endif
#else
#error "property `owned-channels` does not exist"
#endif /* DT_NODE_HAS_PROP(DT_INST(0, nordic_nrf_grtc), owned_channels) */
#endif /* DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_grtc) */
#endif /* NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK */
/**
* @brief NRFX_GRTC_DEFAULT_CONFIG_IRQ_PRIORITY