Allow the IDE to interrupt main.py

This commit is contained in:
iabdalkader 2017-01-13 03:14:07 +02:00
parent f5ce531078
commit c9806c0588
3 changed files with 19 additions and 0 deletions

View File

@ -464,10 +464,19 @@ soft_reset:
if (first_soft_reset && f_res == FR_OK) {
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
// Enable IDE interrupt
usbdbg_set_irq_enabled(true);
// Allow the IDE to interrupt main.py
usbdbg_set_script_running(true);
// Parse, compile and execute the main script.
pyexec_file("main.py");
nlr_pop();
} else {
// Disable IDE interrupt and clear script running
usbdbg_set_irq_enabled(false);
usbdbg_set_script_running(false);
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
if (nlr_push(&nlr) == 0) {
flash_error(3);
@ -476,6 +485,10 @@ soft_reset:
}
}
// Disable IDE interrupt and clear script running
usbdbg_set_irq_enabled(false);
usbdbg_set_script_running(false);
// If there's no script ready, just re-exec REPL
while (!usbdbg_script_ready()) {
nlr_buf_t nlr;

View File

@ -51,6 +51,11 @@ vstr_t *usbdbg_get_script()
return &script_buf;
}
void usbdbg_set_script_running(bool running)
{
script_running = running;
}
inline void usbdbg_set_irq_enabled(bool enabled)
{
if (enabled) {

View File

@ -53,4 +53,5 @@ bool usbdbg_script_ready();
vstr_t *usbdbg_get_script();
bool usbdbg_get_irq_enabled();
void usbdbg_set_irq_enabled(bool enabled);
void usbdbg_set_script_running(bool running);
#endif /* __USBDBG_H__ */