From a4e01f72c6c87bbb405b414a3c4150ed8ea079dd Mon Sep 17 00:00:00 2001 From: Kamimiao <1317379456@qq.com> Date: Wed, 3 Apr 2024 11:40:34 +0800 Subject: [PATCH] vcs: add finish_device for simv_finish (#324) This change will clear device buffer, avoid potential affect between workloads. --- src/test/csrc/common/device.cpp | 10 ++++++++++ src/test/csrc/common/device.h | 1 + src/test/csrc/common/sdcard.cpp | 6 ++++++ src/test/csrc/common/uart.cpp | 6 ++++++ src/test/csrc/common/vga.cpp | 4 ++++ src/test/csrc/vcs/vcs_main.cpp | 1 + 6 files changed, 28 insertions(+) diff --git a/src/test/csrc/common/device.cpp b/src/test/csrc/common/device.cpp index 51d166f1b..f5b84caff 100644 --- a/src/test/csrc/common/device.cpp +++ b/src/test/csrc/common/device.cpp @@ -23,7 +23,9 @@ void send_key(uint8_t, bool); void init_sdl(void); void init_uart(void); +void finish_uart(void); extern "C" void init_sd(void); +extern "C" void finish_sd(void); extern "C" void init_flash(void); void init_device(void) { @@ -34,6 +36,14 @@ void init_device(void) { init_sd(); } +void finish_device(void) { +#ifdef SHOW_SCREEN + finish_sdl(); +#endif + finish_uart(); + finish_sd(); +} + void poll_event() { #ifdef SHOW_SCREEN SDL_Event event; diff --git a/src/test/csrc/common/device.h b/src/test/csrc/common/device.h index eb43f9f03..72a2882ae 100644 --- a/src/test/csrc/common/device.h +++ b/src/test/csrc/common/device.h @@ -20,6 +20,7 @@ #include "common.h" void init_device(); +void finish_device(); void poll_event(); #endif diff --git a/src/test/csrc/common/sdcard.cpp b/src/test/csrc/common/sdcard.cpp index 5d5c559e7..54b32dc41 100644 --- a/src/test/csrc/common/sdcard.cpp +++ b/src/test/csrc/common/sdcard.cpp @@ -62,4 +62,10 @@ void init_sd(void) { check_sdcard(); #endif } + +void finish_sd(void) { +#ifdef SDCARD_IMAGE + fclose(fp); +#endif +} } diff --git a/src/test/csrc/common/uart.cpp b/src/test/csrc/common/uart.cpp index a075da5db..9b1a6d35f 100644 --- a/src/test/csrc/common/uart.cpp +++ b/src/test/csrc/common/uart.cpp @@ -106,3 +106,9 @@ static void preset_input() { void init_uart(void) { preset_input(); } + +void finish_uart(void) { + memset(queue, 0, sizeof(queue)); + f = 0; + r = 0; +} diff --git a/src/test/csrc/common/vga.cpp b/src/test/csrc/common/vga.cpp index a1bc012df..db25bfe99 100644 --- a/src/test/csrc/common/vga.cpp +++ b/src/test/csrc/common/vga.cpp @@ -60,6 +60,10 @@ void init_sdl() { SDL_SetWindowTitle(window, "NOOP"); texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, SCREEN_W, SCREEN_H); } + +void finish_sdl() { + memset(vmem, 0, sizeof(vmem)); +} #else extern "C" void put_pixel(uint32_t pixel) {} extern "C" void vmem_sync(void) {} diff --git a/src/test/csrc/vcs/vcs_main.cpp b/src/test/csrc/vcs/vcs_main.cpp index 3001444c5..1cb1e284c 100644 --- a/src/test/csrc/vcs/vcs_main.cpp +++ b/src/test/csrc/vcs/vcs_main.cpp @@ -202,6 +202,7 @@ void simv_finish() { goldenmem_finish(); difftest_finish(); } + finish_device(); delete simMemory; simMemory = nullptr; }