Browse Source

less hardware info, new gray settings, new timer API

master
Lephe 1 month ago
parent
commit
a8ec615cdc
Signed by: Lephenixnoir <sebastien.michelland@protonmail.com> GPG Key ID: 1BBA026E13FC0495
9 changed files with 60 additions and 528 deletions
  1. +0
    -430
      main.c
  2. +1
    -1
      project.cfg
  3. +21
    -7
      src/gint/gray.c
  4. +3
    -68
      src/gint/hardware.c
  5. +3
    -3
      src/gint/timer.c
  6. +13
    -10
      src/gint/timer_callbacks.c
  7. +8
    -5
      src/gint/tlb.c
  8. +1
    -1
      src/gintctl.c
  9. +10
    -3
      src/perf/libprof.c

+ 0
- 430
main.c View File

@@ -1,430 +0,0 @@
#include <stddef.h>
#include <stdint.h>
#include <stdarg.h>

#define GINT_NEED_VRAM
#include <gint/timer.h>
#include <gint/clock.h>
#include <gint/rtc.h>
#include <gint/keyboard.h>
#include <gint/display.h>


#ifdef FXCG50
extern void PrintXY(int x, int y, const char *str, int, int);
extern void Bdisp_PutDisp_DD(void);
extern void Bdisp_AllClr_VRAM();

#define color_white 0xffff
#endif

void print_bin(int x, int y, uint32_t bin, int digits)
{
char str[33];
str[digits] = 0;

while(--digits >= 0)
{
str[digits] = '0' + (bin & 1);
bin >>= 1;
}

print(x, y, str);
}

#if 0
int callback(void *arg)
{
volatile int *counter = arg;
(*counter)++;
return *counter == 7;
}

void test_clock(void)
{
const clock_frequency_t *freq = clock_freq();

dclear(color_white);
print(1, 1, "FLL: %8d", freq->FLL);
print(1, 2, "PLL: %8d", freq->PLL);

print(1, 3, "div1: B%3d I%3d P%3d",
freq->Bphi_div, freq->Iphi_div, freq->Pphi_dev);

print(1, 5, "Bphi = %10d", freq->Bphi_f);
print(1, 6, "Iphi = %10d", freq->Iphi_f);
print(1, 7, "Pphi = %10d", freq->Pphi_f);

dupdate();
getkey();

volatile unsigned int *FRQCRA = (void *)0xa4150000;
volatile unsigned int *FRQCRB = (void *)0xa4150004;
volatile unsigned int *PLLCR = (void *)0xa4150024;
volatile unsigned int *FLLFRQ = (void *)0xa4150050;

dclear(color_white);
print(1, 1, "%8x", *FRQCRA);
print(1, 2, "%8x", *FRQCRB);
print(1, 3, "%8x", *PLLCR);
print(1, 4, "%8x", *FLLFRQ);
dupdate();
getkey();
}

void test_timer_simultaneous(void)
{
volatile int counters[9] = { 0 };
int count = timer_count();

for(int tid = 0; tid < count; tid++)
{
timer_setup(tid, timer_delay(tid, 1000000), timer_default,
callback, (void *)&counters[tid]);
}

for(int tid = 0; tid < count; tid++) timer_start(tid);

int limit;

#ifdef FX9860G
limit = 4000;
#else
limit = 500;
#endif

for(int i = 0; i < limit; i++)
{
dclear(color_white);
for(int k = 0; k < 9; k++)
print(2 * k + 1, 1, "%1x", counters[k]);

print(1, 8, "%4d", i);
dupdate();
}

for(int tid = 0; tid < count; tid++) timer_free(tid);
}

void test_rtc_time(void)
{
rtc_time_t time;
int limit;

#ifdef FX9860G
limit = 1500;
#else
limit = 200;
#endif

for(int i = 0; i < limit; i++)
{
const char *days[7] = {
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday",
};
dclear(color_white);
rtc_get_time(&time);

print(1, 1, "%2d:%2d:%2d",
time.hours, time.minutes, time.seconds);
print(1, 2, "%2d-%2d-%4d %s",
time.month_day, time.month, time.year,
days[time.week_day]);

print(1, 8, "%4d", i);
dupdate();
}
}

volatile int test_rtc_int_flag = 0;
int test_rtc_int_callback(UNUSED void *arg)
{
static int count = 0;
count++;
print(7, 1, "%2d", count);
Bdisp_PutDisp_DD();

test_rtc_int_flag = (count == 10);
return test_rtc_int_flag;
}
void test_rtc_int(void)
{
test_rtc_int_flag = 0;
rtc_start_timer(rtc_1Hz, test_rtc_int_callback, NULL);

uint32_t vbr = 0x8800df00;
vbr += 0x600;
vbr += 0x20;
vbr += 0xaa0 - 0x400;
vbr += 20;

Bdisp_AllClr_VRAM();
print(1, 1, "count=");
Bdisp_PutDisp_DD();
while(!test_rtc_int_flag) __asm__("sleep");
delay(100);

/* Not needed since the callback stops the timer
rtc_stop_timer(); */
}

/* Count how many interrupts I can process in a second */
volatile int test_timer_stress_counter = 0;
volatile int test_timer_stress_done = 0;
int test_timer_stress_callback(void *arg)
{
volatile int *counter = arg;
(*counter)++;
return 0;
}
int test_timer_stress_stop(UNUSED void *arg)
{
timer_pause(0);
timer_free(0);

test_timer_stress_done = 1;
return 1;
}
int test_timer_stress_start(UNUSED void *arg)
{
rtc_start_timer(rtc_1Hz, test_timer_stress_stop, NULL);
timer_start(0);
return 0;
}
void test_timer_stress(void)
{
int length = 0;
gint_intlevel(isSH3() ? 3 : 40, 15);

Bdisp_AllClr_VRAM();
print(1, 1, "Testing...");
Bdisp_PutDisp_DD();

timer_setup(0, timer_delay(0, length), timer_default,
test_timer_stress_callback, (void*)&test_timer_stress_counter);
rtc_start_timer(rtc_1Hz, test_timer_stress_start, NULL);

do __asm__("sleep");
while(!test_timer_stress_done);

Bdisp_AllClr_VRAM();
print(1, 1, "Test finished!");
print(1, 2, "length = %8d ms", length);
print(1, 3, "Processed interrupts:");
print(1, 4, "%7d", test_timer_stress_counter);
Bdisp_PutDisp_DD();

gint_intlevel(isSH3() ? 3 : 40, 5);
delay(60);
}
#endif

#define TEST_TIMER_FREQ_LIMIT 64
#define TEST_TIMER_FREQ_RTC RTC_16Hz
#define TEST_TIMER_FREQ_TIMER 62500
#define TEST_TIMER_FREQ_TID 7

#include <gint/mpu/rtc.h>

int test_timer_freq_callback(volatile void *arg)
{
volatile int *counter = arg;
(*counter)++;
return (*counter == TEST_TIMER_FREQ_LIMIT);
}
int test_timer_freq_start(volatile void *arg)
{
rtc_start_timer(TEST_TIMER_FREQ_RTC, test_timer_freq_callback, arg);
timer_start(TEST_TIMER_FREQ_TID);
return 0;
}
void test_timer_freq(void)
{
volatile int tmu = 0, rtc = 0;
int tid = TEST_TIMER_FREQ_TID;

timer_setup(tid, timer_delay(tid, TEST_TIMER_FREQ_TIMER),
timer_default, test_timer_freq_callback, &tmu);
rtc_start_timer(TEST_TIMER_FREQ_RTC, test_timer_freq_start, &rtc);

while(rtc < TEST_TIMER_FREQ_LIMIT)
{
dclear(color_white);
print(1, 1, "TMU %4x", tmu);
print(1, 2, "RTC %4x", rtc);

dupdate();
}
}

#ifdef FX9860G
void fx_frame1(void)
{
dclear(color_white);
for(int x = 0; x < 256; x += 4) vram[x] = vram[x + 1] = 0xffffffff;
for(int r = 0; r <= 8; r += 2)
{
for(int x = r; x < 64 - r; x++)
{
dpixel(x, r, color_reverse);
dpixel(x, 127 - r, color_reverse);
}
for(int y = r + 1; y < 128 - r; y++)
{
dpixel(r, y, color_reverse);
dpixel(63 - r, y, color_reverse);
}
}
dupdate();
}
void fx_frame2(void)
{
dclear(color_white);
for(int x = 20; x <= 88; x += 68)
for(int y = 10; y <= 44; y += 34)
{
// drect(x, y, 20, 10, color_black);
}

dline(64, 32, 84, 32, color_reverse);
dline(64, 32, 78, 18, color_reverse);
dline(64, 32, 64, 12, color_reverse);
dline(64, 32, 50, 18, color_reverse);
dline(64, 32, 44, 32, color_reverse);
dline(64, 32, 44, 46, color_reverse);
dline(64, 32, 64, 52, color_reverse);
dline(64, 32, 78, 46, color_reverse);
}
#endif

typedef void asm_text_t(uint32_t *v1, uint32_t *v2, uint32_t *op, int height);
extern asm_text_t *topti_asm_text[8];

static void show_bootlog(void)
{
extern char gint_bootlog[22*9];

int i = 0;
for(int y = 0; y < 9; y++)
{
for(int x = 0; x < 21; x++)
{
if(!gint_bootlog[i]) gint_bootlog[i] = ' ';
i++;
}
gint_bootlog[i] = 0;
i++;
}

dclear(color_white);

for(int y = 0; y < 9; y++)
print(1, y + 1, gint_bootlog + 22 * y);
dupdate();

getkey();
}

int main(GUNUSED int isappli, GUNUSED int optnum)
{
#ifdef FX9860G

// extern image_t pattern;
// extern image_t pattern2;

/* image_t *img = &pattern;

uint32_t *data = (void *)&img->data;

for(int i = 0; i < 32; i++) vram[4 * i] = data[i];
dupdate();
getkey();

fx_frame1();
getkey();
fx_frame2();
getkey(); */

int x = 0, y = 0, k = 0, w, h;

while(k != KEY_EXIT)
{
dclear(color_white);
// bopti_render_clip(x, y, &pattern2, 0, 0, 48, 16);
dtext(x, y, "Hello, World!", color_white, color_black);
dsize("Hello, World!", NULL, &w, &h);
drect(x, y, x + w - 1, y + h - 1, color_reverse);
dupdate();

k = getkey().key;
if(k == KEY_LEFT /* && x > 2 */) x-=3;
if(k == KEY_RIGHT /* && x < 92 */) x+=3;
if(k == KEY_UP /* && y > 2 */) y-=3;
if(k == KEY_DOWN /* && y < 30 */) y+=3;
}

#endif

/* #ifdef FXCG50
initial_timer_status();
Bdisp_PutDisp_DD();
getkey();
#endif */

#ifdef FXCG50
#define rgb(r, g, b) ((r << 11) | (g << 5) | b)

dclear(0xf800);
for(int i = 1; i <= 10; i++)
{
drect(i, i, 395 - i, 223 - i, (i & 1) ? 0xffff: 0xf800);
}

int cx = 100, cy = 100;
int r = 30;

drect(cx-r, cy-r, cx+r, cy+r, 0xffff);
for(int k = -r; k <= r; k += 10)
{
dline(cx, cy, cx+k, cy-r, 0x0000);
dline(cx, cy, cx+k, cy+r, 0x0000);

dline(cx, cy, cx-r, cy+k, 0x0000);
dline(cx, cy, cx+r, cy+k, 0x0000);
}

for(int y = 0; y < 20; y++)
for(int x = 0; x < 20; x++)
{
dpixel(180+x, 30+y, ((x^y) & 1)
? rgb(10, 21, 10)
: rgb(21, 43, 21));
}

dupdate();
getkey();

for(int y = 0; y < 224; y++)
for(int x = 0; x < 396; x++)
{
int v = y >> 3;
int h = x >> 3;
vram[396 * y + x] = 0x3eb7 ^ ((v << 11) + (h << 5) + v);
}

volatile int flag = 0;
int iterations = 0;
timer_setup(0, timer_delay(0, 1000 * 1000), 0, timer_timeout, &flag);
timer_start(0);

while(!flag) r61524_display(vram, 0, 224), iterations++;

Bdisp_AllClr_VRAM();
print(1, 1, "%3d FPS", iterations);
Bdisp_PutDisp_DD();
getkey();
#endif

return 0;
}

+ 1
- 1
project.cfg View File

@@ -69,7 +69,7 @@ LDFLAGS_FX := -T fx9860g.ld -lgint-fx $(LIBS_FX) -lgint-fx -lgcc
LDFLAGS_CG := -T fxcg50.ld -lgint-cg $(LIBS_CG) -lgint-cg -lgcc

# Additional linker flags, if you need any.
LDFLAGS :=
LDFLAGS := -Wl,--print-memory-usage

# Additional platform-specific linker flags.
LDFLAGS_FX += -Wl,-Map=build-fx/map


+ 21
- 7
src/gint/gray.c View File

@@ -2,6 +2,7 @@

#include <gint/gray.h>
#include <gint/keyboard.h>
#include <gint/hardware.h>
#include <gint/std/string.h>
#include <gint/std/stdio.h>
#include <gintctl/gint.h>
@@ -12,6 +13,8 @@ void gintctl_gint_gray(void)
uint32_t delays[2];
gray_config(&delays[0], &delays[1]);

int g35pe2 = (gint[HWCALC] == HWCALC_G35PE2);

int key = 0, sel = 0;
char str[20];

@@ -22,6 +25,8 @@ void gintctl_gint_gray(void)
gclear(C_WHITE);

gtext(1, 0, "Gray engine tuning", C_BLACK, C_NONE);
gtext(1, 8, g35pe2 ? "Graph 35+E II" : "fx-9860G-like",
C_BLACK, C_NONE);

sprintf(str, "Light%5u", delays[0]);
gtext(13, 24, str, C_BLACK, C_NONE);
@@ -36,7 +41,8 @@ void gintctl_gint_gray(void)
grect(96, 32, 127, 47, C_DARK);

extern bopti_image_t img_opt_gint_gray;
gimage(0, 56, &img_opt_gint_gray);
gsubimage(0, 56, &img_opt_gint_gray, 0, 0, g35pe2?128:86, 8,
DIMAGE_NONE);

gupdate();
key = getkey().key;
@@ -48,16 +54,24 @@ void gintctl_gint_gray(void)
delays[sel]--;
else if(key == KEY_RIGHT)
delays[sel]++;
else if(key == KEY_F1)
delays[0] = 680, delays[1] = 1078;
else if(key == KEY_F2)
else if(g35pe2 && key == KEY_F1)
delays[0] = 762, delays[1] = 1311;
else if(key == KEY_F3)
else if(g35pe2 && key == KEY_F2)
delays[0] = 680, delays[1] = 1078;
else if(g35pe2 && key == KEY_F3)
delays[0] = 869, delays[1] = 1097;
else if(key == KEY_F4)
else if(g35pe2 && key == KEY_F4)
delays[0] = 869, delays[1] = 1311;
else if(key == KEY_F5)
else if(g35pe2 && key == KEY_F5)
delays[0] = 937, delays[1] = 1425;
else if(!g35pe2 && key == KEY_F1)
delays[0] = 1075, delays[1] = 1444;
else if(!g35pe2 && key == KEY_F2)
delays[0] = 898, delays[1] = 1350;
else if(!g35pe2 && key == KEY_F3)
delays[0] = 609, delays[1] = 884;
else if(!g35pe2 && key == KEY_F4)
delays[0] = 937, delays[1] = 1333;
else continue;

if(delays[sel] < 100) delays[sel] = 100;


+ 3
- 68
src/gint/hardware.c View File

@@ -41,19 +41,19 @@ static void hw_mpucpu(int *row)
if(!isSH4()) return;
put(_(" PVR:"," Processor Version Register: ") "%08x", gint[HWCPUVR]);
put(_(" PRR:"," Product Register: ") "%08x", gint[HWCPUPR]);

volatile uint32_t *CPUOPM = (void *)0xff2f0000;
put(_(" CPUOPM:"," CPU Operation Mode: ") "%08x", *CPUOPM);
}

/* Memory */
static void hw_memory(int *row)
{
int mmu = gint[HWMMU];
int rom = gint[HWROM];
int ram = gint[HWRAM];
int uram = gint[HWURAM];

put("Memory and MMU" _(,":"));
load_barrier(mmu);

put(" ROM:" _(," ") "%dM", rom >> 20);

#ifdef FX9860G
@@ -61,48 +61,6 @@ static void hw_memory(int *row)
#else
put(" RAM: %dM (%dk mapped in userspace)", ram >> 20, uram >> 10);
#endif

if(mmu & HWMMU_UTLB) put(" TLB is unified");
if(mmu & HWMMU_FITTLB) put(
_(" Add-in fits in TLB"," Add-in is fully mapped in the TLB"));
}

/* Clock Pulse generator */
static void hw_cpg(int *row)
{
int cpg = gint[HWCPG];

put(_("Clock Generator", "Clock Pulse Generator:"));
load_barrier(cpg);

if(cpg & HWCPG_COMP) put(
_(" Input freq known"," Input clock frequency is known"));
if(cpg & HWCPG_EXT) put(
_(" SH7724-style CPG"," SH7724-style extended module"));
}

/* Direct Memory Access Controller */
static GUNUSED void hw_dma(GUNUSED int *row)
{
#ifdef FXCG50
int dma = gint[HWDMA];

put("Direct Memory Access" _(," Controller:"));
load_barrier(dma);

put(" (loaded)");
#endif
}

/* Timer Unit */
static void hw_tmu(int *row)
{
int tmu = gint[HWTMU];

put("Timer Unit" _(,":"));
load_barrier(tmu);

put(" (loaded)");
}

/* Extra Timer Unit */
@@ -129,17 +87,6 @@ static void hw_etmu(int *row)
}
}

/* Real-Time Clock */
static void hw_rtc(int *row)
{
int rtc = gint[HWRTC];

put("Real-Time Clock" _(,":"), rtc);
load_barrier(rtc);

if(rtc & HWRTC_TIMER) put(" timer enabled");
}

/* Keyboard */
static void hw_keyboard(int *row)
{
@@ -196,21 +143,9 @@ static int display_data(int offset)
hw_memory(row);
put("");

hw_cpg(row);
put("");

#ifdef FXCG50
hw_dma(row);
put("");
#endif

hw_tmu(row);
hw_etmu(row);
put("");

hw_rtc(row);
put("");

hw_keyboard(row);
put("");



+ 3
- 3
src/gint/timer.c View File

@@ -98,6 +98,7 @@ void gintctl_gint_timer(void)
program to ~90 FPS.) */
int key=0, tid=0;
GUNUSED int timeout=1;
volatile int flag = 0;

#ifdef FX9860G
int tab = 1;
@@ -142,9 +143,8 @@ void gintctl_gint_timer(void)
/* On F1, pretend to sleep and just see what happens */
if(key == KEY_F1)
{
volatile int flag = 0;
int free = timer_setup(tid, timer_delay(tid, 1000000),
0, timer_timeout, &flag);
int free = timer_setup(tid, timer_delay(tid, 1000000,
TIMER_Pphi_4), NULL);
if(free == tid) timer_start(tid);
}



+ 13
- 10
src/gint/timer_callbacks.c View File

@@ -6,35 +6,39 @@
#include <gintctl/gint.h>
#include <gintctl/util.h>

static int tests = 0;

static int callback_simple(volatile void *arg)
{
/* Perform a multiplication to check basic register saves */
int base = *(volatile int *)arg;
return base * 387 + 1;
tests++;
return base * 387 + TIMER_STOP;
}

static int callback_sleep(GUNUSED volatile void *arg)
{
sleep();
return 1;
tests++;
return TIMER_STOP;
}

static int callback_timer(GUNUSED volatile void *arg)
{
volatile int timeout = 0;

timer_setup(1, timer_delay(1, 10000), timer_default, timer_timeout,
timer_setup(1, timer_delay(1, 10000, TIMER_Pphi_4), timer_timeout,
&timeout);
timer_start(1);
timer_wait(1);
return 1;
tests++;
return TIMER_STOP;
}

/* gintctl_gint_timer_callbacks(): Stunts in the environment of callbacks */
void gintctl_gint_timer_callbacks(void)
{
int key = 0;
int base=0, done=0;
int key=0, base=0;

while(key != KEY_EXIT)
{
@@ -49,7 +53,7 @@ void gintctl_gint_timer_callbacks(void)

extern bopti_image_t img_opt_gint_timer_callbacks;
dimage(0, 56, &img_opt_gint_timer_callbacks);
dprint(69, 56, C_BLACK, "Done:%d", done);
dprint(69, 56, C_BLACK, "Done:%d", tests);
#endif

#ifdef FXCG50
@@ -68,7 +72,7 @@ void gintctl_gint_timer_callbacks(void)
row_print(8, 1,
"own callback) and waits for the interrupt.");

row_print(10, 1, "Tests run: %d", done);
row_print(10, 1, "Tests run: %d", tests);

fkey_action(1, "SIMPLE");
fkey_action(2, "SLEEP");
@@ -87,11 +91,10 @@ void gintctl_gint_timer_callbacks(void)

if(callback)
{
timer_setup(0, timer_delay(0, 10000), timer_default,
timer_setup(0, timer_delay(0, 10000, TIMER_Pphi_4),
callback, arg);
timer_start(0);
timer_wait(0);
done++;
}
}
}


+ 8
- 5
src/gint/tlb.c View File

@@ -340,7 +340,7 @@ static int generate_tlb_miss(volatile void *arg)
{
uint8_t volatile *next_miss = arg;
GUNUSED uint8_t volatile x = *next_miss;
return 1;
return TIMER_STOP;
}

/* gintctl_gint_tlb(): TLB miss handler and TLB management */
@@ -386,10 +386,13 @@ void gintctl_gint_tlb(void)
}
if(key == KEY_F6 && next_miss != 0xffffffff)
{
timer_setup(1, timer_delay(1, 10000), timer_default,
generate_tlb_miss, (volatile void *)next_miss);
timer_start(1);
timer_wait(1);
int timer = timer_setup(TIMER_ANY, 10000,
generate_tlb_miss, next_miss);
if(timer >= 0)
{
timer_start(timer);
timer_wait(timer);
}
}
}
}

+ 1
- 1
src/gintctl.c View File

@@ -118,7 +118,7 @@ int main(GUNUSED int isappli, GUNUSED int optnum)
menu_init(&menu_libs, top, bottom);

/* Start the profiling library */
prof_init(PROFCTX_COUNT, 2);
prof_init(PROFCTX_COUNT);

int key = 0;
struct menu *menu = NULL;


+ 10
- 3
src/perf/libprof.c View File

@@ -1,6 +1,6 @@
#include <gint/keyboard.h>
#include <gint/display.h>
#include <gint/clock.h>
#include <gint/timer.h>

#include <gintctl/util.h>
#include <gintctl/prof-contexts.h>
@@ -15,9 +15,16 @@ static uint32_t run_sleep(int us)
prof_clear(ctx);
prof_enter(ctx);

sleep_us(1, us);
prof_leave(ctx);
/* We can't use sleep_us() as we want a TMU */
volatile int flag = 0;
int timer = timer_setup(TIMER_TMU, us, timer_timeout, &flag);
if(timer >= 0)
{
timer_start(timer);
timer_wait(timer);
}

prof_leave(ctx);
return prof_time(ctx);
}



Loading…
Cancel
Save