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

54 lines
1.2 KiB
C

#include <vhex/timer/fps.h>
#include <vhex/driver/mpu/sh/sh7305/tmu.h>
#include <vhex/driver/mpu/sh/sh7305/cpg.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)
{
sh7305_tmu_prof_init(NULL);
memset(fps, 0x00, sizeof(fps_t));
}
/* sh7305_tmu_fps_sync() : compute frame statistic and wait whanted FPS */
void sh7305_tmu_fps_sync(fps_t *fps, int fps_target)
{
struct cpg_clock_frequency cpg_freq;
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;
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->anchor >= fps->objectif)
break;
}
fps->anchor = snap;
}
/* sh7305_fps_quit() : uninit the fps object */
void sh7305_tmu_fps_quit(fps_t *fps)
{
(void)fps;
sh7305_tmu_prof_quit(NULL);
}