persist uptime during deep sleep
This commit is contained in:
parent
fef0a86c4a
commit
2d486e5ede
@ -15,7 +15,6 @@ extern Ticker cyclicTimer;
|
|||||||
|
|
||||||
void setCyclicIRQ(void);
|
void setCyclicIRQ(void);
|
||||||
void doHousekeeping(void);
|
void doHousekeeping(void);
|
||||||
uint64_t _uptime(uint64_t diff);
|
|
||||||
uint64_t uptime(void);
|
uint64_t uptime(void);
|
||||||
void reset_counters(void);
|
void reset_counters(void);
|
||||||
uint32_t getFreeRAM();
|
uint32_t getFreeRAM();
|
||||||
|
@ -13,4 +13,6 @@ void do_reset(bool warmstart);
|
|||||||
void do_after_reset(void);
|
void do_after_reset(void);
|
||||||
void enter_deepsleep(const uint64_t wakeup_sec, const gpio_num_t wakeup_gpio);
|
void enter_deepsleep(const uint64_t wakeup_sec, const gpio_num_t wakeup_gpio);
|
||||||
|
|
||||||
|
extern RTC_DATA_ATTR unsigned long RTC_millis;
|
||||||
|
|
||||||
#endif // _RESET_H
|
#endif // _RESET_H
|
@ -20,8 +20,6 @@ void setCyclicIRQ() {
|
|||||||
// do all housekeeping
|
// do all housekeeping
|
||||||
void doHousekeeping() {
|
void doHousekeeping() {
|
||||||
|
|
||||||
// update uptime counter
|
|
||||||
uptime();
|
|
||||||
// check if update mode trigger switch was set
|
// check if update mode trigger switch was set
|
||||||
if (RTC_runmode == RUNMODE_UPDATE) {
|
if (RTC_runmode == RUNMODE_UPDATE) {
|
||||||
// check battery status if we can before doing ota
|
// check battery status if we can before doing ota
|
||||||
@ -136,13 +134,7 @@ void doHousekeeping() {
|
|||||||
|
|
||||||
} // doHousekeeping()
|
} // doHousekeeping()
|
||||||
|
|
||||||
uint64_t _uptime(uint64_t diff) {
|
uint64_t uptime() { return (RTC_millis + millis()); }
|
||||||
static uint64_t offset = 0;
|
|
||||||
offset += diff;
|
|
||||||
return millis() + offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t uptime(void){return _uptime(0);};
|
|
||||||
|
|
||||||
uint32_t getFreeRAM() {
|
uint32_t getFreeRAM() {
|
||||||
#ifndef BOARD_HAS_PSRAM
|
#ifndef BOARD_HAS_PSRAM
|
||||||
|
@ -11,6 +11,7 @@ static const char TAG[] = __FILE__;
|
|||||||
// variables keep its values after a wakeup from sleep
|
// variables keep its values after a wakeup from sleep
|
||||||
RTC_DATA_ATTR runmode_t RTC_runmode = RUNMODE_POWERCYCLE;
|
RTC_DATA_ATTR runmode_t RTC_runmode = RUNMODE_POWERCYCLE;
|
||||||
RTC_DATA_ATTR struct timeval RTC_sleep_start_time;
|
RTC_DATA_ATTR struct timeval RTC_sleep_start_time;
|
||||||
|
RTC_DATA_ATTR unsigned long RTC_millis = 0;
|
||||||
timeval sleep_stop_time;
|
timeval sleep_stop_time;
|
||||||
|
|
||||||
const char *runmode[5] = {"powercycle", "normal", "wakeup", "update", "sleep"};
|
const char *runmode[5] = {"powercycle", "normal", "wakeup", "update", "sleep"};
|
||||||
@ -49,7 +50,7 @@ void do_after_reset(void) {
|
|||||||
(sleep_stop_time.tv_sec - RTC_sleep_start_time.tv_sec) * 1000 +
|
(sleep_stop_time.tv_sec - RTC_sleep_start_time.tv_sec) * 1000 +
|
||||||
(sleep_stop_time.tv_usec - RTC_sleep_start_time.tv_usec) / 1000;
|
(sleep_stop_time.tv_usec - RTC_sleep_start_time.tv_usec) / 1000;
|
||||||
ESP_LOGI(TAG, "Time spent in deep sleep: %d ms", sleep_time_ms);
|
ESP_LOGI(TAG, "Time spent in deep sleep: %d ms", sleep_time_ms);
|
||||||
_uptime(sleep_time_ms); // increment uptime
|
RTC_millis += sleep_time_ms; // increment system monotonic time
|
||||||
|
|
||||||
RTC_runmode = RUNMODE_WAKEUP;
|
RTC_runmode = RUNMODE_WAKEUP;
|
||||||
break;
|
break;
|
||||||
@ -180,8 +181,9 @@ void enter_deepsleep(const uint64_t wakeup_sec = 60,
|
|||||||
esp_sleep_enable_ext1_wakeup(1ULL << wakeup_gpio, ESP_EXT1_WAKEUP_ALL_LOW);
|
esp_sleep_enable_ext1_wakeup(1ULL << wakeup_gpio, ESP_EXT1_WAKEUP_ALL_LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
// time stamp sleep start time. Deep sleep.
|
// time stamp sleep start time and save system monotonic time. Deep sleep.
|
||||||
gettimeofday(&RTC_sleep_start_time, NULL);
|
gettimeofday(&RTC_sleep_start_time, NULL);
|
||||||
|
RTC_millis = millis();
|
||||||
ESP_LOGI(TAG, "Going to sleep, good bye.");
|
ESP_LOGI(TAG, "Going to sleep, good bye.");
|
||||||
esp_deep_sleep_start();
|
esp_deep_sleep_start();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user