summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatryk Duda <pdk@semihalf.com>2021-12-30 12:19:30 +0100
committerCommit Bot <commit-bot@chromium.org>2022-01-21 10:49:10 +0000
commitcb89f6e8c25100787992db89c479cebc5f8d71ab (patch)
tree79dac2060ce07c7b2ddd2c7b8e1e62a840e3f1a1
parent46b0dbe56c9450af7debf307ab6691e77e5c62be (diff)
downloadchrome-ec-cb89f6e8c25100787992db89c479cebc5f8d71ab.tar.gz
clock-stm32f4: Improve timestamp calculation after deep sleep
Before this change, the timestamp (t0) and current time from the RTC (rtc0) were not called close together, so some time could have elapsed between them. This would result in the calculation of rtc_diff be a little smaller than it should be: rtc_diff = get_rtc_diff(&rtc0, &rtc1); This patch fixes the problem by obtaining the time from RTC close to obtaining t0 timestamp and using it to calculate the difference after wake up. BUG=b:200828093 BRANCH=none TEST=make -j buildall Signed-off-by: Patryk Duda <pdk@semihalf.com> Change-Id: I4d0ebcf681a70231481cad2401c9f599e8e21da0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3359428 Reviewed-by: Tom Hughes <tomhughes@chromium.org> Reviewed-by: Bobby Casey <bobbycasey@google.com>
-rw-r--r--chip/stm32/clock-stm32f4.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/chip/stm32/clock-stm32f4.c b/chip/stm32/clock-stm32f4.c
index f2efdcb1eb..401c06be1c 100644
--- a/chip/stm32/clock-stm32f4.c
+++ b/chip/stm32/clock-stm32f4.c
@@ -465,7 +465,7 @@ void __idle(void)
timestamp_t t0;
uint32_t rtc_diff;
int next_delay, margin_us;
- struct rtc_time_reg rtc0, rtc1;
+ struct rtc_time_reg rtc0, rtc1, rtc_sleep;
while (1) {
interrupt_disable();
@@ -479,6 +479,7 @@ void __idle(void)
* interrupts were disabled, since clksrc_high (which keeps
* higher 32 bits of the timestamp) will not be updated.
*/
+ rtc_read(&rtc0);
t0 = get_time();
/*
@@ -535,7 +536,7 @@ void __idle(void)
set_rtc_alarm(0, next_delay - STOP_MODE_LATENCY
- PLL_LOCK_LATENCY,
- &rtc0, 0);
+ &rtc_sleep, 0);
/* Switch to HSI */
clock_switch_osc(OSC_HSI);
@@ -563,7 +564,7 @@ void __idle(void)
force_time(t0);
/* Record time spent in deep sleep. */
- idle_dsleep_time_us += rtc_diff;
+ idle_dsleep_time_us += get_rtc_diff(&rtc_sleep, &rtc1);
/* Calculate how close we were to missing deadline */
margin_us = next_delay - rtc_diff;