mirror of
https://github.com/licsber/micropython.git
synced 2024-09-20 00:50:24 +08:00
shared/tinyusb: Schedule TinyUSB task function from dcd_event_handler.
dcd_event_handler() is called from the IRQ when a new DCD event is queued for processing by the TinyUSB thread mode task. This lets us queue the handler to run immediately when MicroPython resumes. Currently this relies on a linker --wrap hack to work, but a PR has been submitted to TinyUSB to allow the function to be called inline from dcd_event_handler() itself. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
This commit is contained in:
parent
bbc5a18d09
commit
2d363a23cb
@ -27,17 +27,40 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "py/mpconfig.h"
|
#include "py/mpconfig.h"
|
||||||
|
#include "py/runtime.h"
|
||||||
|
|
||||||
#if MICROPY_HW_ENABLE_USBDEV
|
#if MICROPY_HW_ENABLE_USBDEV
|
||||||
|
|
||||||
#ifndef NO_QSTR
|
#ifndef NO_QSTR
|
||||||
#include "tusb.h" // TinyUSB is not available when running the string preprocessor
|
#include "tusb.h" // TinyUSB is not available when running the string preprocessor
|
||||||
|
#include "device/dcd.h"
|
||||||
#include "device/usbd.h"
|
#include "device/usbd.h"
|
||||||
#include "device/usbd_pvt.h"
|
#include "device/usbd_pvt.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Legacy TinyUSB task function wrapper, called by some ports from the interpreter hook
|
||||||
void usbd_task(void) {
|
void usbd_task(void) {
|
||||||
tud_task_ext(0, false);
|
tud_task_ext(0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TinyUSB task function wrapper, as scheduled from the USB IRQ
|
||||||
|
static void mp_usbd_task(mp_sched_node_t *node);
|
||||||
|
|
||||||
|
extern void __real_dcd_event_handler(dcd_event_t const *event, bool in_isr);
|
||||||
|
|
||||||
|
// If -Wl,--wrap=dcd_event_handler is passed to the linker, then this wrapper
|
||||||
|
// will be called and allows MicroPython to schedule the TinyUSB task when
|
||||||
|
// dcd_event_handler() is called from an ISR.
|
||||||
|
TU_ATTR_FAST_FUNC void __wrap_dcd_event_handler(dcd_event_t const *event, bool in_isr) {
|
||||||
|
static mp_sched_node_t usbd_task_node;
|
||||||
|
|
||||||
|
__real_dcd_event_handler(event, in_isr);
|
||||||
|
mp_sched_schedule_node(&usbd_task_node, mp_usbd_task);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mp_usbd_task(mp_sched_node_t *node) {
|
||||||
|
(void)node;
|
||||||
|
tud_task_ext(0, false);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,9 +29,6 @@
|
|||||||
|
|
||||||
#include "py/obj.h"
|
#include "py/obj.h"
|
||||||
|
|
||||||
// Call instead of tud_task()
|
|
||||||
void mp_usbd_task(void);
|
|
||||||
|
|
||||||
// Function to be implemented in port code.
|
// Function to be implemented in port code.
|
||||||
// Can write a string up to MICROPY_HW_USB_DESC_STR_MAX characters long, plus terminating byte.
|
// Can write a string up to MICROPY_HW_USB_DESC_STR_MAX characters long, plus terminating byte.
|
||||||
extern void mp_usbd_port_get_serial_number(char *buf);
|
extern void mp_usbd_port_get_serial_number(char *buf);
|
||||||
|
Loading…
Reference in New Issue
Block a user