Merge pull request #17284 from fjmolinas/pr_ztimer_no_periph_rtt

sys/ztimer: add 'ztimer_no_periph_rtt'
This commit is contained in:
Alexandre Abadie 2021-12-02 11:02:24 +01:00 committed by GitHub
commit b6cc07009f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 49 additions and 37 deletions

View File

@ -22,6 +22,10 @@
* On many CPUs, certain power states might need to be blocked in rtt_init(), so * On many CPUs, certain power states might need to be blocked in rtt_init(), so
* that it is ensured that the RTT will function properly while it is enabled. * that it is ensured that the RTT will function properly while it is enabled.
* *
* @warning This module will be automatically be used as a backend for
* ZTIMER_SEC and ZTIMER_MSEC. If direct access to RTT is needed
* then include `ztimer_no_periph_rtt` to avoid auto-selection,
* i.e.: `USEMODULE += ztimer_no_periph_rtt`.
* @{ * @{
* @file * @file
* @brief Low-level RTT (Real Time Timer) peripheral driver interface * @brief Low-level RTT (Real Time Timer) peripheral driver interface

View File

@ -197,6 +197,11 @@
* if if these are missing it will use same basic timer * if if these are missing it will use same basic timer
* as ZTIMER_USEC does. * as ZTIMER_USEC does.
* *
* If `periph_rtt` is required with direct access by another MODULE or
* application, `ztimer_no_periph_rtt` can be included to avoid automatic
* selection of `ztimer_periph_rtt` as a backend for ZTIMER_SEC and ZTIMER_MSEC.
* i.e.: `USEMODULE += ztimer_no_periph_rtt`.
*
* These pointers are defined in `ztimer.h` and can be used like this: * These pointers are defined in `ztimer.h` and can be used like this:
* *
* ztimer_now(ZTIMER_USEC); * ztimer_now(ZTIMER_USEC);

View File

@ -10,6 +10,12 @@ menu "ztimer - High level timer abstraction layer"
config ZTIMER_CUSTOM_BACKEND_CONFIGURATION config ZTIMER_CUSTOM_BACKEND_CONFIGURATION
bool "Override default backend selection" bool "Override default backend selection"
config MODULE_ZTIMER_NO_PERIPH_RTT
bool "Disable ztimer_periph_rtt auto-inclusion"
help
This module disables the auto-inclusion of ztimer_periph_rtt as a backend
for ztimer_msec and ztimer_sec.
menu "Backends" menu "Backends"
visible if ZTIMER_CUSTOM_BACKEND_CONFIGURATION visible if ZTIMER_CUSTOM_BACKEND_CONFIGURATION
@ -56,7 +62,7 @@ config MODULE_ZTIMER_MSEC
choice choice
bool "Backend" bool "Backend"
depends on MODULE_ZTIMER_MSEC depends on MODULE_ZTIMER_MSEC
default ZTIMER_MSEC_BACKEND_RTT default ZTIMER_MSEC_BACKEND_RTT if !MODULE_ZTIMER_NO_PERIPH_RTT
config ZTIMER_MSEC_BACKEND_TIMER config ZTIMER_MSEC_BACKEND_TIMER
bool "Timer" bool "Timer"
@ -85,7 +91,7 @@ config ZTIMER_SEC_BACKEND_TIMER
config ZTIMER_SEC_BACKEND_RTT config ZTIMER_SEC_BACKEND_RTT
bool "RTT" bool "RTT"
depends on HAS_PERIPH_RTT depends on HAS_PERIPH_RTT
select MODULE_ZTIMER_PERIPH_RTT select MODULE_ZTIMER_PERIPH_RTT if !MODULE_ZTIMER_NO_PERIPH_RTT
config ZTIMER_SEC_BACKEND_RTC config ZTIMER_SEC_BACKEND_RTC
bool "RTC" bool "RTC"

View File

@ -78,8 +78,9 @@ ifneq (,$(filter ztimer_usec,$(USEMODULE)))
USEMODULE += ztimer_periph_timer USEMODULE += ztimer_periph_timer
endif endif
ifneq (,$(filter ztimer_msec,$(USEMODULE))) ifneq (,$(filter ztimer_msec ztimer_sec,$(USEMODULE)))
USEMODULE += ztimer USEMODULE += ztimer
ifeq (,$(filter ztimer_no_periph_rtt,$(USEMODULE)))
FEATURES_OPTIONAL += periph_rtt FEATURES_OPTIONAL += periph_rtt
# HACK: periph_rtt will get used only in the next iteration but an updated # HACK: periph_rtt will get used only in the next iteration but an updated
# state for FEATURES_USED is needed here so include `features_check.inc.mk` # state for FEATURES_USED is needed here so include `features_check.inc.mk`
@ -98,15 +99,5 @@ ifneq (,$(filter ztimer_msec,$(USEMODULE)))
else else
USEMODULE += ztimer_periph_timer USEMODULE += ztimer_periph_timer
endif endif
endif
ifneq (,$(filter ztimer_sec,$(USEMODULE)))
USEMODULE += ztimer
FEATURES_OPTIONAL += periph_rtt
# HACK: see above
ifneq (,$(filter periph_rtt,$(FEATURES_USED)))
USEMODULE += ztimer_periph_rtt
else
USEMODULE += ztimer_periph_timer
endif endif
endif endif

View File

@ -4,6 +4,8 @@ ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
PSEUDOMODULES += xtimer PSEUDOMODULES += xtimer
endif endif
MODULES_ZTIMER_ON_RTT_CONFLICT = rtt_rtc gnrc_lwmac gnrc_gomach
# By defaul use highest possible RTT_FREQUENCY for platforms that allow it. This # By defaul use highest possible RTT_FREQUENCY for platforms that allow it. This
# might not be the most optimized for conversion guarantees that ztimer_periph_rtt # might not be the most optimized for conversion guarantees that ztimer_periph_rtt
# will have a capable backend. # will have a capable backend.
@ -12,4 +14,10 @@ ifneq (,$(filter ztimer_periph_rtt,$(USEMODULE)))
RTT_FREQUENCY ?= RTT_MAX_FREQUENCY RTT_FREQUENCY ?= RTT_MAX_FREQUENCY
CFLAGS += -DRTT_FREQUENCY=$(RTT_FREQUENCY) CFLAGS += -DRTT_FREQUENCY=$(RTT_FREQUENCY)
endif endif
MODULES_ZTIMER_ON_RTT_CONFLICTING = $(filter $(MODULES_ZTIMER_ON_RTT_CONFLICT),$(USEMODULE))
ifneq (0,$(words $(MODULES_ZTIMER_ON_RTT_CONFLICTING)))
$(info $(COLOR_YELLOW)WARNING! The following modules conflict with 'ztimer_periph_rtt': '$(MODULES_ZTIMER_ON_RTT_CONFLICTING)')
$(info To disable ztimer periph_rtt auto-inclusion add 'ztimer_no_periph_rtt' to 'USEMODULE'$(COLOR_RESET))
endif
endif endif

View File

@ -2,10 +2,10 @@ include ../Makefile.tests_common
USEMODULE += ztimer_usec USEMODULE += ztimer_usec
# uncomment this to test using ztimer msec on rtt # uncomment this to test using ztimer msec
#USEMODULE += ztimer_msec ztimer_periph_rtt #USEMODULE += ztimer_msec
# uncomment this to test using ztimer sec on rtc # uncomment this to test using ztimer sec
#USEMODULE += ztimer_sec ztimer_periph_rtc #USEMODULE += ztimer_sec
include $(RIOTBASE)/Makefile.include include $(RIOTBASE)/Makefile.include

View File

@ -6,7 +6,6 @@ USEMODULE += ztimer
USEMODULE += ztimer_usec USEMODULE += ztimer_usec
ifeq ($(TEST_ZTIMER_CLOCK), ZTIMER_MSEC) ifeq ($(TEST_ZTIMER_CLOCK), ZTIMER_MSEC)
USEMODULE += ztimer_msec USEMODULE += ztimer_msec
USEMODULE += ztimer_periph_rtt
# the same for Kconfig # the same for Kconfig
ifeq (1,$(TEST_KCONFIG)) ifeq (1,$(TEST_KCONFIG))
KCONFIG_ADD_CONFIG += $(APPDIR)/app.config.msec.test KCONFIG_ADD_CONFIG += $(APPDIR)/app.config.msec.test
@ -14,7 +13,6 @@ ifeq ($(TEST_ZTIMER_CLOCK), ZTIMER_MSEC)
endif endif
ifeq ($(TEST_ZTIMER_CLOCK), ZTIMER_SEC) ifeq ($(TEST_ZTIMER_CLOCK), ZTIMER_SEC)
USEMODULE += ztimer_sec USEMODULE += ztimer_sec
USEMODULE += ztimer_periph_rtc
endif endif
CFLAGS += -DTEST_ZTIMER_CLOCK=$(TEST_ZTIMER_CLOCK) CFLAGS += -DTEST_ZTIMER_CLOCK=$(TEST_ZTIMER_CLOCK)