Skip to content

Commit 364087f

Browse files
rsalvetigalak
authored andcommitted
nrf_rtc_timer: clear events and counter when disabling sys_clock
Clear pending IRQ when starting and restore back the RTC1 state when disabling sys_clock, to avoid issues when soft rebooting the device or chainloading another Zephyr image (e.g. mcuboot). Change-Id: I693d9168196ad2cfb8475ecfa2051eac043b1fbd Signed-off-by: Ricardo Salveti <[email protected]> (cherry picked from commit 6713088cfc813f14e442e4acc01c4c85959dd8df)
1 parent 6e135d0 commit 364087f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

drivers/timer/nrf_rtc_timer.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ int _sys_clock_driver_init(struct device *device)
292292
SYS_CLOCK_RTC->EVTENSET = RTC_EVTENSET_COMPARE0_Msk;
293293
SYS_CLOCK_RTC->INTENSET = RTC_INTENSET_COMPARE0_Msk;
294294

295+
/* Clear the event flag and possible pending interrupt */
296+
RTC_CC_EVENT = 0;
297+
NVIC_ClearPendingIRQ(NRF5_IRQ_RTC1_IRQn);
298+
295299
IRQ_CONNECT(NRF5_IRQ_RTC1_IRQn, 1, rtc1_nrf5_isr, 0, 0);
296300
irq_enable(NRF5_IRQ_RTC1_IRQn);
297301

@@ -325,9 +329,19 @@ uint32_t _timer_cycle_get_32(void)
325329
*/
326330
void sys_clock_disable(void)
327331
{
332+
unsigned int key;
333+
334+
key = irq_lock();
335+
328336
irq_disable(NRF5_IRQ_RTC1_IRQn);
329337

338+
SYS_CLOCK_RTC->EVTENCLR = RTC_EVTENCLR_COMPARE0_Msk;
339+
SYS_CLOCK_RTC->INTENCLR = RTC_INTENCLR_COMPARE0_Msk;
340+
330341
SYS_CLOCK_RTC->TASKS_STOP = 1;
342+
SYS_CLOCK_RTC->TASKS_CLEAR = 1;
343+
344+
irq_unlock(key);
331345

332346
/* TODO: turn off (release) 32 KHz clock source.
333347
* Turning off of 32 KHz clock source is not implemented in clock

0 commit comments

Comments
 (0)