Skip to content

Commit f1053fb

Browse files
committed
Introduce port_yield()
This allows the web workflow send code to yield briefly when waiting for more room to send in a socket. Waiting for an "interrupt" could wait forever because the select task only waits for read and error. Adding wait on write is tricky because much of the time we don't care if the sockets are ready to write. Using yield avoids this trickiness.
1 parent 471053c commit f1053fb

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

ports/espressif/supervisor/port.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,6 @@ void reset_port(void) {
345345

346346
reset_all_pins();
347347

348-
// A larger delay so the idle task can run and do any IDF cleanup needed.
349-
vTaskDelay(4);
350-
351348
#if CIRCUITPY_ANALOGIO
352349
analogout_reset();
353350
#endif
@@ -402,6 +399,9 @@ void reset_port(void) {
402399
#if CIRCUITPY_WATCHDOG
403400
watchdog_reset();
404401
#endif
402+
403+
// Yield so the idle task can run and do any IDF cleanup needed.
404+
port_yield();
405405
}
406406

407407
void reset_to_bootloader(void) {
@@ -492,6 +492,10 @@ void port_wake_main_task_from_isr() {
492492
}
493493
}
494494

495+
void port_yield() {
496+
vTaskDelay(4);
497+
}
498+
495499
void sleep_timer_cb(void *arg) {
496500
port_wake_main_task();
497501
}

supervisor/port.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ void port_wake_main_task(void);
109109
// default weak implementation is provided that does nothing.
110110
void port_wake_main_task_from_isr(void);
111111

112+
// Some ports may use real RTOS tasks besides the background task framework of
113+
// CircuitPython. Calling this will yield to other tasks and then return to the
114+
// CircuitPython task when others are done.
115+
void port_yield(void);
116+
112117
// Some ports need special handling just after completing boot.py execution.
113118
// This function is called once while boot.py's VM is still valid, and
114119
// then a second time after the VM is finalized.

supervisor/shared/port.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ MP_WEAK void port_wake_main_task(void) {
3131

3232
MP_WEAK void port_wake_main_task_from_isr(void) {
3333
}
34+
35+
MP_WEAK void port_yield(void) {
36+
}

supervisor/shared/web_workflow/web_workflow.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ void web_workflow_send_raw(socketpool_socket_obj_t *socket, const uint8_t *buf,
334334
total_sent += sent;
335335
if (total_sent < len) {
336336
// Yield so that network code can run.
337-
port_idle_until_interrupt();
337+
port_yield();
338338
}
339339
}
340340
}

0 commit comments

Comments
 (0)