mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #14936 from kaspar030/ztimer_sleep_adjust
sys/ztimer: allow compensation of ztimer_sleep() overhead
This commit is contained in:
commit
f3a5ee69e0
@ -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);
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ def testfunc(child):
|
||||
sleep_time = int(child.match.group(1))
|
||||
exp = int(child.match.group(2))
|
||||
upper_bound = exp + (exp * INTERNAL_JITTER)
|
||||
if not (exp < sleep_time < upper_bound):
|
||||
if not (exp <= sleep_time < upper_bound):
|
||||
delta = (upper_bound-exp)
|
||||
error = min(upper_bound-sleep_time, sleep_time-exp)
|
||||
raise InvalidTimeout("Invalid timeout %d, expected %d < timeout < %d"
|
||||
|
@ -37,8 +37,8 @@ int main(void)
|
||||
int32_t max = INT32_MIN;
|
||||
|
||||
/* unset configured adjustment */
|
||||
/* ZTIMER_USEC->adjust = 0; */
|
||||
printf("ZTIMER_USEC->adjust = %" PRIu32 "\n", ZTIMER_USEC->adjust);
|
||||
/* ZTIMER_USEC->adjust_set = 0; */
|
||||
printf("ZTIMER_USEC->adjust_set = %" PRIu16 "\n", ZTIMER_USEC->adjust_set);
|
||||
|
||||
unsigned n = SAMPLES;
|
||||
while (n--) {
|
||||
|
Loading…
Reference in New Issue
Block a user