Skip to content

Commit

Permalink
More timer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
endrift committed Jul 5, 2017
1 parent 9541231 commit 632bb12
Showing 1 changed file with 104 additions and 54 deletions.
158 changes: 104 additions & 54 deletions src/timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,72 +13,117 @@
struct TimerTest {
const char* testName;
u32 delay;
u32 irqs;
u32 timer;
u32 addTightLoop;
u32 addLooseLoop;
};

static const struct TimerTest timerTests[] = {
{ "0b, 0d, 0x0001", 0, 0xC0FFFF, 0x0002, 0x0010 },
{ "0b, 0d, 0x0003", 0, 0xC0FFFC, 0x0002, 0x0010 },
{ "0b, 0d, 0x0005", 0, 0xC0FFFB, 0x0003, 0x0010 },
{ "0b, 0d, 0x000C", 0, 0xC0FFF4, 0x0003, 0x0020 },
{ "0b, 0d, 0x000D", 0, 0xC0FFF3, 0x0004, 0x0020 },
{ "0b, 0d, 0x0010", 0, 0xC0FFF0, 0x0004, 0x0020 },
{ "0b, 0d, 0x0014", 0, 0xC0FFEC, 0x0004, 0x0020 },
{ "0b, 0d, 0x0015", 0, 0xC0FFEB, 0x0005, 0x0020 },
{ "0b, 0d, 0x0020", 0, 0xC0FFE0, 0x0006, 0x0020 },
{ "0b, 0d, 0x0024", 0, 0xC0FFDC, 0x0006, 0x0030 },
{ "0b, 0d, 0x0025", 0, 0xC0FFDB, 0x0007, 0x0030 },
{ "0b, 0d, 0x0040", 0, 0xC0FFC0, 0x000A, 0x0040 },
{ "0b, 0d, 0x0080", 0, 0xC0FF80, 0x0012, 0x0070 },
{ "0b, 0d, 0x0100", 0, 0xC0FF00, 0x0022, 0x00C0 },
{ "0b, 0d, 0x0200", 0, 0xC0FE00, 0x0042, 0x0170 },
{ "0b, 0d, 0x0400", 0, 0xC0FC00, 0x0082, 0x02E0 },
{ "0b, 0d, 0x0800", 0, 0xC0F800, 0x0102, 0x05A0 },
{ "0b, 0d, 0x1000", 0, 0xC0F000, 0x0202, 0x0B30 },
{ "0b, 0d, 0x2000", 0, 0xC0E000, 0x0402, 0x1650 },
{ "0b, 0d, 0x4000", 0, 0xC0C000, 0x0802, 0x2C90 },
{ "0b, 0d, 0x8000", 0, 0xC08000, 0x1002, 0x5920 },
{ "6b, 0d, 0x0010", 0, 0xC1FFF0, 0x0082, 0x02D0 },
{ "6b, 0d, 0x0011", 0, 0xC1FFEF, 0x008A, 0x0300 },
{ "6b, 0d, 0x0012", 0, 0xC1FFEE, 0x0092, 0x0330 },
{ "6b, 0d, 0x0013", 0, 0xC1FFED, 0x009A, 0x0360 },
{ "8b, 0d, 0x0010", 0, 0xC2FFF0, 0x01EA, 0x0AB0 },
{ "8b, 0d, 0x0011", 0, 0xC2FFEF, 0x020A, 0x0B60 },
{ "8b, 0d, 0x0012", 0, 0xC2FFEE, 0x022A, 0x0C10 },
{ "8b, 0d, 0x0013", 0, 0xC2FFED, 0x024A, 0x0CC0 },
{ "10b, 0d, 0x0010", 0, 0xC3FFF0, 0x07EA, 0x2C10 },
{ "10b, 0d, 0x0011", 0, 0xC3FFEF, 0x086A, 0x2ED0 },
{ "10b, 0d, 0x0012", 0, 0xC3FFEE, 0x08EA, 0x31A0 },
{ "10b, 0d, 0x0013", 0, 0xC3FFED, 0x096A, 0x3460 },
{ "0b, 1d, 0x0010", 1, 0xC0FFF0, 0x0004, 0x0020 },
{ "0b, 1d, 0x0014", 1, 0xC0FFEC, 0x0004, 0x0020 },
{ "0b, 1d, 0x0015", 1, 0xC0FFEB, 0x0005, 0x0020 },
{ "6b, 1d, 0x0010", 1, 0xC1FFF0, 0x0081, 0x02D0 },
{ "6b, 1d, 0x0011", 1, 0xC1FFEF, 0x0089, 0x0300 },
{ "8b, 1d, 0x0010", 1, 0xC2FFF0, 0x01E9, 0x0AA0 },
{ "8b, 1d, 0x0011", 1, 0xC2FFEF, 0x0209, 0x0B60 },
{ "10b, 1d, 0x0010", 1, 0xC3FFF0, 0x07E9, 0x2C10 },
{ "10b, 1d, 0x0011", 1, 0xC3FFEF, 0x0869, 0x2ED0 },
{ "0b, 2d, 0x0010", 2, 0xC0FFF0, 0x0004, 0x0020 },
{ "0b, 2d, 0x0014", 2, 0xC0FFEC, 0x0004, 0x0020 },
{ "0b, 2d, 0x0015", 2, 0xC0FFEB, 0x0005, 0x0020 },
{ "6b, 2d, 0x0010", 2, 0xC1FFF0, 0x0080, 0x02D0 },
{ "6b, 2d, 0x0011", 2, 0xC1FFEF, 0x0088, 0x0300 },
{ "8b, 2d, 0x0010", 2, 0xC2FFF0, 0x01E8, 0x0AA0 },
{ "8b, 2d, 0x0011", 2, 0xC2FFEF, 0x0208, 0x0B50 },
{ "10b, 2d, 0x0010", 2, 0xC3FFF0, 0x07E8, 0x2C00 },
{ "10b, 2d, 0x0011", 2, 0xC3FFEF, 0x0868, 0x2ED0 },
{ "0b, 0d, 1i, 0x0001", 0, 1, 0xC0FFFF, 0x0002, 0x0010 },
{ "0b, 0d, 1i, 0x0003", 0, 1, 0xC0FFFC, 0x0002, 0x0010 },
{ "0b, 0d, 1i, 0x0005", 0, 1, 0xC0FFFB, 0x0003, 0x0010 },
{ "0b, 0d, 1i, 0x000C", 0, 1, 0xC0FFF4, 0x0003, 0x0020 },
{ "0b, 0d, 1i, 0x000D", 0, 1, 0xC0FFF3, 0x0004, 0x0020 },
{ "0b, 0d, 1i, 0x0010", 0, 1, 0xC0FFF0, 0x0004, 0x0020 },
{ "0b, 0d, 1i, 0x0014", 0, 1, 0xC0FFEC, 0x0004, 0x0020 },
{ "0b, 0d, 1i, 0x0015", 0, 1, 0xC0FFEB, 0x0005, 0x0020 },
{ "0b, 0d, 1i, 0x0020", 0, 1, 0xC0FFE0, 0x0006, 0x0020 },
{ "0b, 0d, 1i, 0x0024", 0, 1, 0xC0FFDC, 0x0006, 0x0030 },
{ "0b, 0d, 1i, 0x0025", 0, 1, 0xC0FFDB, 0x0007, 0x0030 },
{ "0b, 0d, 1i, 0x0040", 0, 1, 0xC0FFC0, 0x000A, 0x0040 },
{ "0b, 0d, 1i, 0x0080", 0, 1, 0xC0FF80, 0x0012, 0x0070 },
{ "0b, 0d, 1i, 0x0100", 0, 1, 0xC0FF00, 0x0022, 0x00C0 },
{ "0b, 0d, 1i, 0x0200", 0, 1, 0xC0FE00, 0x0042, 0x0170 },
{ "0b, 0d, 1i, 0x0400", 0, 1, 0xC0FC00, 0x0082, 0x02E0 },
{ "0b, 0d, 1i, 0x0800", 0, 1, 0xC0F800, 0x0102, 0x05A0 },
{ "0b, 0d, 1i, 0x1000", 0, 1, 0xC0F000, 0x0202, 0x0B30 },
{ "0b, 0d, 1i, 0x2000", 0, 1, 0xC0E000, 0x0402, 0x1650 },
{ "0b, 0d, 1i, 0x4000", 0, 1, 0xC0C000, 0x0802, 0x2C90 },
{ "0b, 0d, 1i, 0x8000", 0, 1, 0xC08000, 0x1002, 0x5920 },
{ "6b, 0d, 1i, 0x0010", 0, 1, 0xC1FFF0, 0x007B, 0x02B0 },
{ "6b, 0d, 1i, 0x0011", 0, 1, 0xC1FFEF, 0x0083, 0x02E0 },
{ "6b, 0d, 1i, 0x0012", 0, 1, 0xC1FFEE, 0x008B, 0x0310 },
{ "6b, 0d, 1i, 0x0013", 0, 1, 0xC1FFED, 0x0093, 0x0340 },
{ "8b, 0d, 1i, 0x0010", 0, 1, 0xC2FFF0, 0x01EB, 0x0AB0 },
{ "8b, 0d, 1i, 0x0011", 0, 1, 0xC2FFEF, 0x020B, 0x0B60 },
{ "8b, 0d, 1i, 0x0012", 0, 1, 0xC2FFEE, 0x022B, 0x0C10 },
{ "8b, 0d, 1i, 0x0013", 0, 1, 0xC2FFED, 0x024B, 0x0CD0 },
{ "10b, 0d, 1i, 0x0010", 0, 1, 0xC3FFF0, 0x07EB, 0x2C10 },
{ "10b, 0d, 1i, 0x0011", 0, 1, 0xC3FFEF, 0x086B, 0x2EE0 },
{ "10b, 0d, 1i, 0x0012", 0, 1, 0xC3FFEE, 0x08EB, 0x31A0 },
{ "10b, 0d, 1i, 0x0013", 0, 1, 0xC3FFED, 0x096B, 0x3470 },
{ "0b, 1d, 1i, 0x0010", 1, 1, 0xC0FFF0, 0x0004, 0x0020 },
{ "0b, 1d, 1i, 0x0014", 1, 1, 0xC0FFEC, 0x0004, 0x0020 },
{ "0b, 1d, 1i, 0x0015", 1, 1, 0xC0FFEB, 0x0005, 0x0020 },
{ "6b, 1d, 1i, 0x0010", 1, 1, 0xC1FFF0, 0x007B, 0x02B0 },
{ "6b, 1d, 1i, 0x0011", 1, 1, 0xC1FFEF, 0x0083, 0x02E0 },
{ "8b, 1d, 1i, 0x0010", 1, 1, 0xC2FFF0, 0x01EB, 0x0AB0 },
{ "8b, 1d, 1i, 0x0011", 1, 1, 0xC2FFEF, 0x020B, 0x0B60 },
{ "10b, 1d, 1i, 0x0010", 1, 1, 0xC3FFF0, 0x07EB, 0x2C10 },
{ "10b, 1d, 1i, 0x0011", 1, 1, 0xC3FFEF, 0x086B, 0x2EE0 },
{ "0b, 2d, 1i, 0x0010", 2, 1, 0xC0FFF0, 0x0004, 0x0020 },
{ "0b, 2d, 1i, 0x0014", 2, 1, 0xC0FFEC, 0x0004, 0x0020 },
{ "0b, 2d, 1i, 0x0015", 2, 1, 0xC0FFEB, 0x0005, 0x0020 },
{ "6b, 2d, 1i, 0x0010", 2, 1, 0xC1FFF0, 0x0082, 0x02E0 },
{ "6b, 2d, 1i, 0x0011", 2, 1, 0xC1FFEF, 0x008A, 0x0300 },
{ "8b, 2d, 1i, 0x0010", 2, 1, 0xC2FFF0, 0x01EA, 0x0AB0 },
{ "8b, 2d, 1i, 0x0011", 2, 1, 0xC2FFEF, 0x020A, 0x0B60 },
{ "10b, 2d, 1i, 0x0010", 2, 1, 0xC3FFF0, 0x07EA, 0x2C10 },
{ "10b, 2d, 1i, 0x0011", 2, 1, 0xC3FFEF, 0x086A, 0x2EE0 },
{ "0b, 0d, 2i, 0x0001", 0, 2, 0xC0FFFF, 0x0002, 0x0010 },
{ "0b, 0d, 2i, 0x0003", 0, 2, 0xC0FFFC, 0x0002, 0x0010 },
{ "0b, 0d, 2i, 0x0005", 0, 2, 0xC0FFFB, 0x0003, 0x0010 },
{ "0b, 0d, 2i, 0x000C", 0, 2, 0xC0FFF4, 0x0003, 0x0020 },
{ "0b, 0d, 2i, 0x000D", 0, 2, 0xC0FFF3, 0x0004, 0x0020 },
{ "0b, 0d, 2i, 0x0010", 0, 2, 0xC0FFF0, 0x0004, 0x0020 },
{ "0b, 0d, 2i, 0x0014", 0, 2, 0xC0FFEC, 0x0004, 0x0020 },
{ "0b, 0d, 2i, 0x0015", 0, 2, 0xC0FFEB, 0x0005, 0x0020 },
{ "0b, 0d, 2i, 0x0020", 0, 2, 0xC0FFE0, 0x0006, 0x0020 },
{ "0b, 0d, 2i, 0x0024", 0, 2, 0xC0FFDC, 0x0006, 0x0030 },
{ "0b, 0d, 2i, 0x0025", 0, 2, 0xC0FFDB, 0x0007, 0x0030 },
{ "0b, 0d, 2i, 0x0080", 0, 2, 0xC0FF80, 0x0013, 0x0070 },
{ "0b, 0d, 2i, 0x0800", 0, 2, 0xC0F800, 0x01F3, 0x0AE0 },
{ "0b, 0d, 2i, 0x8000", 0, 2, 0xC08000, 0x1FF3, 0xB1D0 },
{ "6b, 0d, 2i, 0x0010", 0, 2, 0xC1FFF0, 0x00EC, 0x0520 },
{ "6b, 0d, 2i, 0x0011", 0, 2, 0xC1FFEF, 0x00FC, 0x0580 },
{ "8b, 0d, 2i, 0x0010", 0, 2, 0xC2FFF0, 0x03DC, 0x1580 },
{ "8b, 0d, 2i, 0x0011", 0, 2, 0xC2FFEF, 0x041C, 0x16E0 },
{ "10b, 0d, 2i, 0x0010", 0, 2, 0xC3FFF0, 0x0FDC, 0x5850 },
{ "10b, 0d, 2i, 0x0011", 0, 2, 0xC3FFEF, 0x10DC, 0x5DE0 },
{ "0b, 1d, 2i, 0x0010", 1, 2, 0xC0FFF0, 0x0004, 0x0020 },
{ "0b, 1d, 2i, 0x0014", 1, 2, 0xC0FFEC, 0x0004, 0x0020 },
{ "0b, 1d, 2i, 0x0015", 1, 2, 0xC0FFEB, 0x0005, 0x0020 },
{ "6b, 1d, 2i, 0x0010", 1, 2, 0xC1FFF0, 0x00EB, 0x0520 },
{ "6b, 1d, 2i, 0x0011", 1, 2, 0xC1FFEF, 0x00FB, 0x0580 },
{ "8b, 1d, 2i, 0x0010", 1, 2, 0xC2FFF0, 0x03DB, 0x1580 },
{ "8b, 1d, 2i, 0x0011", 1, 2, 0xC2FFEF, 0x041B, 0x16E0 },
{ "10b, 1d, 2i, 0x0010", 1, 2, 0xC3FFF0, 0x0FDB, 0x5840 },
{ "10b, 1d, 2i, 0x0011", 1, 2, 0xC3FFEF, 0x10DB, 0x5DD0 },
{ "0b, 2d, 2i, 0x0010", 2, 2, 0xC0FFF0, 0x0004, 0x0020 },
{ "0b, 2d, 2i, 0x0014", 2, 2, 0xC0FFEC, 0x0004, 0x0020 },
{ "0b, 2d, 2i, 0x0015", 2, 2, 0xC0FFEB, 0x0005, 0x0020 },
{ "6b, 2d, 2i, 0x0010", 2, 2, 0xC1FFF0, 0x00F3, 0x0550 },
{ "6b, 2d, 2i, 0x0011", 2, 2, 0xC1FFEF, 0x0103, 0x05A0 },
{ "8b, 2d, 2i, 0x0010", 2, 2, 0xC2FFF0, 0x03DB, 0x1580 },
{ "8b, 2d, 2i, 0x0011", 2, 2, 0xC2FFEF, 0x041B, 0x16E0 },
{ "10b, 2d, 2i, 0x0010", 2, 2, 0xC3FFF0, 0x0FDB, 0x5840 },
{ "10b, 2d, 2i, 0x0011", 2, 2, 0xC3FFEF, 0x10DB, 0x5DD0 },
};

static const u32 nTimerTests = sizeof(timerTests) / sizeof(*timerTests);

static unsigned passes;
static unsigned totalResults;

static u32 irqCounter;

IWRAM_CODE
static void testIrq(void) {
REG_TM0CNT_H = 0;
--irqCounter;
if (!irqCounter) {
REG_TM0CNT_H = 0;
}
}

IWRAM_CODE
Expand All @@ -93,11 +138,14 @@ static void runTest(struct TimerTest* test) {
".arm; 0:\n"
"ldr r4, =0x4000100 \n"
"ldr r5, =0x0C3FFFE \n"
"ldr r6, =irqCounter \n"

"str r5, [r4] \n"
"mov r0, #1 \n"
"str r0, [r6] \n"
"mov r1, #8 \n"
"swi 0x40000 \n"
"str %[irqs], [r6] \n"
"mov r0, #0 \n"
"1: \n"
"cmp r0, %[delay] \n"
Expand All @@ -114,8 +162,10 @@ static void runTest(struct TimerTest* test) {

"str r5, [r4] \n"
"mov r0, #1 \n"
"str r0, [r6] \n"
"mov r1, #8 \n"
"swi 0x40000 \n"
"str %[irqs], [r6] \n"
"mov r0, #0 \n"
"1: \n"
"cmp r0, %[delay] \n"
Expand Down Expand Up @@ -150,8 +200,8 @@ static void runTest(struct TimerTest* test) {
".ltorg \n"
".thumb; 2:"
: [tightLoop]"=m"(test->addTightLoop), [looseLoop]"=m"(test->addLooseLoop)
: [timer]"r"(test->timer), [delay]"r"(test->delay)
: "r0", "r1", "r2", "r3", "r4", "r5");
: [timer]"r"(test->timer), [delay]"r"(test->delay), [irqs]"r"(test->irqs)
: "r0", "r1", "r2", "r3", "r4", "r5", "r6");

irqDisable(IRQ_TIMER0);
irqEnable(IRQ_VBLANK);
Expand Down

0 comments on commit 632bb12

Please sign in to comment.