From c4656bf8ba4645f370eabb526e24a9265d69e04b Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Fri, 2 Dec 2016 16:40:48 -0700 Subject: [PATCH] utilities: add Zephyr 1.6 k_timer support (pulled from zupm) Signed-off-by: Jon Trulson --- src/utilities/upm_utilities.c | 38 +++++++++++++++++++++++++++++++++++ src/utilities/upm_utilities.h | 2 ++ 2 files changed, 40 insertions(+) diff --git a/src/utilities/upm_utilities.c b/src/utilities/upm_utilities.c index 926fcff8..74aff7c8 100644 --- a/src/utilities/upm_utilities.c +++ b/src/utilities/upm_utilities.c @@ -30,11 +30,24 @@ void upm_delay(int time){ #if defined(UPM_PLATFORM_LINUX) sleep(time); #elif defined(UPM_PLATFORM_ZEPHYR) +# if SYS_KERNEL_VER_MAJOR(KERNEL_VERSION_NUMBER) == 1 && \ + SYS_KERNEL_VER_MINOR(KERNEL_VERSION_NUMBER) >= 6 + + struct k_timer timer; + k_timer_init(&timer, NULL, NULL); + k_timer_start(&timer, SECONDS(time) + 1, 0); + k_timer_status_sync(&timer); + +# else + struct nano_timer timer; void *timer_data[1]; nano_timer_init(&timer, timer_data); nano_timer_start(&timer, SECONDS(time) + 1); nano_timer_test(&timer, TICKS_UNLIMITED); + +# endif + #endif } @@ -42,11 +55,23 @@ void upm_delay_ms(int time){ #if defined(UPM_PLATFORM_LINUX) usleep(1000 * time); #elif defined(UPM_PLATFORM_ZEPHYR) +# if SYS_KERNEL_VER_MAJOR(KERNEL_VERSION_NUMBER) == 1 && \ + SYS_KERNEL_VER_MINOR(KERNEL_VERSION_NUMBER) >= 6 + + struct k_timer timer; + k_timer_init(&timer, NULL, NULL); + k_timer_start(&timer, MSEC(time) + 1, 0); + k_timer_status_sync(&timer); + +# else + struct nano_timer timer; void *timer_data[1]; nano_timer_init(&timer, timer_data); nano_timer_start(&timer, MSEC(time) + 1); nano_timer_test(&timer, TICKS_UNLIMITED); + +# endif #endif } @@ -54,11 +79,24 @@ void upm_delay_us(int time){ #if defined(UPM_PLATFORM_LINUX) usleep(time); #elif defined(UPM_PLATFORM_ZEPHYR) +# if SYS_KERNEL_VER_MAJOR(KERNEL_VERSION_NUMBER) == 1 && \ + SYS_KERNEL_VER_MINOR(KERNEL_VERSION_NUMBER) >= 6 + + struct k_timer timer; + k_timer_init(&timer, NULL, NULL); + k_timer_start(&timer, USEC(time) + 1, 0); + k_timer_status_sync(&timer); + +# else + struct nano_timer timer; void *timer_data[1]; nano_timer_init(&timer, timer_data); nano_timer_start(&timer, USEC(time) + 1); nano_timer_test(&timer, TICKS_UNLIMITED); + +# endif + #endif } diff --git a/src/utilities/upm_utilities.h b/src/utilities/upm_utilities.h index e20806b4..3a55776e 100644 --- a/src/utilities/upm_utilities.h +++ b/src/utilities/upm_utilities.h @@ -45,6 +45,8 @@ typedef struct timeval upm_clock_t; #include #include #include +#include +#include #if defined(CONFIG_STDOUT_CONSOLE) #include