mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/ztimer: allow compensation of ztimer_sleep() overhead
This commit is contained in:
parent
fdaf7fd822
commit
2fbd85b798
@ -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 */
|
||||
|
@ -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",
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user