Skip to content

Add getAlarmEpoch() method and fix warning on compiling with oldTime.RTC_MODE2_CLOCK_Type::reg #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/RTCZero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void RTCZero::begin(bool resetTime)
// not due to POR or BOD, preserve the clock time
// POR causes a reset anyway, BOD behaviour is?
bool validTime = false;
RTC_MODE2_CLOCK_Type oldTime;
RTC_MODE2_CLOCK_Type oldTime = {.reg=0L};

if ((!resetTime) && (PM->RCAUSE.reg & (PM_RCAUSE_SYST | PM_RCAUSE_WDT | PM_RCAUSE_EXT))) {
if (RTC->MODE2.CTRL.reg & RTC_MODE2_CTRL_MODE_CLOCK) {
Expand Down Expand Up @@ -391,11 +391,32 @@ time_t RTCZero::getEpoch()
return mktime(&tm);
}

uint32_t RTCZero::getY2kEpoch()
time_t RTCZero::getY2kEpoch()
{
return (getEpoch() - EPOCH_TIME_OFF);
}

time_t RTCZero::getAlarmEpoch()
{
RTCreadRequest();
RTC_MODE2_ALARM_Type alarmTime;
alarmTime.reg = RTC->MODE2.Mode2Alarm[0].ALARM.reg;

struct tm tm;

tm.tm_isdst = -1;
tm.tm_yday = 0;
tm.tm_wday = 0;
tm.tm_year = alarmTime.bit.YEAR + EPOCH_TIME_YEAR_OFF;
tm.tm_mon = alarmTime.bit.MONTH - 1;
tm.tm_mday = alarmTime.bit.DAY;
tm.tm_hour = alarmTime.bit.HOUR;
tm.tm_min = alarmTime.bit.MINUTE;
tm.tm_sec = alarmTime.bit.SECOND;

return mktime(&tm);
}

void RTCZero::setAlarmEpoch(uint32_t ts)
{
if (_configured) {
Expand Down
3 changes: 2 additions & 1 deletion src/RTCZero.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ class RTCZero {
/* Epoch Functions */

time_t getEpoch();
uint32_t getY2kEpoch();
time_t getY2kEpoch();
time_t getAlarmEpoch();
void setEpoch(uint32_t ts);
void setY2kEpoch(uint32_t ts);
void setAlarmEpoch(uint32_t ts);
Expand Down