From 6f75dff1de2d23d9c7a7391fe73dddf81d086587 Mon Sep 17 00:00:00 2001 From: Josarn Date: Wed, 11 Apr 2018 15:27:26 +0200 Subject: [PATCH] evtimer: bug ms vs ticks resolved --- sys/evtimer/evtimer.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sys/evtimer/evtimer.c b/sys/evtimer/evtimer.c index 4adfd42637..f920ec7472 100644 --- a/sys/evtimer/evtimer.c +++ b/sys/evtimer/evtimer.c @@ -1,6 +1,7 @@ /* * Copyright (C) 2016-17 Kaspar Schleiser * 2017 Freie Universität Berlin + * 2018 Josua Arndt * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -16,6 +17,7 @@ * * @author Kaspar Schleiser * @author Martine Lenders + * @author Josua Arndt * * @} */ @@ -102,16 +104,17 @@ static void _update_timer(evtimer_t *evtimer) static uint32_t _get_offset(xtimer_t *timer) { - uint64_t now = xtimer_now_usec64(); - uint64_t target = ((uint64_t)timer->long_target) << 32 | timer->target; + uint64_t now_us = xtimer_now_usec64(); + uint64_t target_us = _xtimer_usec_from_ticks64( + ((uint64_t)timer->long_target) << 32 | timer->target); - if (target <= now) { + if (target_us <= now_us) { return 0; } else { - target -= now; + target_us -= now_us; /* add half of 125 so integer division rounds to nearest */ - return div_u64_by_125((target >> 3) + 62); + return div_u64_by_125((target_us >> 3) + 62); } }