diff options
author | Alec Berg <alecaberg@chromium.org> | 2015-02-20 17:51:00 -0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-02-22 01:45:29 +0000 |
commit | 3dffafac6808f8c381749e901c859091c1e5aad4 (patch) | |
tree | 22c314cdf5ef8585cc20e7d4be28890353c471cb | |
parent | 777867a40f0a0c712cf464e75302980f4483fc58 (diff) | |
download | chrome-ec-3dffafac6808f8c381749e901c859091c1e5aad4.tar.gz |
stm32f0: fix handling of RTC alarm 24 hour rollover
Fix bug in RTC module for stm32f0 in which it doesn't handle the
24 hour rollover appropriately and can cause a watchdog reset
if in deep sleep during rollover.
BUG=chrome-os-partner:36920
BRANCH=samus
TEST=add line to rtc_init()
STM32_RTC_TR = 0x00235952
This initializes RTC clock to 8 seconds before rollover. Using samus
make sure unit is allowed to go to deep sleep (S3/S5 and not charging)
and see that without this CL we watchdog most of the time, and with
this CL we don't watchdog ever.
Change-Id: I3f4b4b1ab7b2be1d4e344477d5eaaa0dc916773a
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/251852
Reviewed-by: Alexandru Stan <amstan@chromium.org>
-rw-r--r-- | chip/stm32/clock-stm32f0.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/chip/stm32/clock-stm32f0.c b/chip/stm32/clock-stm32f0.c index 5fcf8f7dfd..fe474fe326 100644 --- a/chip/stm32/clock-stm32f0.c +++ b/chip/stm32/clock-stm32f0.c @@ -158,6 +158,12 @@ void set_rtc_alarm(uint32_t delay_s, uint32_t delay_us, alarm_us = (RTC_PREDIV_S - *rtcss) * US_PER_RTC_TICK + delay_us; alarm_sec = alarm_sec + alarm_us / SECOND; alarm_us = alarm_us % 1000000; + /* + * If seconds is greater than 1 day, subtract by 1 day to deal with + * 24-hour rollover. + */ + if (alarm_sec >= 86400) + alarm_sec -= 86400; /* Set alarm time */ STM32_RTC_ALRMAR = sec_to_rtc(alarm_sec); |