From fdb2baa10a02a29c44c209897527e84d2fc78349 Mon Sep 17 00:00:00 2001 From: Josarn <josuaarndt@live.de> Date: Tue, 24 Jul 2018 02:04:12 +0200 Subject: [PATCH] test/xtimer_drift: interval calculation --- tests/xtimer_drift/main.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/xtimer_drift/main.c b/tests/xtimer_drift/main.c index 814800e575..dcdfa77c8c 100644 --- a/tests/xtimer_drift/main.c +++ b/tests/xtimer_drift/main.c @@ -91,6 +91,10 @@ void *worker_thread(void *arg) { (void) arg; + /* Calculate interval based on possible precision when 'XTIMER_SHIFT > 0', + * to apply precision loss to expected interval length. + * test_interval != TEST_INTERVAL */ + uint32_t test_interval = xtimer_usec_from_ticks(xtimer_ticks_from_usec(TEST_INTERVAL)); uint32_t loop_counter = 0; uint32_t start = 0; uint32_t last = 0; @@ -111,14 +115,14 @@ void *worker_thread(void *arg) else if ((loop_counter % TEST_HZ) == 0) { uint32_t us = now % US_PER_SEC; uint32_t sec = now / US_PER_SEC; - uint32_t expected = start + loop_counter * TEST_INTERVAL; + uint32_t expected = start + loop_counter * test_interval; int32_t drift = now - expected; - expected = last + TEST_HZ * TEST_INTERVAL; + expected = last + TEST_HZ * test_interval; int32_t jitter = now - expected; printf("now=%" PRIu32 ".%06" PRIu32 " (0x%08" PRIx32 " ticks), ", - sec, us, ticks.ticks32); + sec, us, ticks.ticks32); printf("drift=%" PRId32 " us, jitter=%" PRId32 " us\n", - drift, jitter); + drift, jitter); last = now; } ++loop_counter; -- GitLab