From e699a598905c95eb8249e89e436030376a518239 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 3 Feb 2021 11:01:33 +0700 Subject: [PATCH] hack to fix 3986 just a proof to show that issue analysis is correct --- supervisor/shared/background_callback.c | 8 ++++++-- supervisor/shared/usb/usb.c | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/supervisor/shared/background_callback.c b/supervisor/shared/background_callback.c index 288c9a4df2..44709b60b5 100644 --- a/supervisor/shared/background_callback.c +++ b/supervisor/shared/background_callback.c @@ -33,7 +33,7 @@ #include "supervisor/shared/tick.h" #include "shared-bindings/microcontroller/__init__.h" -STATIC volatile background_callback_t *callback_head, *callback_tail; +STATIC volatile background_callback_t * volatile callback_head, * volatile callback_tail; #define CALLBACK_CRITICAL_BEGIN (common_hal_mcu_disable_interrupts()) #define CALLBACK_CRITICAL_END (common_hal_mcu_enable_interrupts()) @@ -50,7 +50,6 @@ void background_callback_add_core(background_callback_t *cb) { cb->prev = (background_callback_t*)callback_tail; if (callback_tail) { callback_tail->next = cb; - cb->prev = (background_callback_t*)callback_tail; } if (!callback_head) { callback_head = cb; @@ -106,6 +105,9 @@ void background_callback_end_critical_section() { CALLBACK_CRITICAL_END; } +extern background_callback_t usb_callback; +extern void usb_background_do(void* unused); + void background_callback_reset() { CALLBACK_CRITICAL_BEGIN; background_callback_t *cb = (background_callback_t*)callback_head; @@ -118,6 +120,8 @@ void background_callback_reset() { callback_tail = NULL; in_background_callback = false; CALLBACK_CRITICAL_END; + + background_callback_add(&usb_callback, usb_background_do, NULL); } void background_callback_gc_collect(void) { diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index 07c6aee6c1..af34f25987 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -93,13 +93,13 @@ void usb_background(void) { } } -static background_callback_t usb_callback; -static void usb_background_do(void* unused) { +/*static*/ background_callback_t usb_callback; +/*static*/ void usb_background_do(void* unused) { usb_background(); } void usb_irq_handler(void) { - tud_int_handler(0); + tud_int_handler(0); \ background_callback_add(&usb_callback, usb_background_do, NULL); }