Skip to content

Commit

Permalink
clock_control: nRF5x: Fix HFSTAT and LFSTAT check
Browse files Browse the repository at this point in the history
Fix the implementation to correctly check the status of
HFCLK and LFCLK states with respect to the requested
sources.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
  • Loading branch information
cvinayak authored and carlescufi committed Aug 1, 2018
1 parent 23c9210 commit 26d22b0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions drivers/clock_control/nrf5_power_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ static u8_t k32src_initialized;

static int _m16src_start(struct device *dev, clock_control_subsys_t sub_system)
{
u32_t imask;
bool blocking;
u32_t imask;
u32_t stat;

/* If the clock is already started then just increment refcount.
* If the start and stop don't happen in pairs, a rollover will
Expand Down Expand Up @@ -94,7 +95,8 @@ static int _m16src_start(struct device *dev, clock_control_subsys_t sub_system)
*/
__ASSERT_NO_MSG(m16src_ref);

if (NRF_CLOCK->HFCLKSTAT & CLOCK_HFCLKSTAT_STATE_Msk) {
stat = CLOCK_HFCLKSTAT_SRC_Xtal | CLOCK_HFCLKSTAT_STATE_Msk;
if ((NRF_CLOCK->HFCLKSTAT & stat) == stat) {
return 0;
} else {
return -EINPROGRESS;
Expand Down Expand Up @@ -146,6 +148,7 @@ static int _k32src_start(struct device *dev, clock_control_subsys_t sub_system)
{
u32_t lf_clk_src;
u32_t imask;
u32_t stat;

#if defined(CONFIG_CLOCK_CONTROL_NRF5_K32SRC_BLOCKING)
u32_t intenset;
Expand Down Expand Up @@ -246,7 +249,9 @@ static int _k32src_start(struct device *dev, clock_control_subsys_t sub_system)
}

lf_already_started:
if (NRF_CLOCK->LFCLKSTAT & CLOCK_LFCLKSTAT_STATE_Msk) {
stat = (NRF_CLOCK->LFCLKSRCCOPY & CLOCK_LFCLKSRCCOPY_SRC_Msk) |
CLOCK_LFCLKSTAT_STATE_Msk;
if ((NRF_CLOCK->LFCLKSTAT & stat) == stat) {
return 0;
} else {
return -EINPROGRESS;
Expand Down

0 comments on commit 26d22b0

Please sign in to comment.