vxKernel/src/driver/mpu/sh/sh7305/tmu/fps.c

53 lines
1.0 KiB
C

#include <vhex/timer/fps.h>
#include <vhex/driver/mpu/sh/sh7305/tmu.h>
#include <vhex/driver/cpu.h>
#include <string.h>
//---
// Public FPS API
//---
extern uint32_t *tmu_prof_tcnt;
/* sh7305_tmu_fps_init() : initialize fps object */
void sh7305_tmu_fps_init(fps_t *fps)
{
cpu_atomic_start();
sh7305_tmu_prof_init(NULL);
memset(fps, 0x00, sizeof(fps_t));
fps->keyframe = *tmu_prof_tcnt;
cpu_atomic_end();
}
/* sh7305_tmu_fps_sync() : compute frame statistic and wait whanted FPS */
void sh7305_tmu_fps_sync(fps_t *fps, int fps_target)
{
uint32_t snap;
snap = *tmu_prof_tcnt;
fps->objectif = 1000000 / fps_target;
fps->render = fps->keyframe - snap;
fps->margin = fps->objectif - fps->render;
fps->fps_real = 1000000 / fps->render;
fps->fps = fps->fps_real;
if (fps->margin <= 0)
fps->fps = fps_target;
while (1) {
if (*tmu_prof_tcnt - fps->keyframe >= fps->objectif)
break;
}
fps->keyframe = *tmu_prof_tcnt;
}
/* sh7305_fps_quit() : uninit the fps object */
void sh7305_tmu_fps_quit(fps_t *fps)
{
(void)fps;
sh7305_tmu_prof_quit(NULL);
}