From 9a73b9c80dfa13755c0bed340045b696650d2f53 Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Fri, 17 Mar 2023 11:20:33 +0100 Subject: [PATCH] hal_nordic: Change scheme for RTC and TIMER reservation In general, RTC and TIMER driver implements counter API but there are exception when those peripherals are used in a custom way (e.g. for system timer or bluetooth). In that case, system must prevent using counter based on a reserved instance. Previously, it was managed by Kconfig options but that cannot be maintained when switching to devicetree configuration of the counter driver. A new approach removes Kconfig options and instead adds static asserts in the files which are using direct peripherals. Those asserts check if given node is not enabled in the device tree. Signed-off-by: Krzysztof Chruscinski --- drivers/timer/Kconfig.nrf_rtc | 1 - drivers/timer/nrf_rtc_timer.c | 3 +++ modules/hal_nordic/Kconfig | 1 - .../radio/platform/nrf_802154_random_zephyr.c | 4 +++ soc/arm/nordic_nrf/Kconfig.peripherals | 25 ------------------- subsys/bluetooth/controller/Kconfig | 2 -- .../ll_sw/nordic/hal/nrf5/radio/radio.c | 4 +++ .../nordic/hal/nrf5/radio/radio_sim_nrfxx.h | 3 +++ 8 files changed, 14 insertions(+), 29 deletions(-) diff --git a/drivers/timer/Kconfig.nrf_rtc b/drivers/timer/Kconfig.nrf_rtc index 853af3a0958..f332113c00a 100644 --- a/drivers/timer/Kconfig.nrf_rtc +++ b/drivers/timer/Kconfig.nrf_rtc @@ -8,7 +8,6 @@ config NRF_RTC_TIMER depends on CLOCK_CONTROL depends on SOC_COMPATIBLE_NRF select TICKLESS_CAPABLE - select NRF_HW_RTC1_RESERVED help This module implements a kernel device driver for the nRF Real Time Counter NRF_RTC1 and provides the standard "system clock driver" diff --git a/drivers/timer/nrf_rtc_timer.c b/drivers/timer/nrf_rtc_timer.c index 870b3f2819e..bef69af38bd 100644 --- a/drivers/timer/nrf_rtc_timer.c +++ b/drivers/timer/nrf_rtc_timer.c @@ -25,6 +25,9 @@ #define RTC_CH_COUNT RTC1_CC_NUM BUILD_ASSERT(CHAN_COUNT <= RTC_CH_COUNT, "Not enough compare channels"); +/* Ensure that counter driver for RTC1 is not enabled. */ +BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(RTC_LABEL), disabled), + "Counter for RTC1 must be disabled"); #define COUNTER_BIT_WIDTH 24U #define COUNTER_SPAN BIT(COUNTER_BIT_WIDTH) diff --git a/modules/hal_nordic/Kconfig b/modules/hal_nordic/Kconfig index 0e904c66069..092ecd07a7b 100644 --- a/modules/hal_nordic/Kconfig +++ b/modules/hal_nordic/Kconfig @@ -23,7 +23,6 @@ menuconfig NRF_802154_RADIO_DRIVER depends on HAS_HW_NRF_RADIO_IEEE802154 select DYNAMIC_INTERRUPTS select ENTROPY_GENERATOR - select NRF_HW_TIMER1_RESERVED help This option enables nRF IEEE 802.15.4 radio driver in Zephyr. Note, that beside the radio peripheral itself, this drivers occupies several diff --git a/modules/hal_nordic/nrf_802154/radio/platform/nrf_802154_random_zephyr.c b/modules/hal_nordic/nrf_802154/radio/platform/nrf_802154_random_zephyr.c index 7645601343b..6b78cd6198b 100644 --- a/modules/hal_nordic/nrf_802154/radio/platform/nrf_802154_random_zephyr.c +++ b/modules/hal_nordic/nrf_802154/radio/platform/nrf_802154_random_zephyr.c @@ -8,6 +8,10 @@ #include #include +/* Ensure that counter driver for TIMER1 is not enabled. */ +BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(timer1), disabled), + "Counter for TIMER1 must be disabled"); + static uint32_t state; static uint32_t next(void) diff --git a/soc/arm/nordic_nrf/Kconfig.peripherals b/soc/arm/nordic_nrf/Kconfig.peripherals index f5ae9041b6e..de3da1f9b7d 100644 --- a/soc/arm/nordic_nrf/Kconfig.peripherals +++ b/soc/arm/nordic_nrf/Kconfig.peripherals @@ -299,28 +299,3 @@ config HAS_HW_NRF_WDT0 config HAS_HW_NRF_WDT1 def_bool $(dt_nodelabel_enabled_with_compat,wdt1,$(DT_COMPAT_NORDIC_NRF_WDT)) - -# Reserved HW peripherals -config NRF_HW_TIMER0_RESERVED - bool - -config NRF_HW_TIMER1_RESERVED - bool - -config NRF_HW_TIMER2_RESERVED - bool - -config NRF_HW_TIMER3_RESERVED - bool - -config NRF_HW_TIMER4_RESERVED - bool - -config NRF_HW_RTC0_RESERVED - bool - -config NRF_HW_RTC1_RESERVED - bool - -config NRF_HW_RTC2_RESERVED - bool diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig index 63c7b83bc3f..ef792cf0fb8 100644 --- a/subsys/bluetooth/controller/Kconfig +++ b/subsys/bluetooth/controller/Kconfig @@ -108,8 +108,6 @@ choice BT_LL_CHOICE config BT_LL_SW_SPLIT bool "Software-based BLE Link Layer" select ENTROPY_GENERATOR - select NRF_HW_TIMER0_RESERVED - select NRF_HW_RTC0_RESERVED help Use Zephyr software BLE Link Layer ULL LLL split implementation. diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c index 1af23246bd6..85dcf4ec3f9 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c @@ -29,6 +29,10 @@ #include "radio_internal.h" +/* Ensure that counter driver for RTC0 is not enabled. */ +BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(rtc0), disabled), + "Counter for RTC0 must be disabled"); + /* Converts the GPIO controller in a FEM property's GPIO specification * to its nRF register map pointer. * diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrfxx.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrfxx.h index 317638eeabf..3090ee09cf1 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrfxx.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrfxx.h @@ -187,6 +187,9 @@ #if defined(CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER) #undef EVENT_TIMER #define EVENT_TIMER NRF_TIMER0 +/* Ensure that counter driver for TIMER0 is not enabled. */ +BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(timer0), disabled), + "Counter for TIMER0 must be disabled"); #define SW_SWITCH_TIMER EVENT_TIMER #define SW_SWITCH_TIMER_EVTS_COMP_BASE 0 #else /* !CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER */