From 54cde6b85446a97d4e980109483b23a758324a8c Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 20 Sep 2012 15:01:28 +0000 Subject: RTCv2. Get fat time function moved to driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4701 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/rtc.h | 1 + os/hal/platforms/STM32/RTCv2/rtc_lld.c | 48 ++++++++++++++++++++++++++++++++++ os/hal/platforms/STM32/RTCv2/rtc_lld.h | 1 + os/hal/src/rtc.c | 12 +++++++++ os/various/chrtclib.c | 4 +-- os/various/chrtclib.h | 2 ++ 6 files changed, 66 insertions(+), 2 deletions(-) diff --git a/os/hal/include/rtc.h b/os/hal/include/rtc.h index 9b5cba848..32ea04958 100644 --- a/os/hal/include/rtc.h +++ b/os/hal/include/rtc.h @@ -157,6 +157,7 @@ extern "C" { const RTCAlarm *alarmspec); void rtcGetAlarm(RTCDriver *rtcp, rtcalarm_t alarm, RTCAlarm *alarmspec); #endif + uint32_t rtcGetTimeFat(RTCDriver *rtcp); #if RTC_SUPPORTS_CALLBACKS void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback); #endif diff --git a/os/hal/platforms/STM32/RTCv2/rtc_lld.c b/os/hal/platforms/STM32/RTCv2/rtc_lld.c index 84295bd76..1fe433324 100644 --- a/os/hal/platforms/STM32/RTCv2/rtc_lld.c +++ b/os/hal/platforms/STM32/RTCv2/rtc_lld.c @@ -266,6 +266,54 @@ void rtcGetPeriodicWakeup_v2(RTCDriver *rtcp, RTCWakeup *wakeupspec){ wakeupspec->wakeup |= (((uint32_t)rtcp->id_rtc->CR) & 0x7) << 16; } +/** + * @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; + RTCTime timespec; + uint32_t tv_time; + uint32_t tv_date; + uint32_t v; + + rtc_lld_get_time(rtcp, ×pec); + tv_time = timespec.tv_time; + tv_date = timespec.tv_date; + + v = (tv_time & RTC_TR_SU) >> RTC_TR_SU_OFFSET; + v += ((tv_time & RTC_TR_ST) >> RTC_TR_ST_OFFSET) * 10; + fattime = v << 1; + + v = (tv_time & RTC_TR_MNU) >> RTC_TR_MNU_OFFSET; + v += ((tv_time & RTC_TR_MNT) >> RTC_TR_MNT_OFFSET) * 10; + fattime |= v << 5; + + v = (tv_time & RTC_TR_HU) >> RTC_TR_HU_OFFSET; + v += ((tv_time & RTC_TR_HT) >> RTC_TR_HT_OFFSET) * 10; + v += 12 * ((tv_time & RTC_TR_PM) >> RTC_TR_PM_OFFSET); + fattime |= v << 11; + + v = (tv_date & RTC_DR_DU) >> RTC_DR_DU_OFFSET; + v += ((tv_date & RTC_DR_DT) >> RTC_DR_DT_OFFSET) * 10; + fattime |= v << 16; + + v = (tv_date & RTC_DR_MU) >> RTC_DR_MU_OFFSET; + v += ((tv_date & RTC_DR_MT) >> RTC_DR_MT_OFFSET) * 10; + fattime |= v << 21; + + v = (tv_date & RTC_DR_YU) >> RTC_DR_YU_OFFSET; + v += ((tv_date & RTC_DR_YT) >> RTC_DR_YT_OFFSET) * 10; + v += 2000 - 1900 - 80; + fattime |= v << 25; + + return fattime; +} + #endif /* HAL_USE_RTC */ /** @} */ diff --git a/os/hal/platforms/STM32/RTCv2/rtc_lld.h b/os/hal/platforms/STM32/RTCv2/rtc_lld.h index 4cae5744d..c598fca51 100644 --- a/os/hal/platforms/STM32/RTCv2/rtc_lld.h +++ b/os/hal/platforms/STM32/RTCv2/rtc_lld.h @@ -198,6 +198,7 @@ extern "C" { RTCAlarm *alarmspec); void rtcSetPeriodicWakeup_v2(RTCDriver *rtcp, RTCWakeup *wakeupspec); void rtcGetPeriodicWakeup_v2(RTCDriver *rtcp, RTCWakeup *wakeupspec); + uint32_t rtc_lld_get_time_fat(RTCDriver *rtcp); #ifdef __cplusplus } #endif diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 01f88e82d..10f09409a 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -167,6 +167,18 @@ void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback) { } #endif /* RTC_SUPPORTS_CALLBACKS */ +/** + * @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 rtcGetTimeFat(RTCDriver *rtcp) { + return rtc_lld_get_time_fat(rtcp); +} + #endif /* HAL_USE_RTC */ /** @} */ diff --git a/os/various/chrtclib.c b/os/various/chrtclib.c index 888ef3a9b..04b3cb25c 100644 --- a/os/various/chrtclib.c +++ b/os/various/chrtclib.c @@ -328,8 +328,6 @@ uint64_t rtcGetTimeUnixUsec(RTCDriver *rtcp) { return (uint64_t)rtcGetTimeUnixSec(rtcp) * 1000000; #endif } -#endif /* STM32_RTC_IS_CALENDAR */ -#endif /* (defined(STM32F4XX) || defined(STM32F2XX) || defined(STM32L1XX) || defined(STM32F1XX)) */ /** * @brief Get current time in format suitable for usage in FatFS. @@ -354,5 +352,7 @@ uint32_t rtcGetTimeFat(RTCDriver *rtcp) { return fattime; } +#endif /* STM32_RTC_IS_CALENDAR */ +#endif /* (defined(STM32F4XX) || defined(STM32F2XX) || defined(STM32L1XX) || defined(STM32F1XX)) */ /** @} */ diff --git a/os/various/chrtclib.h b/os/various/chrtclib.h index c41706f87..c6f6c8d45 100644 --- a/os/various/chrtclib.h +++ b/os/various/chrtclib.h @@ -42,7 +42,9 @@ #ifdef __cplusplus extern "C" { #endif +#if !STM32_RTC_IS_CALENDAR uint32_t rtcGetTimeFat(RTCDriver *rtcp); +#endif void rtcGetTimeTm(RTCDriver *rtcp, struct tm *timp); void rtcSetTimeTm(RTCDriver *rtcp, struct tm *timp); time_t rtcGetTimeUnixSec(RTCDriver *rtcp); -- cgit v1.2.3