From 892e73121acde7a3452bc9f5c380af0450840314 Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 19 Sep 2012 12:25:05 +0000 Subject: RTC. Fixed bug 3568626. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4694 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/various/chrtclib.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'os/various') diff --git a/os/various/chrtclib.c b/os/various/chrtclib.c index 1a0a5487d..888ef3a9b 100644 --- a/os/various/chrtclib.c +++ b/os/various/chrtclib.c @@ -213,8 +213,10 @@ void rtcSetTimeUnixSec(RTCDriver *rtcp, time_t tv_sec) { #else RTCTime timespec = {0,0,FALSE}; #endif + struct tm timp; - stm32_rtc_tm2bcd(localtime(&tv_sec), ×pec); + localtime_r(&tv_sec, &timp); + stm32_rtc_tm2bcd(&timp, ×pec); rtcSetTime(rtcp, ×pec); } @@ -255,8 +257,7 @@ void rtcGetTimeTm(RTCDriver *rtcp, struct tm *timp) { RTCTime timespec = {0,0}; rtcGetTime(rtcp, ×pec); - if (timp != NULL) /* this comparison needed to avoid compiler warning */ - timp = localtime((time_t *)&(timespec.tv_sec)); + localtime_r((time_t *)&(timespec.tv_sec), timp); } /** @@ -339,17 +340,18 @@ uint64_t rtcGetTimeUnixUsec(RTCDriver *rtcp) { * @api */ uint32_t rtcGetTimeFat(RTCDriver *rtcp) { - uint32_t fattime = 0; - struct tm *timp = NULL; + uint32_t fattime; + struct tm timp; + + rtcGetTimeTm(rtcp, &timp); - rtcGetTimeTm(rtcp, timp); + fattime = (timp.tm_sec) << 1; + fattime |= (timp.tm_min) << 5; + fattime |= (timp.tm_hour) << 11; + fattime |= (timp.tm_mday) << 16; + fattime |= (timp.tm_mon + 1) << 21; + fattime |= (timp.tm_year - 80) << 25; - fattime |= (timp->tm_sec / 2); - fattime |= (timp->tm_min) << 5; - fattime |= (timp->tm_hour) << 11; - fattime |= (timp->tm_mday) << 16; - fattime |= (timp->tm_mon + 1) << 21; - fattime |= (timp->tm_year - 80) << 25; return fattime; } -- cgit v1.2.3