mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Cleanup USBDBG code.
This commit is contained in:
parent
a3a1f0cfb9
commit
890d27d1dd
@ -465,9 +465,6 @@ soft_reset:
|
|||||||
while (!usbdbg_script_ready()) {
|
while (!usbdbg_script_ready()) {
|
||||||
nlr_buf_t nlr;
|
nlr_buf_t nlr;
|
||||||
|
|
||||||
// Re-enable FS IRQ (disabled in usbdbg)
|
|
||||||
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
|
|
||||||
|
|
||||||
if (nlr_push(&nlr) == 0) {
|
if (nlr_push(&nlr) == 0) {
|
||||||
// enable IDE interrupt
|
// enable IDE interrupt
|
||||||
usbdbg_set_irq_enabled(true);
|
usbdbg_set_irq_enabled(true);
|
||||||
@ -482,12 +479,11 @@ soft_reset:
|
|||||||
if (usbdbg_script_ready()) {
|
if (usbdbg_script_ready()) {
|
||||||
nlr_buf_t nlr;
|
nlr_buf_t nlr;
|
||||||
|
|
||||||
// Re-enable FS IRQ (disabled in usbdbg)
|
|
||||||
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
|
|
||||||
|
|
||||||
// execute the script
|
// execute the script
|
||||||
if (nlr_push(&nlr) == 0) {
|
if (nlr_push(&nlr) == 0) {
|
||||||
// parse, compile and execute script
|
// enable IDE interrupt
|
||||||
|
usbdbg_set_irq_enabled(true);
|
||||||
|
|
||||||
pyexec_str(usbdbg_get_script());
|
pyexec_str(usbdbg_get_script());
|
||||||
nlr_pop();
|
nlr_pop();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -25,7 +25,6 @@ static enum usbdbg_cmd cmd;
|
|||||||
|
|
||||||
static volatile bool script_ready;
|
static volatile bool script_ready;
|
||||||
static volatile bool script_running;
|
static volatile bool script_running;
|
||||||
static volatile bool irq_enabled;
|
|
||||||
static vstr_t script_buf;
|
static vstr_t script_buf;
|
||||||
static mp_obj_t mp_const_ide_interrupt = MP_OBJ_NULL;
|
static mp_obj_t mp_const_ide_interrupt = MP_OBJ_NULL;
|
||||||
|
|
||||||
@ -36,7 +35,6 @@ extern const char *ffs_strerror(FRESULT res);
|
|||||||
|
|
||||||
void usbdbg_init()
|
void usbdbg_init()
|
||||||
{
|
{
|
||||||
irq_enabled=false;
|
|
||||||
script_ready=false;
|
script_ready=false;
|
||||||
script_running=false;
|
script_running=false;
|
||||||
vstr_init(&script_buf, 32);
|
vstr_init(&script_buf, 32);
|
||||||
@ -53,14 +51,14 @@ vstr_t *usbdbg_get_script()
|
|||||||
return &script_buf;
|
return &script_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool usbdbg_get_irq_enabled()
|
|
||||||
{
|
|
||||||
return irq_enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void usbdbg_set_irq_enabled(bool enabled)
|
inline void usbdbg_set_irq_enabled(bool enabled)
|
||||||
{
|
{
|
||||||
irq_enabled=enabled; __DSB();
|
if (enabled) {
|
||||||
|
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
|
||||||
|
} else {
|
||||||
|
HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
|
||||||
|
}
|
||||||
|
__DSB(); __ISB();
|
||||||
}
|
}
|
||||||
|
|
||||||
void usbdbg_data_in(void *buffer, int length)
|
void usbdbg_data_in(void *buffer, int length)
|
||||||
@ -150,7 +148,7 @@ void usbdbg_data_out(void *buffer, int length)
|
|||||||
// check if GC is locked before allocating memory for vstr. If GC was locked
|
// check if GC is locked before allocating memory for vstr. If GC was locked
|
||||||
// at least once before the script is fully uploaded xfer_bytes will be less
|
// at least once before the script is fully uploaded xfer_bytes will be less
|
||||||
// than the total length (xfer_length) and the script will Not be executed.
|
// than the total length (xfer_length) and the script will Not be executed.
|
||||||
if (!script_running && usbdbg_get_irq_enabled() && !gc_is_locked()) {
|
if (!script_running && !gc_is_locked()) {
|
||||||
vstr_add_strn(&script_buf, buffer, length);
|
vstr_add_strn(&script_buf, buffer, length);
|
||||||
xfer_bytes += length;
|
xfer_bytes += length;
|
||||||
if (xfer_bytes == xfer_length) {
|
if (xfer_bytes == xfer_length) {
|
||||||
@ -163,8 +161,11 @@ void usbdbg_data_out(void *buffer, int length)
|
|||||||
// Disable IDE IRQ (re-enabled by pyexec or main).
|
// Disable IDE IRQ (re-enabled by pyexec or main).
|
||||||
usbdbg_set_irq_enabled(false);
|
usbdbg_set_irq_enabled(false);
|
||||||
|
|
||||||
// interrupt running script/REPL
|
// Clear interrupt traceback
|
||||||
mp_obj_exception_clear_traceback(mp_const_ide_interrupt);
|
mp_obj_exception_clear_traceback(mp_const_ide_interrupt);
|
||||||
|
// Interrupt running REPL
|
||||||
|
// Note: setting pendsv explicitly here because the VM is probably
|
||||||
|
// waiting in REPL and the soft interrupt flag will not be checked.
|
||||||
pendsv_nlr_jump_hard(mp_const_ide_interrupt);
|
pendsv_nlr_jump_hard(mp_const_ide_interrupt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -240,24 +241,21 @@ void usbdbg_control(void *buffer, uint8_t request, uint32_t length)
|
|||||||
|
|
||||||
case USBDBG_SCRIPT_EXEC:
|
case USBDBG_SCRIPT_EXEC:
|
||||||
xfer_bytes = 0;
|
xfer_bytes = 0;
|
||||||
xfer_length =length;
|
xfer_length = length;
|
||||||
vstr_reset(&script_buf);
|
vstr_reset(&script_buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USBDBG_SCRIPT_STOP:
|
case USBDBG_SCRIPT_STOP:
|
||||||
if (usbdbg_get_irq_enabled()) {
|
if (script_running) {
|
||||||
// Set script running flag
|
// Set script running flag
|
||||||
script_running = false;
|
script_running = false;
|
||||||
|
|
||||||
// Disable IDE IRQ (re-enabled by pyexec or main).
|
// Disable IDE IRQ (re-enabled by pyexec or main).
|
||||||
usbdbg_set_irq_enabled(false);
|
usbdbg_set_irq_enabled(false);
|
||||||
|
|
||||||
// We can safely disable FS IRQ here
|
|
||||||
HAL_NVIC_DisableIRQ(OTG_FS_IRQn); __DSB(); __ISB();
|
|
||||||
|
|
||||||
// interrupt running code by raising an exception
|
// interrupt running code by raising an exception
|
||||||
mp_obj_exception_clear_traceback(mp_const_ide_interrupt);
|
mp_obj_exception_clear_traceback(mp_const_ide_interrupt);
|
||||||
pendsv_nlr_jump_hard(mp_const_ide_interrupt);
|
pendsv_nlr_jump(mp_const_ide_interrupt);
|
||||||
}
|
}
|
||||||
cmd = USBDBG_NONE;
|
cmd = USBDBG_NONE;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user