Skip to content

Commit 4ac2c3c

Browse files
committed
Added ReadReq() which ensures the CLOCK register synchronised.
Reading the CLOCK elements when it is not synchronised can cause the bus to stall. This can block interrupts. This code currently increases the cost of calling getEpoch() from 6ms to about 35ms. Todo: Change getEpoch() to single read from the CLOCK register. This will reduce the cost back to ~6ms.
1 parent 152f297 commit 4ac2c3c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/RTCZero.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,31 +121,37 @@ void RTCZero::standbyMode()
121121

122122
uint8_t RTCZero::getSeconds()
123123
{
124+
RTCreadRequest();
124125
return RTC->MODE2.CLOCK.bit.SECOND;
125126
}
126127

127128
uint8_t RTCZero::getMinutes()
128129
{
130+
RTCreadRequest();
129131
return RTC->MODE2.CLOCK.bit.MINUTE;
130132
}
131133

132134
uint8_t RTCZero::getHours()
133135
{
136+
RTCreadRequest();
134137
return RTC->MODE2.CLOCK.bit.HOUR;
135138
}
136139

137140
uint8_t RTCZero::getDay()
138141
{
142+
RTCreadRequest();
139143
return RTC->MODE2.CLOCK.bit.DAY;
140144
}
141145

142146
uint8_t RTCZero::getMonth()
143147
{
148+
RTCreadRequest();
144149
return RTC->MODE2.CLOCK.bit.MONTH;
145150
}
146151

147152
uint8_t RTCZero::getYear()
148153
{
154+
RTCreadRequest();
149155
return RTC->MODE2.CLOCK.bit.YEAR;
150156
}
151157

@@ -357,6 +363,13 @@ void RTCZero::config32kOSC()
357363
SYSCTRL_XOSC32K_ENABLE;
358364
}
359365

366+
/* Synchronise the CLOCK register for reading*/
367+
inline void RTCZero::RTCreadRequest() {
368+
RTC->MODE2.READREQ.reg |= RTC_READREQ_RREQ;
369+
while (RTCisSyncing())
370+
;
371+
}
372+
360373
/* Wait for sync in write operations */
361374
inline bool RTCZero::RTCisSyncing()
362375
{

src/RTCZero.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class RTCZero {
100100

101101
private:
102102
void config32kOSC(void);
103+
void RTCreadRequest();
103104
bool RTCisSyncing(void);
104105
void RTCdisable();
105106
void RTCenable();

0 commit comments

Comments
 (0)