From 904dc0131f991efa538d2068ba65792d39f9fee3 Mon Sep 17 00:00:00 2001 From: Jue Date: Wed, 2 Feb 2022 17:31:28 +0100 Subject: [PATCH] ztimer: don't interact with pm_layered if ztimer_ondemand is used --- sys/include/ztimer.h | 5 +++-- sys/ztimer/Kconfig | 6 ++++++ sys/ztimer/convert.c | 2 +- sys/ztimer/convert_frac.c | 2 +- sys/ztimer/core.c | 8 ++++---- sys/ztimer/init.c | 8 ++++---- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/sys/include/ztimer.h b/sys/include/ztimer.h index 79847799c8..8fb597ec9b 100644 --- a/sys/include/ztimer.h +++ b/sys/include/ztimer.h @@ -379,8 +379,9 @@ struct ztimer_clock { uint32_t lower_last; /**< timer value at last now() call */ ztimer_now_t checkpoint; /**< cumulated time at last now() call */ #endif -#if MODULE_PM_LAYERED || DOXYGEN - uint8_t block_pm_mode; /**< min. pm mode to block for the clock to run */ +#if MODULE_PM_LAYERED && !MODULE_ZTIMER_ONDEMAND || DOXYGEN + uint8_t block_pm_mode; /**< min. pm mode to block for the clock to run + don't use in combination with ztimer_ondemand! */ #endif }; diff --git a/sys/ztimer/Kconfig b/sys/ztimer/Kconfig index 6fb51d7aab..a44ba5b306 100644 --- a/sys/ztimer/Kconfig +++ b/sys/ztimer/Kconfig @@ -228,6 +228,12 @@ config MODULE_ZTIMER_MOCK manually fired to simulate different scenarios and test the ztimer implementation using this as a backing timer. +config MODULE_ZTIMER_ONDEMAND + bool "Run ztimer clocks only on demand" + help + This ztimer extensions keeps track of ztimer users and may disable + underlying peripherals if not users are requiring a ztimer clock. + config MODULE_ZTIMER_INIT bool diff --git a/sys/ztimer/convert.c b/sys/ztimer/convert.c index 921a478155..27ef678716 100644 --- a/sys/ztimer/convert.c +++ b/sys/ztimer/convert.c @@ -46,7 +46,7 @@ void ztimer_convert_init(ztimer_convert_t *ztimer_convert, .arg = ztimer_convert, }, .super.max_value = max_value, -# ifdef MODULE_PM_LAYERED +# if MODULE_PM_LAYERED && !MODULE_ZTIMER_ONDEMAND .super.block_pm_mode = ZTIMER_CLOCK_NO_REQUIRED_PM_MODE, # endif }; diff --git a/sys/ztimer/convert_frac.c b/sys/ztimer/convert_frac.c index 0d3dc66ecd..fcb8535e52 100644 --- a/sys/ztimer/convert_frac.c +++ b/sys/ztimer/convert_frac.c @@ -111,7 +111,7 @@ void ztimer_convert_frac_init(ztimer_convert_frac_t *self, self->round = freq_self / freq_lower; self->super.super.max_value = UINT32_MAX; } -#ifdef MODULE_PM_LAYERED +#if MODULE_PM_LAYERED && !MODULE_ZTIMER_ONDEMAND self->super.super.block_pm_mode = ZTIMER_CLOCK_NO_REQUIRED_PM_MODE; #endif } diff --git a/sys/ztimer/core.c b/sys/ztimer/core.c index e415f49fce..824b6f6a53 100644 --- a/sys/ztimer/core.c +++ b/sys/ztimer/core.c @@ -28,7 +28,7 @@ #include "kernel_defines.h" #include "irq.h" -#ifdef MODULE_PM_LAYERED +#if MODULE_PM_LAYERED && !MODULE_ZTIMER_ONDEMAND #include "pm_layered.h" #endif #include "ztimer.h" @@ -127,7 +127,7 @@ static void _add_entry_to_list(ztimer_clock_t *clock, ztimer_base_t *entry) ztimer_base_t *list = &clock->list; -#ifdef MODULE_PM_LAYERED +#if MODULE_PM_LAYERED && !MODULE_ZTIMER_ONDEMAND /* First timer on the clock's linked list */ if (list->next == NULL && clock->block_pm_mode != ZTIMER_CLOCK_NO_REQUIRED_PM_MODE) { @@ -266,7 +266,7 @@ static bool _del_entry_from_list(ztimer_clock_t *clock, ztimer_base_t *entry) list = list->next; } -#ifdef MODULE_PM_LAYERED +#if MODULE_PM_LAYERED && !MODULE_ZTIMER_ONDEMAND /* The last timer just got removed from the clock's linked list */ if (clock->list.next == NULL && clock->block_pm_mode != ZTIMER_CLOCK_NO_REQUIRED_PM_MODE) { @@ -286,7 +286,7 @@ static ztimer_t *_now_next(ztimer_clock_t *clock) if (!entry->next) { /* The last timer just got removed from the clock's linked list */ clock->last = NULL; -#ifdef MODULE_PM_LAYERED +#if MODULE_PM_LAYERED && !MODULE_ZTIMER_ONDEMAND if (clock->block_pm_mode != ZTIMER_CLOCK_NO_REQUIRED_PM_MODE) { pm_unblock(clock->block_pm_mode); } diff --git a/sys/ztimer/init.c b/sys/ztimer/init.c index 3b652211a8..ca6c262cf5 100644 --- a/sys/ztimer/init.c +++ b/sys/ztimer/init.c @@ -292,7 +292,7 @@ void ztimer_init(void) CONFIG_ZTIMER_USEC_WIDTH); ztimer_periph_timer_init(&ZTIMER_TIMER, CONFIG_ZTIMER_USEC_DEV, ZTIMER_TIMER_FREQ, WIDTH_TO_MAXVAL(CONFIG_ZTIMER_USEC_WIDTH)); -# ifdef MODULE_PM_LAYERED +# if MODULE_PM_LAYERED && !MODULE_ZTIMER_ONDEMAND LOG_DEBUG("ztimer_init(): ZTIMER_TIMER setting block_pm_mode to %i\n", CONFIG_ZTIMER_TIMER_BLOCK_PM_MODE); ZTIMER_TIMER_CLK.block_pm_mode = CONFIG_ZTIMER_TIMER_BLOCK_PM_MODE; @@ -306,7 +306,7 @@ void ztimer_init(void) CONFIG_ZTIMER_LPTIMER_WIDTH); ztimer_periph_timer_init(&ZTIMER_LPTIMER, CONFIG_ZTIMER_LPTIMER_DEV, ZTIMER_LPTIMER_FREQ, WIDTH_TO_MAXVAL(CONFIG_ZTIMER_LPTIMER_WIDTH)); -# ifdef MODULE_PM_LAYERED +# if MODULE_PM_LAYERED && !MODULE_ZTIMER_ONDEMAND LOG_DEBUG("ztimer_init(): ZTIMER_LPTIMER setting block_pm_mode to %i\n", CONFIG_ZTIMER_LPTIMER_BLOCK_PM_MODE); ZTIMER_LPTIMER_CLK.block_pm_mode = CONFIG_ZTIMER_LPTIMER_BLOCK_PM_MODE; @@ -316,7 +316,7 @@ void ztimer_init(void) #if INIT_ZTIMER_RTT LOG_DEBUG("ztimer_init(): initializing rtt\n"); ztimer_periph_rtt_init(&ZTIMER_RTT); -# ifdef MODULE_PM_LAYERED +# if MODULE_PM_LAYERED && !MODULE_ZTIMER_ONDEMAND LOG_DEBUG("ztimer_init(): ZTIMER_RTT setting block_pm_mode to %i\n", CONFIG_ZTIMER_RTT_BLOCK_PM_MODE); ZTIMER_RTT_CLK.block_pm_mode = CONFIG_ZTIMER_RTT_BLOCK_PM_MODE; @@ -326,7 +326,7 @@ void ztimer_init(void) #if INIT_ZTIMER_RTC LOG_DEBUG("ztimer_init(): initializing rtc\n"); ztimer_periph_rtc_init(&ZTIMER_RTC); -# ifdef MODULE_PM_LAYERED +# if MODULE_PM_LAYERED && !MODULE_ZTIMER_ONDEMAND LOG_DEBUG("ztimer_init(): ZTIMER_RTC setting block_pm_mode to %i\n", CONFIG_ZTIMER_RTC_BLOCK_PM_MODE); ZTIMER_RTC_CLK.block_pm_mode = CONFIG_ZTIMER_RTC_BLOCK_PM_MODE;