mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
misc: Schedule TinyUSB task in VM node.
This commit is contained in:
parent
ce35afbeb5
commit
edff6d338e
@ -123,9 +123,6 @@ MICROPY_ARGS = PORT=$(PORT) BOARD=$(TARGET) DEBUG=$(DEBUG) MICROPY_MANIFEST_OMV_
|
||||
FROZEN_MANIFEST=$(FROZEN_MANIFEST) OMV_SRC_QSTR="$(OMV_SRC_QSTR)"\
|
||||
MICROPY_ROM_TEXT_COMPRESSION=$(ROM_TEXT_COMPRESSION) USER_C_MODULES=$(TOP_DIR)/$(OMV_DIR)
|
||||
|
||||
# TinyUSB CDC debugger PendSV dispatch entry
|
||||
MPY_PENDSV_ENTRIES += PENDSV_DISPATCH_CDC,
|
||||
|
||||
# Configure additional built-in modules. Note must define both the CFLAGS and the Make command line args.
|
||||
ifeq ($(MICROPY_PY_CSI), 1)
|
||||
MPY_CFLAGS += -DMICROPY_PY_CSI=1
|
||||
|
||||
@ -38,7 +38,6 @@
|
||||
void *pendsv_object;
|
||||
static int pendsv_lock;
|
||||
|
||||
|
||||
#if defined(PENDSV_DISPATCH_NUM_SLOTS)
|
||||
uint32_t pendsv_dispatch_active;
|
||||
pendsv_dispatch_t pendsv_dispatch_table[PENDSV_DISPATCH_NUM_SLOTS];
|
||||
@ -79,6 +78,7 @@ void pendsv_suspend(void) {
|
||||
void pendsv_resume(void) {
|
||||
pendsv_lock--;
|
||||
assert(pendsv_lock >= 0);
|
||||
#if defined(PENDSV_DISPATCH_NUM_SLOTS)
|
||||
// Run pendsv if needed. Find an entry with a dispatch and call pendsv dispatch
|
||||
// with it. If pendsv runs it will service all slots.
|
||||
int count = PENDSV_DISPATCH_NUM_SLOTS;
|
||||
@ -88,21 +88,16 @@ void pendsv_resume(void) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This will always force the exception by using the hardware PENDSV
|
||||
void pendsv_nlr_jump(void *o) {
|
||||
MP_STATE_MAIN_THREAD(mp_pending_exception) = MP_OBJ_NULL;
|
||||
pendsv_dispatch_active = false;
|
||||
pendsv_object = o;
|
||||
SCB->ICSR = SCB_ICSR_PENDSVSET_Msk;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(PENDSV_DISPATCH_NUM_SLOTS)
|
||||
void pendsv_schedule_dispatch(size_t slot, pendsv_dispatch_t f) {
|
||||
pendsv_dispatch_table[slot] = f;
|
||||
pendsv_dispatch_active = true;
|
||||
SCB->ICSR = SCB_ICSR_PENDSVSET_Msk;
|
||||
if (slot < PENDSV_DISPATCH_NUM_SLOTS) {
|
||||
pendsv_dispatch_table[slot] = f;
|
||||
pendsv_dispatch_active = true;
|
||||
SCB->ICSR = SCB_ICSR_PENDSVSET_Msk;
|
||||
}
|
||||
}
|
||||
|
||||
void pendsv_dispatch_handler(void) {
|
||||
|
||||
@ -42,6 +42,7 @@
|
||||
#define DEBUG_EP_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
void NORETURN __fatal_error(const char *msg);
|
||||
static mp_sched_node_t tusb_debug_node;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t cmd;
|
||||
@ -127,7 +128,6 @@ extern mp_uint_t __real_mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
|
||||
mp_uint_t __wrap_mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
|
||||
if (tinyusb_debug_enabled()) {
|
||||
if (tud_cdc_connected()) {
|
||||
NVIC_DisableIRQ(PendSV_IRQn);
|
||||
for (int i = 0; i < len; i++) {
|
||||
// The ring buffer overflows occasionally, espcially when using a slow poll
|
||||
// rate and fast print rate. When this happens, reset the buffer and start
|
||||
@ -138,7 +138,6 @@ mp_uint_t __wrap_mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
|
||||
tx_ringbuf.iput = 0;
|
||||
}
|
||||
}
|
||||
NVIC_EnableIRQ(PendSV_IRQn);
|
||||
}
|
||||
return len;
|
||||
} else {
|
||||
@ -146,7 +145,7 @@ mp_uint_t __wrap_mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
|
||||
}
|
||||
}
|
||||
|
||||
static void tinyusb_debug_task(void) {
|
||||
void tinyusb_debug_task(mp_sched_node_t *node) {
|
||||
tud_task_ext(0, false);
|
||||
|
||||
if (!tinyusb_debug_enabled() || !tud_cdc_connected() || tud_cdc_available() < 6) {
|
||||
@ -197,7 +196,7 @@ void OMV_USB1_IRQ_HANDLER(void) {
|
||||
dcd_int_handler(0);
|
||||
// If there are any event to process, schedule a call to cdc loop.
|
||||
if (tud_task_event_ready()) {
|
||||
pendsv_schedule_dispatch(PENDSV_DISPATCH_CDC, tinyusb_debug_task);
|
||||
mp_sched_schedule_node(&tusb_debug_node, tinyusb_debug_task);
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,7 +205,7 @@ void OMV_USB2_IRQ_HANDLER(void) {
|
||||
dcd_int_handler(1);
|
||||
// If there are any event to process, schedule a call to cdc loop.
|
||||
if (tud_task_event_ready()) {
|
||||
pendsv_schedule_dispatch(PENDSV_DISPATCH_CDC, tinyusb_debug_task);
|
||||
mp_sched_schedule_node(&tusb_debug_node, tinyusb_debug_task);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -84,7 +84,6 @@ pico_set_linker_script(${MICROPY_TARGET} ${BUILD}/rp2.ld)
|
||||
file(GLOB OMV_SRC_QSTR1 ${TOP_DIR}/${OMV_DIR}/modules/*.c)
|
||||
file(GLOB OMV_SRC_QSTR2 ${TOP_DIR}/${OMV_DIR}/ports/${PORT}/modules/*.c)
|
||||
list(APPEND MICROPY_SOURCE_QSTR ${OMV_SRC_QSTR1} ${OMV_SRC_QSTR2})
|
||||
set(MPY_PENDSV_ENTRIES PENDSV_DISPATCH_CDC,)
|
||||
|
||||
target_include_directories(${MICROPY_TARGET} PRIVATE
|
||||
${TOP_DIR}/${CMSIS_DIR}/include/
|
||||
@ -300,7 +299,6 @@ if(MICROPY_PY_ULAB)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(${MICROPY_TARGET} PRIVATE
|
||||
MICROPY_BOARD_PENDSV_ENTRIES=${MPY_PENDSV_ENTRIES}
|
||||
MP_CONFIGFILE="${TOP_DIR}/${OMV_DIR}/ports/${PORT}/omv_mpconfigport.h"
|
||||
)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user