gintctl/src/gint/timer.c

167 lines
3.9 KiB
C
Raw Normal View History

2019-07-17 18:59:17 +02:00
#include <gint/mpu/tmu.h>
#include <gint/timer.h>
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/clock.h>
2019-07-17 18:59:17 +02:00
#include <gintctl/util.h>
#include <gintctl/gint.h>
#include <stdio.h>
2019-07-18 23:53:54 +02:00
/* timer_print(): Print a timer's details */
void timer_print(int x, int y, char const *name, uint32_t TCOR, uint32_t TCNT,
int UNIE, int UNF, int STR)
2019-07-17 18:59:17 +02:00
{
2019-07-18 23:53:54 +02:00
int dy = _(8,14);
dprint(x, y, C_BLACK, "%s:", name);
2019-07-17 18:59:17 +02:00
#if GINT_RENDER_RGB
dprint(x, y+dy, C_BLACK, "TCOR");
dprint(x, y+2*dy, C_BLACK, "TCNT");
2019-07-18 23:53:54 +02:00
#endif
2019-07-17 18:59:17 +02:00
dprint(_(x+6, x+45), y+dy, C_BLACK, "%08X", TCOR);
dprint(_(x+60, x+45), _(y+dy, y+2*dy), C_BLACK, "%08X", TCNT);
2019-07-17 18:59:17 +02:00
dprint(_(x+36, x), _(y, y+3*dy), C_BLACK, "%s%s%s",
2019-07-18 23:53:54 +02:00
UNIE ? "UNIE " : "",
UNF ? "UNF " : "",
STR ? "STR " : ""
2019-07-17 18:59:17 +02:00
);
}
2019-07-18 23:53:54 +02:00
/* tmu_print(): Print a TMU's details */
void tmu_print(int x, int y, char const *name, tmu_t *tmu, int STR)
{
timer_print(x, y, name, tmu->TCOR, tmu->TCNT, tmu->TCR.UNIE,
tmu->TCR.UNF, STR);
}
2019-07-17 18:59:17 +02:00
/* etmu_print(): Print an ETMU's details */
void etmu_print(int x, int y, char const *name, etmu_t *etmu)
{
2019-07-18 23:53:54 +02:00
timer_print(x, y, name, etmu->TCOR, etmu->TCNT, etmu->TCR.UNIE,
etmu->TCR.UNF, etmu->TSTR);
}
2019-07-17 18:59:17 +02:00
#if GINT_RENDER_MONO
2019-07-18 23:53:54 +02:00
static int x[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 };
static int y[] = { 0, 16, 32, 0, 16, 32, 0, 16, 32 };
#else
static int x[] = { 6, 138, 270, 6, 138, 270, 6, 138, 270 };
static int y[] = { 24, 24, 24, 84, 84, 84, 144, 144, 144 };
#endif
2019-07-17 18:59:17 +02:00
2019-07-18 23:53:54 +02:00
void show_tmu(void)
{
tmu_t *TMU = SH7305_TMU.TMU;
volatile uint8_t *TSTR = &SH7305_TMU.TSTR;
2019-07-18 23:53:54 +02:00
if(isSH3())
{
TMU = SH7705_TMU.TMU;
TSTR = &SH7705_TMU.TSTR;
}
tmu_print(x[0], y[0], "TMU0", &TMU[0], *TSTR & 0x1);
tmu_print(x[1], y[1], "TMU1", &TMU[1], *TSTR & 0x2);
tmu_print(x[2], y[2], "TMU2", &TMU[2], *TSTR & 0x4);
2019-07-18 23:53:54 +02:00
}
void show_etmu_1(void)
{
etmu_t *ETMU = isSH3() ? SH7705_ETMU : SH7305_ETMU;
etmu_print(x[3], y[3], "ETMU0", &ETMU[0]);
2019-07-18 23:53:54 +02:00
if(isSH3()) return;
etmu_print(x[4], y[4], "ETMU1", &ETMU[1]);
etmu_print(x[5], y[5], "ETMU2", &ETMU[2]);
2019-07-18 23:53:54 +02:00
}
void show_etmu_2(void)
{
etmu_t *ETMU = SH7305_ETMU;
2019-07-18 23:53:54 +02:00
if(isSH3()) return;
etmu_print(x[6], y[6], "ETMU3", &ETMU[3]);
etmu_print(x[7], y[7], "ETMU4", &ETMU[4]);
etmu_print(x[8], y[8], "ETMU5", &ETMU[5]);
2019-07-17 18:59:17 +02:00
}
/* gintctl_gint_timer(): Show the timer status in real-time */
void gintctl_gint_timer(void)
{
/* In this program we'll display the timer status at "full speed" and
hence ask getkey() to never wait. (The processor is still sleeping
during the DMA transfer to the screen on fxcg50, limiting the
program to ~90 FPS.) */
int key=0, tid=0;
GUNUSED int timeout=1;
2019-07-17 18:59:17 +02:00
#if GINT_RENDER_MONO
2019-07-18 23:53:54 +02:00
int tab = 1;
#endif
while(!keydown(KEY_EXIT))
2019-07-17 18:59:17 +02:00
{
dclear(C_WHITE);
#if GINT_RENDER_MONO
2019-07-18 23:53:54 +02:00
if(tab == 1) show_tmu();
if(tab == 2) show_etmu_1();
if(tab == 3) show_etmu_2();
extern bopti_image_t img_opt_gint_timers;
dimage(0, 56, &img_opt_gint_timers);
extern font_t font_mini;
font_t const *old_font = dfont(&font_mini);
if(tid < 3) dprint(24, 57, C_BLACK, "\x01 TMU%d \x02", tid);
else dprint(24, 57, C_BLACK, "\x01 ETMU%d \x02", tid-3);
dfont(old_font);
2019-07-17 18:59:17 +02:00
#endif
#if GINT_RENDER_RGB
2019-07-17 18:59:17 +02:00
row_title("Timer status");
2019-07-18 23:53:54 +02:00
show_tmu();
show_etmu_1();
show_etmu_2();
2019-07-17 18:59:17 +02:00
fkey_action(1, "SLEEP");
if(tid < 3) dprint(72, 210, C_BLACK, "TMU%d", tid);
else dprint(72, 210, C_BLACK, "ETMU%d", tid-3);
2019-07-17 18:59:17 +02:00
#endif
dupdate();
int timeout = 1;
key_event_t ev = getkey_opt(GETKEY_DEFAULT, &timeout);
if(ev.type == KEYEV_NONE) continue;
key = ev.key;
2019-07-17 18:59:17 +02:00
/* On F1, pretend to sleep and just see what happens */
if(key == KEY_F1)
2019-07-17 18:59:17 +02:00
{
2021-04-27 14:57:27 +02:00
int free = timer_configure(tid, timer_delay(tid, 1000000,
TIMER_Pphi_4), GINT_CALL_NULL);
2019-07-18 23:53:54 +02:00
if(free == tid) timer_start(tid);
2019-07-17 18:59:17 +02:00
}
2019-07-18 23:53:54 +02:00
#if GINT_RENDER_MONO
2019-07-18 23:53:54 +02:00
/* On F4, F5 and F6, switch tabs */
if(key == KEY_F4) tab = 1;
if(key == KEY_F5) tab = 2;
if(key == KEY_F6) tab = 3;
2019-07-18 23:53:54 +02:00
#endif
if(key == KEY_LEFT)
tid = (tid + timer_count() - 1) % timer_count();
if(key == KEY_RIGHT)
tid = (tid + 1) % timer_count();
2019-07-17 18:59:17 +02:00
}
}