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/] [grcan.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
 
2
grcan_test(int paddr)
3
   {
4
 
5
   // start of test
6
   report_device(0x0103D000);
7
 
8
   // can register structures
9
   struct grcan_ctrl {
10
      volatile unsigned long conf;           /* 0x000 */
11
      volatile unsigned long stat;           /* 0x004 */
12
      volatile unsigned long ctrl;           /* 0x008 */
13
      volatile unsigned long dummy0c;        /* 0x00C */
14
      volatile unsigned long dummy10;        /* 0x010 */
15
      volatile unsigned long dummy14;        /* 0x014 */
16
      volatile unsigned long smask;          /* 0x018 */
17
      volatile unsigned long scode;          /* 0x01C */
18
   };
19
 
20
   struct grcan_irq {
21
      volatile unsigned long pimsr;          /* 0x100 */
22
      volatile unsigned long pimr;           /* 0x104 */
23
      volatile unsigned long pisr;           /* 0x108 */
24
      volatile unsigned long pir;            /* 0x10C */
25
      volatile unsigned long imr;            /* 0x110 */
26
      volatile unsigned long picr;           /* 0x114 */
27
   };
28
 
29
   struct grcan_tx {
30
      volatile unsigned long ctrl;           /* 0x200 */
31
      volatile unsigned long addr;           /* 0x204 */
32
      volatile unsigned long size;           /* 0x208 */
33
      volatile unsigned long wr;             /* 0x20C */
34
      volatile unsigned long rd;             /* 0x210 */
35
      volatile unsigned long irq;            /* 0x214 */
36
   };
37
 
38
//   struct grcan_rx {
39
//      volatile unsigned long ctrl;           /* 0x300 */
40
//      volatile unsigned long addr;           /* 0x304 */
41
//      volatile unsigned long size;           /* 0x308 */
42
//      volatile unsigned long wr;             /* 0x30C */
43
//      volatile unsigned long rd;             /* 0x310 */
44
//      volatile unsigned long irq;            /* 0x314 */
45
//      volatile unsigned long mask;           /* 0x318 */
46
//      volatile unsigned long code;           /* 0x31C */
47
//   };
48
 
49
   // local registers
50
   struct grcan_ctrl *lctrl = (struct grcan_ctrl *) (paddr);
51
   struct grcan_irq  *lirq =  (struct grcan_irq *)  (paddr+0x100);
52
   struct grcan_tx   *ltx0 =  (struct grcan_tx *)   (paddr+0x200);
53
//   struct grcan_rx   *lrx0 =  (struct grcan_rx *)   (paddr+0x300);
54
 
55
   // transmit and receive memory, allocate 2k memory
56
   volatile long int memory[512];
57
 
58
   // search for start of allocated memory
59
   long int memorytxbase;
60
   memorytxbase = (long int)&memory[0];
61
   // search for 1k boundary within allocated memory, store as base
62
   memorytxbase = memorytxbase & 0xFFFFFC00;
63
   memorytxbase = memorytxbase + 0x400;
64
 
65
   // baud rate configuration
66
   int SCALER = 0;
67
   int PS1 = 2;
68
   int PS2 = 2;
69
   int RSJ = 1;
70
   int BPR = 0;
71
   int SELECTION = 0;
72
   int ENABLE = 0x1;
73
 
74
   // setup transmit memory
75
//   report_subtest(0x1);
76
 
77
   // set temporary pointer to base memory start
78
   volatile int *memorytx;
79
   memorytx = (int*)memorytxbase;
80
   *memorytx = 0x913579BD;
81
   memorytx++;
82
   *memorytx = 0x80000000;
83
   memorytx++;
84
   *memorytx = 0x01020304;
85
   memorytx++;
86
   *memorytx = 0x05060708;
87
   memorytx++;
88
 
89
   // reset controller, setup baud rate, clear int erupts, enable codec
90
//   report_subtest(0x2);
91
 
92
   lctrl->ctrl = 0x00000002;
93
   lctrl->conf = (SCALER<<24) | (PS1<<20) | (PS2<<16) | (RSJ<<12) | (BPR<<8) | (SELECTION<<3) | (ENABLE<<1);
94
   lirq->picr  = 0xFFFFFFFF;
95
//   lirq->imr   = 0x00000540;
96
   lctrl->ctrl = 0x00000001;
97
 
98
   // transmit messages test
99
//   report_subtest(0x3);
100
 
101
   ltx0->addr   = memorytxbase;
102
   ltx0->size   = 0x00000080;
103
//   ltx0->wr     = 0x00000000;
104
//   ltx0->rd     = 0x00000000;
105
   ltx0->irq    = 0x00000010; // number of packets
106
   ltx0->ctrl   = 0x00000001;
107
 
108
   // send message
109
   ltx0->wr     = 0x00000010; // number of packets
110
 
111
   // wait for four messages being sent
112
   while ((ltx0->rd & 0xFFFF) != 0x0010) ;
113
 
114
   // check status
115
//   report_subtest(0x4);
116
   if (lctrl->stat != 0x00000000) fail(1);
117
   if (lirq->pir != 0x00000540) fail(2);
118
 
119
   // clear interrupt
120
   lirq->picr  = 0xFFFFFFFF;
121
 
122
   // reset controller, setup baud rate, clear int erupts, enable codec
123
   SELECTION = 1;
124
   ENABLE = 2;
125
 
126
   lctrl->ctrl = 0x00000002;
127
   lctrl->conf = (SCALER<<24) | (PS1<<20) | (PS2<<16) | (RSJ<<12) | (BPR<<8) | (SELECTION<<3) | (ENABLE<<1);
128
   lirq->picr  = 0xFFFFFFFF;
129
//   lirq->imr   = 0x00000540;
130
   lctrl->ctrl = 0x00000001;
131
 
132
   // transmit messages test
133
//   report_subtest(0x5);
134
 
135
   ltx0->addr   = memorytxbase;
136
   ltx0->size   = 0x00000080;
137
//   ltx0->wr     = 0x00000000;
138
//   ltx0->rd     = 0x00000000;
139
   ltx0->irq    = 0x00000010; // number of packets
140
   ltx0->ctrl   = 0x00000001;
141
 
142
   // send message
143
   ltx0->wr     = 0x00000010; // number of packets
144
 
145
   // wait for four messages being sent
146
   while ((ltx0->rd & 0xFFFF) != 0x0010) ;
147
 
148
   // check status
149
//   report_subtest(0x6);
150
   if (lctrl->stat != 0x00000000) fail(3);
151
   if (lirq->pir != 0x00000540) fail(4);
152
 
153
   // clear interrupt
154
   lirq->picr  = 0xFFFFFFFF;
155
 
156
   // reset core
157
   lctrl->ctrl = 0x00000002;
158
}

powered by: WebSVN 2.1.0

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