Skip to content

Commit 37fbff6

Browse files
ananglcarlescufi
authored andcommitted
drivers: nrf: Adjust clock_control and timer drivers for nRF9160
Minor adjustments are done to the nRF clock_control and rtc_timer drivers to make them usable on nRF9160 as well. The arm_irq_vector_table test code is modified only because it uses the function that has been renamed in the nrf_rtc_timer driver. Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent 0cc8f30 commit 37fbff6

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

drivers/clock_control/nrf_power_clock.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <device.h>
1212
#include <clock_control.h>
1313
#include <misc/__assert.h>
14-
#include "nrf_clock.h"
14+
#include <nrf_clock.h>
1515
#if defined(CONFIG_USB) && defined(CONFIG_SOC_NRF52840)
1616
#include <nrf_power.h>
1717
#include <drivers/clock_control/nrf_clock_control.h>
@@ -95,7 +95,7 @@ static int _m16src_start(struct device *dev, clock_control_subsys_t sub_system)
9595
*/
9696
__ASSERT_NO_MSG(m16src_ref);
9797

98-
stat = CLOCK_HFCLKSTAT_SRC_Xtal | CLOCK_HFCLKSTAT_STATE_Msk;
98+
stat = NRF_CLOCK_HFCLK_HIGH_ACCURACY | CLOCK_HFCLKSTAT_STATE_Msk;
9999
if ((NRF_CLOCK->HFCLKSTAT & stat) == stat) {
100100
return 0;
101101
} else {
@@ -216,6 +216,7 @@ static int _k32src_start(struct device *dev, clock_control_subsys_t sub_system)
216216
nrf_clock_task_trigger(NRF_CLOCK_TASK_LFCLKSTART);
217217
#endif /* !CONFIG_CLOCK_CONTROL_NRF_K32SRC_BLOCKING */
218218

219+
#if NRF_CLOCK_HAS_CALIBRATION
219220
/* If RC selected, calibrate and start timer for consecutive
220221
* calibrations.
221222
*/
@@ -254,6 +255,7 @@ static int _k32src_start(struct device *dev, clock_control_subsys_t sub_system)
254255
__ASSERT_NO_MSG(err == -EINPROGRESS);
255256
}
256257
}
258+
#endif /* NRF_CLOCK_HAS_CALIBRATION */
257259

258260
lf_already_started:
259261
stat = (NRF_CLOCK->LFCLKSRCCOPY & CLOCK_LFCLKSRCCOPY_SRC_Msk) |
@@ -276,11 +278,14 @@ static inline void power_event_cb(nrf_power_event_t event)
276278

277279
static void _power_clock_isr(void *arg)
278280
{
279-
u8_t pof, hf_intenset, hf, lf_intenset, lf, done, ctto;
281+
u8_t pof, hf_intenset, hf, lf_intenset, lf;
282+
#if NRF_CLOCK_HAS_CALIBRATION
283+
u8_t ctto, done;
284+
struct device *dev = arg;
285+
#endif
280286
#if defined(CONFIG_USB) && defined(CONFIG_SOC_NRF52840)
281287
bool usb_detected, usb_pwr_rdy, usb_removed;
282288
#endif
283-
struct device *dev = arg;
284289

285290
pof = (NRF_POWER->EVENTS_POFWARN != 0);
286291

@@ -292,19 +297,24 @@ static void _power_clock_isr(void *arg)
292297
CLOCK_INTENSET_LFCLKSTARTED_Msk) != 0);
293298
lf = (NRF_CLOCK->EVENTS_LFCLKSTARTED != 0);
294299

300+
#if NRF_CLOCK_HAS_CALIBRATION
295301
done = (NRF_CLOCK->EVENTS_DONE != 0);
296302
ctto = (NRF_CLOCK->EVENTS_CTTO != 0);
297-
303+
#endif
298304
#if defined(CONFIG_USB) && defined(CONFIG_SOC_NRF52840)
299305
usb_detected = nrf_power_event_check(NRF_POWER_EVENT_USBDETECTED);
300306
usb_pwr_rdy = nrf_power_event_check(NRF_POWER_EVENT_USBPWRRDY);
301307
usb_removed = nrf_power_event_check(NRF_POWER_EVENT_USBREMOVED);
308+
#endif
302309

303-
__ASSERT_NO_MSG(pof || hf || hf_intenset || lf || done || ctto ||
304-
usb_detected || usb_pwr_rdy || usb_removed);
305-
#else
306-
__ASSERT_NO_MSG(pof || hf || hf_intenset || lf || done || ctto);
310+
__ASSERT_NO_MSG(pof || hf || hf_intenset || lf
311+
#if NRF_CLOCK_HAS_CALIBRATION
312+
|| done || ctto
313+
#endif
314+
#if defined(CONFIG_USB) && defined(CONFIG_SOC_NRF52840)
315+
|| usb_detected || usb_pwr_rdy || usb_removed
307316
#endif
317+
);
308318

309319
if (pof) {
310320
NRF_POWER->EVENTS_POFWARN = 0;
@@ -332,8 +342,10 @@ static void _power_clock_isr(void *arg)
332342
*(volatile u32_t *)0x40000C34 = 0x00000002;
333343
#endif /* CONFIG_SOC_SERIES_NRF52X */
334344

345+
#if NRF_CLOCK_HAS_CALIBRATION
335346
/* Start Calibration */
336347
NRF_CLOCK->TASKS_CAL = 1;
348+
#endif
337349
}
338350

339351
if (lf) {
@@ -345,14 +357,17 @@ static void _power_clock_isr(void *arg)
345357
*/
346358
NRF_CLOCK->INTENCLR = CLOCK_INTENCLR_LFCLKSTARTED_Msk;
347359

360+
#if NRF_CLOCK_HAS_CALIBRATION
348361
/* Start HF Clock if LF RC is used. */
349362
if ((NRF_CLOCK->LFCLKSRCCOPY & CLOCK_LFCLKSRCCOPY_SRC_Msk) ==
350363
CLOCK_LFCLKSRCCOPY_SRC_RC) {
351364
ctto = 1U;
352365
}
366+
#endif
353367
}
354368
}
355369

370+
#if NRF_CLOCK_HAS_CALIBRATION
356371
if (done) {
357372
int err;
358373

@@ -392,6 +407,7 @@ static void _power_clock_isr(void *arg)
392407
__ASSERT_NO_MSG(err == -EINPROGRESS);
393408
}
394409
}
410+
#endif /* NRF_CLOCK_HAS_CALIBRATION */
395411

396412
#if defined(CONFIG_USB) && defined(CONFIG_SOC_NRF52840)
397413
if (usb_detected) {

drivers/timer/nrf_rtc_timer.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static u32_t counter(void)
4949
* it by pointer at runtime, maybe?) so we don't have this leaky
5050
* symbol.
5151
*/
52-
void rtc1_nrf5_isr(void *arg)
52+
void rtc1_nrf_isr(void *arg)
5353
{
5454
ARG_UNUSED(arg);
5555
RTC->EVENTS_COMPARE[0] = 0;
@@ -94,10 +94,10 @@ int z_clock_driver_init(struct device *device)
9494

9595
/* Clear the event flag and possible pending interrupt */
9696
nrf_rtc_event_clear(RTC, NRF_RTC_EVENT_COMPARE_0);
97-
NVIC_ClearPendingIRQ(NRF5_IRQ_RTC1_IRQn);
97+
NVIC_ClearPendingIRQ(RTC1_IRQn);
9898

99-
IRQ_CONNECT(NRF5_IRQ_RTC1_IRQn, 1, rtc1_nrf5_isr, 0, 0);
100-
irq_enable(NRF5_IRQ_RTC1_IRQn);
99+
IRQ_CONNECT(RTC1_IRQn, 1, rtc1_nrf_isr, 0, 0);
100+
irq_enable(RTC1_IRQn);
101101

102102
nrf_rtc_task_trigger(RTC, NRF_RTC_TASK_CLEAR);
103103
nrf_rtc_task_trigger(RTC, NRF_RTC_TASK_START);

tests/kernel/arm_irq_vector_table/src/arm_irq_vector_table.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ void test_arm_irq_vector_table(void)
120120
* SysTick. Therefore, a pointer to the timer ISR needs to be added in
121121
* the custom vector table to handle the timer "tick" interrupts.
122122
*/
123-
void rtc1_nrf5_isr(void);
123+
void rtc1_nrf_isr(void);
124124
typedef void (*vth)(void); /* Vector Table Handler */
125125
vth __irq_vector_table _irq_vector_table[RTC1_IRQn + 1] = {
126126
isr0, isr1, isr2,
127127
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
128-
rtc1_nrf5_isr
128+
rtc1_nrf_isr
129129
};
130130
#else
131131
typedef void (*vth)(void); /* Vector Table Handler */

0 commit comments

Comments
 (0)