From c8de4cc348d3f865017d151759d38156b4449715 Mon Sep 17 00:00:00 2001 From: Andrzej Kaczmarek Date: Wed, 31 Jul 2024 11:05:22 +0200 Subject: [PATCH] nimble/ll: Update ticks conversions for MCUs with idiv support We can use simple calculations for MCUs that support idiv. This has also larger range of allowed values on uint32_t values. --- nimble/controller/include/controller/ble_ll_tmr.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nimble/controller/include/controller/ble_ll_tmr.h b/nimble/controller/include/controller/ble_ll_tmr.h index 2d79427b63..bf62503824 100644 --- a/nimble/controller/include/controller/ble_ll_tmr.h +++ b/nimble/controller/include/controller/ble_ll_tmr.h @@ -64,9 +64,17 @@ ble_ll_tmr_u2t(uint32_t usecs) return usecs / 32; #endif #if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768 +#if __ARM_FEATURE_IDIV + if (usecs < 131072) { + return (usecs * 32768) / 1000000; + } else { + return ((uint64_t)usecs * 32768) / 1000000; + } +#else if (usecs <= 31249) { return (usecs * 137439) / 4194304; } +#endif #endif return os_cputime_usecs_to_ticks(usecs);