From 31767a0bcea8df57d8a619ee2a778d4b22a70309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Thu, 17 Nov 2022 13:45:47 +0100 Subject: [PATCH] tests: drivers: nrf_lf_clock_control: Fix test initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This test needs an initialization step to be done soon after the system clock is started. ZTEST setup function is too late for that, so use an initialization function executed at the POST_KERNEL stage instead. Signed-off-by: Andrzej Głąbek --- .../nrf_lf_clock_start/src/main.c | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/tests/drivers/clock_control/nrf_lf_clock_start/src/main.c b/tests/drivers/clock_control/nrf_lf_clock_start/src/main.c index fd481b710cc..09e6c996d24 100644 --- a/tests/drivers/clock_control/nrf_lf_clock_start/src/main.c +++ b/tests/drivers/clock_control/nrf_lf_clock_start/src/main.c @@ -89,15 +89,6 @@ ZTEST(nrf_lf_clock_start, test_wait_in_thread) void *test_init(void) { - /* Do clock state read as early as possible. When RC is already running - * and XTAL has been started then LFSRCSTAT register content might be - * not valid, in that case read system clock to check if it has - * progressed. - */ - on = nrf_clock_is_running(NRF_CLOCK, NRF_CLOCK_DOMAIN_LFCLK, &type); - k_busy_wait(100); - rtc_cnt = k_cycle_get_32(); - TC_PRINT("CLOCK_CONTROL_NRF_K32SRC=%s\n", IS_ENABLED(CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC) ? "RC" : IS_ENABLED(CONFIG_CLOCK_CONTROL_NRF_K32SRC_SYNTH) ? "SYNTH" @@ -114,3 +105,26 @@ void *test_init(void) return NULL; } ZTEST_SUITE(nrf_lf_clock_start, NULL, test_init, NULL, NULL, NULL); + +/* This test needs to read the LF clock state soon after the system clock is + * started (to check if the starting routine waits for the LF clock or not), + * so do it at the beginning of the POST_KERNEL stage (the system clock is + * started in PRE_KERNEL_2). Reading of the clock state in the ZTEST setup + * function turns out to be too late. + */ +static int get_lfclk_state(const struct device *dev) +{ + ARG_UNUSED(dev); + + /* Do clock state read as early as possible. When RC is already running + * and XTAL has been started then LFSRCSTAT register content might be + * not valid, in that case read system clock to check if it has + * progressed. + */ + on = nrf_clock_is_running(NRF_CLOCK, NRF_CLOCK_DOMAIN_LFCLK, &type); + k_busy_wait(100); + rtc_cnt = k_cycle_get_32(); + + return 0; +} +SYS_INIT(get_lfclk_state, POST_KERNEL, 0);