si_controller.c
13.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
/**************************************************************************
*
* Joy Controller read test
*
* $Revision: 1.2 $
*
*/
#include <sys/types.h>
#ifdef __sgi__
#include <sys/sbd.h>
#endif
#include <sys/stat.h>
#include <sys/mman.h>
#ifdef __sgi__
#include <sys/sema.h>
#endif
#include <netinet/in.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <getopt.h>
#include <sys/u64driver.h>
#include <rcp.h>
/*
* From $ROOT/usr/include/ide, which is installed from $ROOT/PR/diags/include
*/
#include "diag.h"
#include "dbg_comm.h"
/**************************************************************************
*
* Main definitions
*
*/
#define DIR_READ 0 /* Rdram <- device */
#define DIR_WRITE 1 /* Rdram -> device */
#define SI_TEST_BASE 1
/**************************************************************************
*
* Function prototypes
*
*/
static int testInit();
static int testDo(TEST_REF *test_ref);
static int siReadJoyButton(TEST_REF *test_ref);
static int siPollStatus(unsigned int, int);
extern int siDmaCopy(int, unsigned int, unsigned int);
int siCompare(unsigned int, unsigned int, int);
/**************************************************************************
*
* Private global variables
*
*/
/*
* Create an array of tests, each of which corresponds to a separate menu
* item callable from the master ide menu.
*/
static TEST_REF testRefs[] = {
{"Joy Button Read Test", SI_TEST_BASE+0, siReadJoyButton},
{"END OF TESTS",0,0}
};
static int Initialize = 1;
static int NumFailures = 0;
static int Failed = 0;
/**************************************************************************
*
* Functions
*
*/
/*
* diagnostic entry point:
*
* Each separately invokable ide diagnostic command corresponds to an
* independent ".c" module; the entry point herein must match
* the test name as specified in the rdpcmd.awk script. These command
* names correspond to the names you see from the ide menu. For this
* module, there will be an ide command "si" (until this
* silly module is retired, that is).
*/
int siController()
{
int c;
int testNum;
Initialize = 1;
Failed = 0;
NumFailures = 0;
/*
* Sample of how to parse command line args received from ide
*/
while ((c = getopt(pGlobalComm->argc, pGlobalComm->argv, "ht:I")) != EOF) {
switch(c) {
case 'h':
/*
* Print out the available subtests, then return without
* invoking any subtests (which is done by calling diaginit()).
*/
dgListSubTests(testRefs);
return(0);
break;
case 't':
testNum = atoi(optarg);
pGlobalComm->entryNum = -(testNum);
break;
case 'I':
Initialize = 0;
break;
default:
printf("weird option character %c = 0x%x\n", c, c);
break;
}
}
/*
* IDE will call our one-time initialization function testInit(),
* then invoke testDo() for as many tests as we've put into the
* global test array "testRefs", declared at the top of this module.
*/
diaginit(testRefs, testInit, testDo);
if (Failed) {
errlog(INFO, "... test %s FAILED", ideTestName);
} else {
errlog(INFO, "... test %s PASSED", ideTestName);
}
} /* siTestEntry */
/**************************************************************************
* Test init fuction
*/
static int testInit()
{
errlog(INFO, "Starting test %s ... ", ideTestName);
return(0);
} /* testInit */
/**************************************************************************
* Test caller
*/
static int testDo(TEST_REF *test_ref)
{
int rc;
int errorCount;
errlog(INFO, "--- starting subtest %s (%d)", test_ref->name, test_ref->num);
/*
* Reset the target system, if necessary
* Setup the diagnostic communication link to the target system.
*/
if (Initialize) {
errlog(DEBUG, "--- initializing target");
dgInitComm();
}
/*
* Invoke the actual test from the "TEST_REF" array statically declared
* as a global within this test module.
*/
if (errorCount = test_ref->fnc(test_ref)) {
NumFailures += errorCount;
Failed = 1;
errlog(INFO, "--- subtest %s FAILED, %d failures",
test_ref->name, errorCount);
} else {
errlog(INFO, "--- subtest %s PASSED", test_ref->name);
}
return(0);
} /* testDo */
/**************************************************************************
*
* The following functions are derived from IOSIM environment
*
**************************************************************************/
/**************************************************************************
* Poll SI status register for bit pattern to either be set or cleared
*/
static int
siPollStatus(unsigned int bits, int cleared)
{
/* Poll SI status register for the statBits set */
unsigned int stat;
while (1) {
if (dgReadWord(SI_STATUS_REG, &stat)) return (1);
errlog (DEBUG,"SI Status Read is %08x",stat);
if (cleared) {
if (!(stat & bits)) break;
}
else {
if (stat & bits) break;
}
}
return((int)stat);
} /* siPollStatus */
/**************************************************************************
* Start SI DMA transaction between RDRAM and ROM
*/
int
XXsiDmaCopy(int dir, unsigned int siAddr, unsigned int dramAddr)
{
int ret;
unsigned int stat;
unsigned int buf;
ret = 0;
/* wait for dma not busy */
siPollStatus(SI_STATUS_DMA_BUSY | SI_STATUS_RD_BUSY, 1);
if (dgWriteWord(SI_DRAM_ADDR_REG, dramAddr)) return (1);
/* verify the address write */
if (dgReadWord (SI_DRAM_ADDR_REG, &buf) ) return (1);
if ( buf != dramAddr) {
errlog (ERR_SEVERE,
"SI Dram Addr Reg not written correctly actual = %08x, expected = %08x",
buf, dramAddr);
}
switch (dir) {
case DIR_READ: { /* PIF_RAM -> RDRAM */
if (dgWriteWord(SI_PIF_ADDR_RD64B_REG, siAddr)) return(1);
break;
}
case DIR_WRITE: { /* PIF_RAM <- RDRAM */
if (dgWriteWord(SI_PIF_ADDR_WR64B_REG, siAddr)) return (1);
break;
}
default: {
ret = 1;
}
} /* switch */
return(ret);
} /* siDmaCopy */
#define _PIF3
#ifndef _PIF3
/* Data table */
static unsigned int channelDataTable[] = {
0xff010401,
0xffffffff,
0xff010401,
0xffffffff,
0xff010401,
0xffffffff,
0xff010401,
0xffffffff,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000
};
#else
/* pif3 Data table */
static unsigned int channelDataTable[] = {
0xff010401,
0xffffffff,
0xff010401,
0xffffffff,
0xff010401,
0xffffffff,
0xff010401,
0xffffffff,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000001
};
#endif
static unsigned int channelDataTableSize= sizeof(channelDataTable)/sizeof(unsigned int);
/* Sample the controller button depressions and print the changes */
int
siReadJoyButton(TEST_REF *test_ref)
{
int errorCount = 0;
int i;
int PifRdPointer;
unsigned char rdbuf[64];
unsigned char oldrdbuf[64];
unsigned int * prdbuf;
unsigned int * poldrdbuf;
unsigned int buf;
int newData;
int joyRead;
int newDataWord;
int newDataPtr;
int oldDataWord;
int joyPort;
int firstTime;
prdbuf = (unsigned int *) rdbuf;
poldrdbuf = (unsigned int *) oldrdbuf;
#ifndef _PIF3
printf ("Configured for PIF01A\n");
/* Reset the channels with reset channel write dma */
siPollStatus(SI_STATUS_DMA_BUSY | SI_STATUS_RD_BUSY, 1);
/* write pif reset all channels bit */
dgWriteWord(0x1fc007fc, 0x10);
/* wait for write to complete */
siPollStatus(SI_STATUS_RD_BUSY, 1);
/* perform pif macro now to reset the channels */
PifRdPointer = dgRdramFree + 0x00 ;
/* kick off the dma pif to rdram */
siDmaCopy(DIR_READ, PIF_RAM_START, PifRdPointer);
/* wait for dma to finish */
siPollStatus(SI_STATUS_DMA_BUSY, 1);
#endif
/* Channel Descriptor */
/* Stuff the channel descriptor data table in rdram */
if (dgWriteMem(dgRdramFree, 64, ((char *)channelDataTable))) return (1);
/* verify rdram was loaded correctly */
if (dgReadMem (dgRdramFree, 64, rdbuf)) return (1);
prdbuf = (unsigned int *) rdbuf;
for (i = 0; i < 16 ; i++) {
errlog(DEBUG,"Channel Descriptor Data for DMA @Rdram(%x) Data = %08x",
(dgRdramFree +(i*4)), *(prdbuf+i) );
if ((*(prdbuf+i) != channelDataTable[i])) {
errorCount ++;
errlog(ERR_SEVERE,
" Failed Rdram Memory Load index %x actual = %08x, expected = %08x",
i,*(prdbuf+i), channelDataTable[i] );
}
}
/* dma to pif ram to describe the controller channels */
siDmaCopy(DIR_WRITE, PIF_RAM_START, dgRdramFree);
/* end of Channel Description load */
printf("Controller Interface Test\n\n");
printf(" In Series Activate Each Controller Button and Watch Respsonse\n");
printf(" Simultaneously Depress L and R Buttons to Quit\n");
/* Read the controller buttons */
firstTime = 1;
while (1){
/* trash rdram to insure the pif transfer to rdram overwrites it */
for (i = 0; i < 16; i++) {
dgWriteWord((dgRdramFree +(i*4)), 0xdeaddead);
}
/* DMA from PIF to RDRAM to get the controller data */
PifRdPointer = dgRdramFree + 0x00 ;
siDmaCopy(DIR_READ, PIF_RAM_START, PifRdPointer);
/* wait for dma to finish */
siPollStatus(SI_STATUS_DMA_BUSY, 1);
/* read and dump the pif read buffer from Rdram */
if (dgReadMem (PifRdPointer, 64, rdbuf) ) return (1);
/* copy new buf to old buf if firstTime through */
if (firstTime) {
firstTime = 0;
for (i = 0; i < 16; i++)
*(poldrdbuf+i) = *(prdbuf+i) ;
}
newData = 0;
for (i = 0; i < 15 ; i++) {
if ( *(prdbuf+i) != *(poldrdbuf+i) ) {
newData = 1;
oldDataWord = *(poldrdbuf+i);
newDataWord = *(prdbuf+i);
newDataPtr = i;
*(poldrdbuf+i) = *(prdbuf+i) ;
}
}
if (newData){
/* check for break condition of L and R */
if ((newDataWord & 0x00300000) == 0x00300000 ){
printf("Detected Simultaneous L and R, Quitting\n");
break;
}
if (newDataPtr == 1) joyPort = 1;
if (newDataPtr == 3) joyPort = 2;
if (newDataPtr == 5) joyPort = 3;
if (newDataPtr == 7) joyPort = 4;
if (newDataPtr == 9) joyPort = 5;
if (newDataWord & 0x80000000)
printf("Controller Port %d, Button A\n",joyPort);
if (newDataWord & 0x40000000)
printf("Controller Port %d, Button B\n",joyPort);
if (newDataWord & 0x20000000)
printf("Controller Port %d, Fire Button G\n",joyPort);
if (newDataWord & 0x10000000)
printf("Controller Port %d, Button START\n",joyPort);
if (newDataWord & 0x08000000)
printf("Controller Port %d, Pad Up\n",joyPort);
if (newDataWord & 0x04000000)
printf("Controller Port %d, Pad Down\n",joyPort);
if (newDataWord & 0x02000000)
printf("Controller Port %d, Pad Left\n",joyPort);
if (newDataWord & 0x01000000)
printf("Controller Port %d, Pad Right\n",joyPort);
if (newDataWord & 0x00200000)
printf("Controller Port %d, Button L\n",joyPort);
if (newDataWord & 0x00100000)
printf("Controller Port %d, Button R\n",joyPort);
if (newDataWord & 0x00080000)
printf("Controller Port %d, Button UP/E\n",joyPort);
if (newDataWord & 0x00040000)
printf("Controller Port %d, Button Down/D\n",joyPort);
if (newDataWord & 0x00020000)
printf("Controller Port %d, Button Left/C\n",joyPort);
if (newDataWord & 0x00010000)
printf("Controller Port %d, Button Right/F\n",joyPort);
if ((newDataWord & 0x0000ff00) != (oldDataWord & 0x0000ff00))
{
joyRead = ((newDataWord & 0x0000ff00) >> 8);
if (joyRead & 0x80) joyRead = joyRead | 0xffffff00 ;
printf("Controller Port %d, JoyStick X = %d \n"
,joyPort, (int) joyRead);
}
if ((newDataWord & 0x000000ff) != (oldDataWord & 0x000000ff))
{
joyRead = (newDataWord & 0x000000ff);
if (joyRead & 0x80) joyRead = joyRead | 0xffffff00 ;
printf("Controller Port %d, JoyStick Y = %d \n"
,joyPort, (int) joyRead);
}
}
} /* while */
return(0);
} /* siReadJoyButton */