Skip to content

Commit 74e5edd

Browse files
committed
wip
1 parent 77e1fa3 commit 74e5edd

File tree

13 files changed

+48
-25
lines changed

13 files changed

+48
-25
lines changed

ports/atmel-samd/common-hal/busio/SPI.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,14 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
194194
}
195195
allow_reset_sercom(self->spi_desc.dev.prvt);
196196

197-
// Mark as deinit early in case we are used in an interrupt.
198-
common_hal_busio_spi_mark_deinit(self);
199-
200197
spi_m_sync_disable(&self->spi_desc);
201198
spi_m_sync_deinit(&self->spi_desc);
202199
reset_pin_number(self->clock_pin);
203200
reset_pin_number(self->MOSI_pin);
204201
reset_pin_number(self->MISO_pin);
202+
203+
// This smashes self->clock_pin, so don't do it before resetting the pin above.
204+
common_hal_busio_spi_mark_deinit(self);
205205
}
206206

207207
bool common_hal_busio_spi_configure(busio_spi_obj_t *self,

ports/espressif/background.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include "freertos/task.h"
1414

1515
void port_background_tick(void) {
16-
// Zero delay in case FreeRTOS wants to switch to something else.
17-
vTaskDelay(0);
16+
// Yield with zero delay in case FreeRTOS wants to switch to something else.
17+
port_task_yield();
1818
}
1919

2020
void port_background_task(void) {

ports/espressif/supervisor/port.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ void reset_port(void) {
404404
watchdog_reset();
405405
#endif
406406

407-
// Yield so the idle task can run and do any IDF cleanup needed.
408-
port_yield();
407+
// Yield so the idle task, at priority 0, can run and do any IDF cleanup needed.
408+
port_task_sleep_ms(4);
409409
}
410410

411411
void reset_to_bootloader(void) {
@@ -483,8 +483,13 @@ void port_wake_main_task_from_isr(void) {
483483
}
484484
}
485485

486-
void port_yield(void) {
487-
vTaskDelay(4);
486+
// Yield to other tasks at the same priority.
487+
void port_task_yield(void) {
488+
vTaskDelay(0);
489+
}
490+
491+
void port_task_sleep_ms(uint32_t msecs) {
492+
vTaskDelay(pdMS_TO_TICKS(msecs));
488493
}
489494

490495
void sleep_timer_cb(void *arg) {

ports/espressif/supervisor/usb.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ static void usb_device_task(void *param) {
5656
tud_task();
5757
tud_cdc_write_flush();
5858
}
59-
vTaskDelay(1);
59+
// Yield with zero delay to switch to any other tasks at same priority.
60+
port_task_yield();
6061
}
6162
}
6263
#endif // CIRCUITPY_USB_DEVICE
@@ -112,7 +113,7 @@ void init_usb_hardware(void) {
112113
"usbd",
113114
USBD_STACK_SIZE,
114115
NULL,
115-
5,
116+
1,
116117
usb_device_stack,
117118
&usb_device_taskdef,
118119
xPortGetCoreID());

ports/raspberrypi/supervisor/port.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ __attribute__((used)) void __not_in_flash_func(isr_hardfault)(void) {
600600
}
601601
}
602602

603-
void port_yield(void) {
603+
void port_task_yield(void) {
604604
#if CIRCUITPY_CYW43
605605
cyw43_arch_poll();
606606
#endif

ports/renode/supervisor/port.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ __attribute__((used)) void HardFault_Handler(void) {
210210
}
211211
}
212212

213-
void port_yield(void) {
213+
void port_task_yield(void) {
214214
}
215215

216216
void port_boot_info(void) {

ports/zephyr-cp/supervisor/port.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,18 @@ void port_wake_main_task_from_isr(void) {
6565
k_event_set(&main_needed, 1);
6666
}
6767

68-
void port_yield(void) {
68+
void port_task_yield(void) {
6969
k_yield();
7070
// Make sure time advances in the simulator.
7171
#if defined(CONFIG_ARCH_POSIX)
7272
k_busy_wait(100);
7373
#endif
7474
}
7575

76+
void port_task_sleep_ms(uint32_t msecs) {
77+
k_msleep(msecs));
78+
}
79+
7680
void port_boot_info(void) {
7781
}
7882

supervisor/port.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,17 @@ void port_wake_main_task(void);
9292
void port_wake_main_task_from_isr(void);
9393

9494
// Some ports may use real RTOS tasks besides the background task framework of
95-
// CircuitPython. Calling this will yield to other tasks and then return to the
96-
// CircuitPython task when others are done.
97-
void port_yield(void);
95+
// CircuitPython. Calling this will yield to other tasks at the same priority level
96+
// (or higher priority level if pre-emption is not immediate in the RTOS)
97+
// and then return to the CircuitPython task when others are done.
98+
// Note that this does NOT yield to lower priority tasks. Use port_task_sleep_ms() instead.
99+
void port_task_yield(void);
100+
101+
// On ports using real RTOS tasks, yield to other tasks for at least msecs.
102+
// This will allow lower priority tasks to run.
103+
// On non-RTOS implementations, this just sleeps for msecs and will run CircuitPython
104+
// background tasks.
105+
void port_task_sleep_ms(uint32_t msecs);
98106

99107
// Some ports want to add information to boot_out.txt.
100108
// A default weak implementation is provided that does nothing.

supervisor/shared/background_callback.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void PLACE_IN_ITCM(background_callback_run_all)(void) {
6363
if (!background_callback_pending()) {
6464
// TEMPORARY to fix #10822
6565
#ifdef __ZEPHYR__
66-
port_yield();
66+
port_task_yield();
6767
#endif
6868
return;
6969
}
@@ -93,7 +93,7 @@ void PLACE_IN_ITCM(background_callback_run_all)(void) {
9393
CALLBACK_CRITICAL_END;
9494
// TEMPORARY to fix #10822
9595
#ifdef __ZEPHYR__
96-
port_yield();
96+
port_task_yield();
9797
#endif
9898
}
9999

supervisor/shared/port.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <string.h>
1010

11+
#include "py/mphal.h"
1112
#include "py/runtime.h"
1213
#include "py/gc.h"
1314

@@ -26,7 +27,11 @@ MP_WEAK void port_wake_main_task(void) {
2627
MP_WEAK void port_wake_main_task_from_isr(void) {
2728
}
2829

29-
MP_WEAK void port_yield(void) {
30+
MP_WEAK void port_task_yield(void) {
31+
}
32+
33+
MP_WEAK void port_task_sleep_ms(uint32_t msecs) {
34+
mp_hal_delay_ms(msecs);
3035
}
3136

3237
MP_WEAK void port_boot_info(void) {

0 commit comments

Comments
 (0)