bb_test.c
43.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
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
#include <ultra64.h>
#include "gng.h"
#include "os_bbcard.h"
#include <PR/os_bb.h>
#include <PR/bcp.h>
#include <PR/bbnand.h>
#include <PR/bbskapi.h>
#include "testDriver.h"
#include "version.h"
#define JCTRL1_ERR 0x1
#define JCTRL2_ERR 0x10
#define JCTRL3_ERR 0x100
#define ERR_OFF IO_WRITE(PI_GPIO_REG, \
((PI_GPIO_ERROR_BIT | PI_GPIO_POWER_BIT) << PI_GPIO_ENABLE_SHIFT) | \
(PI_GPIO_ERROR_BIT | PI_GPIO_POWER_BIT))
#define ERR_ON IO_WRITE(PI_GPIO_REG, \
((PI_GPIO_ERROR_BIT | PI_GPIO_POWER_BIT) << PI_GPIO_ENABLE_SHIFT) | \
PI_GPIO_POWER_BIT)
int my_strcat(char *dst, const char *append);
int polling_button_down(int which, int key_mask);
void breakout_box_test();
#define NDIR 100
#define ONE_SEC 46882325
static OSBbDirEnt dir[NDIR];
static u8 blocks[BB_FL_BLOCK_SIZE];
static OSBbFs fs;
static OSBbStatFs fsb;
static int no_pause = 0;
int my_poweroff()
{
osBbPowerOff();
/* Busy loop to let CPU spin */
for (; ;);
}
/* write timestamp at offset 16352 */
#define TIME_STAMP_OFF 16352
void write_log_file()
{
int fd;
u8 *p = blocks + TIME_STAMP_OFF;
osBbCardInit();
osBbFDelete("errlog.gng");
osBbRtcGet(p, p+1, p+2, p+3, p+4, p+5, p+6);
fd = osBbFCreate("errlog.gng", 1, BB_FL_BLOCK_SIZE);
if (fd >= 0) {
osBbFWrite(fd, 0, blocks, sizeof(blocks));
osBbFClose(fd);
}
return;
}
void do_rtc_check(u8 *pold)
{
u8 pnew[8];
int i;
char msg[256], stmp[128];
osBbRtcGet(pnew, pnew+1, pnew+2, pnew+3, pnew+4, pnew+5, pnew+6);
for (i=0; i<7; i++) {
if (i==3) continue;
if (pnew[i] > pold[i])
break;
if (pnew[i] < pold[i]) {
sprintf(msg, " RTC check error\n\n");
sprintf(stmp, " Log file timestamp: \n");
my_strcat(msg, stmp);
sprintf(stmp, " %02d/%02d/%02d %d:%d:%d \n\n",
pold[1], pold[2], pold[0], pold[4], pold[5], pold[6]);
my_strcat(msg, stmp);
sprintf(stmp, " Current time is: \n");
my_strcat(msg, stmp);
sprintf(stmp, " %02d/%02d/%02d %d:%d:%d \n\n",
pnew[1], pnew[2], pnew[0], pnew[4], pnew[5], pnew[6]);
my_strcat(msg, stmp);
my_strcat(msg, "Press C button to continue");
gng_report(msg , 1, GNG_INHIBIT_PRINT, 1);
polling_button_down(-1, CONT_C | CONT_D | CONT_E | CONT_F);
return;
}
}
return;
}
#define PAUSE_BUT CONT_B
#define CONTINUE_BUT CONT_A
int pause_start(int which)
{
int but;
if (IO_READ(MI_EINTR_REG) & MI_EINTR_BUT_STATUS)
my_poweroff();
if (no_pause) return 0;
but = get_button_status(which);
if ((but & PAUSE_BUT) == PAUSE_BUT) {
for (;;) {
but = get_button_status(which);
if (IO_READ(MI_EINTR_REG) & MI_EINTR_BUT_STATUS)
my_poweroff();
if ((but & CONTINUE_BUT) == CONTINUE_BUT)
break;
}
}
return 0;
}
int __osDisableInt();
int polling_poweroff()
{
__osDisableInt();
for (; ;) {
if (IO_READ(MI_EINTR_REG) & MI_EINTR_BUT_STATUS)
my_poweroff();
}
}
int get_button_status(int which)
{
OSContStatus sdata[MAXCONTROLLERS];
OSContPad ctrl_data[MAXCONTROLLERS];
char pattern;
int key, i;
osSetEventMesg(OS_EVENT_SI, &siMessageQ, (OSMesg)NULL);
osContInit(&siMessageQ, &pattern, &sdata[0]);
osContStartReadData(&siMessageQ);
osRecvMesg(&siMessageQ, NULL, OS_MESG_BLOCK);
osContGetReadData(ctrl_data);
for (i=key=0; i<MAXCONTROLLERS; i++) {
if ( (!(ctrl_data[i].errno &CONT_NO_RESPONSE_ERROR)) &&
((which < 0) || (which == i)))
key |= ctrl_data[i].button;
}
return key;
}
int polling_button_down(int which, int key_mask)
{
OSContStatus sdata[MAXCONTROLLERS];
OSContPad ctrl_data[MAXCONTROLLERS];
char pattern;
int key, i;
osSetEventMesg(OS_EVENT_SI, &siMessageQ, (OSMesg)NULL);
osContInit(&siMessageQ, &pattern, &sdata[0]);
for (; ;) {
if (IO_READ(MI_EINTR_REG) & MI_EINTR_BUT_STATUS)
my_poweroff();
osContStartReadData(&siMessageQ);
osRecvMesg(&siMessageQ, NULL, OS_MESG_BLOCK);
osContGetReadData(ctrl_data);
for (i=key=0; i<MAXCONTROLLERS; i++) {
if ( (!(ctrl_data[i].errno & CONT_NO_RESPONSE_ERROR)) &&
((which < 0) || (which == i)))
key |= ctrl_data[i].button;
}
if (key & key_mask) break;
}
return key;
}
FONT_RENDER font_render;
char font_msg[128*5];
#define DONE_INTERVAL 8438818565 /* 3 minutes */
int bb_jctrl_test()
{
FONT_RENDER *jctrl=&font_render;
int i, done[3], buf_change=1;
OSTime end, pause;
OSContStatus sdata[MAXCONTROLLERS];
OSContPad ctrl_data[MAXCONTROLLERS];
u16 but, old_but[MAXCONTROLLERS], key;
s8 stickX, old_stickX[MAXCONTROLLERS],
stickY, old_stickY[MAXCONTROLLERS];
char *msg, sxy[64];
char pattern;
jctrl->num = 5;
jctrl->xpos[0] = 70; jctrl->ypos[0] = 50;
jctrl->xpos[1] = 40; jctrl->ypos[1] = 80;
jctrl->xpos[2] = 40; jctrl->ypos[2] = 110;
jctrl->xpos[3] = 40; jctrl->ypos[3] = 140;
jctrl->xpos[4] = 30; jctrl->ypos[4] = 190;
for (i=0; i<jctrl->num; i++) {
jctrl->r[i] = jctrl->b[i] = jctrl->g[i] = jctrl->a[i] = 255;
jctrl->width[i] = 32;
jctrl->height[i] = 2;
jctrl->text[i] = font_msg + 128*i;
}
sprintf(jctrl->text[0], "BB joy controller test");
sprintf(jctrl->text[1], "J1 : ");
sprintf(jctrl->text[2], "J2 : ");
sprintf(jctrl->text[3], "J3 : ");
sprintf(jctrl->text[4], " Please pressed A on all \n controllers within 3 minutes");
my_gngreport(jctrl);
for (i=0; i<3; i++) done[i] = 0;
end = osGetTime() + DONE_INTERVAL;
osSetEventMesg(OS_EVENT_SI, &siMessageQ, (OSMesg)NULL);
osContInit(&siMessageQ, &pattern, &sdata[0]);
while (osGetTime() < end) {
osContStartReadData(&siMessageQ);
osRecvMesg(&siMessageQ, NULL, OS_MESG_BLOCK);
osContGetReadData(ctrl_data);
for (i=1, buf_change=0; i<MAXCONTROLLERS; i++) {
but = ctrl_data[i].button;
stickX = ctrl_data[i].stick_x & 0xff;
stickY = ctrl_data[i].stick_y & 0xff;
buf_change |= (but != old_but[i]) || (old_stickY[i] != stickY)
|| (old_stickX[i] != stickX);
}
for (i=1; i<MAXCONTROLLERS; i++) {
but = ctrl_data[i].button;
stickX = ctrl_data[i].stick_x & 0xff;
stickY = ctrl_data[i].stick_y & 0xff;
msg = jctrl->text[i];
sprintf(msg, "J%d :", i);
if ( !(ctrl_data[i].errno & CONT_NO_RESPONSE_ERROR )) {
if (but & CONT_START) my_strcat(msg, " Start");
if (but & CONT_A) {
my_strcat(msg, " A");
done[i-1] = 1;
jctrl->r[i] = jctrl->b[i] = jctrl->g[i] = 64;
}
if (but & CONT_B) my_strcat(msg, " B");
if (but & CONT_G) my_strcat(msg, " G");
if (but & CONT_L) my_strcat(msg, " L");
if (but & CONT_R) my_strcat(msg, " R");
if (but & CONT_E) my_strcat(msg, " E");
if (but & CONT_C) my_strcat(msg, " C");
if (but & CONT_F) my_strcat(msg, " F");
if (but & CONT_D) my_strcat(msg, " D");
if (but & CONT_UP) my_strcat(msg, " Up");
if (but & CONT_DOWN) my_strcat(msg, " Down");
if (but & CONT_LEFT) my_strcat(msg, " Left");
if (but & CONT_RIGHT) my_strcat(msg, " Right");
if (but) my_strcat(msg, " pressed");
sprintf(sxy, "\n x=%d, y=%d\n", stickX, stickY);
my_strcat(msg, sxy);
}
old_but[i] = but;
old_stickX[i] = stickX;
old_stickY[i] = stickY;
}
if (buf_change) my_gngreport(jctrl);
if ((done[0] + done[1] + done[2]) == 3) return 0;
key = CONT_B | CONT_A | CONT_START;
if ((ctrl_data[0].button & key) == key) return 0;
key = CONT_B | CONT_A | CONT_G;
if ((ctrl_data[0].button & key) == key)
return (done[0]?0:JCTRL1_ERR) | (done[1]?0:JCTRL2_ERR) |
(done[2]?0:JCTRL3_ERR);
if ((ctrl_data[0].button & PAUSE_BUT) == PAUSE_BUT) {
pause = end - osGetTime();
polling_button_down(0, CONTINUE_BUT);
end = osGetTime() + pause;
}
if (IO_READ(MI_EINTR_REG) & MI_EINTR_BUT_STATUS)
my_poweroff();
}
return (done[0]?0:JCTRL1_ERR) | (done[1]?0:JCTRL2_ERR) |
(done[2]?0:JCTRL3_ERR);
}
int bb_sp_test()
{
rsp();
return 0;
}
int bb_dp_test()
{
dlDriver();
return 0;
}
void my_SasanoFunc();
void my_colorbar();
int bb_vi_test()
{
my_SasanoFunc();
my_colorbar();
gng_report("Video test passed" , 1, GNG_INHIBIT_PRINT, 1);
return 0;
}
int my_aitest();
int bb_ai_test()
{
#if DVT_1
gng_report("\n Output Sin wave \n 1000 Hz \n\n\n Left channel only" , 1, GNG_INHIBIT_PRINT, 1);
audioTest(ZARU_ONLYL,SNDLENGTHDEFAULT, 1000);
gng_report("\n Output Sin wave \n 1000 Hz \n\n\n Right channel only" , 1, GNG_INHIBIT_PRINT, 1);
audioTest(ZARU_ONLYR,SNDLENGTHDEFAULT, 1000);
gng_report("\n Output Sin wave \n 1000 Hz \n\n\n Both channel (stereo)" , 1, GNG_INHIBIT_PRINT, 1);
audioTest(ZARU_SINWAVE, SNDLENGTHDEFAULT, 1000);
gng_report("\n Output Sin wave \n 5000 Hz \n\n\n Left channel only" , 1, GNG_INHIBIT_PRINT, 1);
audioTest(ZARU_ONLYL,SNDLENGTHDEFAULT, 5000);
gng_report("\n Output Sin wave \n 5000 Hz \n\n\n Right channel only" , 1, GNG_INHIBIT_PRINT, 1);
audioTest(ZARU_ONLYR,SNDLENGTHDEFAULT, 5000);
gng_report("\n Output Sin wave \n 5000 Hz \n\n\n Both channel (stereo)" , 1, GNG_INHIBIT_PRINT, 1);
audioTest(ZARU_SINWAVE, SNDLENGTHDEFAULT, 5000);
#else
gng_report("\n Audio output \n\n\n Left channel only" , 1, GNG_INHIBIT_PRINT, 1);
my_aitest(ZARU_ONLYL);
gng_report("\n Audio output \n\n\n Right channel only" , 1, GNG_INHIBIT_PRINT, 1);
my_aitest(ZARU_ONLYR);
gng_report("\n Audio output \n\n\n Both channel (stereo)" , 1, GNG_INHIBIT_PRINT, 1);
my_aitest(ZARU_SINWAVE);
#endif
return 0;
}
int bb_flash_err()
{
int rv, ret=1, count, i;
char msg[256];
msg[0] = '\0';
osBbCardInit();
if ((rv = osBbFInit(&fs)) < 0) {
sprintf(msg, "osBbFInit\n Failed %d", rv);
goto out;
}
if ((rv = osBbFStatFs(&fsb)) < 0) {
sprintf(msg, "osBbFStatFs\n Failed %d", rv);
goto out;
}
if (fsb.files < 1 /* At lease should have 00000000.app */
|| fsb.freeFiles != BB_INODE16_ENTRIES-fsb.files) {
sprintf(msg, "osBbFFStatFS files failed");
goto out;
}
if ((count = osBbFReadDir(dir, NDIR)) < 0) {
sprintf(msg, "osBbFReadDir\n failed %d", count);
goto out;
}
if ((i = osBbFCreate("junk.gng", 1, BB_FL_BLOCK_SIZE)) == BBFS_ERR_EXISTS) {
if ((rv = osBbFDelete("junk.gng")) < 0) {
sprintf(msg, "Cannot delete existing GNG test %d", rv);
goto out;
}
i = osBbFCreate("junk.gng", 1, BB_FL_BLOCK_SIZE);
}
if (i<0) {
sprintf(msg, "osBbFCreate\n junk.gng failed %d", i);
goto out;
}
for (count =0; count < sizeof(blocks); count++)
blocks[count] = (u8) (count & 0xff);
if ((rv = osBbFWrite(i, 0, blocks, sizeof blocks)) < 0) {
sprintf(msg, "osBbFWrite failed");
goto out;
}
if ((rv = osBbFWrite(i, 2, blocks, sizeof blocks/2)) != BBFS_ERR_INVALID) {
sprintf(msg, "osBbFWrite unaligned test failed");
goto out;
}
bzero(blocks, sizeof blocks);
if ((rv = osBbFRead(i, 0, blocks, sizeof blocks)) < 0
|| rv != sizeof blocks) {
sprintf(msg, "osBbFRead failed %d\n", rv);
goto out;
}
for (count =0; count < sizeof(blocks); count++)
if ( blocks[count] != (u8) (count & 0xff)) {
sprintf(msg, "mismatch at %d \n Exp=%d ret=%d",
count, (u8) (count & 0xff), blocks[count]);
goto out;
}
if ((rv = osBbFClose(i)) < 0) {
sprintf(msg, "osBbFClose failed %d", rv);
goto out;
}
if ((rv = osBbFDelete("junk.gng")) < 0) {
sprintf(msg, "Cannot delete GNG tmp file %d", rv);
goto out;
}
/* test bad parameters descriptors */
if ((rv = osBbFClose(-1)) != BBFS_ERR_INVALID ||
(rv = osBbFClose(1000)) != BBFS_ERR_INVALID ||
(rv = osBbFClose(400)) != BBFS_ERR_INVALID) {
sprintf(msg, "osBBFClose error test failed %d", rv);
goto out;
}
if ((rv = osBbFRead(-1, 0, blocks, 0)) != BBFS_ERR_INVALID ||
(rv = osBbFRead(1000, 0, blocks, 0)) != BBFS_ERR_INVALID ||
(rv = osBbFRead(400, 0, blocks, 0)) != BBFS_ERR_INVALID) {
sprintf(msg, "osBBFRead error test failed %d", rv);
goto out;
}
if ((rv = osBbFWrite(1000, 0, blocks, 0)) != BBFS_ERR_INVALID ||
(rv = osBbFWrite(400, 0, blocks, 0)) != BBFS_ERR_INVALID ||
(rv = osBbFWrite(-1, 0, blocks, 1)) != BBFS_ERR_INVALID) {
sprintf(msg, "osBBFWrite error test failed %d", rv);
goto out;
}
if ((rv = osBbFStat(-1, 0, 0, 0)) != BBFS_ERR_INVALID ||
(rv = osBbFStat(1000, 0, 0, 0)) != BBFS_ERR_INVALID ||
(rv = osBbFStat(400, 0, 0, 0)) != BBFS_ERR_INVALID) {
sprintf(msg, "osBBFStat error test failed %d", rv);
goto out;
}
if ((rv = osBbFOpen("", "r")) != BBFS_ERR_INVALID ||
(rv = osBbFOpen(".", "r")) != BBFS_ERR_INVALID ||
(rv = osBbFOpen("blahblah", "r")) != BBFS_ERR_ENTRY) {
sprintf(msg, "osBBFOpen error test failed %d", rv);
goto out;
}
if ((rv = osBbFCreate("", 1, 0)) != BBFS_ERR_INVALID ||
(rv = osBbFCreate(".", 1, 0)) != BBFS_ERR_INVALID) {
sprintf(msg, "osBBFCreate error test failed %d", rv);
goto out;
}
if ((rv = osBbFDelete("")) != BBFS_ERR_INVALID ||
(rv = osBbFDelete(".")) != BBFS_ERR_INVALID) {
sprintf(msg, "osBBFDelete error test failed %d", rv);
goto out;
}
if ((rv = osBbFRename("", "foo")) != BBFS_ERR_INVALID ||
(rv = osBbFRename(".", "foo")) != BBFS_ERR_INVALID ||
(rv = osBbFRename("foo", "")) != BBFS_ERR_INVALID ||
(rv = osBbFRename("foo", ".")) != BBFS_ERR_INVALID
) {
sprintf(msg, "osBbFRename invalid param failed %d\n", rv);
goto out;
}
sprintf(msg, "FS test passed\n");
ret = 0;
out:
if (ret) my_strcat(msg, "\n\nPress Z to continue...");
gng_report(msg, 1, GNG_INHIBIT_PRINT,1);
if (ret) polling_button_down(-1, CONT_G);
return ret;
}
#define MON_START_ADDR (0x01A00000 | K0BASE)
#define LAUNCHER_ADDR (MON_START_ADDR + (1<<16))
#define NO_SYS_BLOCK 0x01
#define FINIT_ERR 0x10
#define FOPEN_ERR 0x100
#define FSTAT_ERR 0x1000
#define FREAD_ERR 0x10000
#define FWRITE_ERR 0x100000
static u8 block[BB_FL_BLOCK_SIZE] __attribute__((aligned(16)));
static u8 spare[16];
static u32 launcher_size;
static u32 launcher_tik_size;
static u16 blockList[4096];
int cp_system_data_into_mem()
{
int rv, i, bad, sysblk=0, fd, offset;
OSBbStatBuf sb;
osBbCardInit();
for (i=0; i<osBbCardBlocks(0); i++) {
rv = osBbCardReadBlock(0, i, block, spare);
bad = (rv < 0) | (spare[BB_FL_BLOCK_STATUS_OFF] != 0xff);
if (bad==0) {
bcopy(block, (void *) (MON_START_ADDR + sysblk*BB_FL_BLOCK_SIZE), BB_FL_BLOCK_SIZE);
sysblk++;
if (sysblk == 4) break;
}
}
if (sysblk < 4) return NO_SYS_BLOCK;
if ((rv = osBbFInit(&fs)) < 0) return FINIT_ERR;
/* Load burn-in test */
launcher_size = 0;
if ((fd = osBbFOpen("bbgng2.rom", "r")) < 0)
return FOPEN_ERR;
if (osBbFStat(fd, &sb, blockList, sizeof(blockList)) < 0)
return FSTAT_ERR;
launcher_size = sb.size;
offset = 0;
while (offset < launcher_size) {
if (osBbFRead(fd, offset, (void *) (LAUNCHER_ADDR+offset), BB_FL_BLOCK_SIZE) < 0)
return FREAD_ERR;
offset += BB_FL_BLOCK_SIZE;
}
osBbFClose(fd);
/* Load burn-in test ticket file */
launcher_tik_size = 0;
if ((fd = osBbFOpen("bbgng2.tik", "r")) < 0)
return FOPEN_ERR;
if (osBbFStat(fd, &sb, blockList, sizeof(blockList)) < 0)
return FSTAT_ERR;
launcher_tik_size = sb.size;
offset = 0;
while (offset < launcher_tik_size) {
if (osBbFRead(fd, offset, (void *) (LAUNCHER_ADDR+offset+launcher_size), BB_FL_BLOCK_SIZE) < 0)
return FREAD_ERR;
offset += BB_FL_BLOCK_SIZE;
}
osBbFClose(fd);
/* Recycling sp segment for reading sk and sysapp */
return 0;
}
#define GNG_NO_CARD 0x1
#define GNG_BAD_PLUG 0x10
#define GNG_SYS_CARD 0x100
int write_system_data()
{
int rv, fd, offset;
osBbCardInit();
if ((rv = osBbFInit(&fs)) < 0) return FINIT_ERR;
osBbFDelete("bbgng.gng");
osBbFDelete("bbgng2.tik");
osBbFDelete("errlog.gng");
osBbFRename("bbgng.rom", "bbgng.gng");
osBbFRename("bbgng.tik", "bbgng2.tik");
/* Write run-in test */
if ((fd = osBbFCreate("bbgng.rom", 1, launcher_size)) < 0)
return FOPEN_ERR;
offset = 0;
while (offset < launcher_size) {
if (osBbFWrite(fd, offset, (void *) (LAUNCHER_ADDR+offset), BB_FL_BLOCK_SIZE) < 0)
return FWRITE_ERR;
offset += BB_FL_BLOCK_SIZE;
}
osBbFClose(fd);
if ((fd = osBbFCreate("bbgng.tik", 1, launcher_tik_size)) < 0)
return FOPEN_ERR;
offset = 0;
while (offset < launcher_tik_size) {
if (osBbFWrite(fd, offset, (void *) (LAUNCHER_ADDR+offset+launcher_size), BB_FL_BLOCK_SIZE) < 0)
return FWRITE_ERR;
offset += BB_FL_BLOCK_SIZE;
}
osBbFClose(fd);
return 0;
}
#if 0
int create_burnin_card()
{
char msg[128];
int rv, last_status=0, i, present, key, ret;
osBbCardInit();
for (; ;) {
if (IO_READ(MI_EINTR_REG) & MI_EINTR_BUT_STATUS)
my_poweroff();
rv = osBbCardUnhappy();
switch (rv) {
case BBCARD_ERR_NO_CARD:
gng_report("System card removed. \n\n Please insert a blank card ...",
1, GNG_INHIBIT_PRINT, 1);
osBbCardClearChange();
break;
case BBCARD_ERR_CHANGED:
present = osBbCardClearChange();
if (!present) break;
if ((ret = osBbFInit(&fs)) <0 ) break;
i = osBbFOpen("bbgng2.rom", "r");
if (i >= 0) {
osBbFClose(i);
gng_report("Sorry...\n\nYou might put system card back",
1, GNG_INHIBIT_PRINT, 1);
break;
} else {
gng_report(" WARNING\n\n\nLaunch program wil be replaced. \n\nContinue? (A-Yes B-No)",
1, GNG_INHIBIT_PRINT, 1);
key = polling_button_down(-1, CONT_A | CONT_B);
if (key & CONT_B) {
gng_report("\n\nPlease re-insert a blank card...", 1, GNG_INHIBIT_PRINT, 1);
break;
}
rv = write_system_data();
if (rv) {
sprintf(msg, "Failed error = %d \n\nPlease re-insert another\n blank card...",
rv);
gng_report(msg, 1, GNG_INHIBIT_PRINT, 1);
break;
}
}
gng_report("\n\n Succeed! \n\n Press Yellow button to\nturn off power ...",
1, GNG_INHIBIT_PRINT, 1);
polling_button_down(-1, CONT_C | CONT_D | CONT_E | CONT_F);
my_poweroff();
break;
default:
osBbCardClearChange();
break;
}
}
return 0;
}
#endif
static OSBbUsbInfo UsbInfo;
#define LOOP_COUNT 200
#define ECHO_DATA_SIZE 64
int do_one_usb_loopback(OSBbUsbHandle handle)
{
char outbuf[ECHO_DATA_SIZE], inbuf[ECHO_DATA_SIZE];
u32 i, start;
int nc;
start = osGetCount();
for (i=0; i<ECHO_DATA_SIZE; i++)
outbuf[i] = (u8) (i + start);
bzero((void *)inbuf, sizeof inbuf);
nc = osBbUsbDevWrite(handle, &outbuf[0], sizeof outbuf, (u64)0);
if (nc < 0)
return 1;
nc = osBbUsbDevRead(handle, &inbuf[0], sizeof inbuf, (u64)0);
if (nc < 0)
return 1;
for (i=0; i<ECHO_DATA_SIZE; i++)
if (inbuf[i] != outbuf[i])
return 1;
return 0;
}
int bb_usb_test()
{
int err = 0, i, nusb;
char msg[256];
OSBbUsbHandle h;
sprintf(msg, " USB Loopback Test\n\n");
nusb = osBbUsbInit();
if (nusb < 2) {
my_strcat(msg, "USB controller not functional");
err++;
}
/* Query USB0 (should be device) */
osBbUsbDevQuery(0, &UsbInfo, 1);
if (UsbInfo.ua_type != OS_USB_TYPE_DEVICE) {
err++;
my_strcat(msg, "Dev(usb0) cable is mini-A\n");
}
if (UsbInfo.ua_state != OS_USB_STATE_ATTACHED) {
err++;
my_strcat(msg, "Dev(usb0) cable not plugin\n");
}
osBbUsbDevQuery(1, &UsbInfo, 1);
if (UsbInfo.ua_state != OS_USB_STATE_ATTACHED) {
err++;
my_strcat(msg, "Host(usb1) cable not plugin\n");
}
h = NULL;
if (osBbUsbDevGetHandle(1, &UsbInfo, &h) == 0) {
if (UsbInfo.ua_vendor != 0x05a3 || UsbInfo.ua_product != 0x0001) {
if (UsbInfo.ua_state == OS_USB_STATE_ATTACHED)
my_strcat(msg, "Not echo driver\n");
err++;
}
} else {
err++;
my_strcat(msg, "Host driver uninstalled\n");
}
if (err) {
my_strcat(msg, "\n\n\nPress A button to continue ...");
gng_report(msg, 1, GNG_INHIBIT_PRINT, 1);
polling_button_down(-1, CONT_A);
return err;
}
gng_report(msg, 1, GNG_INHIBIT_PRINT, 1);
for (i=err=0; i<LOOP_COUNT; i++) {
err = do_one_usb_loopback(h);
sprintf(msg, "\n USB Loopback Test\n\n\n %d passed \n %d Failed", i+1-err, err);
gng_report(msg, 1, GNG_INHIBIT_PRINT, 1);
pause_start(0);
}
return err;
}
u8 test_date[8] = {3, 9, 7, 7, 23, 59, 59 };
int rtc_test()
{
int err = 0;
u8 read_date[8];
u64 end;
osBbRtcInit();
bzero(read_date, 7);
osBbRtcSet(test_date[0], test_date[1], test_date[2], test_date[3],
test_date[4], test_date[5], test_date[6]);
end = OS_CYCLES_TO_USEC(osGetTime()) + 1100000;
while (OS_CYCLES_TO_USEC(osGetTime()) < end);
osBbRtcGet(read_date, read_date+1, read_date+2, read_date+3,
read_date+4, read_date+5, read_date+6);
if ( (read_date[0] != test_date[0]) ||
(read_date[1] != test_date[1]) ||
(read_date[2] != 8) ||
(read_date[3] == 7) ||
(read_date[4] != 0) ||
(read_date[5] != 0) ||
(read_date[6] > 2))
err |= 1;
test_date[1]=12;
test_date[2]=31;
test_date[3]=4;
osBbRtcSet(test_date[0], test_date[1], test_date[2], test_date[3],
test_date[4], test_date[5], test_date[6]);
end = OS_CYCLES_TO_USEC(osGetTime()) + 1100000;
while (OS_CYCLES_TO_USEC(osGetTime()) < end);
osBbRtcGet(read_date, read_date+1, read_date+2, read_date+3,
read_date+4, read_date+5, read_date+6);
if ((read_date[0] == test_date[0]) ||
(read_date[1] != 1) ||
(read_date[2] != 1) ||
(read_date[3] != 5)) {
err |= 2;
}
return err;
}
void board_level_test()
{
int dp_err=0, sp_err=0, vi_err=0, ai_err=0, usb_err;
int total, jctrl_err=0, pi_err=0, rtc_err=0, i;
FONT_RENDER *p_report=&font_render;
char *msg;
gng_report(" BB Tests", 1, GNG_INHIBIT_PRINT, 1);
jctrl_err = bb_jctrl_test();
sp_err = bb_sp_test();
dp_err = bb_dp_test();
vi_err = bb_vi_test();
ai_err = bb_ai_test();
usb_err = bb_usb_test();
rtc_err = rtc_test();
osBbCardInit();
pi_err = bb_flash_err();
total = jctrl_err | sp_err | dp_err | vi_err | ai_err | pi_err | usb_err | rtc_err;
if (total) ERR_ON;
else my_poweroff();
p_report->num = 10;
for (i=0; i<p_report->num; i++) {
p_report->xpos[i] = 50;
p_report->ypos[i] = 30 + i*18;
p_report->r[i] = p_report->b[i] = p_report->g[i] = p_report->a[i] = 255;
p_report->width[i] = 32;
p_report->height[i] = 1;
p_report->text[i] = font_msg + 32*i;
sprintf(p_report->text[i], " ");
}
sprintf(p_report->text[0], "Board test Report");
p_report->xpos[0] = 90;
p_report->ypos[0] -= 5;
msg = p_report->text[1];
sprintf(msg, "Jctrl ");
if (jctrl_err & JCTRL1_ERR) my_strcat(msg, "1 ");
if (jctrl_err & JCTRL2_ERR) my_strcat(msg, "2 ");
if (jctrl_err & JCTRL3_ERR) my_strcat(msg, "3 ");
if (jctrl_err) {
my_strcat(msg, " failed");
p_report->b[1] = p_report->g[1] = 0;
} else my_strcat(p_report->text[1], " tests passed");
if (sp_err) {
sprintf(p_report->text[2], "%d of 392 SP tests failed", sp_err);
p_report->b[2] = p_report->g[2] = 0;
} else sprintf(p_report->text[2], "All 392 sp tests passed");
if (dp_err) {
sprintf(p_report->text[3], "%d of 340 DP tests failed", dp_err);
p_report->b[3] = p_report->g[3] = 0;
} else sprintf(p_report->text[3], "All 340 DP tests passed");
if (vi_err) {
sprintf(p_report->text[4], "Video test failed");
p_report->b[4] = p_report->g[4] = 0;
} else sprintf(p_report->text[4], "Video test passed");
if ( ai_err ) {
sprintf(p_report->text[5], "Audio test failed");
p_report->b[5] = p_report->g[5] = 0;
} else sprintf(p_report->text[5], "Audio test passed");
if (usb_err) {
sprintf(p_report->text[6], "USB test failed");
p_report->b[6] = p_report->g[6] = 0;
} else sprintf(p_report->text[6], "USB test passed");
if (pi_err) {
sprintf(p_report->text[7], "Flash test failed");
p_report->b[7] = p_report->g[7] = 0;
} else sprintf(p_report->text[7], "Flash test passed");
if (rtc_err) {
sprintf(p_report->text[8], "RTC test failed");
p_report->b[8] = p_report->g[8] = 0;
} else sprintf(p_report->text[8], "RTC test passed");
sprintf(p_report->text[9], "Press C button to poweroff");
p_report->g[9] = 0;
p_report->xpos[9] = 40;
p_report->ypos[9] += 5;
my_gngreport(p_report);
polling_button_down(-1, CONT_C | CONT_E | CONT_F | CONT_D);
return;
}
#define BURN_IN_CHECK_BUT 5*1000000
#define BURN_IN_LEN 25*1000000 /* 20 sec burn-in test */
#define MAX_ERR_LOG 2000
#define BOARD_TEST_DONE 0x100000
#define SYSTEM_TEST_DONE 0x200000
#define SYSTEM_TEST_FAIL 0x180000
int stop_heart_beat;
#define HEART_BEAT_PRI 12
static OSThread heartThread;
static u64 heartThreadStack[STACKSIZE/sizeof(u64)];
OSMesg heartMessageBuf;
OSMesgQueue heartMessageQ;
int rdp_timeout;
int err_keep_on;
#define RDP_TIMEOUT_ERR 88888
#define RDP_TIMEOUT_COUNT 30
extern OSMesgQueue rdpMessageQ;
extern OSMesg dummyMessage;
static void heartproc(void *arg)
{
int on = 1;
OSTimer timer;
int *p = (int *) (blocks + 4);
int *p_num = (int *) blocks;
err_keep_on = 0;
osCreateMesgQueue(&heartMessageQ, &heartMessageBuf, 1);
while (stop_heart_beat == 0) {
if (IO_READ(MI_EINTR_REG) & MI_EINTR_BUT_STATUS)
my_poweroff();
rdp_timeout--;
if (rdp_timeout <= 0) { /* DP test timeout */
err_keep_on = 1;
p = p_num + (p_num[0] * 2 + 1);
p_num[0] = p_num[0] + 1;
*p++ = RDP_TIMEOUT_ERR;
*p++ = (int) (OS_CYCLES_TO_USEC(osGetTime()) / ((u64) 1000));
/* Try to recovered DP test */
rdp_timeout = RDP_TIMEOUT_COUNT;
osSendMesg(&rdpMessageQ, &dummyMessage, OS_MESG_NOBLOCK);
}
if (on || err_keep_on) ERR_ON;
else ERR_OFF;
osSetTimer(&timer, OS_USEC_TO_CYCLES((u64)500000), 0, &heartMessageQ, NULL);
osRecvMesg(&heartMessageQ, NULL, OS_MESG_BLOCK);
on = 1 - on;
}
}
#define DP_ERR_START 20000
#define SP_ERR_START 10000
int do_burn_in_test()
{
u64 end, done;
OSContStatus sdata[MAXCONTROLLERS];
OSContPad ctrl_data[MAXCONTROLLERS];
char pattern, s_version[32];
int key, i, key_mask1=CONT_G|CONT_L|CONT_R, burns=0;
int key_mask2=CONT_B|CONT_L|CONT_R;
int key_8hr = CONT_A | CONT_B | CONT_L;
int key_16hr = CONT_A | CONT_B | CONT_R;
int key_4hr = CONT_A | CONT_B | CONT_G;
int key_2hr = CONT_A | CONT_B | CONT_START;
int *p, err=0, ret, *p_num;
osSetEventMesg(OS_EVENT_SI, &siMessageQ, (OSMesg)NULL);
osContInit(&siMessageQ, &pattern, &sdata[0]);
// Add VERSION NUMBER
sprintf(s_version, " BB System test %d.%d", DIAG_VER_MAJ, DIAG_VER_MIN);
gng_report(s_version , 1, GNG_INHIBIT_PRINT, 1);
done = OS_CYCLES_TO_USEC(osGetTime()) + BURN_IN_LEN;
bzero(blocks, BB_FL_BLOCK_SIZE);
p = (int *) (blocks + 4);
p_num = (int *) blocks;
stop_heart_beat = 0;
/* create heart-beat thread */
no_pause = 1;
rdp_timeout = 0xFFFFFF;
osCreateThread(&heartThread, 1, heartproc, NULL,
heartThreadStack+STACKSIZE/sizeof(u64), HEART_BEAT_PRI);
osStartThread(&heartThread);
done = OS_CYCLES_TO_USEC(osGetTime()) + BURN_IN_CHECK_BUT;
end = OS_CYCLES_TO_USEC(osGetTime()) + BURN_IN_LEN;
while (OS_CYCLES_TO_USEC(osGetTime()) < done) {
if (IO_READ(MI_EINTR_REG) & MI_EINTR_BUT_STATUS)
my_poweroff();
osContStartReadData(&siMessageQ);
osRecvMesg(&siMessageQ, NULL, OS_MESG_BLOCK);
osContGetReadData(ctrl_data);
if ((ctrl_data[0].button & key_8hr) == key_8hr) {
end = OS_CYCLES_TO_USEC(osGetTime()) + (u64) 8*3600*1000000;
break;
}
if ((ctrl_data[0].button & key_4hr) == key_4hr) {
end = OS_CYCLES_TO_USEC(osGetTime()) + (u64) 4*3600*1000000;
break;
}
if ((ctrl_data[0].button & key_2hr) == key_2hr) {
end = OS_CYCLES_TO_USEC(osGetTime()) + (u64) 2*3600*1000000;
break;
}
if ((ctrl_data[0].button & key_16hr) == key_16hr) {
end = OS_CYCLES_TO_USEC(osGetTime()) + (u64) 16*3600*1000000;
break;
}
}
while (OS_CYCLES_TO_USEC(osGetTime()) < end) {
rdp_timeout = RDP_TIMEOUT_COUNT;
if (IO_READ(MI_EINTR_REG) & MI_EINTR_BUT_STATUS) {
if (!err) my_poweroff();
else break;
}
osContStartReadData(&siMessageQ);
osRecvMesg(&siMessageQ, NULL, OS_MESG_BLOCK);
osContGetReadData(ctrl_data);
for (i=key=0; i<MAXCONTROLLERS; i++) {
if ( !(ctrl_data[i].errno & CONT_NO_RESPONSE_ERROR ))
key |= ctrl_data[i].button;
}
if ((key & key_mask1) == key_mask1) {
if (err < MAX_ERR_LOG) err++;
else break;
p = p_num + (p_num[0] * 2 + 1);
*p++ = 1234;
*p++ = (int) (OS_CYCLES_TO_USEC(osGetTime()) / ((u64) 1000));
p_num[0] = p_num[0] + 1;;
write_log_file();
stop_heart_beat = 1;
ERR_ON;
}
if ((key & key_mask2) == key_mask2) {
if (err < MAX_ERR_LOG) err++;
else break;
p = p_num + (p_num[0] * 2 + 1);
*p++ = 3589;
*p++ = (int) (OS_CYCLES_TO_USEC(osGetTime()) / ((u64) 1000));
p_num[0] = p_num[0] + 1;;
write_log_file();
stop_heart_beat = 1;
ERR_ON;
}
ret = rsp();
if (ret) {
if (err < MAX_ERR_LOG) err++;
else break;
p = p_num + (p_num[0] * 2 + 1);
*p++ = SP_ERR_START + ret;
*p++ = (int) (OS_CYCLES_TO_USEC(osGetTime()) / ((u64) 1000));
p_num[0] = p_num[0] + 1;;
write_log_file();
stop_heart_beat = 1;
ERR_ON;
}
ret = dlDriver();
if (ret) {
if (err < MAX_ERR_LOG) err++;
else break;
p = p_num + (p_num[0] * 2 + 1);
*p++ = DP_ERR_START + ret;
*p++ = (int) (OS_CYCLES_TO_USEC(osGetTime()) / ((u64) 1000));
p_num[0] = p_num[0] + 1;;
write_log_file();
stop_heart_beat = 1;
ERR_ON;
}
burns = 1;
}
stop_heart_beat = 1;
if (!err) ERR_OFF;
else ERR_ON;
return err;
}
#define JOY_XY_MIN 52
int bb_lctrl_test()
{
FONT_RENDER *lctrl=&font_render;
OSContStatus sdata[MAXCONTROLLERS];
OSContPad ctrl_data[MAXCONTROLLERS];
char lctrl_down[19];
char pattern;
u32 bb_id = 0;
int width[19] = { 32, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8};
int xpos[19] = { 80, 80, 30, 120, 80, 80, 30, 120, 80, 60, 260, 100, 150,
240, 210, 270, 240, 200, 230}, done=-1, but, i;
int ypos[19] = { 20, 90, 110, 110, 130, 160, 180, 180, 200, 60, 60, 60, 80,
90, 110, 110, 130, 155, 180};
char *lctrl_name[19]={"BB Local Ctrl Test", "JT", "JL", "JR", "JB", "Up", "Left",
"Right", "Down", "L", "R", "Z", "Start",
"C", "D", "E", "F", "B", "A"}, x, y, old_x=0, old_y=0, buf_change=1;
lctrl->num = 19;
skGetId(&bb_id);
for (i=0; i<lctrl->num; i++) {
lctrl->xpos[i] = xpos[i];
lctrl->ypos[i] = ypos[i];
lctrl->r[i] = lctrl->b[i] = lctrl->g[i] = lctrl->a[i] = 255;
lctrl->width[i] = width[i];
lctrl->height[i] = 1;
lctrl->text[i] = font_msg + 32*i;
if (i) sprintf(lctrl->text[i], "%s", lctrl_name[i]);
else sprintf(lctrl->text[0], "BB %d LCtrl Test", bb_id);
lctrl_down[i] = 0;
}
osSetEventMesg(OS_EVENT_SI, &siMessageQ, (OSMesg)NULL);
osContInit(&siMessageQ, &pattern, &sdata[0]);
for ( ; ;) {
if (IO_READ(MI_EINTR_REG) & MI_EINTR_BUT_STATUS)
return 1;
osContStartReadData(&siMessageQ);
osRecvMesg(&siMessageQ, NULL, OS_MESG_BLOCK);
osContGetReadData(ctrl_data);
x = ctrl_data[0].stick_x & 0xff;
y = ctrl_data[0].stick_y & 0xff;
but = ctrl_data[0].button;
if (y > JOY_XY_MIN) lctrl_down[1] = 1;
if (x < -JOY_XY_MIN) lctrl_down[2] = 1;
if (x > JOY_XY_MIN) lctrl_down[3] = 1;
if (y < -JOY_XY_MIN) lctrl_down[4] = 1;
if (but & CONT_UP) lctrl_down[5] = 1;
if (but & CONT_LEFT) lctrl_down[6] = 1;
if (but & CONT_RIGHT) lctrl_down[7] = 1;
if (but & CONT_DOWN) lctrl_down[8] = 1;
if (but & CONT_L) lctrl_down[9] = 1;
if (but & CONT_R) lctrl_down[10] = 1;
if (but & CONT_G) lctrl_down[11] = 1;
if (but & CONT_START) lctrl_down[12] = 1;
if (but & CONT_E) lctrl_down[13] = 1;
if (but & CONT_C) lctrl_down[14] = 1;
if (but & CONT_F) lctrl_down[15] = 1;
if (but & CONT_D) lctrl_down[16] = 1;
if (but & CONT_A) lctrl_down[18] = 1;
if (but & CONT_B) lctrl_down[17] = 1;
for (i=but=0; i<19; i++) {
if (lctrl_down[i]) {
but++;
lctrl->r[i] = lctrl->b[i] = lctrl->g[i] = lctrl->a[i] = 64;
}
}
sprintf(lctrl->text[2], "%s(%d)", lctrl_name[2], x);
sprintf(lctrl->text[4], "%s(%d)", lctrl_name[4], y);
if (!buf_change) {
if ((x != old_x) || (y != old_y) || (but != done)) buf_change=1;
}
if (buf_change) my_gngreport(lctrl);
buf_change = 0;
old_x = x;
old_y = y;
done = but;
if (done >= 18) break;
}
return 0;
}
void error_report()
{
int key, err_num, cur_num, *p, i, k;
char message[768], buf[64];
u64 end;
ERR_ON;
p = (int *) blocks;
if (*p == SYSTEM_TEST_FAIL) {
gng_report("\n System Test Failed \n\n\n Press A to restart ...",
1, GNG_INHIBIT_PRINT, 1);
polling_button_down(-1, CONT_A);
ERR_OFF;
return;
}
if (*p == SYSTEM_TEST_DONE) {
gng_report("\n System Controller Test Passed \n\n\n Press A to poweroff",
1, GNG_INHIBIT_PRINT, 1);
polling_button_down(-1, CONT_A);
my_poweroff();
return;
}
err_num = (*p > MAX_ERR_LOG) ? (MAX_ERR_LOG) : (*p);
cur_num = 0;
for (; ;) {
sprintf(message, " Burn in test Failure report\n (Total error = %d)\n\n", err_num);
my_strcat(message, " No. Code Time\n");
for (i=0, k=cur_num; i<4; i++, k++) {
if (k < err_num)
sprintf(buf, "%4d %5d %8.3fsec\n",
k+1, p[k+k+1], (float) (1.0*p[k+k+2]/1000));
else sprintf(buf, "\n");
my_strcat(message, buf);
}
if (err_num > 4) my_strcat(message, "\nL --- PageUp R --- PgDn");
else my_strcat(message, "\n");
my_strcat(message, "\nPress A to rerun the test");
gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
key = polling_button_down(-1, CONT_L | CONT_R | CONT_A);
end = OS_CYCLES_TO_USEC(osGetTime()) + 300000;
while (OS_CYCLES_TO_USEC(osGetTime()) < end);
if (key & CONT_A) {
ERR_OFF;
break;
}
if (key & CONT_L)
cur_num -= 4;
if (key & CONT_R) {
cur_num += 4;
if (cur_num >= err_num) cur_num = err_num - 4;
}
if (cur_num < 0) cur_num = 0;
}
return;
}
int do_system_test()
{
bb_vi_test();
bb_ai_test();
return bb_lctrl_test();
}
void do_d_pad_test();
void display_version(char *s)
{
u64 done;
gng_report(s , 1, GNG_INHIBIT_PRINT, 1);
done = OS_CYCLES_TO_USEC(osGetTime()) + BURN_IN_CHECK_BUT/2;
while (OS_CYCLES_TO_USEC(osGetTime()) < done) {
if (IO_READ(MI_EINTR_REG) & MI_EINTR_BUT_STATUS)
my_poweroff();
}
}
void manufacture_test()
{
int rv, fd, *p, rerun, err;
char s_version[64];
#ifdef DVT_BOARD /* XXXXX delete for PVT */
sprintf(s_version, "\n\n BB Board test %d.%d", BOARD_VER_MAJ, BOARD_VER_MIN);
display_version(s_version);
board_level_test();
my_poweroff();
#endif
#ifdef BB_DUMMY
sprintf(s_version, "\n\n BB Dummy test %d.%d", DUMMY_VER_MAJ, DUMMY_VER_MIN);
display_version(s_version);
new_dummy_test();
my_poweroff();
#endif
#ifdef BB_BREAKOUT
sprintf(s_version, "\n\n Breakout box %d.%d", BREAKOUT_VER_MAJ, BREAKOUT_VER_MIN);
display_version(s_version);
breakout_box_test();
my_poweroff();
#endif
#ifdef DVT_SYSTEM
// Add D-pad test to OQC test
sprintf(s_version, "\n\n OQC TEST %d.%d", OQC_VER_MAJ, OQC_VER_MIN);
display_version(s_version);
do_d_pad_test();
do_system_test();
my_poweroff();
#endif
osBbRtcInit();
osBbCardInit();
p = (int *) blocks;
if ((rv = osBbFInit(&fs)) < 0) {
ERR_ON;
polling_poweroff();
return;
}
if ((fd = osBbFOpen("errlog.gng", "r")) < 0) {
#ifndef DVT_BURN
board_level_test();
#endif
*p = BOARD_TEST_DONE;
} else {
bzero(blocks, sizeof blocks);
rv = osBbFRead(fd, 0, blocks, sizeof blocks);
osBbFClose(fd);
#ifdef DVT_BURN
} /* end of else */
{
#endif
restart:
rerun = 0;
err = 0;
switch (*p) {
case BOARD_TEST_DONE:
err = do_burn_in_test();
break;
case 0: /* Burn-in test done and no err */
/* check RTC across power-cycle boundary between burn-in and
system test */
sprintf(s_version, "\n\n BB SYSTEM TEST %d.%d",
SYS_VER_MAJ, SYS_VER_MIN);
display_version(s_version);
do_rtc_check(((u8 *) blocks) + TIME_STAMP_OFF);
*p = (do_system_test()==0) ? SYSTEM_TEST_DONE: SYSTEM_TEST_FAIL;
break;
case SYSTEM_TEST_FAIL:
default:
sprintf(s_version, "\n\n BB System TEST %d.%d",
DIAG_VER_MAJ, DIAG_VER_MIN);
display_version(s_version);
error_report(); /* if returned, means continuing */
if (*p == SYSTEM_TEST_FAIL) *p = 0;
else *p = BOARD_TEST_DONE;
rerun = 1;
break;
}
}
write_log_file();
if (rerun) goto restart;
if (err) {
ERR_ON;
polling_poweroff();
}
my_poweroff();
return;
}
void breakout_box_test()
{
int vi_err=0, ai_err=0, usb_err, i;
int total, jctrl_err=0;
FONT_RENDER *p_report=&font_render;
char *msg;
gng_report(" Breakout box Tests", 1, GNG_INHIBIT_PRINT, 1);
vi_err = bb_vi_test();
ai_err = bb_ai_test();
usb_err = bb_usb_test();
jctrl_err = bb_jctrl_test();
total = jctrl_err | vi_err | ai_err |usb_err ;
if (total) ERR_ON;
else my_poweroff();
p_report->num = 6;
for (i=0; i<p_report->num; i++) {
p_report->xpos[i] = 50;
p_report->ypos[i] = 50 + i*20;
p_report->r[i] = p_report->b[i] = p_report->g[i] = p_report->a[i] = 255;
p_report->width[i] = 32;
p_report->height[i] = 1;
p_report->text[i] = font_msg + 32*i;
sprintf(p_report->text[i], " ");
}
sprintf(p_report->text[0], "Breakout box test Report");
p_report->xpos[0] = 50;
p_report->ypos[0] -= 10;
msg = p_report->text[4];
sprintf(msg, "Jctrl ");
if (jctrl_err & JCTRL1_ERR) my_strcat(msg, "1 ");
if (jctrl_err & JCTRL2_ERR) my_strcat(msg, "2 ");
if (jctrl_err & JCTRL3_ERR) my_strcat(msg, "3 ");
if (jctrl_err) {
my_strcat(msg, " failed");
p_report->b[4] = p_report->g[4] = 0;
} else my_strcat(p_report->text[4], " tests passed");
if (vi_err) {
sprintf(p_report->text[1], "Video test failed");
p_report->b[1] = p_report->g[1] = 0;
} else sprintf(p_report->text[1], "Video test passed");
if ( ai_err ) {
sprintf(p_report->text[2], "Audio test failed");
p_report->b[2] = p_report->g[2] = 0;
} else sprintf(p_report->text[2], "Audio test passed");
if (usb_err) {
sprintf(p_report->text[3], "USB test failed");
p_report->b[3] = p_report->g[3] = 0;
} else sprintf(p_report->text[3], "USB test passed");
sprintf(p_report->text[5], "Press C button to poweroff");
p_report->g[5] = 0;
p_report->xpos[5] = 40;
p_report->ypos[5] += 5;
my_gngreport(p_report);
polling_button_down(-1, CONT_C | CONT_E | CONT_F | CONT_D);
return;
}