mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Use pendsv exception to interrupt running code
This commit is contained in:
parent
427b03aaed
commit
7891a89723
@ -20,6 +20,7 @@
|
|||||||
#include "py_sensor.h"
|
#include "py_sensor.h"
|
||||||
#include "py_imlib.h"
|
#include "py_imlib.h"
|
||||||
#include "py_file.h"
|
#include "py_file.h"
|
||||||
|
#include "usbdbg.h"
|
||||||
|
|
||||||
int errno;
|
int errno;
|
||||||
|
|
||||||
@ -224,6 +225,9 @@ int main(void)
|
|||||||
/* Init MicroPython */
|
/* Init MicroPython */
|
||||||
libmp_init();
|
libmp_init();
|
||||||
|
|
||||||
|
/* init USB debug */
|
||||||
|
usbdbg_init();
|
||||||
|
|
||||||
/* add some functions to the global python namespace */
|
/* add some functions to the global python namespace */
|
||||||
rt_store_name(MP_QSTR_help, rt_make_function_n(0, py_help));
|
rt_store_name(MP_QSTR_help, rt_make_function_n(0, py_help));
|
||||||
rt_store_name(MP_QSTR_delay, rt_make_function_n(1, py_delay));
|
rt_store_name(MP_QSTR_delay, rt_make_function_n(1, py_delay));
|
||||||
@ -290,9 +294,5 @@ int main(void)
|
|||||||
|
|
||||||
libmp_do_repl();
|
libmp_do_repl();
|
||||||
|
|
||||||
printf("PYB: sync filesystems\n");
|
|
||||||
py_sync();
|
|
||||||
|
|
||||||
printf("PYB: soft reboot\n");
|
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
|||||||
17
src/usbdbg.c
17
src/usbdbg.c
@ -7,6 +7,12 @@
|
|||||||
static int xfer_bytes;
|
static int xfer_bytes;
|
||||||
static int xfer_length;
|
static int xfer_length;
|
||||||
static enum usbdbg_cmd cmd;
|
static enum usbdbg_cmd cmd;
|
||||||
|
mp_obj_t mp_const_ide_interrupt = MP_OBJ_NULL;
|
||||||
|
|
||||||
|
void usbdbg_init()
|
||||||
|
{
|
||||||
|
mp_const_ide_interrupt = mp_obj_new_exception_msg(&mp_type_OSError, "IDEInterrupt");
|
||||||
|
}
|
||||||
|
|
||||||
void usbdbg_data_in(void *buffer, int *length)
|
void usbdbg_data_in(void *buffer, int *length)
|
||||||
{
|
{
|
||||||
@ -39,7 +45,7 @@ void usbdbg_data_out(void *buffer, int length)
|
|||||||
xfer_bytes += length;
|
xfer_bytes += length;
|
||||||
if (xfer_bytes == xfer_length) {
|
if (xfer_bytes == xfer_length) {
|
||||||
/* interrupt do_repl */
|
/* interrupt do_repl */
|
||||||
libmp_line_feed();
|
libmp_int_repl();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -56,6 +62,7 @@ void usbdbg_control(uint8_t request, int length)
|
|||||||
xfer_bytes = 0;
|
xfer_bytes = 0;
|
||||||
xfer_length = 12;
|
xfer_length = 12;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USBDBG_DUMP_FB: /* dump framebuffer */
|
case USBDBG_DUMP_FB: /* dump framebuffer */
|
||||||
/* reset bytes counter */
|
/* reset bytes counter */
|
||||||
xfer_bytes = 0;
|
xfer_bytes = 0;
|
||||||
@ -68,6 +75,14 @@ void usbdbg_control(uint8_t request, int length)
|
|||||||
xfer_length =length;
|
xfer_length =length;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case USBDBG_STOP_SCRIPT:
|
||||||
|
if (libmp_code_running()) {
|
||||||
|
/* Stop any running code by raising an exception */
|
||||||
|
mp_obj_exception_clear_traceback(mp_const_ide_interrupt);
|
||||||
|
pendsv_nlr_jump(mp_const_ide_interrupt);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default: /* error */
|
default: /* error */
|
||||||
cmd = USBDBG_NONE;
|
cmd = USBDBG_NONE;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
#ifndef __USBDBG_H__
|
#ifndef __USBDBG_H__
|
||||||
#define __USBDBG_H__
|
#define __USBDBG_H__
|
||||||
enum usbdbg_cmd {
|
enum usbdbg_cmd {
|
||||||
USBDBG_NONE=0,
|
USBDBG_NONE=0,
|
||||||
USBDBG_FB_SIZE,
|
USBDBG_FB_SIZE,
|
||||||
USBDBG_DUMP_FB,
|
USBDBG_DUMP_FB,
|
||||||
USBDBG_EXEC_SCRIPT,
|
USBDBG_EXEC_SCRIPT,
|
||||||
USBDBG_READ_SCRIPT,
|
USBDBG_READ_SCRIPT,
|
||||||
USBDBG_WRITE_SCRIPT,
|
USBDBG_WRITE_SCRIPT,
|
||||||
|
USBDBG_STOP_SCRIPT,
|
||||||
};
|
};
|
||||||
|
void usbdbg_init();
|
||||||
#endif /* __USBDBG_H__ */
|
#endif /* __USBDBG_H__ */
|
||||||
|
|||||||
@ -86,13 +86,13 @@ class OMVGtk:
|
|||||||
def execute_clicked(self, widget):
|
def execute_clicked(self, widget):
|
||||||
buf = self.buffer.get_text(self.buffer.get_start_iter(), self.buffer.get_end_iter())
|
buf = self.buffer.get_text(self.buffer.get_start_iter(), self.buffer.get_end_iter())
|
||||||
# interrupt any running code
|
# interrupt any running code
|
||||||
self.terminal.feed_child("\x03")
|
openmv.stop_script()
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
# exec script
|
# exec script
|
||||||
openmv.exec_script(buf)
|
openmv.exec_script(buf)
|
||||||
|
|
||||||
def stop_clicked(self, widget):
|
def stop_clicked(self, widget):
|
||||||
self.terminal.feed_child("\x03\r\n")
|
openmv.stop_script();
|
||||||
|
|
||||||
def motion_notify(self, widget, event):
|
def motion_notify(self, widget, event):
|
||||||
x = int(event.x)
|
x = int(event.x)
|
||||||
|
|||||||
@ -11,6 +11,7 @@ __USBDBG_DUMP_FB=2
|
|||||||
__USBDBG_EXEC_SCRIPT=3
|
__USBDBG_EXEC_SCRIPT=3
|
||||||
__USBDBG_READ_SCRIPT=4
|
__USBDBG_READ_SCRIPT=4
|
||||||
__USBDBG_WRITE_SCRIPT=5
|
__USBDBG_WRITE_SCRIPT=5
|
||||||
|
__USBDBG_STOP_SCRIPT=6
|
||||||
|
|
||||||
# Debug __INTERFACE
|
# Debug __INTERFACE
|
||||||
__INTERFACE = 2;
|
__INTERFACE = 2;
|
||||||
@ -80,6 +81,9 @@ def exec_script(buf):
|
|||||||
__dev.ctrl_transfer(0x41, __USBDBG_EXEC_SCRIPT, len(buf), __INTERFACE, None, __TIMEOUT)
|
__dev.ctrl_transfer(0x41, __USBDBG_EXEC_SCRIPT, len(buf), __INTERFACE, None, __TIMEOUT)
|
||||||
__dev.write(0x03, buf, __INTERFACE, __TIMEOUT)
|
__dev.write(0x03, buf, __INTERFACE, __TIMEOUT)
|
||||||
|
|
||||||
|
def stop_script():
|
||||||
|
__dev.ctrl_transfer(0x41, __USBDBG_STOP_SCRIPT, 0, __INTERFACE, None, __TIMEOUT)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv)!= 2:
|
if len(sys.argv)!= 2:
|
||||||
print 'usage: openmv.py <script>'
|
print 'usage: openmv.py <script>'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user