Skip to content

Commit 324dbaf

Browse files
committed
Low power timer fine tuned for smaller duration
1 parent 22c50d3 commit 324dbaf

File tree

1 file changed

+14
-13
lines changed
  • targets/TARGET_ONSEMI/TARGET_NCS36510

1 file changed

+14
-13
lines changed

targets/TARGET_ONSEMI/TARGET_NCS36510/rtc.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void fRtcInit(void)
7979
NVIC_ClearPendingIRQ(Rtc_IRQn);
8080
NVIC_EnableIRQ(Rtc_IRQn);
8181

82-
while(RTCREG->STATUS.BITS.BSY_ANY_WRT == True); /* Wait for RTC to finish writing register - RTC operates on 32K clock as compared to 32M core*/
82+
while(RTCREG->STATUS.BITS.BSY_CTRL_REG_WRT == True); /* Wait for RTC to finish writing register - RTC operates on 32K clock as compared to 32M core*/
8383

8484
return;
8585
}
@@ -93,14 +93,14 @@ void fRtcFree(void)
9393
/* disable interruption associated with the rtc */
9494
NVIC_DisableIRQ(Rtc_IRQn);
9595

96-
while(RTCREG->STATUS.BITS.BSY_ANY_WRT == True); /* Wait for RTC to finish writing register - RTC operates on 32K clock as compared to 32M core*/
96+
while(RTCREG->STATUS.BITS.BSY_CTRL_REG_WRT == True); /* Wait for RTC to finish writing register - RTC operates on 32K clock as compared to 32M core*/
9797
}
9898

9999
/* See rtc.h for details */
100100
void fRtcSetInterrupt(uint32_t timestamp)
101101
{
102-
SubSecond = False;
103-
uint32_t Second = False;
102+
SubSecond = False;
103+
uint32_t Second = False;
104104
uint8_t DividerAdjust = 1;
105105

106106
if(timestamp) {
@@ -137,6 +137,7 @@ void fRtcSetInterrupt(uint32_t timestamp)
137137
RTCREG->SUB_SECOND_ALARM = SubSecond; /* Write to sub second alarm */
138138

139139
/* Enable sub second interrupt */
140+
while(RTCREG->STATUS.BITS.BSY_CTRL_REG_WRT == True);
140141
RTCREG->CONTROL.WORD |= (True << RTC_CONTROL_SUBSEC_CNT_INT_BIT_POS);
141142
}
142143
}
@@ -151,15 +152,15 @@ void fRtcDisableInterrupt(void)
151152
{
152153
/* Disable subsec/sec interrupt */
153154
RTCREG->CONTROL.WORD &= ~((RTC_ALL_INTERRUPT_BIT_VAL) << RTC_CONTROL_SUBSEC_CNT_INT_BIT_POS);
154-
while(RTCREG->STATUS.BITS.BSY_ANY_WRT == True); /* Wait for RTC to finish writing register - RTC operates on 32K clock as compared to 32M core*/
155+
while(RTCREG->STATUS.BITS.BSY_CTRL_REG_WRT == True); /* Wait for RTC to finish writing register - RTC operates on 32K clock as compared to 32M core*/
155156
}
156157

157158
/* See rtc.h for details */
158159
void fRtcEnableInterrupt(void)
159160
{
160161
/* Disable subsec/sec interrupt */
161162
RTCREG->CONTROL.WORD |= ((RTC_ALL_INTERRUPT_BIT_VAL) << RTC_CONTROL_SUBSEC_CNT_INT_BIT_POS);
162-
while(RTCREG->STATUS.BITS.BSY_ANY_WRT == True); /* Wait for RTC to finish writing register - RTC operates on 32K clock as compared to 32M core*/
163+
while(RTCREG->STATUS.BITS.BSY_CTRL_REG_WRT == True); /* Wait for RTC to finish writing register - RTC operates on 32K clock as compared to 32M core*/
163164
}
164165

165166
/* See rtc.h for details */
@@ -237,40 +238,40 @@ void fRtcWrite(uint64_t RtcTimeus)
237238
/* See rtc.h for details */
238239
void fRtcHandler(void)
239240
{
240-
while(RTCREG->STATUS.BITS.BSY_ANY_WRT == True); /* Wait for RTC to finish writing register - RTC operates on 32K clock as compared to 32M core*/
241241
/* SUB_SECOND/SECOND interrupt occured */
242242
volatile uint32_t TempStatus = RTCREG->STATUS.WORD;
243243

244-
/* disable all interrupts */
245-
RTCREG->CONTROL.WORD &= ~((RTC_ALL_INTERRUPT_BIT_VAL) << RTC_CONTROL_SUBSEC_CNT_INT_BIT_POS);
244+
/* Disable RTC interrupt */
245+
NVIC_DisableIRQ(Rtc_IRQn);
246246

247247
/* Clear sec & sub_sec interrupts */
248248
RTCREG->INT_CLEAR.WORD = ((True << RTC_INT_CLR_SUB_SEC_BIT_POS) |
249249
(True << RTC_INT_CLR_SEC_BIT_POS));
250250

251-
/* TODO ANDing SUB_SEC & SEC interrupt - work around for RTC issue - will be solved in REV G */
251+
/* TODO ANDing SUB_SEC & SEC interrupt - work around for RTC issue - will be resolved in REV G */
252252
if(TempStatus & RTC_SEC_INT_STATUS_MASK) {
253253
/* Second interrupt occured */
254254
if(SubSecond > False) {
255255
/* Set SUB SEC_ALARM */
256256
RTCREG->SUB_SECOND_ALARM = SubSecond + RTCREG->SUB_SECOND_COUNTER;
257257
/* Enable sub second interrupt */
258-
while(RTCREG->STATUS.BITS.BSY_CTRL_REG_WRT == True);
259258
RTCREG->CONTROL.WORD |= (True << RTC_CONTROL_SUBSEC_CNT_INT_BIT_POS);
260259
} else {
261260
/* We reach here after second interrupt is occured */
262-
while(RTCREG->STATUS.BITS.BSY_CTRL_REG_WRT == True);
263261
RTCREG->CONTROL.WORD &= ~(True << RTC_CONTROL_SUBSEC_CNT_INT_BIT_POS) |
264262
(True << RTC_CONTROL_SEC_CNT_INT_BIT_POS);
265263
}
266264
} else {
267265
/* We reach here after sub_second or (Sub second + second) interrupt occured */
268-
while(RTCREG->STATUS.BITS.BSY_CTRL_REG_WRT == True);
269266
/* Disable Second and sub_second interrupt */
270267
RTCREG->CONTROL.WORD &= ~(True << RTC_CONTROL_SUBSEC_CNT_INT_BIT_POS) |
271268
(True << RTC_CONTROL_SEC_CNT_INT_BIT_POS);
272269
}
273270

271+
NVIC_EnableIRQ(Rtc_IRQn);
272+
273+
while(RTCREG->STATUS.BITS.BSY_ANY_WRT == True); /* Wait for RTC to finish writing register - RTC operates on 32K clock as compared to 32M core*/
274+
274275
lp_ticker_irq_handler();
275276
}
276277

0 commit comments

Comments
 (0)