sys_clock: add option for setting timer frequency at runtime

Some timer devices, such as the HPET, read their frequencies at runtime.
All global constant values must be set at runtime in that case.

Change-Id: I408babce6deb857748a87691132d7e27e88f0bb8
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
This commit is contained in:
Benjamin Walsh 2015-11-20 16:26:25 -05:00 committed by Anas Nashif
parent cdf8123589
commit fde6458f0b
3 changed files with 18 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -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