aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-09-19 12:25:05 +0000
committerbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-09-19 12:25:05 +0000
commit892e73121acde7a3452bc9f5c380af0450840314 (patch)
tree2dd2a3481ff091e63272e8aa4bb402e420337670
parent23973e3f9ac81cc62ac9cd5d1acd091563dbc0ed (diff)
downloadChibiOS-892e73121acde7a3452bc9f5c380af0450840314.tar.gz
ChibiOS-892e73121acde7a3452bc9f5c380af0450840314.tar.bz2
ChibiOS-892e73121acde7a3452bc9f5c380af0450840314.zip
RTC. Fixed bug 3568626.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4694 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--os/various/chrtclib.c26
1 files changed, 14 insertions, 12 deletions
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), &timespec);
+ localtime_r(&tv_sec, &timp);
+ stm32_rtc_tm2bcd(&timp, &timespec);
rtcSetTime(rtcp, &timespec);
}
@@ -255,8 +257,7 @@ void rtcGetTimeTm(RTCDriver *rtcp, struct tm *timp) {
RTCTime timespec = {0,0};
rtcGetTime(rtcp, &timespec);
- 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;
}