use native esp32 64bit timer for uptime

This commit is contained in:
MichaelDvP
2021-03-30 11:26:34 +02:00
parent d9b577d944
commit 81e2c31dd3
2 changed files with 6 additions and 27 deletions

View File

@@ -22,44 +22,24 @@
namespace uuid { namespace uuid {
#define UPTIME_OVERFLOW 4294967295 // Uptime overflow value // added by proddy, modified
static uint64_t now_millis = 0;
// returns system uptime in seconds // returns system uptime in seconds
uint32_t get_uptime_sec() { uint32_t get_uptime_sec() {
static uint32_t last_uptime = 0; return (uint32_t)(now_millis / 1000ULL);
static uint8_t uptime_overflows = 0;
if (millis() < last_uptime) {
++uptime_overflows;
}
last_uptime = millis();
uint32_t uptime_seconds = uptime_overflows * (UPTIME_OVERFLOW / 1000) + (last_uptime / 1000);
return uptime_seconds;
} }
uint64_t get_uptime_ms() { uint64_t get_uptime_ms() {
static uint32_t high_millis = 0; return now_millis;;
static uint32_t low_millis = 0;
if (get_uptime() < low_millis) {
high_millis++;
} }
low_millis = get_uptime();
return ((uint64_t)high_millis << 32) | low_millis;
}
// added by proddy
static uint32_t now_millis;
void set_uptime() { void set_uptime() {
now_millis = ::millis(); now_millis = esp_timer_get_time() / 1000ULL;
} }
uint32_t get_uptime() { uint32_t get_uptime() {
return now_millis; return (uint32_t)now_millis;
} }
} // namespace uuid } // namespace uuid

View File

@@ -22,7 +22,6 @@ namespace uuid {
void loop() { void loop() {
set_uptime(); // added by proddy set_uptime(); // added by proddy
get_uptime_ms();
} }
} // namespace uuid } // namespace uuid