From df520a70a7fb0611f84ab9fad826ec3efc328382 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 27 Jan 2020 15:28:33 +0100 Subject: [PATCH] sys/evtimer: make use of xtimer_left_usec() --- sys/evtimer/evtimer.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/sys/evtimer/evtimer.c b/sys/evtimer/evtimer.c index aabff9fafc..3c9e13973b 100644 --- a/sys/evtimer/evtimer.c +++ b/sys/evtimer/evtimer.c @@ -114,20 +114,9 @@ static void _update_timer(evtimer_t *evtimer) static uint32_t _get_offset(xtimer_t *timer) { - uint64_t now_us = xtimer_now_usec64(); - uint64_t start_us = _xtimer_usec_from_ticks64( - ((uint64_t)timer->long_start_time << 32) | timer->start_time); - uint64_t target_us = start_us + _xtimer_usec_from_ticks64( - ((uint64_t)timer->long_offset) << 32 | timer->offset); - - if (target_us <= now_us) { - return 0; - } - else { - target_us -= now_us; - /* add half of 125 so integer division rounds to nearest */ - return div_u64_by_125((target_us >> 3) + 62); - } + uint64_t left = xtimer_left_usec(timer); + /* add half of 125 so integer division rounds to nearest */ + return div_u64_by_125((left >> 3) + 62); } static void _update_head_offset(evtimer_t *evtimer)