From aa5e108553ace3079c6087dec796b9e58fe45fa4 Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Thu, 22 Oct 2015 22:36:58 +0000 Subject: [PATCH] NOUP: stm32f3: rcc: provide async osc checks replace bulky hardcoded wait for set and wait for clear with a single asynch routine. Leave the blocking routines in for compatibility at this point. NOUP: should be added to other rcc.c files too. --- include/libopencm3/stm32/f3/rcc.h | 1 + lib/stm32/f3/rcc.c | 41 +++++++++---------------------- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/include/libopencm3/stm32/f3/rcc.h b/include/libopencm3/stm32/f3/rcc.h index 7c8ebf85..457aecc2 100644 --- a/include/libopencm3/stm32/f3/rcc.h +++ b/include/libopencm3/stm32/f3/rcc.h @@ -587,6 +587,7 @@ void rcc_osc_ready_int_disable(enum rcc_osc osc); int rcc_osc_ready_int_flag(enum rcc_osc osc); void rcc_css_int_clear(void); int rcc_css_int_flag(void); +bool rcc_is_osc_ready(enum rcc_osc osc); void rcc_wait_for_osc_ready(enum rcc_osc osc); void rcc_wait_for_osc_not_ready(enum rcc_osc osc); void rcc_wait_for_sysclk_status(enum rcc_osc osc); diff --git a/lib/stm32/f3/rcc.c b/lib/stm32/f3/rcc.c index f915772d..42dc6929 100644 --- a/lib/stm32/f3/rcc.c +++ b/lib/stm32/f3/rcc.c @@ -176,47 +176,30 @@ int rcc_css_int_flag(void) return ((RCC_CIR & RCC_CIR_CSSF) != 0); } -void rcc_wait_for_osc_ready(enum rcc_osc osc) -{ +bool rcc_is_osc_ready(enum rcc_osc osc) { switch (osc) { case RCC_PLL: - while ((RCC_CR & RCC_CR_PLLRDY) == 0); - break; + return (RCC_CR & RCC_CR_PLLRDY); case RCC_HSE: - while ((RCC_CR & RCC_CR_HSERDY) == 0); - break; + return (RCC_CR & RCC_CR_HSERDY); case RCC_HSI: - while ((RCC_CR & RCC_CR_HSIRDY) == 0); - break; + return (RCC_CR & RCC_CR_HSIRDY); case RCC_LSE: - while ((RCC_BDCR & RCC_BDCR_LSERDY) == 0); - break; + return (RCC_BDCR & RCC_BDCR_LSERDY); case RCC_LSI: - while ((RCC_CSR & RCC_CSR_LSIRDY) == 0); - break; + return (RCC_CSR & RCC_CSR_LSIRDY); } + return false; } +void rcc_wait_for_osc_ready(enum rcc_osc osc) +{ + while (!rcc_is_osc_ready(osc)); +} void rcc_wait_for_osc_not_ready(enum rcc_osc osc) { - switch (osc) { - case RCC_PLL: - while ((RCC_CR & RCC_CR_PLLRDY) != 0); - break; - case RCC_HSE: - while ((RCC_CR & RCC_CR_HSERDY) != 0); - break; - case RCC_HSI: - while ((RCC_CR & RCC_CR_HSIRDY) != 0); - break; - case RCC_LSE: - while ((RCC_BDCR & RCC_BDCR_LSERDY) != 0); - break; - case RCC_LSI: - while ((RCC_CSR & RCC_CSR_LSIRDY) != 0); - break; - } + while (rcc_is_osc_ready(osc)); } void rcc_wait_for_sysclk_status(enum rcc_osc osc)