Skip to content

Commit 2050095

Browse files
committed
[NANO130] remove usage of mktime/localtime in rtc_api.c
1 parent 83f395c commit 2050095

File tree

1 file changed

+15
-11
lines changed
  • targets/TARGET_NUVOTON/TARGET_NANO100

1 file changed

+15
-11
lines changed

targets/TARGET_NUVOTON/TARGET_NANO100/rtc_api.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "mbed_error.h"
2323
#include "nu_modutil.h"
2424
#include "nu_miscutil.h"
25+
#include "mbed_mktime.h"
2526

2627
#define YEAR0 1900
2728

@@ -90,7 +91,7 @@ time_t rtc_read(void)
9091
timeinfo.tm_sec = rtc_datetime.u32Second;
9192

9293
// Convert to timestamp
93-
time_t t = mktime(&timeinfo);
94+
time_t t = _rtc_mktime(&timeinfo);
9495

9596
return t;
9697
}
@@ -102,23 +103,26 @@ void rtc_write(time_t t)
102103
}
103104

104105
// Convert timestamp to struct tm
105-
struct tm *timeinfo = localtime(&t);
106+
struct tm timeinfo;
107+
if (_rtc_localtime(t, &timeinfo) == false) {
108+
return;
109+
}
106110

107111
S_RTC_TIME_DATA_T rtc_datetime;
108112

109113
// Convert S_RTC_TIME_DATA_T to struct tm
110-
rtc_datetime.u32Year = timeinfo->tm_year + YEAR0;
111-
rtc_datetime.u32Month = timeinfo->tm_mon + 1;
112-
rtc_datetime.u32Day = timeinfo->tm_mday;
113-
rtc_datetime.u32DayOfWeek = timeinfo->tm_wday;
114-
rtc_datetime.u32Hour = timeinfo->tm_hour;
115-
rtc_datetime.u32Minute = timeinfo->tm_min;
116-
rtc_datetime.u32Second = timeinfo->tm_sec;
114+
rtc_datetime.u32Year = timeinfo.tm_year + YEAR0;
115+
rtc_datetime.u32Month = timeinfo.tm_mon + 1;
116+
rtc_datetime.u32Day = timeinfo.tm_mday;
117+
rtc_datetime.u32DayOfWeek = timeinfo.tm_wday;
118+
rtc_datetime.u32Hour = timeinfo.tm_hour;
119+
rtc_datetime.u32Minute = timeinfo.tm_min;
120+
rtc_datetime.u32Second = timeinfo.tm_sec;
117121
rtc_datetime.u32TimeScale = RTC_CLOCK_24;
118122

119123
RTC_SetDateAndTime(&rtc_datetime);
120-
// Wait 3 cycles of engine clock to ensure this RTC write is active
121-
nu_nop(SystemCoreClock / __LXT * 3);
124+
// Wait 3 cycles of engine clock to ensure previous CTL write action is finish
125+
wait_us(30 * 3);
122126
}
123127

124128
#endif

0 commit comments

Comments
 (0)