From 83803b3148f31316962484ac54a0635d8f4db46e Mon Sep 17 00:00:00 2001 From: xiaenling Date: Tue, 30 Jul 2024 19:24:28 +0800 Subject: [PATCH] Update soft reboot run boot.py logic. --- micropython/port/builtin_py/media/media.py | 5 +++++ micropython/port/builtin_py/media/sensor.py | 22 ++++++++++++------- .../port/builtin_py/mpp_binding/vb_func_def.h | 3 +++ micropython/port/core/main.c | 2 ++ micropython/port/include/core/mpp_vb_mgmt.h | 3 +++ micropython/port/omv/ide_dbg.c | 2 +- 6 files changed, 28 insertions(+), 9 deletions(-) diff --git a/micropython/port/builtin_py/media/media.py b/micropython/port/builtin_py/media/media.py index 4db7bbb..0b3a9ba 100755 --- a/micropython/port/builtin_py/media/media.py +++ b/micropython/port/builtin_py/media/media.py @@ -207,6 +207,11 @@ def deinit(cls, force = False): if not force: return + dma_dev_deinit() + ret = vb_mgmt_deinit() + if ret: + raise RuntimeError(f"MediaManager, vb_mgmt_deinit failed({ret})") + ret = kd_mpi_vb_exit() if ret: raise RuntimeError(f"MediaManager, vb deinit failed({ret})") diff --git a/micropython/port/builtin_py/media/sensor.py b/micropython/port/builtin_py/media/sensor.py index f6d9750..e45173a 100644 --- a/micropython/port/builtin_py/media/sensor.py +++ b/micropython/port/builtin_py/media/sensor.py @@ -351,10 +351,12 @@ def snapshot(self, chn = CAM_CHN_ID_0): status = 0 frame_info = k_video_frame_info() try: + old = os.exitpoint(os.EXITPOINT_ENABLE_SLEEP) virt_addr = 0 ret = kd_mpi_vicap_dump_frame(self._dev_id, chn, VICAP_DUMP_YUV, frame_info, 1000) self._imgs[chn].push_phys(frame_info.v_frame.phys_addr[0]) if ret: + os.exitpoint(old) raise RuntimeError(f"sensor({self._dev_id}) snapshot chn({chn}) failed({ret})") status = 1 phys_addr = frame_info.v_frame.phys_addr[0] @@ -371,6 +373,7 @@ def snapshot(self, chn = CAM_CHN_ID_0): img_size = img_width * img_height * 3 img_fmt = image.RGBP888 else: + os.exitpoint(old) raise RuntimeError(f"sensor({self._dev_id}) snapshot chn({chn}) not support pixelformat({fmt})") virt_addr = kd_mpi_sys_mmap_cached(phys_addr, img_size) self._imgs[chn].push_virt(virt_addr, img_size) @@ -384,8 +387,10 @@ def snapshot(self, chn = CAM_CHN_ID_0): else: img = image.Image(img_width, img_height, img_fmt, alloc=image.ALLOC_VB, phyaddr=phys_addr, virtaddr=virt_addr, poolid=frame_info.pool_id) else: + os.exitpoint(old) raise RuntimeError(f"sensor({self._dev_id}) snapshot chn({chn}) mmap failed") + os.exitpoint(old) return img except Exception as e: raise e @@ -871,17 +876,18 @@ def stop(self, is_del = False): raise AssertionError("should call reset() first") if not is_del and not self._is_started: - raise AssertionError("should call run() first") + print("warning: sensor not call run()") - ret = kd_mpi_vicap_stop_stream(self._dev_id) - if not is_del and ret: - raise RuntimeError(f"sensor({self._dev_id}) stop error, stop stream failed({ret})") + if self._is_started: + ret = kd_mpi_vicap_stop_stream(self._dev_id) + if not is_del and ret: + raise RuntimeError(f"sensor({self._dev_id}) stop error, stop stream failed({ret})") - ret = kd_mpi_vicap_deinit(self._dev_id) - if not is_del and ret: - raise RuntimeError(f"sensor({self._dev_id}) stop error, vicap deinit failed({ret})") + ret = kd_mpi_vicap_deinit(self._dev_id) + if not is_del and ret: + raise RuntimeError(f"sensor({self._dev_id}) stop error, vicap deinit failed({ret})") - vb_mgmt_vicap_dev_deinited(self._dev_id) + vb_mgmt_vicap_dev_deinited(self._dev_id) self._dev_attr.dev_enable = False self._release_all_chn_image() diff --git a/micropython/port/builtin_py/mpp_binding/vb_func_def.h b/micropython/port/builtin_py/mpp_binding/vb_func_def.h index ec757e1..273c02f 100644 --- a/micropython/port/builtin_py/mpp_binding/vb_func_def.h +++ b/micropython/port/builtin_py/mpp_binding/vb_func_def.h @@ -43,6 +43,9 @@ DEF_INT_FUNC_INT(kd_mpi_vb_exit_mod_common_pool) DEF_INT_FUNC_INT_STRUCTPTR(kd_mpi_vb_set_mod_pool_config, k_vb_config) DEF_INT_FUNC_INT_STRUCTPTR(kd_mpi_vb_get_mod_pool_config, k_vb_config) +DEF_INT_FUNC_VOID(vb_mgmt_deinit) +DEF_VOID_FUNC_VOID(dma_dev_deinit) + DEF_INT_FUNC_STRUCTPTR(vb_mgmt_get_block, vb_block_info) DEF_INT_FUNC_STRUCTPTR(vb_mgmt_put_block, vb_block_info) diff --git a/micropython/port/core/main.c b/micropython/port/core/main.c index 3e6139e..d27020f 100644 --- a/micropython/port/core/main.c +++ b/micropython/port/core/main.c @@ -783,6 +783,8 @@ MP_NOINLINE int main_(int argc, char **argv) { // clear terminal // mp_hal_stdout_tx_strn("\033[H\033[2J", 7); do_repl(); + + is_repl_intr = false; } fprintf(stderr, "[mpy] exit, reset\n"); main_thread_exit: diff --git a/micropython/port/include/core/mpp_vb_mgmt.h b/micropython/port/include/core/mpp_vb_mgmt.h index b162349..bff712b 100644 --- a/micropython/port/include/core/mpp_vb_mgmt.h +++ b/micropython/port/include/core/mpp_vb_mgmt.h @@ -14,6 +14,9 @@ typedef struct k_u32 size; // self.size = size, user set }vb_block_info; +// in ide_dbg.c +extern void dma_dev_deinit(void); + extern k_s32 vb_mgmt_init(void); extern k_s32 vb_mgmt_deinit(void); diff --git a/micropython/port/omv/ide_dbg.c b/micropython/port/omv/ide_dbg.c index 2944944..56d611a 100644 --- a/micropython/port/omv/ide_dbg.c +++ b/micropython/port/omv/ide_dbg.c @@ -357,7 +357,7 @@ int kd_mpi_vo_osd_rotation(int flag, k_video_frame_info *in, k_video_frame_info if(false == _dma_dev_init_flag) { printf("did't init dma_dev\n"); - return -1; + dma_dev_init(); } kd_mpi_dma_stop_chn(OSD_ROTATION_DMA_CHN);