drivers: timer: Do not use CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC
On some SoCs the frequency of the system clock is obtained at run time as the exact configuration of the hardware is not known at compile time. On such platforms using CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC define directly introduces timing errors. This commit replaces CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC by the call to inline function sys_clock_hw_cycles_per_sec() which always returns correct frequency of the system clock. Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
This commit is contained in:
parent
129a23bea7
commit
0c0c0d93ea
7 changed files with 9 additions and 8 deletions
|
@ -25,7 +25,7 @@
|
|||
#define MIN_DELAY 512
|
||||
#define COUNTER_MAX 0xffffffff
|
||||
#define TIMER_STOPPED 0x0
|
||||
#define CYC_PER_TICK (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC \
|
||||
#define CYC_PER_TICK (sys_clock_hw_cycles_per_sec() \
|
||||
/ CONFIG_SYS_CLOCK_TICKS_PER_SEC)
|
||||
|
||||
#define MAX_TICKS ((COUNTER_MAX / CYC_PER_TICK) - 1)
|
||||
|
|
|
@ -13,7 +13,7 @@ void z_ExcExit(void);
|
|||
#define COUNTER_MAX 0x00ffffff
|
||||
#define TIMER_STOPPED 0xff000000
|
||||
|
||||
#define CYC_PER_TICK (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC \
|
||||
#define CYC_PER_TICK (sys_clock_hw_cycles_per_sec() \
|
||||
/ CONFIG_SYS_CLOCK_TICKS_PER_SEC)
|
||||
#define MAX_TICKS ((COUNTER_MAX / CYC_PER_TICK) - 1)
|
||||
#define MAX_CYCLES (MAX_TICKS * CYC_PER_TICK)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#define RTC NRF_RTC1
|
||||
|
||||
#define COUNTER_MAX 0x00ffffff
|
||||
#define CYC_PER_TICK (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC \
|
||||
#define CYC_PER_TICK (sys_clock_hw_cycles_per_sec() \
|
||||
/ CONFIG_SYS_CLOCK_TICKS_PER_SEC)
|
||||
#define MAX_TICKS ((COUNTER_MAX - CYC_PER_TICK) / CYC_PER_TICK)
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <spinlock.h>
|
||||
#include <soc.h>
|
||||
|
||||
#define CYC_PER_TICK ((u32_t)((u64_t)CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC \
|
||||
#define CYC_PER_TICK ((u32_t)((u64_t)sys_clock_hw_cycles_per_sec() \
|
||||
/ (u64_t)CONFIG_SYS_CLOCK_TICKS_PER_SEC))
|
||||
#define MAX_TICKS ((0xffffffffu - CYC_PER_TICK) / CYC_PER_TICK)
|
||||
#define MIN_DELAY 1000
|
||||
|
|
|
@ -19,14 +19,15 @@
|
|||
* - no tickless
|
||||
*/
|
||||
|
||||
#define CYCLES_PER_SEC CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC
|
||||
#define CYCLES_PER_SEC sys_clock_hw_cycles_per_sec()
|
||||
#define CYCLES_PER_TICK (CYCLES_PER_SEC / CONFIG_SYS_CLOCK_TICKS_PER_SEC)
|
||||
|
||||
/*
|
||||
* As a simplifying assumption, we only support a clock ticking at the
|
||||
* SIRC reset rate of 8MHz.
|
||||
*/
|
||||
#if MHZ(8) != CYCLES_PER_SEC
|
||||
#if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME) || \
|
||||
(MHZ(8) != CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC)
|
||||
#error "system timer misconfiguration; unsupported clock rate"
|
||||
#endif
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#define RTC0 ((RtcMode0 *) DT_INST_0_ATMEL_SAM0_RTC_BASE_ADDRESS)
|
||||
|
||||
/* Number of sys timer cycles per on tick. */
|
||||
#define CYCLES_PER_TICK (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC \
|
||||
#define CYCLES_PER_TICK (SOC_ATMEL_SAM0_GCLK0_FREQ_HZ \
|
||||
/ CONFIG_SYS_CLOCK_TICKS_PER_SEC)
|
||||
|
||||
/* Maximum number of ticks. */
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#define TIMER_IRQ UTIL_CAT(XCHAL_TIMER, \
|
||||
UTIL_CAT(CONFIG_XTENSA_TIMER_ID, _INTERRUPT))
|
||||
|
||||
#define CYC_PER_TICK (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC \
|
||||
#define CYC_PER_TICK (sys_clock_hw_cycles_per_sec() \
|
||||
/ CONFIG_SYS_CLOCK_TICKS_PER_SEC)
|
||||
#define MAX_TICKS ((0xffffffffu - CYC_PER_TICK) / CYC_PER_TICK)
|
||||
#define MIN_DELAY 1000
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue