helpfor studient
Dependents: STM32_F103-C8T6basecanblink_led
Fork of mbed-dev by
Diff: targets/TARGET_NUVOTON/TARGET_NUC472/rtc_api.c
- Revision:
- 167:e84263d55307
- Parent:
- 160:d5399cc887bb
- Child:
- 172:7d866c31b3c5
diff -r c97ed07ec1a8 -r e84263d55307 targets/TARGET_NUVOTON/TARGET_NUC472/rtc_api.c --- a/targets/TARGET_NUVOTON/TARGET_NUC472/rtc_api.c Thu Jun 08 15:02:37 2017 +0100 +++ b/targets/TARGET_NUVOTON/TARGET_NUC472/rtc_api.c Wed Jun 21 17:46:44 2017 +0100 @@ -22,6 +22,7 @@ #include "mbed_error.h" #include "nu_modutil.h" #include "nu_miscutil.h" +#include "mbed_mktime.h" #define YEAR0 1900 //#define EPOCH_YR 1970 @@ -86,7 +87,7 @@ timeinfo.tm_sec = rtc_datetime.u32Second; // Convert to timestamp - time_t t = mktime(&timeinfo); + time_t t = _rtc_mktime(&timeinfo); return t; } @@ -98,18 +99,21 @@ } // Convert timestamp to struct tm - struct tm *timeinfo = localtime(&t); + struct tm timeinfo; + if (_rtc_localtime(t, &timeinfo) == false) { + return; + } S_RTC_TIME_DATA_T rtc_datetime; // Convert S_RTC_TIME_DATA_T to struct tm - rtc_datetime.u32Year = timeinfo->tm_year + YEAR0; - rtc_datetime.u32Month = timeinfo->tm_mon + 1; - rtc_datetime.u32Day = timeinfo->tm_mday; - rtc_datetime.u32DayOfWeek = timeinfo->tm_wday; - rtc_datetime.u32Hour = timeinfo->tm_hour; - rtc_datetime.u32Minute = timeinfo->tm_min; - rtc_datetime.u32Second = timeinfo->tm_sec; + rtc_datetime.u32Year = timeinfo.tm_year + YEAR0; + rtc_datetime.u32Month = timeinfo.tm_mon + 1; + rtc_datetime.u32Day = timeinfo.tm_mday; + rtc_datetime.u32DayOfWeek = timeinfo.tm_wday; + rtc_datetime.u32Hour = timeinfo.tm_hour; + rtc_datetime.u32Minute = timeinfo.tm_min; + rtc_datetime.u32Second = timeinfo.tm_sec; rtc_datetime.u32TimeScale = RTC_CLOCK_24; // NOTE: Timing issue with write to RTC registers. This delay is empirical, not rational.