summaryrefslogtreecommitdiffstatshomepage
path: root/esp8266
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-09-20 14:28:17 +1000
committerDamien George <damien.p.george@gmail.com>2016-09-20 14:28:17 +1000
commit34e01984368ff2c689808ef8de182d838cd96725 (patch)
tree1c11ed0ec0571d05fb654f43981a234a6b83b53a /esp8266
parentcc7c311b5eab2749bc071716eec8a06271278f01 (diff)
downloadmicropython-34e01984368ff2c689808ef8de182d838cd96725.tar.gz
micropython-34e01984368ff2c689808ef8de182d838cd96725.zip
esp8266: Extend system microsecond counter to 64-bits; use in ticks_ms.
So now ticks_ms can count up to the full 30 bits. Fixes issue #2412.
Diffstat (limited to 'esp8266')
-rw-r--r--esp8266/esp_mphal.c2
-rw-r--r--esp8266/ets_alt_task.c12
-rw-r--r--esp8266/ets_alt_task.h2
3 files changed, 15 insertions, 1 deletions
diff --git a/esp8266/esp_mphal.c b/esp8266/esp_mphal.c
index 7c9590ab67..b0755239fc 100644
--- a/esp8266/esp_mphal.c
+++ b/esp8266/esp_mphal.c
@@ -117,7 +117,7 @@ void mp_hal_debug_tx_strn_cooked(void *env, const char *str, uint32_t len) {
}
uint32_t mp_hal_ticks_ms(void) {
- return system_get_time() / 1000;
+ return ((uint64_t)system_time_high_word << 32 | (uint64_t)system_get_time()) / 1000;
}
uint32_t mp_hal_ticks_us(void) {
diff --git a/esp8266/ets_alt_task.c b/esp8266/ets_alt_task.c
index ef1d8aaede..6434f23660 100644
--- a/esp8266/ets_alt_task.c
+++ b/esp8266/ets_alt_task.c
@@ -110,10 +110,22 @@ bool ets_post(uint8 prio, os_signal_t sig, os_param_t param) {
int ets_loop_iter_disable = 0;
+// to implement a 64-bit wide microsecond counter
+static uint32_t system_time_prev = 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
+ uint32_t system_time_cur = system_get_time();
+ if (system_time_cur < system_time_prev) {
+ system_time_high_word += 1; // record overflow of low 32-bits
+ }
+ system_time_prev = system_time_cur;
+
//static unsigned cnt;
bool progress = false;
for (volatile struct task_entry *t = emu_tasks; t < &emu_tasks[MP_ARRAY_SIZE(emu_tasks)]; t++) {
diff --git a/esp8266/ets_alt_task.h b/esp8266/ets_alt_task.h
index 4b5ba26dbd..dba0c5fa64 100644
--- a/esp8266/ets_alt_task.h
+++ b/esp8266/ets_alt_task.h
@@ -1,2 +1,4 @@
extern int ets_loop_iter_disable;
+extern uint32_t system_time_high_word;
+
bool ets_loop_iter(void);