diff options
| author | Damien George <damien.p.george@gmail.com> | 2019-05-22 15:05:03 +1000 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2019-05-24 15:37:34 +1000 |
| commit | 5357dad52efbe5773f4beda7ad014dc62ad8e44f (patch) | |
| tree | 777a3d888b3437f1b0aa5cb756fa3b1a47a5b586 /ports/esp8266/ets_alt_task.c | |
| parent | c4a6d9c631a3e529aeedeaf5c24fa1bd748d493f (diff) | |
esp8266: Fix ticks_ms to correctly handle wraparound of system counter.
Fixes issue #4795.
Diffstat (limited to 'ports/esp8266/ets_alt_task.c')
| -rw-r--r-- | ports/esp8266/ets_alt_task.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/ports/esp8266/ets_alt_task.c b/ports/esp8266/ets_alt_task.c index b724b8f14..0b1615d65 100644 --- a/ports/esp8266/ets_alt_task.c +++ b/ports/esp8266/ets_alt_task.c @@ -112,22 +112,27 @@ int ets_loop_iter_disable = 0; int ets_loop_dont_feed_sw_wdt = 0; // to implement a 64-bit wide microsecond counter -static uint32_t system_time_prev = 0; +uint32_t system_time_low_word = 0; uint32_t system_time_high_word = 0; -bool ets_loop_iter(void) { - if (ets_loop_iter_disable) { - return false; - } - - // handle overflow of system microsecond counter +void system_time_update(void) { + // Handle overflow of system microsecond counter ets_intr_lock(); uint32_t system_time_cur = system_get_time(); - if (system_time_cur < system_time_prev) { + if (system_time_cur < system_time_low_word) { system_time_high_word += 1; // record overflow of low 32-bits } - system_time_prev = system_time_cur; + system_time_low_word = system_time_cur; ets_intr_unlock(); +} + +bool ets_loop_iter(void) { + if (ets_loop_iter_disable) { + return false; + } + + // Update 64-bit microsecond counter + system_time_update(); // 6 words before pend_flag_noise_check is a variable that is used by // the software WDT. A 1.6 second period timer will increment this |
