From e01329796d87bbea75dcf75d2bf2e63c6e262b9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Canet?= Date: Thu, 9 Jul 2015 16:09:59 +0200 Subject: [PATCH] native: timer: synchronize HWTIMER_SPIN_BARRIER with timer min resolution This keeps the test/hwtimer_wait test duration correct. --- cpu/native/include/hwtimer_cpu.h | 4 +++- cpu/native/include/periph_conf.h | 7 +++++++ cpu/native/periph/timer.c | 2 -- tests/hwtimer_spin/main.c | 2 +- tests/hwtimer_wait/main.c | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cpu/native/include/hwtimer_cpu.h b/cpu/native/include/hwtimer_cpu.h index d324b4ff9a..2e4ba477c1 100644 --- a/cpu/native/include/hwtimer_cpu.h +++ b/cpu/native/include/hwtimer_cpu.h @@ -14,6 +14,8 @@ * @} */ +#include "periph_conf.h" + #ifndef HWTIMER_CPU_H_ #define HWTIMER_CPU_H_ @@ -24,7 +26,7 @@ extern "C" { #define HWTIMER_MAXTIMERS 1 #define HWTIMER_SPEED 1000000 #define HWTIMER_MAXTICKS (0xFFFFFFFF) -#define HWTIMER_SPIN_BARRIER 20 +#define HWTIMER_SPIN_BARRIER NATIVE_TIMER_MIN_RES #ifdef __cplusplus } diff --git a/cpu/native/include/periph_conf.h b/cpu/native/include/periph_conf.h index 187de84d6e..7efe40b488 100644 --- a/cpu/native/include/periph_conf.h +++ b/cpu/native/include/periph_conf.h @@ -20,6 +20,13 @@ extern "C" { #endif +/** + * @name hardware timer clock skew avoidance + * @{ + */ +#define NATIVE_TIMER_MIN_RES 200 +/** @} */ + /** * @name Random Number Generator configuration * @{ diff --git a/cpu/native/periph/timer.c b/cpu/native/periph/timer.c index df6bf996f4..f9e356e127 100644 --- a/cpu/native/periph/timer.c +++ b/cpu/native/periph/timer.c @@ -46,8 +46,6 @@ #define NATIVE_TIMER_SPEED 1000000 -#define NATIVE_TIMER_MIN_RES 200 - static unsigned long time_null; static void (*_callback)(int); diff --git a/tests/hwtimer_spin/main.c b/tests/hwtimer_spin/main.c index 7a411d514d..dc0842b4ec 100644 --- a/tests/hwtimer_spin/main.c +++ b/tests/hwtimer_spin/main.c @@ -32,7 +32,7 @@ int main(void) " this test was successful."); puts("If you do not see that message, something went wrong.\n"); - for (unsigned long r = 10000; r > 0; r--) { + for (unsigned long r = 1000; r > 0; r--) { for (unsigned long i = HWTIMER_SPIN_BARRIER; i > 0; i--) { hwtimer_wait(i); } diff --git a/tests/hwtimer_wait/main.c b/tests/hwtimer_wait/main.c index 70c9f68ac8..b6aad533eb 100644 --- a/tests/hwtimer_wait/main.c +++ b/tests/hwtimer_wait/main.c @@ -29,7 +29,7 @@ int main(void) puts("This is a regression test for a race condition in hwtimer_wait."); puts("When the race condition is hit, the timer will wait for a very very long time."); - long iterations = 10000; + long iterations = 1000; long start_duration = (HWTIMER_SPIN_BARRIER + 1) << 5; long duration = iterations * start_duration * 2L;