From e1cb4ca0f4a6b2531a7722c03da528a619fc672c Mon Sep 17 00:00:00 2001 From: "Charles E. Youse" Date: Tue, 7 May 2019 15:53:51 -0700 Subject: [PATCH] include/sys_clock.h: simplify _NEED_PRECISE_TICK_MS_CONVERSION This is just hygiene. Some preprocessor logic is optimized, eliminating a temporary (_NON_OPTIMIZED_TICKS_PER_SEC) in the process. Signed-off-by: Charles E. Youse --- include/sys_clock.h | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/include/sys_clock.h b/include/sys_clock.h index 287d1c77c34..0f485a77118 100644 --- a/include/sys_clock.h +++ b/include/sys_clock.h @@ -79,27 +79,20 @@ static inline int sys_clock_hw_cycles_per_tick(void) /* kernel clocks */ -#ifdef CONFIG_SYS_CLOCK_EXISTS - /* - * If timer frequency is known at compile time, a simple (32-bit) - * tick <-> ms conversion could be used for some combinations of - * hardware timer frequency and tick rate. Otherwise precise - * (64-bit) calculations are used. + * We default to using 64-bit intermediates in timescale conversions, + * but if the HW timer cycles/sec, ticks/sec and ms/sec are all known + * to be nicely related, then we can cheat with 32 bits instead. */ -#if !defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME) -#if (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC % CONFIG_SYS_CLOCK_TICKS_PER_SEC) != 0 - #define _NEED_PRECISE_TICK_MS_CONVERSION -#elif (MSEC_PER_SEC % CONFIG_SYS_CLOCK_TICKS_PER_SEC) != 0 - #define _NON_OPTIMIZED_TICKS_PER_SEC -#endif +#ifdef CONFIG_SYS_CLOCK_EXISTS + +#if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME) || \ + (MSEC_PER_SEC % CONFIG_SYS_CLOCK_TICKS_PER_SEC) || \ + (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC % CONFIG_SYS_CLOCK_TICKS_PER_SEC) +#define _NEED_PRECISE_TICK_MS_CONVERSION #endif -#if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME) || \ - defined(_NON_OPTIMIZED_TICKS_PER_SEC) - #define _NEED_PRECISE_TICK_MS_CONVERSION -#endif #endif static ALWAYS_INLINE s32_t z_ms_to_ticks(s32_t ms)