aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--os/hal/platforms/STM32/RTCv1/rtc_lld.c27
-rw-r--r--os/hal/platforms/STM32/RTCv1/rtc_lld.h1
-rw-r--r--os/various/chrtclib.c4
3 files changed, 28 insertions, 4 deletions
diff --git a/os/hal/platforms/STM32/RTCv1/rtc_lld.c b/os/hal/platforms/STM32/RTCv1/rtc_lld.c
index 1b0fd433c..bc083ffbd 100644
--- a/os/hal/platforms/STM32/RTCv1/rtc_lld.c
+++ b/os/hal/platforms/STM32/RTCv1/rtc_lld.c
@@ -30,10 +30,9 @@
* @{
*/
-#include <time.h>
-
#include "ch.h"
#include "hal.h"
+#include "chrtclib.h"
#if HAL_USE_RTC || defined(__DOXYGEN__)
@@ -300,6 +299,30 @@ void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t callback) {
rtcp->callback = NULL;
}
}
+
+/**
+ * @brief Get current time in format suitable for usage in FatFS.
+ *
+ * @param[in] rtcp pointer to RTC driver structure
+ * @return FAT time value.
+ *
+ * @api
+ */
+uint32_t rtc_lld_get_time_fat(RTCDriver *rtcp) {
+ uint32_t fattime;
+ struct tm 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;
+
+ return fattime;
+}
#endif /* HAL_USE_RTC */
/** @} */
diff --git a/os/hal/platforms/STM32/RTCv1/rtc_lld.h b/os/hal/platforms/STM32/RTCv1/rtc_lld.h
index 4944ff735..c0ad92525 100644
--- a/os/hal/platforms/STM32/RTCv1/rtc_lld.h
+++ b/os/hal/platforms/STM32/RTCv1/rtc_lld.h
@@ -178,6 +178,7 @@ extern "C" {
rtcalarm_t alarm,
RTCAlarm *alarmspec);
void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t callback);
+ uint32_t rtc_lld_get_time_fat(RTCDriver *rtcp);
#ifdef __cplusplus
}
#endif
diff --git a/os/various/chrtclib.c b/os/various/chrtclib.c
index 04b3cb25c..04c0b67db 100644
--- a/os/various/chrtclib.c
+++ b/os/various/chrtclib.c
@@ -337,13 +337,13 @@ uint64_t rtcGetTimeUnixUsec(RTCDriver *rtcp) {
*
* @api
*/
-uint32_t rtcGetTimeFat(RTCDriver *rtcp) {
+uint32_t rtcGetTimeFatFromCounter(RTCDriver *rtcp) {
uint32_t fattime;
struct tm timp;
rtcGetTimeTm(rtcp, &timp);
- fattime = (timp.tm_sec) << 1;
+ fattime = (timp.tm_sec) >> 1;
fattime |= (timp.tm_min) << 5;
fattime |= (timp.tm_hour) << 11;
fattime |= (timp.tm_mday) << 16;