diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2020-03-06 18:15:16 -0800 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2020-03-13 11:12:31 -0700 |
| commit | 418333979ae007b28855079c64ee3c65f76ecbc7 (patch) | |
| tree | dea0de8db2b059e6de6abc864df29b0005ac5e1c /supervisor | |
| parent | 6f60afe8c521011d1a2d34a2632295b483a8cee3 (diff) | |
Fix autoreload, neopixel, monotonic_ns and sleep w/o SD
Diffstat (limited to 'supervisor')
| -rw-r--r-- | supervisor/port.h | 10 | ||||
| -rw-r--r-- | supervisor/shared/autoreload.c | 5 | ||||
| -rw-r--r-- | supervisor/shared/tick.c | 37 | ||||
| -rw-r--r-- | supervisor/shared/tick.h | 3 |
4 files changed, 41 insertions, 14 deletions
diff --git a/supervisor/port.h b/supervisor/port.h index dd7093f43..ccbb314ad 100644 --- a/supervisor/port.h +++ b/supervisor/port.h @@ -70,9 +70,10 @@ uint32_t *port_heap_get_top(void); void port_set_saved_word(uint32_t); uint32_t port_get_saved_word(void); -// Get the raw tick count since start up. A tick is 1/32768 of a second, a common low frequency -// clock rate. -uint64_t port_get_raw_ticks(void); +// Get the raw tick count since start up. A tick is 1/1024 of a second, a common low frequency +// clock rate. If subticks is not NULL then the port will fill in the number of subticks where each +// tick is 32 subticks (for a resolution of 1/32768 or 30.5ish microseconds.) +uint64_t port_get_raw_ticks(uint8_t* subticks); // Enable 1/1024 second tick. void port_enable_tick(void); @@ -80,7 +81,8 @@ void port_enable_tick(void); // Disable 1/1024 second tick. void port_disable_tick(void); -// Wake the CPU after the given number of ticks or sooner. +// Wake the CPU after the given number of ticks or sooner. Only the last call to this will apply. +// Only the common sleep routine should use it. void port_interrupt_after_ticks(uint32_t ticks); // Sleep the CPU until an interrupt is received. diff --git a/supervisor/shared/autoreload.c b/supervisor/shared/autoreload.c index a6212c1a9..bc818e6b0 100644 --- a/supervisor/shared/autoreload.c +++ b/supervisor/shared/autoreload.c @@ -28,6 +28,7 @@ #include "py/mphal.h" #include "py/reload.h" +#include "supervisor/shared/tick.h" static volatile uint32_t autoreload_delay_ms = 0; static bool autoreload_enabled = false; @@ -43,6 +44,7 @@ inline void autoreload_tick() { !autoreload_suspended && !reload_requested) { mp_raise_reload_exception(); reload_requested = true; + supervisor_disable_tick(); } autoreload_delay_ms--; } @@ -69,6 +71,9 @@ inline bool autoreload_is_enabled() { } void autoreload_start() { + if (autoreload_delay_ms == 0) { + supervisor_enable_tick(); + } autoreload_delay_ms = CIRCUITPY_AUTORELOAD_DELAY_MS; } diff --git a/supervisor/shared/tick.c b/supervisor/shared/tick.c index b8776f563..20ca3abb7 100644 --- a/supervisor/shared/tick.c +++ b/supervisor/shared/tick.c @@ -52,7 +52,7 @@ void supervisor_tick(void) { autoreload_tick(); #endif #ifdef CIRCUITPY_GAMEPAD_TICKS - if (!(port_get_raw_ticks() & CIRCUITPY_GAMEPAD_TICKS)) { + if (!(port_get_raw_ticks(NULL) & CIRCUITPY_GAMEPAD_TICKS)) { #if CIRCUITPY_GAMEPAD gamepad_tick(); #endif @@ -66,7 +66,7 @@ void supervisor_tick(void) { uint64_t supervisor_ticks_ms64() { uint64_t result; common_hal_mcu_disable_interrupts(); - result = port_get_raw_ticks(); + result = port_get_raw_ticks(NULL); common_hal_mcu_enable_interrupts(); result = result * 1000 / 1024; return result; @@ -79,23 +79,24 @@ uint32_t supervisor_ticks_ms32() { extern void run_background_tasks(void); void PLACE_IN_ITCM(supervisor_run_background_tasks_if_tick)() { - // uint64_t now = port_get_raw_ticks(); + uint8_t subticks; + uint64_t now = port_get_raw_ticks(&subticks); - // if (now == background_ticks) { - // return; - // } - // background_ticks = now; + if (now == background_ticks && (subticks & 0x3) != 0) { + return; + } + background_ticks = now; run_background_tasks(); } void supervisor_fake_tick() { - uint32_t now = port_get_raw_ticks(); + uint32_t now = port_get_raw_ticks(NULL); background_ticks = (now - 1); } void mp_hal_delay_ms(mp_uint_t delay) { - uint64_t start_tick = port_get_raw_ticks(); + uint64_t start_tick = port_get_raw_ticks(NULL); // Adjust the delay to ticks vs ms. delay = delay * 1024 / 1000; uint64_t duration = 0; @@ -110,7 +111,23 @@ void mp_hal_delay_ms(mp_uint_t delay) { // Sleep until an interrupt happens. port_sleep_until_interrupt(); // asm("bkpt"); - duration = (port_get_raw_ticks() - start_tick); + duration = (port_get_raw_ticks(NULL) - start_tick); + port_interrupt_after_ticks(duration); + } +} + +volatile size_t tick_enable_count = 0; +extern void supervisor_enable_tick(void) { + if (tick_enable_count == 0) { + port_enable_tick(); + } + tick_enable_count++; +} + +extern void supervisor_disable_tick(void) { + tick_enable_count--; + if (tick_enable_count == 0) { + port_disable_tick(); } } diff --git a/supervisor/shared/tick.h b/supervisor/shared/tick.h index 7ce8281ba..e7e808058 100644 --- a/supervisor/shared/tick.h +++ b/supervisor/shared/tick.h @@ -64,4 +64,7 @@ extern uint64_t supervisor_ticks_ms64(void); */ extern void supervisor_run_background_if_tick(void); +extern void supervisor_enable_tick(void); +extern void supervisor_disable_tick(void); + #endif |
