Merge pull request #9625 from Josar/pr/xtimer_drift/interval

test/xtimer_drift: interval calculation
This commit is contained in:
Andreas "Paul" Pauli 2018-09-06 14:24:26 +02:00 committed by GitHub
commit 775acf9268
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -91,6 +91,10 @@ void *worker_thread(void *arg)
{ {
(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 loop_counter = 0;
uint32_t start = 0; uint32_t start = 0;
uint32_t last = 0; uint32_t last = 0;
@ -111,9 +115,9 @@ void *worker_thread(void *arg)
else if ((loop_counter % TEST_HZ) == 0) { else if ((loop_counter % TEST_HZ) == 0) {
uint32_t us = now % US_PER_SEC; uint32_t us = now % US_PER_SEC;
uint32_t sec = 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; int32_t drift = now - expected;
expected = last + TEST_HZ * TEST_INTERVAL; expected = last + TEST_HZ * test_interval;
int32_t jitter = now - expected; int32_t jitter = now - expected;
printf("now=%" PRIu32 ".%06" PRIu32 " (0x%08" PRIx32 " ticks), ", printf("now=%" PRIu32 ".%06" PRIu32 " (0x%08" PRIx32 " ticks), ",
sec, us, ticks.ticks32); sec, us, ticks.ticks32);