OpenCores
URL https://opencores.org/ocsvn/mips_enhanced/mips_enhanced/trunk

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [software/] [leon3/] [gptimer.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
#include "testmod.h"
2
#include "irqmp.h"
3
 
4
struct timerreg {
5
    volatile unsigned int counter;              /* 0x0 */
6
    volatile unsigned int reload;               /* 0x4 */
7
    volatile unsigned int control;              /* 0x8 */
8
    volatile unsigned int dummy;                /* 0xC */
9
};
10
 
11
struct gptimer {
12
    volatile unsigned int scalercnt;            /* 0x00 */
13
    volatile unsigned int scalerload;           /* 0x04 */
14
    volatile unsigned int configreg;            /* 0x08 */
15
    volatile unsigned int dummy1;               /* 0x0C */
16
    struct timerreg timer[7];
17
};
18
 
19
#define IRQPEND 0x10
20
#define CHAIN_TEST 8
21
 
22
static volatile gpirq = 0;
23
 
24
static gptimer_irqhandler(int irq)
25
{
26
    gpirq += 1;
27
}
28
 
29
gptimer_test(int addr, int irq)
30
{
31
        struct gptimer *lr = (struct gptimer *) addr;
32
        extern volatile int irqtbl[];
33
        int i, j, pil, ntimers;
34
 
35
        report_device(0x01011000);
36
        ntimers = lr->configreg & 0x7;
37
        lr->scalerload = -1;
38
        if (lr->scalercnt == lr->scalercnt) fail(1);
39
 
40
/* timer 1 test */
41
 
42
        lr->scalerload = 31;
43
        lr->scalercnt = 31;
44
        for (i=0; i<ntimers; i++) lr->timer[i].control = 0; // halt all timers
45
 
46
        /* test basic functions */
47
        for (i=0; i<ntimers; i++) {
48
            report_subtest(i);
49
            lr->timer[i].counter = 0;
50
            lr->timer[i].reload = 15;
51
            lr->timer[i].control = 0x6;
52
            if (lr->timer[i].counter != 15) fail(3); // check loading
53
            lr->timer[i].control = 0xf;
54
            for (j=14; j >= 0; j--) { while (lr->timer[i].counter != j) {}}
55
            while (lr->timer[i].counter != 15) {}
56
 
57
            if (!(lr->timer[i].control & IRQPEND)) fail(4);
58
            lr->timer[i].control = 0;
59
            if (lr->timer[i].control & IRQPEND) fail(5);
60
        }
61
 
62
        if (ntimers > 1) {              /* simple check of chain function */
63
            report_subtest(CHAIN_TEST);
64
            lr->timer[0].control = 0xf;
65
            lr->timer[1].control = 0x2f;
66
            while (lr->timer[1].counter != 13) {}
67
        }
68
 
69
        for (i=0; i<ntimers; i++) lr->timer[i].control = 0; // halt all timers
70
 
71
        if (irqmp_base) {
72
            catch_interrupt(gptimer_irqhandler, irq);
73
            init_irqmp(irqmp_base);
74
            irqmp_base->irqmask = 1 << irq;       /* unmask interrupt */
75
            lr->timer[0].reload = 15;
76
            lr->timer[0].control = 0xd;
77
            asm("wr %g0, %g0, %asr19");         /* power-down */
78
        }
79
}
80
 
81
 
82
/*
83
gptimer_test_pp(int addr, int irq)
84
{
85
    struct ambadev dev;
86
 
87
    if (find_ahb_slvi(&dev) == 0)
88
        gptimer_test(dev.start[0], dev.irq);
89
}
90
*/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.