From f0fa6f7b68853449407357ee19d3bb6476a617b6 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Fri, 30 Sep 2016 17:05:15 -0600 Subject: [PATCH] utilities/101: Add 1 tick offset to nanotimer In certain cases with the Arduino 101/Zephyr, using the upm_delay*() functions can cause hangs and/or exceptions. Adding a single tick to the generated offset resolves these issues. The documentation warns that this is a good idea to ensure that a timer does not expire early. Adding this made the random hangs and CPU exceptions go away. Signed-off-by: Jon Trulson --- src/utilities/upm_utilities.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utilities/upm_utilities.c b/src/utilities/upm_utilities.c index a428df15..2ebca71b 100644 --- a/src/utilities/upm_utilities.c +++ b/src/utilities/upm_utilities.c @@ -32,7 +32,7 @@ void upm_delay(int time){ struct nano_timer timer; void *timer_data[1]; nano_timer_init(&timer, timer_data); - nano_timer_start(&timer, SECONDS(time)); + nano_timer_start(&timer, SECONDS(time) + 1); nano_timer_test(&timer, TICKS_UNLIMITED); #endif } @@ -44,7 +44,7 @@ void upm_delay_ms(int time){ struct nano_timer timer; void *timer_data[1]; nano_timer_init(&timer, timer_data); - nano_timer_start(&timer, MSEC(time)); + nano_timer_start(&timer, MSEC(time) + 1); nano_timer_test(&timer, TICKS_UNLIMITED); #endif } @@ -56,7 +56,7 @@ void upm_delay_us(int time){ struct nano_timer timer; void *timer_data[1]; nano_timer_init(&timer, timer_data); - nano_timer_start(&timer, USEC(time)); + nano_timer_start(&timer, USEC(time) + 1); nano_timer_test(&timer, TICKS_UNLIMITED); #endif }