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
This commit is contained in:
barthess 2012-09-20 15:01:28 +00:00
parent d4fd78d689
commit 54cde6b854
6 changed files with 66 additions and 2 deletions

View File

@ -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

View File

@ -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, &timespec);
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 */
/** @} */

View File

@ -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

View File

@ -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 */
/** @} */

View File

@ -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)) */
/** @} */

View File

@ -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);