diff --git a/sys/include/ztimer.h b/sys/include/ztimer.h index 32c0a1fb2a..e17f78f227 100644 --- a/sys/include/ztimer.h +++ b/sys/include/ztimer.h @@ -295,7 +295,9 @@ struct ztimer_clock { ztimer_base_t list; /**< list of active timers */ const ztimer_ops_t *ops; /**< pointer to methods structure */ ztimer_base_t *last; /**< last timer in queue, for _is_set() */ - uint32_t adjust; /**< will be subtracted on every set() */ + uint16_t adjust_set; /**< will be subtracted on every set() */ + uint16_t adjust_sleep; /**< will be subtracted on every sleep(), + in addition to adjust_set */ #if MODULE_ZTIMER_EXTEND || MODULE_ZTIMER_NOW64 || DOXYGEN /* values used for checkpointed intervals and 32bit extension */ uint32_t max_value; /**< maximum relative timer value */ diff --git a/sys/ztimer/auto_init.c b/sys/ztimer/auto_init.c index 489b86ac93..a2bca399af 100644 --- a/sys/ztimer/auto_init.c +++ b/sys/ztimer/auto_init.c @@ -125,10 +125,15 @@ void ztimer_init(void) FREQ_1MHZ, CONFIG_ZTIMER_USEC_BASE_FREQ); # endif # endif -# ifdef CONFIG_ZTIMER_USEC_ADJUST - LOG_DEBUG("ztimer_init(): ZTIMER_USEC setting adjust value to %i\n", - CONFIG_ZTIMER_USEC_ADJUST); - ZTIMER_USEC->adjust = CONFIG_ZTIMER_USEC_ADJUST; +# ifdef CONFIG_ZTIMER_USEC_ADJUST_SET + LOG_DEBUG("ztimer_init(): ZTIMER_USEC setting adjust_set value to %i\n", + CONFIG_ZTIMER_USEC_ADJUST_SET ); + ZTIMER_USEC->adjust_set = CONFIG_ZTIMER_USEC_ADJUST_SET; +# endif +# ifdef CONFIG_ZTIMER_USEC_ADJUST_SLEEP + LOG_DEBUG("ztimer_init(): ZTIMER_USEC setting adjust_sleep value to %i\n", + CONFIG_ZTIMER_USEC_ADJUST_SLEEP ); + ZTIMER_USEC->adjust_sleep = CONFIG_ZTIMER_USEC_ADJUST_SLEEP; # endif # ifdef MODULE_PM_LAYERED LOG_DEBUG("ztimer_init(): ZTIMER_USEC setting required_pm_mode to %i\n", diff --git a/sys/ztimer/core.c b/sys/ztimer/core.c index 5e333d7d15..2230f0cfc6 100644 --- a/sys/ztimer/core.c +++ b/sys/ztimer/core.c @@ -84,8 +84,8 @@ void ztimer_set(ztimer_clock_t *clock, ztimer_t *timer, uint32_t val) } /* optionally subtract a configurable adjustment value */ - if (val > clock->adjust) { - val -= clock->adjust; + if (val > clock->adjust_set) { + val -= clock->adjust_set; } else { val = 0; diff --git a/sys/ztimer/util.c b/sys/ztimer/util.c index e8074f6ebf..0a8fb9b2cf 100644 --- a/sys/ztimer/util.c +++ b/sys/ztimer/util.c @@ -51,6 +51,14 @@ void ztimer_sleep(ztimer_clock_t *clock, uint32_t duration) .arg = (void *)&mutex, }; + /* correct board / MCU specific overhead */ + if (duration > clock->adjust_sleep) { + duration -= clock->adjust_sleep; + } + else { + duration = 0; + } + ztimer_set(clock, &timer, duration); mutex_lock(&mutex); }