1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cpu/sam0_common: RTC: avoid negative month after POR

This commit is contained in:
Benjamin Valentin 2024-03-06 18:48:26 +01:00
parent 31d2300b8a
commit 897a3ceda9

View File

@ -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;
}
@ -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;
}