From d59a8c986fdba5dceaf2b034e22028b9b524ea53 Mon Sep 17 00:00:00 2001 From: Yann MAGNIN Date: Tue, 17 Jan 2023 22:13:43 +0100 Subject: [PATCH] vxkernel - v0.6.0-31 : fix vxdev + fix FPS synchronization API + disable DMA *fix* > [vxdev] | proper send script arguments | proper boards scanning > [src/driver/screen/r61524] | disable double buffering per default > [FPS] | fix FPS sync --- kernel/include/vhex/driver/mpu/sh/sh7305/tmu.h | 4 ++-- kernel/include/vhex/timer/fps.h | 5 +++-- kernel/include/vhex/timer/interface.h | 4 ++-- kernel/src/drivers/mpu/common/sdl2/timer.c | 18 ++++++++++++------ kernel/src/drivers/mpu/sh/sh7305/tmu/fps.c | 16 +++++++++++----- kernel/src/drivers/screen/R61524/r61524.c | 6 ++++++ kernel/src/modules/timer/fps.c | 8 ++++---- scripts/vxdev/core/board.py | 2 +- vxdev | 2 +- vxsdk.toml | 2 +- 10 files changed, 43 insertions(+), 24 deletions(-) diff --git a/kernel/include/vhex/driver/mpu/sh/sh7305/tmu.h b/kernel/include/vhex/driver/mpu/sh/sh7305/tmu.h index e4c6094..19ac67a 100644 --- a/kernel/include/vhex/driver/mpu/sh/sh7305/tmu.h +++ b/kernel/include/vhex/driver/mpu/sh/sh7305/tmu.h @@ -147,10 +147,10 @@ extern int sh7305_tmu_prof_quit(timer_prof_t *prof); #include /* sh7305_tmu_fps_init() : initialize fps object */ -extern void sh7305_tmu_fps_init(fps_t *fps); +extern void sh7305_tmu_fps_init(fps_t *fps, int fps_target); /* sh7305_tmu_fps_sync() : compute frame statistic and wait whanted FPS */ -extern void sh7305_tmu_fps_sync(fps_t *fps, int fps_target); +extern void sh7305_tmu_fps_sync(fps_t *fps); /* sh7305_fps_quit() : uninit the fps object */ extern void sh7305_tmu_fps_quit(fps_t *fps); diff --git a/kernel/include/vhex/timer/fps.h b/kernel/include/vhex/timer/fps.h index e3bb707..8b1dafc 100644 --- a/kernel/include/vhex/timer/fps.h +++ b/kernel/include/vhex/timer/fps.h @@ -7,6 +7,7 @@ struct timer_fps { int fps; int fps_real; + int fps_target; uint32_t render; int32_t margin; uint32_t objectif; @@ -15,10 +16,10 @@ struct timer_fps { typedef struct timer_fps fps_t; /* timer_fps_init() : initialize fps object */ -extern void timer_fps_init(fps_t *fps); +extern void timer_fps_init(fps_t *fps, int fps_target); /* timer_fps_sync() : try to syncronize to X frame per seconds */ -extern void timer_fps_sync(fps_t *fps, int fps_target); +extern void timer_fps_sync(fps_t *fps); /* timer_fps_quit() : uninit fps object */ extern void timer_fps_quit(fps_t *fps); diff --git a/kernel/include/vhex/timer/interface.h b/kernel/include/vhex/timer/interface.h index 097cdd1..f4aef40 100644 --- a/kernel/include/vhex/timer/interface.h +++ b/kernel/include/vhex/timer/interface.h @@ -26,8 +26,8 @@ struct timer_drv_interface uint32_t (*timer_prof_time)(timer_prof_t *prof); int (*timer_prof_quit)(timer_prof_t *prof); /* FPS */ - void (*timer_fps_init)(fps_t *fps); - void (*timer_fps_sync)(fps_t *fps, int fps_target); + void (*timer_fps_init)(fps_t *fps, int fps_target); + void (*timer_fps_sync)(fps_t *fps); void (*timer_fps_quit)(fps_t *fps); }; diff --git a/kernel/src/drivers/mpu/common/sdl2/timer.c b/kernel/src/drivers/mpu/common/sdl2/timer.c index 2c64b60..130191b 100644 --- a/kernel/src/drivers/mpu/common/sdl2/timer.c +++ b/kernel/src/drivers/mpu/common/sdl2/timer.c @@ -182,30 +182,36 @@ int sdl_tmu_prof_quit(timer_prof_t *prof) //--- /* sh7305_tmu_fps_init() : initialize fps object */ -void sdl_tmu_fps_init(fps_t *fps) +void sdl_tmu_fps_init(fps_t *fps, int fps_target) { memset(fps, 0x00, sizeof(fps_t)); fps->anchor = SDL_GetTicks(); + fps->objectif = 1000 / fps_target; + fps->fps_target = fps_target; } /* sdl_tmu_fps_sync() : compute frame statistic and wait whanted FPS */ -void sdl_tmu_fps_sync(fps_t *fps, int fps_target) +void sdl_tmu_fps_sync(fps_t *fps) { uint32_t snapshot; + uint32_t target_ticks; snapshot = SDL_GetTicks(); - fps->objectif = 1000 / fps_target; fps->render = snapshot - fps->anchor; fps->margin = fps->objectif - fps->render; - fps->fps_real = 1000 / fps->render; + + fps->fps_real = 1000; + if (fps->render > 0) + fps->fps_real /= fps->render; fps->fps = fps->fps_real; if (fps->margin > 0) - fps->fps = fps_target; + fps->fps = fps->fps_target; + target_ticks = snapshot + fps->objectif; while (1) { - if (SDL_GetTicks() - fps->anchor >= fps->objectif) + if (SDL_GetTicks() >= target_ticks) break; } diff --git a/kernel/src/drivers/mpu/sh/sh7305/tmu/fps.c b/kernel/src/drivers/mpu/sh/sh7305/tmu/fps.c index adac722..2bd18af 100644 --- a/kernel/src/drivers/mpu/sh/sh7305/tmu/fps.c +++ b/kernel/src/drivers/mpu/sh/sh7305/tmu/fps.c @@ -9,36 +9,42 @@ // Public FPS API //--- +// TODO : proper handle extern uint32_t *tmu_prof_tcnt; /* sh7305_tmu_fps_init() : initialize fps object */ -void sh7305_tmu_fps_init(fps_t *fps) +void sh7305_tmu_fps_init(fps_t *fps, int fps_target) { sh7305_tmu_prof_init(NULL); memset(fps, 0x00, sizeof(fps_t)); + fps->objectif = 1000000 / fps_target; + fps->fps_target = fps_target; } /* sh7305_tmu_fps_sync() : compute frame statistic and wait whanted FPS */ -void sh7305_tmu_fps_sync(fps_t *fps, int fps_target) +void sh7305_tmu_fps_sync(fps_t *fps) { struct cpg_clock_frequency cpg_freq; + uint32_t target_ticks; uint32_t snap; //TODO: proper freq calculation cpg_clock_freq(&cpg_freq); snap = (uint32_t)(((uint64_t)*tmu_prof_tcnt * 4 * 1000000) / cpg_freq.Pphi_f); - fps->objectif = 1000000 / fps_target; fps->render = fps->anchor - snap; fps->margin = fps->objectif - fps->render; + + /* we don't secure the division because it negligent */ fps->fps_real = 1000000 / fps->render; fps->fps = fps->fps_real; if (fps->margin > 0) - fps->fps = fps_target; + fps->fps = fps->fps_target; + target_ticks = snap + fps->objectif; while (1) { - if (*tmu_prof_tcnt - fps->anchor >= fps->objectif) + if (*tmu_prof_tcnt >= target_ticks) break; } diff --git a/kernel/src/drivers/screen/R61524/r61524.c b/kernel/src/drivers/screen/R61524/r61524.c index eaf8d47..5e38492 100644 --- a/kernel/src/drivers/screen/R61524/r61524.c +++ b/kernel/src/drivers/screen/R61524/r61524.c @@ -62,6 +62,7 @@ VALIGNED(4) VWEAK int r61524_frame_frag_send(dsurface_t *surface) if (dma >= 0) sh7305_dma_wait(dma); +#if 0 /* Set the windows size */ r61524_select(horizontal_ram_start); r61524_write(0); @@ -71,6 +72,7 @@ VALIGNED(4) VWEAK int r61524_frame_frag_send(dsurface_t *surface) r61524_write(0); r61524_select(vertical_ram_end); r61524_write(223); +#endif /* Set the RAM position */ r61524_select(ram_address_horizontal); @@ -128,6 +130,10 @@ struct r61524_ctx { static void __r61524_configure(struct r61524_ctx *s) { + /* disable double-buffering display */ + r61524_atomic_transfert = true; + + /* screen information */ s->HSA = 0; s->HEA = 395; s->VSA = 0; diff --git a/kernel/src/modules/timer/fps.c b/kernel/src/modules/timer/fps.c index 78e8eb0..042c703 100644 --- a/kernel/src/modules/timer/fps.c +++ b/kernel/src/modules/timer/fps.c @@ -12,17 +12,17 @@ extern struct { /* timer_fps_init() : initialize fps object */ -void timer_fps_init(fps_t *fps) +void timer_fps_init(fps_t *fps, int target_ticks) { if (timer_info.driver.timer_fps_init != NULL) - timer_info.driver.timer_fps_init(fps); + timer_info.driver.timer_fps_init(fps, target_ticks); } /* timer_fps_sync() : try to syncronize to X frame per seconds */ -void timer_fps_sync(fps_t *fps, int fps_target) +void timer_fps_sync(fps_t *fps) { if (timer_info.driver.timer_fps_sync != NULL) - timer_info.driver.timer_fps_sync(fps, fps_target); + timer_info.driver.timer_fps_sync(fps); } /* timer_fps_quit() : uninit fps object */ diff --git a/scripts/vxdev/core/board.py b/scripts/vxdev/core/board.py index c936fdc..95181e5 100644 --- a/scripts/vxdev/core/board.py +++ b/scripts/vxdev/core/board.py @@ -14,7 +14,7 @@ __all__ = [ # Internal functions #--- -__PROJ_PREFIX__ = f"{os.path.dirname(__file__)}/../.." +__PROJ_PREFIX__ = f"{os.path.dirname(__file__)}/../../.." def _warning(text): print(text, file=sys.stderr) diff --git a/vxdev b/vxdev index 0561103..4005185 100755 --- a/vxdev +++ b/vxdev @@ -1,3 +1,3 @@ #!/usr/bin/env bash -python3 scripts/vxdev +python3 scripts/vxdev $@ diff --git a/vxsdk.toml b/vxsdk.toml index f210b47..e7eacfc 100644 --- a/vxsdk.toml +++ b/vxsdk.toml @@ -43,7 +43,7 @@ assets_prefix = [ ] VXSDK_PUBLIC_BUILD_LDFLAGS = [ '-T {VXSDK_CURRENT_SOURCE_DIR}/boards/fxcg50/fxcg50.ld', - '-static-pie', + '-static', '-Wl,-q' ]