reset.cpp/.h code sanitizations
This commit is contained in:
parent
d626f86754
commit
3b6ecf7b36
@ -15,7 +15,7 @@ void reset_rtc_vars(void);
|
|||||||
void do_reset(bool warmstart);
|
void do_reset(bool warmstart);
|
||||||
void do_after_reset(void);
|
void do_after_reset(void);
|
||||||
void enter_deepsleep(uint32_t wakeup_sec, const gpio_num_t wakeup_gpio);
|
void enter_deepsleep(uint32_t wakeup_sec, const gpio_num_t wakeup_gpio);
|
||||||
unsigned long long uptime(void);
|
uint64_t uptime(void);
|
||||||
|
|
||||||
enum runmode_t {
|
enum runmode_t {
|
||||||
RUNMODE_POWERCYCLE,
|
RUNMODE_POWERCYCLE,
|
||||||
|
@ -5,14 +5,14 @@
|
|||||||
// Conversion factor for micro seconds to seconds
|
// Conversion factor for micro seconds to seconds
|
||||||
#define uS_TO_S_FACTOR 1000000ULL
|
#define uS_TO_S_FACTOR 1000000ULL
|
||||||
|
|
||||||
// RTC_NOINIT_ATTR -> keep value after a software restart or system crash
|
// RTC_NOINIT_ATTR -> keeps value after a software restart or system crash
|
||||||
RTC_NOINIT_ATTR runmode_t RTC_runmode;
|
RTC_NOINIT_ATTR runmode_t RTC_runmode;
|
||||||
RTC_NOINIT_ATTR uint32_t RTC_restarts;
|
RTC_NOINIT_ATTR uint32_t RTC_restarts;
|
||||||
// RTC_DATA_ATTR -> keep values after a wakeup from sleep
|
// RTC_DATA_ATTR -> keeps value after a wakeup from sleep
|
||||||
RTC_DATA_ATTR struct timeval RTC_sleep_start_time;
|
RTC_DATA_ATTR struct timeval sleep_start_time;
|
||||||
RTC_DATA_ATTR unsigned long long RTC_millis = 0;
|
RTC_DATA_ATTR int64_t RTC_millis = 0;
|
||||||
|
|
||||||
timeval sleep_stop_time;
|
struct timeval sleep_stop_time;
|
||||||
|
|
||||||
void reset_rtc_vars(void) {
|
void reset_rtc_vars(void) {
|
||||||
RTC_runmode = RUNMODE_POWERCYCLE;
|
RTC_runmode = RUNMODE_POWERCYCLE;
|
||||||
@ -36,7 +36,7 @@ void do_reset(bool warmstart) {
|
|||||||
|
|
||||||
void do_after_reset(void) {
|
void do_after_reset(void) {
|
||||||
struct timeval sleep_stop_time;
|
struct timeval sleep_stop_time;
|
||||||
uint64_t sleep_time_ms;
|
int64_t sleep_time_ms;
|
||||||
|
|
||||||
// read (and initialize on first run) runtime settings from NVRAM
|
// read (and initialize on first run) runtime settings from NVRAM
|
||||||
loadConfig();
|
loadConfig();
|
||||||
@ -62,9 +62,11 @@ void do_after_reset(void) {
|
|||||||
case RESET_REASON_CORE_DEEP_SLEEP:
|
case RESET_REASON_CORE_DEEP_SLEEP:
|
||||||
// calculate time spent in deep sleep
|
// calculate time spent in deep sleep
|
||||||
gettimeofday(&sleep_stop_time, NULL);
|
gettimeofday(&sleep_stop_time, NULL);
|
||||||
sleep_time_ms =
|
sleep_time_ms = ((int64_t)sleep_stop_time.tv_sec * 1000000L +
|
||||||
(sleep_stop_time.tv_sec - RTC_sleep_start_time.tv_sec) * 1000 +
|
(int64_t)sleep_stop_time.tv_usec -
|
||||||
(sleep_stop_time.tv_usec - RTC_sleep_start_time.tv_usec) / 1000;
|
(int64_t)sleep_start_time.tv_sec * 1000000L -
|
||||||
|
(int64_t)sleep_start_time.tv_usec) /
|
||||||
|
1000LL;
|
||||||
RTC_millis += sleep_time_ms; // increment system monotonic time
|
RTC_millis += sleep_time_ms; // increment system monotonic time
|
||||||
ESP_LOGI(TAG, "Time spent in deep sleep: %llu ms", sleep_time_ms);
|
ESP_LOGI(TAG, "Time spent in deep sleep: %llu ms", sleep_time_ms);
|
||||||
// do we have a valid time? -> set global variable
|
// do we have a valid time? -> set global variable
|
||||||
@ -180,8 +182,8 @@ void enter_deepsleep(uint32_t wakeup_sec, gpio_num_t wakeup_gpio) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// time stamp sleep start time and save system monotonic time. Deep sleep.
|
// time stamp sleep start time and save system monotonic time. Deep sleep.
|
||||||
gettimeofday(&RTC_sleep_start_time, NULL);
|
gettimeofday(&sleep_start_time, NULL);
|
||||||
RTC_millis += esp_timer_get_time() / 1000;
|
RTC_millis += esp_timer_get_time() / 1000LL;
|
||||||
ESP_LOGI(TAG, "Going to sleep, good bye.");
|
ESP_LOGI(TAG, "Going to sleep, good bye.");
|
||||||
|
|
||||||
// flush & close sd card, if we have
|
// flush & close sd card, if we have
|
||||||
@ -192,6 +194,6 @@ void enter_deepsleep(uint32_t wakeup_sec, gpio_num_t wakeup_gpio) {
|
|||||||
esp_deep_sleep_start();
|
esp_deep_sleep_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long long uptime() {
|
uint64_t uptime() {
|
||||||
return (RTC_millis + esp_timer_get_time() / 1000);
|
return (uint64_t)(RTC_millis + esp_timer_get_time() / 1000LL);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user