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
master
barthess 2012-09-21 09:26:41 +00:00
parent bf0682028d
commit 7a68e17dd0
3 changed files with 28 additions and 4 deletions

View File

@ -30,10 +30,9 @@
* @{ * @{
*/ */
#include <time.h>
#include "ch.h" #include "ch.h"
#include "hal.h" #include "hal.h"
#include "chrtclib.h"
#if HAL_USE_RTC || defined(__DOXYGEN__) #if HAL_USE_RTC || defined(__DOXYGEN__)
@ -300,6 +299,30 @@ void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t callback) {
rtcp->callback = NULL; 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 */ #endif /* HAL_USE_RTC */
/** @} */ /** @} */

View File

@ -178,6 +178,7 @@ extern "C" {
rtcalarm_t alarm, rtcalarm_t alarm,
RTCAlarm *alarmspec); RTCAlarm *alarmspec);
void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t callback); void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t callback);
uint32_t rtc_lld_get_time_fat(RTCDriver *rtcp);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -337,13 +337,13 @@ uint64_t rtcGetTimeUnixUsec(RTCDriver *rtcp) {
* *
* @api * @api
*/ */
uint32_t rtcGetTimeFat(RTCDriver *rtcp) { uint32_t rtcGetTimeFatFromCounter(RTCDriver *rtcp) {
uint32_t fattime; uint32_t fattime;
struct tm timp; struct tm timp;
rtcGetTimeTm(rtcp, &timp); rtcGetTimeTm(rtcp, &timp);
fattime = (timp.tm_sec) << 1; fattime = (timp.tm_sec) >> 1;
fattime |= (timp.tm_min) << 5; fattime |= (timp.tm_min) << 5;
fattime |= (timp.tm_hour) << 11; fattime |= (timp.tm_hour) << 11;
fattime |= (timp.tm_mday) << 16; fattime |= (timp.tm_mday) << 16;