Merge pull request #7893 from tannewt/fix_rp2040_idle

Fix RP2040 idle
This commit is contained in:
Dan Halbert 2023-04-24 13:53:12 -04:00 committed by GitHub
commit 2b95fc3029
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

10
main.c
View File

@ -716,9 +716,15 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
// time_to_next_change is in ms and ticks are slightly shorter so // time_to_next_change is in ms and ticks are slightly shorter so
// we'll undersleep just a little. It shouldn't matter. // we'll undersleep just a little. It shouldn't matter.
port_interrupt_after_ticks(time_to_next_change); if (time_to_next_change > 0) {
#endif port_interrupt_after_ticks(time_to_next_change);
port_idle_until_interrupt();
}
#else
// No status LED can we sleep until we are interrupted by some
// interaction.
port_idle_until_interrupt(); port_idle_until_interrupt();
#endif
} }
} }

View File

@ -257,6 +257,7 @@ uint32_t port_get_saved_word(void) {
} }
static volatile bool ticks_enabled; static volatile bool ticks_enabled;
static volatile bool _woken_up;
uint64_t port_get_raw_ticks(uint8_t *subticks) { uint64_t port_get_raw_ticks(uint8_t *subticks) {
uint64_t microseconds = time_us_64(); uint64_t microseconds = time_us_64();
@ -268,6 +269,7 @@ STATIC void _tick_callback(uint alarm_num) {
supervisor_tick(); supervisor_tick();
hardware_alarm_set_target(0, delayed_by_us(get_absolute_time(), 977)); hardware_alarm_set_target(0, delayed_by_us(get_absolute_time(), 977));
} }
_woken_up = true;
} }
// Enable 1/1024 second tick. // Enable 1/1024 second tick.
@ -291,11 +293,12 @@ void port_interrupt_after_ticks(uint32_t ticks) {
if (!ticks_enabled) { if (!ticks_enabled) {
hardware_alarm_set_target(0, delayed_by_us(get_absolute_time(), ticks * 977)); hardware_alarm_set_target(0, delayed_by_us(get_absolute_time(), ticks * 977));
} }
_woken_up = false;
} }
void port_idle_until_interrupt(void) { void port_idle_until_interrupt(void) {
common_hal_mcu_disable_interrupts(); common_hal_mcu_disable_interrupts();
if (!background_callback_pending() && !tud_task_event_ready()) { if (!background_callback_pending() && !tud_task_event_ready() && !_woken_up) {
__DSB(); __DSB();
__WFI(); __WFI();
} }