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

Subversion Repositories z80soc

[/] [z80soc/] [trunk/] [V0.7.3/] [Software/] [C/] [testsys/] [testsys.c.morecode] - Blame information for rev 46

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 46 rrred
#include 
2
#include 
3
#include 
4
#include 
5
#include 
6
#include 
7
 
8
void delay(int count) {
9
        if (count > 0) {
10
                for (count; count>0; count--) {
11
                        readMemory(0x0000);
12
                }
13
        }
14
}
15
 
16
// Stedy LEDs for Success
17
// Blinking LEDs for error
18
// Keeps looping until push button 1 is pressed
19
void flashAlert(unsigned char al) {
20
    while (pushButton() != 0b00000010) {
21
        greenLeds(0xFF);
22
        if (al == Error) {
23
            delay(2000);
24
            greenLeds(0x00);
25
            delay(5000);
26
        }
27
    }
28
}
29
 
30
void alert(unsigned char rc) {
31
    cursorxy(5,13);
32
    if (rc == Success) {
33
        printf("Test passed.");
34
        flashAlert(greenAlert);
35
    } else {
36
        printf("Test Failed !!!");
37
        flashAlert(redAlert);
38
    }
39
}
40
 
41
static bool testram(unsigned int baseAddress, unsigned int endAddress) {
42
 
43
    unsigned char mychar0;
44
    unsigned char mychar1;
45
    unsigned char mychar2;
46
 
47
    while (baseAddress < endAddress) {
48
 
49
        // save current byte in memory
50
        mychar0 = readMemory(baseAddress);
51
 
52
        // write test values to memory
53
        writeMemory(baseAddress, 0x41);
54
        mychar1 = readMemory(baseAddress);
55
        writeMemory(baseAddress, 0x42);
56
        mychar2 = readMemory(baseAddress);
57
 
58
        // restore original byte to memory
59
        writeMemory(baseAddress, mychar0);
60
 
61
        cursorxy(5,11);
62
        printf("Writing to address: 0x%x     ",baseAddress);
63
 
64
        if ( mychar1 != 0x41 || mychar2 != 0x42) {
65
            alert(Error);
66
            return false;
67
        }
68
 
69
        baseAddress++;
70
    }
71
 
72
    alert(Success);
73
    return true;
74
}
75
 
76
void redefineChar(unsigned int baseAddress) {
77
    // will redefine char with ascii codes 1 to 4
78
    short int i;
79
    unsigned char hero_bits[] = {
80
        0x01,0x01,0x03,0x13,0x13,0x97,0x97,0x9e,
81
        0x80,0x80,0xc0,0xc8,0xc8,0xe9,0xe9,0x79,
82
        0xbc,0xbd,0xff,0xff,0xfb,0xf3,0xe1,0xc1,
83
        0x3d,0xbd,0xff,0xff,0xdf,0xcf,0x87,0x83
84
    };
85
 
86
    baseAddress = baseAddress + 8;
87
 
88
    for (i = 0; i < 32; i++) {
89
        writeMemory(baseAddress + i, hero_bits[i]);
90
    }
91
 
92
    writeMemory(readMemoryInt(0x57D4) + 14*80 + 5,1);
93
    writeMemory(readMemoryInt(0x57D4) + 14*80 + 6,2);
94
    writeMemory(readMemoryInt(0x57D4) + 15*80 + 5,3);
95
    writeMemory(readMemoryInt(0x57D4) + 15*80 + 6,4);
96
 
97
    alert(Success);
98
 
99
}
100
 
101
static bool testlcd(void) {
102
    unsigned char platf = readMemory(0x57DF);
103
 
104
    cursorxy(5,11);
105
 
106
    if (platf == S3E || platf == DE2115 || platf == O3S) {
107
        printf("Writing to LCD now...");
108
        printlcd(0,"**** Z80SoC ****");
109
        printlcd(16,"  Retro-CPU.run ");
110
        alert(Success);
111
        return true;
112
    } else {
113
        printf("This platform does not have LCD Display");
114
        alert(Error);
115
        return false;
116
       }
117
}
118
 
119
void clslcd(void) {
120
    printlcd(0,"                                ");
121
}
122
 
123
unsigned char testprintf(char s[]) {
124
    // set device output to video
125
    writeMemory(0x57CD,0);
126
 
127
    hexlsb0(readMemory(0x57D0));
128
    hexmsb0(readMemory(0x57D1));
129
 
130
    printf(s);
131
 
132
    return 0xAA;
133
}
134
 
135
bool platformCheck(unsigned char testId) {
136
    // testId = 0  => RAM
137
    // testId = 1  => VRAM
138
    // testId = 2  => CharRAM
139
    // testId = 3  => LCDRAM
140
    // testId = 4  => LCD On/Off
141
    // testId = 5  => Rotary Button
142
    // testId = 6  => Pushbuttons
143
 
144
    unsigned char platf = readMemory(0x57DF);
145
 
146
        if (platf == S3E || platf == DE2115 || platf == O3S )
147
            return true;
148
        else
149
            return false;
150
 
151
}
152
 
153
// read character from registry
154
unsigned char mygetchar(void) {
155
    return readMemory(0x57DE);
156
}
157
 
158
static bool testkbd(void) {
159
    unsigned char platf = readMemory(0x57DF);
160
    unsigned char c, b;
161
    if (platf > 0) lcdonoff(1);
162
    cursorxy(5,11);
163
    printf("Starting pressing keys in the keyboard now.\n");
164
    cursorxy(5,12);
165
    printf("When you press ENTER the test will finish.\n");
166
    cursorxy(5,14);
167
    c = mygetchar();
168
    b = 0;
169
    while (c != 13) {
170
        if (c != b) printf("%c",c);
171
        b = c;
172
        c = mygetchar();
173
        if (platf != 1) {
174
            hexlsb0(c);
175
            //hexmsb0(c && 0xf0);
176
        }
177
    }
178
 
179
    alert(Success);
180
    if (platf > 0) lcdonoff(0);
181
    return true;
182
}
183
 
184
void main(void) {
185
 
186
    unsigned char SW = 0;
187
    unsigned char LEDCOUNT = 1;
188
 
189
    unsigned int baseAddress = 0;
190
    unsigned int endAddress = 0;
191
    int i;
192
    int direction;
193
    unsigned char platf = readMemory(0x57DF);
194
 
195
    /*
196
    char *PLATFDESC;
197
 
198
    switch (platf) {
199
        case 0: *PLATFDESC="DE1";
200
        case 1: *PLATFDESC="SPARTAN-3E";
201
        case 2: *PLATFDESC="DE2-115";
202
        case 3: *PLATFDESC="Open3S500E";
203
       default: *PLATFDESC="Unknown";
204
    }
205
    */
206
 
207
    // TestSys runs in a continuous loop
208
    while (1) {
209
 
210
    // clear video screen
211
    cls();
212
    cursorxy(15,3);
213
    printf("TestSys - A hardware test program for the Z80SoC");
214
    cursorxy(15,4);
215
    printf("Running on Platform %u",platf);
216
 
217
    cursorxy(0,20);
218
    printf("     CONTROLS\n");
219
    printf("     ========\n\n");
220
 
221
    if (platf == DE1) {
222
        printf("     Switch 9      ==> Reset\n");
223
        printf("     Switch 8      ==> 3.57Mh / 10Mhz\n");
224
    }
225
 
226
    if (platf == DE2115) {
227
        printf("     Switch 17     ==> Reset\n");
228
        printf("     Switch 16     ==> 3.57Mh / 10Mhz\n");
229
    }
230
 
231
    if (platf == S3E) {
232
        printf("     Rotary Putton ==> Reset\n");
233
        printf("     Switch 3      ==> 3.57Mh / 10Mhz\n");
234
    }
235
 
236
    if (platf == O3S) {
237
        printf("     North Button  ==> Reset\n");
238
        printf("     South Button  ==> 3.57Mh / 10Mhz\n");
239
    }
240
 
241
    if (platf == O3S) {
242
        printf("\n\n");
243
        printf("     This instructons assume you have the pushbuttons module installed.\n");
244
        printf("\n\n");
245
        printf("     These pushbutons will trigger the tests:\n\n");
246
        printf("     0  ==> RAM     read/write test\n");
247
        printf("     1  ==> VRAM    read/write test\n");
248
        printf("     2  ==> CharRAM read/write test (!!will mess screen!!)\n");
249
        printf("     3  ==> CharRAM character redefinition\n");
250
        printf("     4  ==> LCD     Print text to LCD screen\n");
251
        printf("\n\n");
252
        printf("     After test ends, press left Joy button to return to main screen\n");
253
        printf("\n\n");
254
    } else {
255
        printf("\n\n");
256
        printf("     Use the three right Switches to run different tests.\n");
257
        printf("     Switch positions and tests:\n\n");
258
        printf("     001  ==> RAM      read/write test\n");
259
        printf("     010  ==> VRAM     read/write test\n");
260
        printf("     011  ==> CharRAM  read/write test (!!will mess screen!!)\n");
261
        printf("     100  ==> CharRAM  character redefinition\n");
262
        printf("     101  ==> LCD      Print text to LCD screen\n");
263
        printf("     110  ==> KBD/7SEG Test Keyboard and 7 Seg Display\n");
264
        printf("\n\n");
265
        printf("     Set the Switch and press button 0 to start the test\n");
266
        printf("     After test ends, press button 1 to return to main screen\n");
267
        printf("\n\n");
268
 
269
    }
270
        printf("     If green leds are steady, tests passed successfuly\n");
271
        printf("     If green leds are flashing, test failed.\n");
272
 
273
    // Wait until user press push button 0
274
    // Switch On/Off Green leds from right to left
275
    while (pushButton() != 0b00000001) {
276
        if (LEDCOUNT == 0) LEDCOUNT = 1;
277
        greenLeds(LEDCOUNT);
278
        delay(1000);
279
        LEDCOUNT=LEDCOUNT*2;
280
    }
281
 
282
    // When user press pushbutton, he has defined what test to run on dip switches
283
    greenLeds(0);
284
    SW = dipSwitchA();
285
 
286
     switch (SW) {
287
        case 1:
288
            // test read/write to RAM
289
             cursorxy(5,10);
290
             printf("Testing: RAM");
291
             baseAddress = readMemoryInt(0x57D8);
292
 
293
             // end address leaves 50 bytes for Stack
294
             endAddress = readMemoryInt(0x57DA) - 50;
295
             testram(baseAddress, endAddress);
296
             break;
297
        case 2:
298
            // test read/write to VRAM
299
             cursorxy(5,10);
300
             printf("Testing: VRAM");
301
             baseAddress = readMemoryInt(0x57D4);
302
             endAddress = readMemoryInt(0x57D4) + 4800;
303
             testram(baseAddress, endAddress);
304
             break;
305
         case 3:
306
             // test read/write to CharRAM
307
             cursorxy(5,10);
308
             printf("Testing: CharRAM");
309
             baseAddress = readMemoryInt(0x57D6);
310
             // CharRAM size is 8 bits x 256 characters = 2048 bytes
311
             endAddress = readMemoryInt(0x57D6) + 8 * 256;
312
             testram(baseAddress, endAddress);
313
             break;
314
         case 4:
315
             // redefine characters in CharRAM and display on screen
316
             cursorxy(5,10);
317
             printf("Testing: CharRAM redefinition");
318
             baseAddress = readMemoryInt(0x57D6);
319
             redefineChar(baseAddress);
320
             break;
321
         case 5:
322
             // switch on LCD
323
             lcdonoff(1);
324
             // print text to lcd display
325
             testlcd();
326
             // clear LCD
327
             clslcd();
328
             // switch off lcd
329
             lcdonoff(0);
330
             break;
331
         case 6:
332
             // test keyboard
333
             cursorxy(5,10);
334
             printf("Testing: Keyboard input");
335
             testkbd();
336
             break;
337
         case 32:
338
             printf("\n\n\n              Testing the printf C function and newlines \\n");
339
             cursorxy(10,10);
340
             printf("1******************** Z80SoC ********************");
341
             cursorxy(10,11);
342
             printf("2******************** Z80SoC ********************");
343
             cursorxy(10,12);
344
             printf("3******************** Z80SoC ********************");
345
             printf("<< end>>");
346
 
347
             printf("\n>>>printing after\n\n\n\n>>>four new lines\n");
348
 
349
             hexlsb0(readMemory(0x57D0));
350
             hexmsb0(readMemory(0x57D1));
351
 
352
             printf("    1\n");
353
             printf("    2\n");
354
             printf("    3\n\n");
355
             printf("    4\n");
356
 
357
             cls();
358
             break;
359
         case 64:
360
             cls();
361
             cursorxy(5,2);
362
             printf("Testing char type storage and retrieve using writeMemory() function\n");
363
             cursorxy(5,3);
364
             printf("Confirms that a single byte is being written");
365
             baseAddress = readMemoryInt(0x57D8);
366
             for (i=0; i<10; i++) {
367
                 writeMemory(baseAddress + i, i);
368
                 writeMemory(baseAddress + 20 + 9 - i, 9 - i);
369
             }
370
 
371
             cursorxy(5,5);
372
             printf("written up down");
373
             cursorxy(40,5);
374
             printf("written down up");
375
 
376
             for (i=0; i<10; i++) {
377
                 cursorxy(5,6+i);
378
                 printf("%d",readMemory(baseAddress + i));
379
                 cursorxy(40,6+i);
380
                 printf("%d",readMemory(baseAddress + 20 + i));
381
             }
382
 
383
             cls();
384
             break;
385
         case 128:
386
             // random number generator test
387
             printf("\n    Testing the random integer number generator implemented inside thr FPGA (0xFFCA)");
388
             cursorxy(5,5);
389
             for (i=0; i<2000; i++) {
390
                 direction = readMemoryInt(0x57C9); // get a rumdom number - integer
391
                 printf("%i ",direction);
392
             }
393
 
394
             cls();
395
             break;
396
     }
397
   }
398
}
399
 
400
 

powered by: WebSVN 2.1.0

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