Update RTC drivers for extended RTC.

pull/5363/head
Przemyslaw Stekiel 2017-11-16 14:42:49 +01:00
parent fcdaeccea1
commit 106561669f
11 changed files with 60 additions and 27 deletions

View File

@ -71,7 +71,11 @@ time_t rtc_read(void)
timeinfo.tm_year = (ul_year - 1900);
/* Convert to timestamp */
time_t t = _rtc_mktime(&timeinfo);
time_t t;
if (_rtc_maketime(&timeinfo, &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
return 0;
}
return t;
}
@ -81,8 +85,9 @@ void rtc_write(time_t t)
/* Initialize the RTC is not yet initialized */
rtc_init();
}
struct tm timeinfo;
if (_rtc_localtime(t, &timeinfo) == false) {
if (_rtc_localtime(t, &timeinfo, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
return;
}
uint32_t ul_hour, ul_minute, ul_second;

View File

@ -94,7 +94,10 @@ time_t rtc_read(void)
timeinfo.tm_sec = rtc_datetime.u32Second;
// Convert to timestamp
time_t t = _rtc_mktime(&timeinfo);
time_t t;
if (_rtc_maketime(&timeinfo, &t, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
return 0;
}
return t;
}
@ -107,7 +110,7 @@ void rtc_write(time_t t)
// Convert timestamp to struct tm
struct tm timeinfo;
if (_rtc_localtime(t, &timeinfo) == false) {
if (_rtc_localtime(t, &timeinfo, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
return;
}

View File

@ -96,7 +96,10 @@ time_t rtc_read(void)
timeinfo.tm_sec = rtc_datetime.u32Second;
// Convert to timestamp
time_t t = _rtc_mktime(&timeinfo);
time_t t;
if (_rtc_maketime(&timeinfo, &t, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
return 0;
}
return t;
}
@ -109,7 +112,7 @@ void rtc_write(time_t t)
// Convert timestamp to struct tm
struct tm timeinfo;
if (_rtc_localtime(t, &timeinfo) == false) {
if (_rtc_localtime(t, &timeinfo, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
return;
}

View File

@ -94,7 +94,10 @@ time_t rtc_read(void)
timeinfo.tm_sec = rtc_datetime.u32Second;
// Convert to timestamp
time_t t = _rtc_mktime(&timeinfo);
time_t t;
if (_rtc_maketime(&timeinfo, &t, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
return 0;
}
return t;
}
@ -107,7 +110,7 @@ void rtc_write(time_t t)
// Convert timestamp to struct tm
struct tm timeinfo;
if (_rtc_localtime(t, &timeinfo) == false) {
if (_rtc_localtime(t, &timeinfo, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
return;
}

View File

@ -94,7 +94,10 @@ time_t rtc_read(void)
timeinfo.tm_sec = rtc_datetime.u32Second;
// Convert to timestamp
time_t t = _rtc_mktime(&timeinfo);
time_t t;
if (_rtc_maketime(&timeinfo, &t, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
return 0;
}
return t;
}
@ -107,7 +110,7 @@ void rtc_write(time_t t)
// Convert timestamp to struct tm
struct tm timeinfo;
if (_rtc_localtime(t, &timeinfo) == false) {
if (_rtc_localtime(t, &timeinfo, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
return;
}

View File

@ -89,7 +89,10 @@ time_t rtc_read(void) {
timeinfo.tm_year = LPC_RTC->YEAR - 1900;
// Convert to timestamp
time_t t = _rtc_mktime(&timeinfo);
time_t t;
if (_rtc_maketime(&timeinfo, &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
return 0;
}
return t;
}
@ -97,7 +100,7 @@ time_t rtc_read(void) {
void rtc_write(time_t t) {
// Convert the time in to a tm
struct tm timeinfo;
if (_rtc_localtime(t, &timeinfo) == false) {
if (_rtc_localtime(t, &timeinfo, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
return;
}

View File

@ -88,7 +88,10 @@ time_t rtc_read(void) {
timeinfo.tm_year = LPC_RTC->YEAR - 1900;
// Convert to timestamp
time_t t = _rtc_mktime(&timeinfo);
time_t t;
if (_rtc_maketime(&timeinfo, &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
return 0;
}
return t;
}
@ -96,7 +99,7 @@ time_t rtc_read(void) {
void rtc_write(time_t t) {
// Convert the time in to a tm
struct tm timeinfo;
if (_rtc_localtime(t, &timeinfo) == false) {
if (_rtc_localtime(t, &timeinfo, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
return;
}

View File

@ -102,7 +102,10 @@ time_t rtc_read(void) {
timeinfo.tm_year = LPC_RTC->TIME[RTC_TIMETYPE_YEAR] - 1900;
// Convert to timestamp
time_t t = _rtc_mktime(&timeinfo);
time_t t;
if (_rtc_maketime(&timeinfo, &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
return 0;
}
return t;
}
@ -110,7 +113,7 @@ time_t rtc_read(void) {
void rtc_write(time_t t) {
// Convert the time in to a tm
struct tm timeinfo;
if (_rtc_localtime(t, &timeinfo) == false) {
if (_rtc_localtime(t, &timeinfo, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
return;
}

View File

@ -308,6 +308,7 @@ void rtc_write(time_t t) {
if (_rtc_localtime(t, &timeinfo) == false) {
return;
}
volatile uint16_t dummy_read;
if (rtc_isenabled() != 0) {

View File

@ -70,7 +70,7 @@
#define SHIFT_1BYTE (8u)
#define SHIFT_2BYTE (16u)
#define TIME_ERROR_VAL (0xFFFFFFFFu)
#define TIME_ERROR_VAL (0u)
static int rtc_dec8_to_hex(uint8_t dec_val, uint8_t offset, int *hex_val);
static int rtc_dec16_to_hex(uint16_t dec_val, uint16_t offset, int *hex_val);
@ -248,7 +248,9 @@ time_t rtc_read(void) {
if (err == 0) {
// Convert to timestamp
t = _rtc_mktime(&timeinfo);
if (_rtc_maketime(&timeinfo, &t, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
return TIME_ERROR_VAL;
}
} else {
// Error
t = TIME_ERROR_VAL;
@ -339,9 +341,10 @@ static int rtc_dec16_to_hex(uint16_t dec_val, uint16_t offset, int *hex_val) {
void rtc_write(time_t t) {
struct tm timeinfo;
if (_rtc_localtime(t, &timeinfo) == false) {
if (_rtc_localtime(t, &timeinfo, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
return;
}
volatile uint16_t dummy_read;
if (rtc_isenabled() != 0) {

View File

@ -241,7 +241,10 @@ time_t rtc_read(void)
timeinfo.tm_isdst = -1;
// Convert to timestamp
time_t t = _rtc_mktime(&timeinfo);
time_t t;
if (_rtc_maketime(&timeinfo, &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
return 0;
}
return t;
}
@ -255,7 +258,7 @@ void rtc_write(time_t t)
// Convert the time into a tm
struct tm timeinfo;
if (_rtc_localtime(t, &timeinfo) == false) {
if (_rtc_localtime(t, &timeinfo, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
return;
}