Skip to content

Commit 61071cb

Browse files
committed
Improve update to mp_hal_delay_ms:
o Test for console interrupt during RUN_BACKGROUND_TASK o Handle signedness of remaining tick/subtick values correctly for very large delays o Improve comments
1 parent fcf7df8 commit 61071cb

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

supervisor/shared/tick.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,14 @@ void mp_hal_delay_ms(mp_uint_t delay_ms) {
114114
// or the user.
115115
while (remaining > 0 && !mp_hal_is_interrupted()) {
116116
RUN_BACKGROUND_TASKS;
117-
remaining = end_subtick - supervisor_get_raw_subticks();
118-
// We break a bit early so we don't risk setting the alarm before the time when we call
119-
// sleep.
120-
if (remaining < 1) {
117+
// Exit if interrupted while running background tasks
118+
if (mp_hal_is_interrupted()) {
121119
break;
122120
}
123-
uint32_t remaining_ticks = remaining / 32;
121+
// Recalculate remaining delay after running background tasks
122+
remaining = end_subtick - supervisor_get_raw_subticks();
123+
// If remaining delay is less than 1 tick, idle loop until end of delay
124+
int64_t remaining_ticks = remaining / 32;
124125
if (remaining_ticks > 0) {
125126
port_interrupt_after_ticks(remaining_ticks);
126127
// Idle until an interrupt happens.

0 commit comments

Comments
 (0)