diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig index f360c150fbc..eead7314618 100644 --- a/drivers/timer/Kconfig +++ b/drivers/timer/Kconfig @@ -148,4 +148,10 @@ config SYSTEM_CLOCK_DISABLE needed by some subsystems (which will automatically select it), but is rarely needed by applications. +config TIMER_READS_ITS_FREQUENCY_AT_RUNTIME + bool "Timer queries its hardware to find its frequency at runtime" + default n + help + The drivers select this option automatically when needed. Do not modify + this unless you have a very good reason for it. endmenu diff --git a/include/sys_clock.h b/include/sys_clock.h index 2bf6eabda48..df5ae1c4012 100644 --- a/include/sys_clock.h +++ b/include/sys_clock.h @@ -35,7 +35,12 @@ #endif #define sys_clock_ticks_per_sec CONFIG_SYS_CLOCK_TICKS_PER_SEC + +#if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME) +extern int sys_clock_hw_cycles_per_sec; +#else #define sys_clock_hw_cycles_per_sec CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC +#endif /* * sys_clock_us_per_tick global variable represents a number diff --git a/kernel/nanokernel/nano_sys_clock.c b/kernel/nanokernel/nano_sys_clock.c index cce0347489a..a3eca389627 100644 --- a/kernel/nanokernel/nano_sys_clock.c +++ b/kernel/nanokernel/nano_sys_clock.c @@ -26,11 +26,17 @@ #ifdef CONFIG_SYS_CLOCK_EXISTS int sys_clock_us_per_tick = 1000000 / sys_clock_ticks_per_sec; int sys_clock_hw_cycles_per_tick = - sys_clock_hw_cycles_per_sec / sys_clock_ticks_per_sec; + CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC / sys_clock_ticks_per_sec; +#if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME) +int sys_clock_hw_cycles_per_sec = CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC; +#endif #else /* don't initialize to avoid division-by-zero error */ int sys_clock_us_per_tick; int sys_clock_hw_cycles_per_tick; +#if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME) +int sys_clock_hw_cycles_per_sec; +#endif #endif #ifdef CONFIG_NANOKERNEL