From 2aa2b7669f16bff4e3be40fd7912018ef2611456 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Sat, 10 Apr 2021 20:04:37 -0400 Subject: [PATCH] stm32f7 tickless: Fix handling of overflow for different width timers. --- arch/arm/src/stm32f7/stm32_tickless.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/arm/src/stm32f7/stm32_tickless.c b/arch/arm/src/stm32f7/stm32_tickless.c index e54e4d422d..7d8301f4bb 100644 --- a/arch/arm/src/stm32f7/stm32_tickless.c +++ b/arch/arm/src/stm32f7/stm32_tickless.c @@ -401,8 +401,13 @@ static int stm32_tickless_handler(int irq, void *context, void *arg) static uint64_t stm32_get_counter(void) { +#ifdef HAVE_32BIT_TICKLESS return ((uint64_t)g_tickless.overflow << 32) | STM32_TIM_GETCOUNTER(g_tickless.tch); +#else + return ((uint64_t)g_tickless.overflow << 16) | + STM32_TIM_GETCOUNTER(g_tickless.tch); +#endif } /**************************************************************************** @@ -1060,8 +1065,13 @@ int up_alarm_start(FAR const struct timespec *ts) int up_alarm_cancel(FAR struct timespec *ts) { +#ifdef HAVE_32BIT_TICKLESS uint64_t nsecs = (((uint64_t)g_tickless.overflow << 32) | STM32_TIM_GETCOUNTER(g_tickless.tch)) * NSEC_PER_TICK; +#else + uint64_t nsecs = (((uint64_t)g_tickless.overflow << 16) | + STM32_TIM_GETCOUNTER(g_tickless.tch)) * NSEC_PER_TICK; +#endif ts->tv_sec = nsecs / NSEC_PER_SEC; ts->tv_nsec = nsecs - ts->tv_sec * NSEC_PER_SEC;