logging: 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
5fbf05ce15
commit
ec857d0e4a
2 changed files with 16 additions and 10 deletions
|
@ -46,7 +46,7 @@ static u32_t timestamp_freq(void)
|
||||||
#ifdef CONFIG_SOC_FAMILY_NRF
|
#ifdef CONFIG_SOC_FAMILY_NRF
|
||||||
return 32768 / (NRF_RTC1->PRESCALER + 1);
|
return 32768 / (NRF_RTC1->PRESCALER + 1);
|
||||||
#else
|
#else
|
||||||
return CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;
|
return sys_clock_hw_cycles_per_sec();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -432,19 +432,18 @@ void log_hexdump_sync(struct log_msg_ids src_level, const char *metadata,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static u32_t timestamp_get(void)
|
static u32_t k_cycle_get_32_wrapper(void)
|
||||||
{
|
{
|
||||||
if (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC > 1000000) {
|
/*
|
||||||
return k_uptime_get_32();
|
* The k_cycle_get_32() is a define which cannot be referenced
|
||||||
} else {
|
* by timestamp_func. Instead, this wrapper is used.
|
||||||
return k_cycle_get_32();
|
*/
|
||||||
}
|
return k_cycle_get_32();
|
||||||
}
|
}
|
||||||
|
|
||||||
void log_core_init(void)
|
void log_core_init(void)
|
||||||
{
|
{
|
||||||
u32_t freq = (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC > 1000000) ?
|
u32_t freq;
|
||||||
1000 : CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;
|
|
||||||
|
|
||||||
if (!IS_ENABLED(CONFIG_LOG_IMMEDIATE)) {
|
if (!IS_ENABLED(CONFIG_LOG_IMMEDIATE)) {
|
||||||
log_msg_pool_init();
|
log_msg_pool_init();
|
||||||
|
@ -456,7 +455,14 @@ void log_core_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set default timestamp. */
|
/* Set default timestamp. */
|
||||||
timestamp_func = timestamp_get;
|
if (sys_clock_hw_cycles_per_sec() > 1000000) {
|
||||||
|
timestamp_func = k_uptime_get_32;
|
||||||
|
freq = 1000;
|
||||||
|
} else {
|
||||||
|
timestamp_func = k_cycle_get_32_wrapper;
|
||||||
|
freq = sys_clock_hw_cycles_per_sec();
|
||||||
|
}
|
||||||
|
|
||||||
log_output_timestamp_freq_set(freq);
|
log_output_timestamp_freq_set(freq);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue