drivers/timer/gecko_burtc: allow queries prior to timer initialization

Before BURTC is initialized, clock to its APB CSR file is stopped, so
any attempt to read BURTC regs results in BusFault. However,
many parts of Zephyr may call sys_clock getters even before sys_clock
driver itself is initialized. This change adds support for that:
sys_clock_elapsed() and sys_clock_cycle_get_32() simply return 0
if BURTC is not init yet.

Signed-off-by: Roman Dobrodii <rdobrodii@antmicro.com>
This commit is contained in:
Roman Dobrodii 2023-05-11 18:02:18 +02:00 committed by Anas Nashif
commit 549358255f

View file

@ -69,6 +69,8 @@ static atomic_t g_last_count;
/* Spinlock to sync between Compare ISR and update of Compare register */
static struct k_spinlock g_lock;
/* Set to true when timer is initialized */
static atomic_t g_init = ATOMIC_INIT(0);
static void burtc_isr(const void *arg)
{
@ -161,8 +163,10 @@ uint32_t sys_clock_elapsed(void)
{
if (!IS_ENABLED(CONFIG_TICKLESS_KERNEL)) {
return 0;
} else {
} else if (atomic_get(&g_init)) {
return (BURTC_CounterGet() - g_last_count) / g_cyc_per_tick;
} else {
return 0;
}
}
@ -172,7 +176,11 @@ uint32_t sys_clock_cycle_get_32(void)
* a value of some 32-bit hw_cycles counter which counts with
* z_clock_hw_cycles_per_sec frequency
*/
return BURTC_CounterGet();
if (atomic_get(&g_init)) {
return BURTC_CounterGet();
} else {
return 0;
}
}
static int burtc_init(void)
@ -214,6 +222,7 @@ static int burtc_init(void)
init.clkDiv = 1;
init.start = false;
BURTC_Init(&init);
atomic_set(&g_init, 1);
/* Enable compare match interrupt */
BURTC_IntClear(BURTC_IF_COMP);