1
0
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:
Kaspar Schleiser 2020-09-03 10:36:35 +02:00
parent fdaf7fd822
commit 2fbd85b798
4 changed files with 22 additions and 7 deletions

View File

@ -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 */

View File

@ -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",

View File

@ -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;

View File

@ -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);
}