mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-26 15:03:53 +01:00
Merge pull request #14726 from benpicco/riot_epoch
drivers/periph_common: RTC: use RIOT_EPOCH as the RTC reset value
This commit is contained in:
commit
4635be207b
@ -57,7 +57,7 @@ void rtc_init(void)
|
||||
* after cold boot or external reset.
|
||||
*/
|
||||
if ((RSIR == RSIR_POR) || (RSIR == (RSIR_POR | RSIR_EXTR))) {
|
||||
struct tm localt = { .tm_year = 70 };
|
||||
struct tm localt = { .tm_year = RIOT_EPOCH - 1900 };
|
||||
rtc_set_time(&localt);
|
||||
}
|
||||
|
||||
|
||||
@ -62,9 +62,10 @@ static rtc_state_t alarm_cb;
|
||||
static rtc_state_t overflow_cb;
|
||||
|
||||
/* At 1Hz, RTC goes till 63 years (2^5, see 17.8.22 in datasheet)
|
||||
* reference_year is set to 100 (offset) to be in our current time (2000)
|
||||
* Thanks to this, the user will be able to set time in 2000's*/
|
||||
static uint16_t reference_year = 100;
|
||||
* struct tm younts the year since 1900, use the difference to RIOT_EPOCH
|
||||
* as an offset so the user can set years in RIOT_EPOCH + 63
|
||||
*/
|
||||
static uint16_t reference_year = RIOT_EPOCH - 1900;
|
||||
|
||||
static void _wait_syncbusy(void)
|
||||
{
|
||||
|
||||
@ -163,9 +163,8 @@
|
||||
#error "rtc: unable to determine RTC SYNC and ASYNC prescalers from LSI value"
|
||||
#endif
|
||||
|
||||
/* struct tm counts years since 1900 but RTC has only two-digit year hence the
|
||||
* offset of 100 years. */
|
||||
#define YEAR_OFFSET (100)
|
||||
/* struct tm counts years since 1900 but RTC has only two-digit year, hence the offset */
|
||||
#define YEAR_OFFSET (RIOT_EPOCH - 1900)
|
||||
|
||||
/* Use a magic number to determine the initial RTC source. This will be used
|
||||
to know if a reset of the RTC is required at initialization. */
|
||||
@ -273,7 +272,7 @@ int rtc_set_time(struct tm *time)
|
||||
|
||||
rtc_unlock();
|
||||
|
||||
RTC->DR = (val2bcd((time->tm_year % 100), RTC_DR_YU_Pos, DR_Y_MASK) |
|
||||
RTC->DR = (val2bcd((time->tm_year - YEAR_OFFSET), RTC_DR_YU_Pos, DR_Y_MASK) |
|
||||
val2bcd(time->tm_mon + 1, RTC_DR_MU_Pos, DR_M_MASK) |
|
||||
val2bcd(time->tm_mday, RTC_DR_DU_Pos, DR_D_MASK));
|
||||
RTC->TR = (val2bcd(time->tm_hour, RTC_TR_HU_Pos, TR_H_MASK) |
|
||||
|
||||
@ -46,6 +46,18 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !defined(RIOT_EPOCH) || DOXYGEN
|
||||
/**
|
||||
* @brief Earliest year of the RTC
|
||||
*
|
||||
* 01.01.$RIOT_EPOCH will be the reset value of the RTC if supported.
|
||||
*
|
||||
* Internal RTC helper functions such as @see rtc_mktime and @see rtc_localtime
|
||||
* will not work on dates earlier than that.
|
||||
*/
|
||||
#define RIOT_EPOCH (2020)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Signature for alarm Callback
|
||||
*
|
||||
|
||||
@ -31,10 +31,6 @@
|
||||
#define HOUR (60U * MINUTE)
|
||||
#define DAY (24U * HOUR)
|
||||
|
||||
#ifndef RIOT_EPOCH
|
||||
#define RIOT_EPOCH (2020)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The rules here are (to be checked in that explicit order):
|
||||
* 1. If the year is not a multiple of four, it is not a leap year.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user