Skip to content

Commit 2b95fc3

Browse files
authored
Merge pull request #7893 from tannewt/fix_rp2040_idle
Fix RP2040 idle
2 parents aae1b1d + b59f0e1 commit 2b95fc3

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

main.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,15 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
716716

717717
// time_to_next_change is in ms and ticks are slightly shorter so
718718
// we'll undersleep just a little. It shouldn't matter.
719-
port_interrupt_after_ticks(time_to_next_change);
720-
#endif
719+
if (time_to_next_change > 0) {
720+
port_interrupt_after_ticks(time_to_next_change);
721+
port_idle_until_interrupt();
722+
}
723+
#else
724+
// No status LED can we sleep until we are interrupted by some
725+
// interaction.
721726
port_idle_until_interrupt();
727+
#endif
722728
}
723729
}
724730

ports/raspberrypi/supervisor/port.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ uint32_t port_get_saved_word(void) {
257257
}
258258

259259
static volatile bool ticks_enabled;
260+
static volatile bool _woken_up;
260261

261262
uint64_t port_get_raw_ticks(uint8_t *subticks) {
262263
uint64_t microseconds = time_us_64();
@@ -268,6 +269,7 @@ STATIC void _tick_callback(uint alarm_num) {
268269
supervisor_tick();
269270
hardware_alarm_set_target(0, delayed_by_us(get_absolute_time(), 977));
270271
}
272+
_woken_up = true;
271273
}
272274

273275
// Enable 1/1024 second tick.
@@ -291,11 +293,12 @@ void port_interrupt_after_ticks(uint32_t ticks) {
291293
if (!ticks_enabled) {
292294
hardware_alarm_set_target(0, delayed_by_us(get_absolute_time(), ticks * 977));
293295
}
296+
_woken_up = false;
294297
}
295298

296299
void port_idle_until_interrupt(void) {
297300
common_hal_mcu_disable_interrupts();
298-
if (!background_callback_pending() && !tud_task_event_ready()) {
301+
if (!background_callback_pending() && !tud_task_event_ready() && !_woken_up) {
299302
__DSB();
300303
__WFI();
301304
}

0 commit comments

Comments
 (0)