mirror of https://github.com/ARMmbed/mbed-os.git
[NANO130] remove usage of mktime/localtime in rtc_api.c
parent
83f395c07c
commit
2050095b0f
|
@ -22,6 +22,7 @@
|
|||
#include "mbed_error.h"
|
||||
#include "nu_modutil.h"
|
||||
#include "nu_miscutil.h"
|
||||
#include "mbed_mktime.h"
|
||||
|
||||
#define YEAR0 1900
|
||||
|
||||
|
@ -90,7 +91,7 @@ time_t rtc_read(void)
|
|||
timeinfo.tm_sec = rtc_datetime.u32Second;
|
||||
|
||||
// Convert to timestamp
|
||||
time_t t = mktime(&timeinfo);
|
||||
time_t t = _rtc_mktime(&timeinfo);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
@ -102,23 +103,26 @@ void rtc_write(time_t t)
|
|||
}
|
||||
|
||||
// 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;
|
||||
|
||||
RTC_SetDateAndTime(&rtc_datetime);
|
||||
// Wait 3 cycles of engine clock to ensure this RTC write is active
|
||||
nu_nop(SystemCoreClock / __LXT * 3);
|
||||
// Wait 3 cycles of engine clock to ensure previous CTL write action is finish
|
||||
wait_us(30 * 3);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue