Skip to content

Commit

Permalink
Merge pull request RIOT-OS#20448 from benpicco/cpu/sam0_common-rtc-0
Browse files Browse the repository at this point in the history
cpu/sam0_common: RTC: avoid negative month after POR
  • Loading branch information
benpicco authored Mar 7, 2024
2 parents 31d2300 + 897a3ce commit 1bf643d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions cpu/sam0_common/periph/rtc_rtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,18 @@ int rtc_get_alarm(struct tm *time)
return -1;
}

time->tm_mon = alarm.bit.MONTH - 1;
time->tm_mon = alarm.bit.MONTH;
time->tm_mday = alarm.bit.DAY;
time->tm_hour = alarm.bit.HOUR;
time->tm_min = alarm.bit.MINUTE;
time->tm_sec = alarm.bit.SECOND;

/* struct tm has January as 0, RTC has January as 1 */
/* But after power-on reset, all RTC values are 0 - avoid negative month */
if (time->tm_mon) {
--time->tm_mon;
}

return 0;
}

Expand All @@ -583,11 +589,18 @@ int rtc_get_time(struct tm *time)
return -1;
}

time->tm_mon = clock.bit.MONTH - 1;
time->tm_mon = clock.bit.MONTH;
time->tm_mday = clock.bit.DAY;
time->tm_hour = clock.bit.HOUR;
time->tm_min = clock.bit.MINUTE;
time->tm_sec = clock.bit.SECOND;

/* struct tm has January as 0, RTC has January as 1 */
/* But after power-on reset, all RTC values are 0 - avoid negative month */
if (time->tm_mon) {
--time->tm_mon;
}

return 0;
}

Expand Down

0 comments on commit 1bf643d

Please sign in to comment.