Skip to content

Commit fb4f5e7

Browse files
nordic-krchcarlescufi
authored andcommitted
logging: Use k_uptime_get_32 for high frequency system clock
If system clock runs fast k_cycle_get_32(), which is the timestamp source, wraps often (few minutes). This patch changes default timestamp function to use k_uptime_get_32() if system clock frequency is higher than 1 MHz and k_cycle_get_32() otherwise. If system clock runs at 1 MHz, counter will wrap every 71.5 minutes. Signed-off-by: Krzysztof Chruscinski <[email protected]>
1 parent 2d91e5c commit fb4f5e7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

subsys/logging/log_core.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,18 @@ void log_hexdump_sync(struct log_msg_ids src_level, const char *metadata,
282282

283283
static u32_t timestamp_get(void)
284284
{
285-
return k_cycle_get_32();
285+
if (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC > 1000000) {
286+
return k_uptime_get_32();
287+
} else {
288+
return k_cycle_get_32();
289+
}
286290
}
287291

288292
void log_core_init(void)
289293
{
294+
u32_t freq = (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC > 1000000) ?
295+
1000 : CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;
296+
290297
if (!IS_ENABLED(CONFIG_LOG_IMMEDIATE)) {
291298
log_msg_pool_init();
292299
log_list_init(&list);
@@ -298,7 +305,7 @@ void log_core_init(void)
298305

299306
/* Set default timestamp. */
300307
timestamp_func = timestamp_get;
301-
log_output_timestamp_freq_set(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC);
308+
log_output_timestamp_freq_set(freq);
302309

303310
/*
304311
* Initialize aggregated runtime filter levels (no backends are

0 commit comments

Comments
 (0)