浏览代码

Another dsleep fix (or rather a not-deep-sleep case) (#2155)

* Make the rtc variables not be cleared by the .bss initialization
* Move the save to the right place
* Make sure that we reset the rtctime to 0 if we didn't sleep properly.
* Setting the seconds to zero doesn't update the dsleep calibration
Philip Gladstone 6 年之前
父节点
当前提交
5ece2fda20
共有 1 个文件被更改,包括 9 次插入9 次删除
  1. 9 9
      app/include/rtc/rtctime_internal.h

+ 9 - 9
app/include/rtc/rtctime_internal.h

@@ -753,11 +753,9 @@ static void rtc_time_register_bootup(void)
     return;
   }
 
-  if (rtc_time_check_magic())
-  {
-    // We did not go to sleep properly. All our time keeping is f*cked!
-    rtc_time_reset(erase_calibration); // Possibly keep the calibration, it should still be good
-  }
+  // We did not go to sleep properly. All our time keeping is f*cked!
+  rtc_time_reset(erase_calibration); // Possibly keep the calibration, it should still be good
+
   RTC_DBG_ENABLED();
 }
 
@@ -859,7 +857,8 @@ static void rtc_time_settimeofday(const struct rtc_timeval* tv)
 
   // calibrate sleep period based on difference between expected time and actual time
   if (sleep_us>0 && sleep_us<0xffffffff &&
-      sleep_cycles>0 && sleep_cycles<0xffffffff)
+      sleep_cycles>0 && sleep_cycles<0xffffffff &&
+      tv->tv_sec)
   {
     uint64_t actual_sleep_us=sleep_us-diff_us;
     uint32_t cali=(actual_sleep_us<<12)/sleep_cycles;
@@ -875,14 +874,15 @@ static void rtc_time_settimeofday(const struct rtc_timeval* tv)
   rtc_usrate = 0;
 
   // Deal with time adjustment if necessary
-  if (diff_us>0) // Time went backwards. Avoid that....
+  if (diff_us>0 && tv->tv_sec) // Time went backwards. Avoid that....
   {
     if (diff_us>0xffffffffULL)
       diff_us=0xffffffffULL;
     now_ntp_us+=diff_us;
-  }
-  else
+  } else {
     diff_us=0;
+  }
+
   rtc_todoffsetus = diff_us;
 
   uint32_t now_s=now_ntp_us/1000000;