Skip to content
Permalink
Browse files

drivers: clock_control: Use nrf_clock HAL for registers w sideeffects

To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
  • Loading branch information...
aescolar authored and carlescufi committed Jun 15, 2018
1 parent 785faea commit 532201980df90dfbf8d25188949b3979a7561200
Showing with 14 additions and 12 deletions.
  1. +14 −12 drivers/clock_control/nrf5_power_clock.c
@@ -11,6 +11,7 @@
#include <device.h>
#include <clock_control.h>
#include <misc/__assert.h>
#include "nrf_clock.h"
#if defined(CONFIG_USB) && defined(CONFIG_SOC_NRF52840)
#include <nrf_power.h>
#include <drivers/clock_control/nrf5_clock_control.h>
@@ -59,9 +60,9 @@ static int _m16src_start(struct device *dev, clock_control_subsys_t sub_system)
NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;

intenset = NRF_CLOCK->INTENSET;
NRF_CLOCK->INTENSET = CLOCK_INTENSET_HFCLKSTARTED_Msk;
nrf_clock_int_enable(NRF_CLOCK_INT_HF_STARTED_MASK);

NRF_CLOCK->TASKS_HFCLKSTART = 1;
nrf_clock_task_trigger(NRF_CLOCK_TASK_HFCLKSTART);

while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {
__WFE();
@@ -72,7 +73,7 @@ static int _m16src_start(struct device *dev, clock_control_subsys_t sub_system)
NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;

if (!(intenset & CLOCK_INTENSET_HFCLKSTARTED_Msk)) {
NRF_CLOCK->INTENCLR = CLOCK_INTENCLR_HFCLKSTARTED_Msk;
nrf_clock_int_disable(NRF_CLOCK_INT_HF_STARTED_MASK);
}

NVIC_ClearPendingIRQ(POWER_CLOCK_IRQn);
@@ -81,7 +82,7 @@ static int _m16src_start(struct device *dev, clock_control_subsys_t sub_system)
} else {
NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;

NRF_CLOCK->TASKS_HFCLKSTART = 1;
nrf_clock_task_trigger(NRF_CLOCK_TASK_HFCLKSTART);
}

/* release resource guard */
@@ -133,7 +134,7 @@ static int _m16src_stop(struct device *dev, clock_control_subsys_t sub_system)

/* re-entrancy and mult-context safe, and reference count is zero, */

NRF_CLOCK->TASKS_HFCLKSTOP = 1;
nrf_clock_task_trigger(NRF_CLOCK_TASK_HFCLKSTOP);

/* release resource guard */
m16src_grd = 0;
@@ -174,14 +175,14 @@ static int _k32src_start(struct device *dev, clock_control_subsys_t sub_system)
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;

intenset = NRF_CLOCK->INTENSET;
NRF_CLOCK->INTENSET = CLOCK_INTENSET_LFCLKSTARTED_Msk;
nrf_clock_int_enable(NRF_CLOCK_INT_LF_STARTED_MASK);

/* Set LF Clock Source */
lf_clk_src = POINTER_TO_UINT(sub_system);
NRF_CLOCK->LFCLKSRC = lf_clk_src;

/* Start and spin-wait until clock settles */
NRF_CLOCK->TASKS_LFCLKSTART = 1;
nrf_clock_task_trigger(NRF_CLOCK_TASK_LFCLKSTART);

while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {
__WFE();
@@ -192,7 +193,7 @@ static int _k32src_start(struct device *dev, clock_control_subsys_t sub_system)
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;

if (!(intenset & CLOCK_INTENSET_LFCLKSTARTED_Msk)) {
NRF_CLOCK->INTENCLR = CLOCK_INTENCLR_LFCLKSTARTED_Msk;
nrf_clock_int_disable(NRF_CLOCK_INT_LF_STARTED_MASK);
}

NVIC_ClearPendingIRQ(POWER_CLOCK_IRQn);
@@ -202,7 +203,8 @@ static int _k32src_start(struct device *dev, clock_control_subsys_t sub_system)
/* If RC selected, calibrate and start timer for consecutive
* calibrations.
*/
NRF_CLOCK->INTENCLR = CLOCK_INTENCLR_DONE_Msk | CLOCK_INTENCLR_CTTO_Msk;
nrf_clock_int_disable(NRF_CLOCK_INT_DONE_MASK |
NRF_CLOCK_INT_CTTO_MASK);
NRF_CLOCK->EVENTS_DONE = 0;
NRF_CLOCK->EVENTS_CTTO = 0;

@@ -213,15 +215,15 @@ static int _k32src_start(struct device *dev, clock_control_subsys_t sub_system)
NRF_CLOCK->CTIV = 16; /* 4s in 0.25s units */

/* Enable DONE and CTTO IRQs */
NRF_CLOCK->INTENSET =
CLOCK_INTENSET_DONE_Msk | CLOCK_INTENSET_CTTO_Msk;
nrf_clock_int_enable(NRF_CLOCK_INT_DONE_MASK |
NRF_CLOCK_INT_CTTO_MASK);

/* Start HF clock, if already started then explicitly
* assert IRQ.
* NOTE: The INTENSET is used as state flag to start
* calibration in ISR.
*/
NRF_CLOCK->INTENSET = CLOCK_INTENSET_HFCLKSTARTED_Msk;
nrf_clock_int_enable(NRF_CLOCK_INT_HF_STARTED_MASK);

err = _m16src_start(dev, false);
if (!err) {

0 comments on commit 5322019

Please sign in to comment.
You can’t perform that action at this time.