void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, mp_uint_t line, qstr block) { GET_NATIVE_EXCEPTION(self, self_in); #if MICROPY_ENABLE_GC if (gc_is_locked()) { if (self->traceback == MP_OBJ_NULL) { // We can't allocate any memory, and no memory has been // pre-allocated, so there is nothing else we can do. return; } mp_obj_list_t *list = self->traceback; if (list->alloc <= (list->len + 3)) { // There is some preallocated memory, but not enough to store an // entire record. return; } } #endif // for traceback, we are just using the list object for convenience, it's not really a list of Python objects if (self->traceback == MP_OBJ_NULL) { self->traceback = mp_obj_new_list(0, NULL); } mp_obj_list_append(self->traceback, (mp_obj_t)(mp_uint_t)file); mp_obj_list_append(self->traceback, (mp_obj_t)(mp_uint_t)line); mp_obj_list_append(self->traceback, (mp_obj_t)(mp_uint_t)block); }
void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, machine_uint_t line, qstr block) { #if MICROPY_ENABLE_GC if (gc_is_locked()) { // We can't allocate memory, so don't bother to try return; } #endif GET_NATIVE_EXCEPTION(self, self_in); // for traceback, we are just using the list object for convenience, it's not really a list of Python objects if (self->traceback == MP_OBJ_NULL) { self->traceback = mp_obj_new_list(0, NULL); } mp_obj_list_append(self->traceback, (mp_obj_t)(machine_uint_t)file); mp_obj_list_append(self->traceback, (mp_obj_t)(machine_uint_t)line); mp_obj_list_append(self->traceback, (mp_obj_t)(machine_uint_t)block); }
void usbdbg_data_out(void *buffer, int length) { switch (cmd) { case USBDBG_SCRIPT_EXEC: // 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 // than the total length (xfer_length) and the script will Not be executed. if (!script_running && !gc_is_locked()) { vstr_add_strn(&script_buf, buffer, length); xfer_bytes += length; if (xfer_bytes == xfer_length) { // Set script ready flag script_ready = true; // Set script running flag script_running = true; // Disable IDE IRQ (re-enabled by pyexec or main). usbdbg_set_irq_enabled(false); // Clear interrupt traceback 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); } } break; case USBDBG_TEMPLATE_SAVE: { image_t image ={ .w = MAIN_FB()->w, .h = MAIN_FB()->h, .bpp = MAIN_FB()->bpp, .pixels = MAIN_FB()->pixels }; // null terminate the path length = (length == 64) ? 63:length; ((char*)buffer)[length] = 0; rectangle_t *roi = (rectangle_t*)buffer; char *path = (char*)buffer+sizeof(rectangle_t); imlib_save_image(&image, path, roi, 50); // raise a flash IRQ to flush image //NVIC->STIR = FLASH_IRQn; break; } case USBDBG_DESCRIPTOR_SAVE: { image_t image ={ .w = MAIN_FB()->w, .h = MAIN_FB()->h, .bpp = MAIN_FB()->bpp, .pixels = MAIN_FB()->pixels }; // null terminate the path length = (length == 64) ? 63:length; ((char*)buffer)[length] = 0; rectangle_t *roi = (rectangle_t*)buffer; char *path = (char*)buffer+sizeof(rectangle_t); py_image_descriptor_from_roi(&image, path, roi); break; } default: /* error */ break; } }
void usbdbg_data_out(void *buffer, int length) { switch (cmd) { case USBDBG_SCRIPT_EXEC: // 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 // than the total length (xfer_length) and the script will Not be executed. if (usbdbg_get_irq_enabled() && !gc_is_locked()) { vstr_add_strn(&script_buf, buffer, length); xfer_bytes += length; if (xfer_bytes == xfer_length) { // Set script ready flag script_ready = 1; // Disable IDE IRQ (re-enabled by pyexec or main). usbdbg_set_irq_enabled(false); // interrupt running script/REPL mp_obj_exception_clear_traceback(mp_const_ide_interrupt); pendsv_nlr_jump_hard(mp_const_ide_interrupt); } } break; case USBDBG_TEMPLATE_SAVE: { image_t image ={ .w = fb->w, .h = fb->h, .bpp = fb->bpp, .pixels = fb->pixels }; // null terminate the path length = (length == 64) ? 63:length; ((char*)buffer)[length] = 0; rectangle_t *roi = (rectangle_t*)buffer; char *path = (char*)buffer+sizeof(rectangle_t); int res=imlib_save_image(&image, path, roi); if (res != FR_OK) { nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res))); } // raise a flash IRQ to flush image //NVIC->STIR = FLASH_IRQn; break; } case USBDBG_DESCRIPTOR_SAVE: { image_t image ={ .w = fb->w, .h = fb->h, .bpp = fb->bpp, .pixels = fb->pixels }; // null terminate the path length = (length == 64) ? 63:length; ((char*)buffer)[length] = 0; rectangle_t *roi = (rectangle_t*)buffer; char *path = (char*)buffer+sizeof(rectangle_t); py_image_descriptor_from_roi(&image, path, roi); break; } default: /* error */ break; } } void usbdbg_control(void *buffer, uint8_t request, uint32_t length) { cmd = (enum usbdbg_cmd) request; switch (cmd) { case USBDBG_FW_VERSION: xfer_bytes = 0; xfer_length = length; break; case USBDBG_FRAME_SIZE: xfer_bytes = 0; xfer_length = length; break; case USBDBG_FRAME_DUMP: xfer_bytes = 0; xfer_length = length; break; case USBDBG_FRAME_LOCK: xfer_bytes = 0; xfer_length = length; break; case USBDBG_FRAME_UPDATE: sensor_snapshot(NULL); cmd = USBDBG_NONE; break; case USBDBG_SCRIPT_EXEC: xfer_bytes = 0; xfer_length =length; vstr_reset(&script_buf); break; case USBDBG_SCRIPT_STOP: if (usbdbg_get_irq_enabled()) { // Disable IDE IRQ (re-enabled by pyexec or main). usbdbg_set_irq_enabled(false); // interrupt running code by raising an exception mp_obj_exception_clear_traceback(mp_const_ide_interrupt); pendsv_nlr_jump_hard(mp_const_ide_interrupt); } cmd = USBDBG_NONE; break; case USBDBG_SCRIPT_SAVE: /* save running script */ break; case USBDBG_TEMPLATE_SAVE: case USBDBG_DESCRIPTOR_SAVE: /* save template */ xfer_bytes = 0; xfer_length =length; break; case USBDBG_ATTR_WRITE: { /* write sensor attribute */ int16_t attr= *((int16_t*)buffer); int16_t val = *((int16_t*)buffer+1); switch (attr) { case ATTR_CONTRAST: sensor_set_contrast(val); break; case ATTR_BRIGHTNESS: sensor_set_brightness(val); break; case ATTR_SATURATION: sensor_set_saturation(val); break; case ATTR_GAINCEILING: sensor_set_gainceiling(val); break; default: break; } cmd = USBDBG_NONE; break; } case USBDBG_SYS_RESET: NVIC_SystemReset(); break; case USBDBG_BOOT: *((uint32_t *)0x20002000) = 0xDEADBEEF; NVIC_SystemReset(); break; case USBDBG_TX_BUF: case USBDBG_TX_BUF_LEN: xfer_bytes = 0; xfer_length = length; break; default: /* error */ cmd = USBDBG_NONE; break; } }
ide_dbg_status_t ide_dbg_receive_data(machine_uart_obj_t* uart, uint8_t* data) { switch (cmd) { case USBDBG_SCRIPT_EXEC: // 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 // than the total length (xfer_length) and the script will Not be executed. if (!script_running && !gc_is_locked()) { vstr_add_strn_00(&script_buf, data, 1); if (xfer_bytes+1 == xfer_length) { // Set script ready flag script_ready = true; // Set script running flag script_running = true; // Disable IDE IRQ (re-enabled by pyexec or main). // usbdbg_set_irq_enabled(false); // Clear interrupt traceback 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. // nlr_jump(mp_const_ide_interrupt); MP_STATE_VM(mp_pending_exception) = mp_const_ide_interrupt;//MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)); #if MICROPY_ENABLE_SCHEDULER if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) { MP_STATE_VM(sched_state) = MP_SCHED_PENDING; } #endif } } break; case USBDBG_FILE_SAVE: { p_data_temp[xfer_bytes] = *data; if (xfer_bytes+1 == xfer_length) { //save to FS ide_file_save_status = 5; mp_obj_exception_clear_traceback(mp_const_ide_interrupt); MP_STATE_VM(mp_pending_exception) = mp_const_ide_interrupt;//MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)); #if MICROPY_ENABLE_SCHEDULER if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) { MP_STATE_VM(sched_state) = MP_SCHED_PENDING; } #endif } break; } case USBDBG_TEMPLATE_SAVE: { //TODO: save image support // image_t image ={ // .w = MAIN_FB()->w, // .h = MAIN_FB()->h, // .bpp = MAIN_FB()->bpp, // .pixels = MAIN_FB()->pixels // }; // // null terminate the path // length = (length == 64) ? 63:length; // ((char*)buffer)[length] = 0; // rectangle_t *roi = (rectangle_t*)buffer; // char *path = (char*)buffer+sizeof(rectangle_t); // imlib_save_image(&image, path, roi, 50); // raise a flash IRQ to flush image //NVIC->STIR = FLASH_IRQn; break; } case USBDBG_DESCRIPTOR_SAVE: { //TODO: save descriptor support // image_t image ={ // .w = MAIN_FB()->w, // .h = MAIN_FB()->h, // .bpp = MAIN_FB()->bpp, // .pixels = MAIN_FB()->pixels // }; // // null terminate the path // length = (length == 64) ? 63:length; // ((char*)buffer)[length] = 0; // rectangle_t *roi = (rectangle_t*)buffer; // char *path = (char*)buffer+sizeof(rectangle_t); // py_image_descriptor_from_roi(&image, path, roi); break; } default: /* error */ break; } }