From 7a68e17dd09c3c148ba9d50a5728491988940d69 Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 21 Sep 2012 09:26:41 +0000 Subject: RTCv1. Added FAT timestamp support in driver using chrtclib for deviced without hardware calendar. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4706 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/STM32/RTCv1/rtc_lld.c | 27 +++++++++++++++++++++++++-- os/hal/platforms/STM32/RTCv1/rtc_lld.h | 1 + 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'os/hal') 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 - #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 -- cgit v1.2.3