Implements CONFIG_TIME_EXTENDED as we discussed relative to providing the last 3 members of the tm struct and support for filling them in and even using the wday in the STM32 RTC. From David Sidrane.

This commit is contained in:
Gregory Nutt 2015-04-08 06:56:43 -06:00
parent c226d51c3c
commit dd3457173d

View File

@ -880,6 +880,7 @@ int up_rtc_getdatetime(FAR struct tm *tp)
* Days: 1-31 match in both cases.
* Month: STM32 is 1-12, struct tm is 0-11.
* Years: STM32 is 00-99, struct tm is years since 1900.
* WeekDay: STM32 is 1 = Mon - 7 = Sun
*
* Issue: I am not sure what the STM32 years mean. Are these the
* years 2000-2099? I'll assume so.
@ -894,6 +895,13 @@ int up_rtc_getdatetime(FAR struct tm *tp)
tmp = (dr & (RTC_DR_YU_MASK|RTC_DR_YT_MASK)) >> RTC_DR_YU_SHIFT;
tp->tm_year = rtc_bcd2bin(tmp) + 100;
#if defined(CONFIG_TIME_EXTENDED)
tmp = (dr & RTC_DR_WDU_MASK) >> RTC_DR_WDU_SHIFT;
tp->tm_wday = tmp % 7;
tp->tm_yday = tp->tm_mday + clock_daysbeforemonth(tp->tm_mon, clock_isleapyear(tp->tm_year + 1900));
tp->tm_isdst = 0
#endif
#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
/* Return RTC sub-seconds if no configured and if a non-NULL value
* of nsec has been provided to receive the sub-second value.
@ -992,14 +1000,18 @@ int stm32_rtc_setdatetime(FAR const struct tm *tp)
* Days: 1-31 match in both cases.
* Month: STM32 is 1-12, struct tm is 0-11.
* Years: STM32 is 00-99, struct tm is years since 1900.
*
* WeekDay: STM32 is 1 = Mon - 7 = Sun
* Issue: I am not sure what the STM32 years mean. Are these the
* years 2000-2099? I'll assume so.
*/
dr = (rtc_bin2bcd(tp->tm_mday) << RTC_DR_DU_SHIFT) |
((rtc_bin2bcd(tp->tm_mon + 1)) << RTC_DR_MU_SHIFT) |
#if defined(CONFIG_TIME_EXTENDED)
((tp->tm_wday == 0 ? 7 : (tp->tm_wday & 7)) << RTC_DR_WDU_SHIFT) |
#endif
((rtc_bin2bcd(tp->tm_year - 100)) << RTC_DR_YU_SHIFT);
dr &= ~RTC_DR_RESERVED_BITS;
/* Disable the write protection for RTC registers */