mirror of
https://github.com/nodemcu/nodemcu-firmware.git
synced 2025-01-30 21:12:55 +08:00
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
This commit is contained in:
parent
0f7716297c
commit
5ece2fda20
@ -753,11 +753,9 @@ static void rtc_time_register_bootup(void)
|
|||||||
return;
|
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();
|
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
|
// calibrate sleep period based on difference between expected time and actual time
|
||||||
if (sleep_us>0 && sleep_us<0xffffffff &&
|
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;
|
uint64_t actual_sleep_us=sleep_us-diff_us;
|
||||||
uint32_t cali=(actual_sleep_us<<12)/sleep_cycles;
|
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;
|
rtc_usrate = 0;
|
||||||
|
|
||||||
// Deal with time adjustment if necessary
|
// 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)
|
if (diff_us>0xffffffffULL)
|
||||||
diff_us=0xffffffffULL;
|
diff_us=0xffffffffULL;
|
||||||
now_ntp_us+=diff_us;
|
now_ntp_us+=diff_us;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
diff_us=0;
|
diff_us=0;
|
||||||
|
}
|
||||||
|
|
||||||
rtc_todoffsetus = diff_us;
|
rtc_todoffsetus = diff_us;
|
||||||
|
|
||||||
uint32_t now_s=now_ntp_us/1000000;
|
uint32_t now_s=now_ntp_us/1000000;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user