Skip to content

Commit 1065616

Browse files
committed
Update RTC drivers for extended RTC.
1 parent fcdaecc commit 1065616

File tree

11 files changed

+60
-27
lines changed

11 files changed

+60
-27
lines changed

targets/TARGET_Atmel/TARGET_SAM_CortexM4/rtc_api.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ time_t rtc_read(void)
7171
timeinfo.tm_year = (ul_year - 1900);
7272

7373
/* Convert to timestamp */
74-
time_t t = _rtc_mktime(&timeinfo);
74+
time_t t;
75+
if (_rtc_maketime(&timeinfo, &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
76+
return 0;
77+
}
78+
7579
return t;
7680
}
7781

@@ -81,8 +85,9 @@ void rtc_write(time_t t)
8185
/* Initialize the RTC is not yet initialized */
8286
rtc_init();
8387
}
88+
8489
struct tm timeinfo;
85-
if (_rtc_localtime(t, &timeinfo) == false) {
90+
if (_rtc_localtime(t, &timeinfo, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
8691
return;
8792
}
8893
uint32_t ul_hour, ul_minute, ul_second;

targets/TARGET_NUVOTON/TARGET_M451/rtc_api.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ time_t rtc_read(void)
9494
timeinfo.tm_sec = rtc_datetime.u32Second;
9595

9696
// Convert to timestamp
97-
time_t t = _rtc_mktime(&timeinfo);
97+
time_t t;
98+
if (_rtc_maketime(&timeinfo, &t, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
99+
return 0;
100+
}
98101

99102
return t;
100103
}
@@ -104,10 +107,10 @@ void rtc_write(time_t t)
104107
if (! rtc_isenabled()) {
105108
rtc_init();
106109
}
107-
110+
108111
// Convert timestamp to struct tm
109112
struct tm timeinfo;
110-
if (_rtc_localtime(t, &timeinfo) == false) {
113+
if (_rtc_localtime(t, &timeinfo, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
111114
return;
112115
}
113116

targets/TARGET_NUVOTON/TARGET_M480/rtc_api.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ time_t rtc_read(void)
9696
timeinfo.tm_sec = rtc_datetime.u32Second;
9797

9898
// Convert to timestamp
99-
time_t t = _rtc_mktime(&timeinfo);
99+
time_t t;
100+
if (_rtc_maketime(&timeinfo, &t, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
101+
return 0;
102+
}
100103

101104
return t;
102105
}
@@ -109,7 +112,7 @@ void rtc_write(time_t t)
109112

110113
// Convert timestamp to struct tm
111114
struct tm timeinfo;
112-
if (_rtc_localtime(t, &timeinfo) == false) {
115+
if (_rtc_localtime(t, &timeinfo, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
113116
return;
114117
}
115118

targets/TARGET_NUVOTON/TARGET_NANO100/rtc_api.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ time_t rtc_read(void)
9494
timeinfo.tm_sec = rtc_datetime.u32Second;
9595

9696
// Convert to timestamp
97-
time_t t = _rtc_mktime(&timeinfo);
97+
time_t t;
98+
if (_rtc_maketime(&timeinfo, &t, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
99+
return 0;
100+
}
98101

99102
return t;
100103
}
@@ -104,10 +107,10 @@ void rtc_write(time_t t)
104107
if (! rtc_isenabled()) {
105108
rtc_init();
106109
}
107-
110+
108111
// Convert timestamp to struct tm
109112
struct tm timeinfo;
110-
if (_rtc_localtime(t, &timeinfo) == false) {
113+
if (_rtc_localtime(t, &timeinfo, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
111114
return;
112115
}
113116

targets/TARGET_NUVOTON/TARGET_NUC472/rtc_api.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ time_t rtc_read(void)
9494
timeinfo.tm_sec = rtc_datetime.u32Second;
9595

9696
// Convert to timestamp
97-
time_t t = _rtc_mktime(&timeinfo);
97+
time_t t;
98+
if (_rtc_maketime(&timeinfo, &t, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
99+
return 0;
100+
}
98101

99102
return t;
100103
}
@@ -104,10 +107,10 @@ void rtc_write(time_t t)
104107
if (! rtc_isenabled()) {
105108
rtc_init();
106109
}
107-
110+
108111
// Convert timestamp to struct tm
109112
struct tm timeinfo;
110-
if (_rtc_localtime(t, &timeinfo) == false) {
113+
if (_rtc_localtime(t, &timeinfo, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
111114
return;
112115
}
113116

targets/TARGET_NXP/TARGET_LPC176X/rtc_api.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,21 @@ time_t rtc_read(void) {
8989
timeinfo.tm_year = LPC_RTC->YEAR - 1900;
9090

9191
// Convert to timestamp
92-
time_t t = _rtc_mktime(&timeinfo);
92+
time_t t;
93+
if (_rtc_maketime(&timeinfo, &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
94+
return 0;
95+
}
9396

9497
return t;
9598
}
9699

97100
void rtc_write(time_t t) {
98101
// Convert the time in to a tm
99102
struct tm timeinfo;
100-
if (_rtc_localtime(t, &timeinfo) == false) {
103+
if (_rtc_localtime(t, &timeinfo, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
101104
return;
102105
}
103-
106+
104107
// Pause clock, and clear counter register (clears us count)
105108
LPC_RTC->CCR |= 2;
106109

targets/TARGET_NXP/TARGET_LPC408X/rtc_api.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,21 @@ time_t rtc_read(void) {
8888
timeinfo.tm_year = LPC_RTC->YEAR - 1900;
8989

9090
// Convert to timestamp
91-
time_t t = _rtc_mktime(&timeinfo);
91+
time_t t;
92+
if (_rtc_maketime(&timeinfo, &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
93+
return 0;
94+
}
9295

9396
return t;
9497
}
9598

9699
void rtc_write(time_t t) {
97100
// Convert the time in to a tm
98101
struct tm timeinfo;
99-
if (_rtc_localtime(t, &timeinfo) == false) {
102+
if (_rtc_localtime(t, &timeinfo, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
100103
return;
101104
}
102-
105+
103106
// Pause clock, and clear counter register (clears us count)
104107
LPC_RTC->CCR |= 2;
105108

targets/TARGET_NXP/TARGET_LPC43XX/rtc_api.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,21 @@ time_t rtc_read(void) {
102102
timeinfo.tm_year = LPC_RTC->TIME[RTC_TIMETYPE_YEAR] - 1900;
103103

104104
// Convert to timestamp
105-
time_t t = _rtc_mktime(&timeinfo);
105+
time_t t;
106+
if (_rtc_maketime(&timeinfo, &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
107+
return 0;
108+
}
106109

107110
return t;
108111
}
109112

110113
void rtc_write(time_t t) {
111114
// Convert the time in to a tm
112115
struct tm timeinfo;
113-
if (_rtc_localtime(t, &timeinfo) == false) {
116+
if (_rtc_localtime(t, &timeinfo, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
114117
return;
115118
}
116-
119+
117120
// Pause clock, and clear counter register (clears us count)
118121
LPC_RTC->CCR |= 2;
119122

targets/TARGET_RENESAS/TARGET_RZ_A1H/rtc_api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ void rtc_write(time_t t) {
308308
if (_rtc_localtime(t, &timeinfo) == false) {
309309
return;
310310
}
311+
311312
volatile uint16_t dummy_read;
312313

313314
if (rtc_isenabled() != 0) {

targets/TARGET_RENESAS/TARGET_VK_RZ_A1H/rtc_api.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
#define SHIFT_1BYTE (8u)
7171
#define SHIFT_2BYTE (16u)
7272

73-
#define TIME_ERROR_VAL (0xFFFFFFFFu)
73+
#define TIME_ERROR_VAL (0u)
7474

7575
static int rtc_dec8_to_hex(uint8_t dec_val, uint8_t offset, int *hex_val);
7676
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) {
248248

249249
if (err == 0) {
250250
// Convert to timestamp
251-
t = _rtc_mktime(&timeinfo);
251+
if (_rtc_maketime(&timeinfo, &t, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
252+
return TIME_ERROR_VAL;
253+
}
252254
} else {
253255
// Error
254256
t = TIME_ERROR_VAL;
@@ -339,9 +341,10 @@ static int rtc_dec16_to_hex(uint16_t dec_val, uint16_t offset, int *hex_val) {
339341
void rtc_write(time_t t) {
340342

341343
struct tm timeinfo;
342-
if (_rtc_localtime(t, &timeinfo) == false) {
344+
if (_rtc_localtime(t, &timeinfo, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
343345
return;
344346
}
347+
345348
volatile uint16_t dummy_read;
346349

347350
if (rtc_isenabled() != 0) {

targets/TARGET_STM/rtc_api.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ time_t rtc_read(void)
241241
timeinfo.tm_isdst = -1;
242242

243243
// Convert to timestamp
244-
time_t t = _rtc_mktime(&timeinfo);
244+
time_t t;
245+
if (_rtc_maketime(&timeinfo, &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
246+
return 0;
247+
}
245248

246249
return t;
247250
}
@@ -255,7 +258,7 @@ void rtc_write(time_t t)
255258

256259
// Convert the time into a tm
257260
struct tm timeinfo;
258-
if (_rtc_localtime(t, &timeinfo) == false) {
261+
if (_rtc_localtime(t, &timeinfo, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
259262
return;
260263
}
261264

0 commit comments

Comments
 (0)