From 82d126158e48362ec2845cbc79777e024d53f9f9 Mon Sep 17 00:00:00 2001 From: josar Date: Wed, 14 Nov 2018 00:46:30 +0100 Subject: [PATCH] test/xtimer_hang: use xtimer_periodic_wakeup When sleeping in the main function with xtimer_sleep not every percentage will be printed as the sleep duration and the processing time added do not result in full percentage values. Using xtimer_periodic_wakeup ensures that every integer percentage is printed. --- tests/xtimer_hang/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/xtimer_hang/main.c b/tests/xtimer_hang/main.c index f661dddd81c8..5aeb1f59e045 100644 --- a/tests/xtimer_hang/main.c +++ b/tests/xtimer_hang/main.c @@ -78,13 +78,16 @@ int main(void) uint32_t now = 0; uint32_t start = xtimer_now_usec(); uint32_t until = start + (TEST_TIME_S * US_PER_SEC); + uint32_t interval = TEST_INTERVAL_MS * US_PER_MS; + xtimer_ticks32_t last_wakeup = xtimer_now(); + puts("[START]"); while((now = xtimer_now_usec()) < until) { unsigned percent = (100 * (now - start)) / (until - start); #if defined(MAIN_THREAD_PIN) gpio_set(main_pin); #endif - xtimer_usleep(TEST_INTERVAL_MS * US_PER_MS); + xtimer_periodic_wakeup(&last_wakeup, interval); #if defined(MAIN_THREAD_PIN) gpio_clear(main_pin); #endif