aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/platforms/STM32/RTCv2
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/platforms/STM32/RTCv2')
-rw-r--r--os/hal/platforms/STM32/RTCv2/rtc_lld.c23
-rw-r--r--os/hal/platforms/STM32/RTCv2/rtc_lld.h1
2 files changed, 24 insertions, 0 deletions
diff --git a/os/hal/platforms/STM32/RTCv2/rtc_lld.c b/os/hal/platforms/STM32/RTCv2/rtc_lld.c
index cae3f812b..c2268fd82 100644
--- a/os/hal/platforms/STM32/RTCv2/rtc_lld.c
+++ b/os/hal/platforms/STM32/RTCv2/rtc_lld.c
@@ -265,6 +265,29 @@ void rtcGetPeriodicWakeup_v2(RTCDriver *rtcp, RTCWakeup *wakeupspec){
}
/**
+ * @brief Get current time in format suitable for usage in FatFS.
+ *
+ * @param[in] timespec pointer to RTCTime structure
+ * @return FAT time value.
+ *
+ * @api
+ */
+uint32_t rtc_lld_calc_fat_time(RTCTime *timespec){
+ uint32_t fattime = 0;
+ struct tm timp;
+
+ stm32_rtc_bcd2tm(&timp, timespec);
+
+ 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;
+}
+
+/**
* @brief Converts from STM32 BCD to canonicalized time format.
*
* @param[out] timp pointer to a @p tm structure defined in time.h
diff --git a/os/hal/platforms/STM32/RTCv2/rtc_lld.h b/os/hal/platforms/STM32/RTCv2/rtc_lld.h
index 3f0139f00..88959294c 100644
--- a/os/hal/platforms/STM32/RTCv2/rtc_lld.h
+++ b/os/hal/platforms/STM32/RTCv2/rtc_lld.h
@@ -200,6 +200,7 @@ extern "C" {
RTCAlarm *alarmspec);
void rtcSetPeriodicWakeup_v2(RTCDriver *rtcp, RTCWakeup *wakeupspec);
void rtcGetPeriodicWakeup_v2(RTCDriver *rtcp, RTCWakeup *wakeupspec);
+ uint32_t rtc_lld_calc_fat_time(RTCTime *timespec);
void stm32_rtc_bcd2tm(struct tm *timp, RTCTime *timespec);
void stm32_rtc_tm2bcd(struct tm *timp, RTCTime *timespec);
#ifdef __cplusplus