Skip to content
Permalink
Browse files

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>
  • Loading branch information...
pizi-nordic authored and carlescufi committed Apr 23, 2019
1 parent 5fbf05c commit ec857d0e4a99767ace8b957614e0db8401903ea7
Showing with 16 additions and 10 deletions.
  1. +1 −1 samples/subsys/logging/logger/src/main.c
  2. +15 −9 subsys/logging/log_core.c
@@ -46,7 +46,7 @@ static u32_t timestamp_freq(void)
#ifdef CONFIG_SOC_FAMILY_NRF
return 32768 / (NRF_RTC1->PRESCALER + 1);
#else
return CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;
return sys_clock_hw_cycles_per_sec();
#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();
} else {
return k_cycle_get_32();
}
/*
* The k_cycle_get_32() is a define which cannot be referenced
* by timestamp_func. Instead, this wrapper is used.
*/
return k_cycle_get_32();
}

void log_core_init(void)
{
u32_t freq = (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC > 1000000) ?
1000 : CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;
u32_t freq;

if (!IS_ENABLED(CONFIG_LOG_IMMEDIATE)) {
log_msg_pool_init();
@@ -456,7 +455,14 @@ void log_core_init(void)
}

/* 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);

/*

0 comments on commit ec857d0

Please sign in to comment.
You can’t perform that action at this time.