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

Subversion Repositories z80soc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 46 rrred
#include <z80soc.h>
2
#include <string.h>
3
#include <stdio.h>
4
#include <stdlib.h>
5
#include <time.h>
6
#include <stdbool.h>
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
 
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
    return true;
181
}
182
 
183
void main(void) {
184
 
185
    unsigned char SW = 0;
186
    unsigned char LEDCOUNT = 1;
187
 
188
    unsigned int baseAddress = 0;
189
    unsigned int endAddress = 0;
190
    unsigned char platf = readMemory(0x57DF);
191
 
192
    /*
193
    char *PLATFDESC;
194
 
195
    switch (platf) {
196
        case 0: *PLATFDESC="DE1";
197
        case 1: *PLATFDESC="SPARTAN-3E";
198
        case 2: *PLATFDESC="DE2-115";
199
        case 3: *PLATFDESC="Open3S500E";
200
       default: *PLATFDESC="Unknown";
201
    }
202
    */
203
 
204
    // TestSys runs in a continuous loop
205
    while (1) {
206
 
207
    // clear video screen
208
    cls();
209
    cursorxy(15,3);
210
    printf("TestSys - A hardware test program for the Z80SoC");
211
    cursorxy(15,4);
212
    printf("Running on Platform %u",platf);
213
 
214
    cursorxy(0,20);
215
    printf("     CONTROLS\n");
216
    printf("     ========\n\n");
217
 
218
    if (platf == DE1) {
219
        printf("     Switch 9      ==> Reset\n");
220
        printf("     Switch 8      ==> 3.57Mh / 10Mhz\n");
221
    }
222
 
223
    if (platf == DE2115) {
224
        printf("     Switch 17     ==> Reset\n");
225
        printf("     Switch 16     ==> 3.57Mh / 10Mhz\n");
226
    }
227
 
228
    if (platf == S3E) {
229
        printf("     Rotary Putton ==> Reset\n");
230
        printf("     Switch 3      ==> 3.57Mh / 10Mhz\n");
231
    }
232
 
233
    if (platf == O3S) {
234
        printf("     North Button  ==> Reset\n");
235
        printf("     South Button  ==> 3.57Mh / 10Mhz\n");
236
    }
237
 
238
    if (platf == O3S) {
239
        printf("\n\n");
240
        printf("     This instructons assume you have the pushbuttons module installed.\n");
241
        printf("\n\n");
242
        printf("     These pushbutons will trigger the tests:\n\n");
243
        printf("     0  ==> RAM      read/write test\n");
244
        printf("     1  ==> VRAM     read/write test\n");
245
        printf("     2  ==> CharRAM  read/write test (!!will mess screen!!)\n");
246
        printf("     3  ==> CharRAM  character redefinition\n");
247
        printf("     4  ==> LCD      Print text to LCD screen\n");
248
        printf("     5  ==> KBD/7SEG Test Keyboard and 7 Seg Display\n");
249
        printf("\n\n");
250
        printf("     After test ends, press left Joy button to return to main screen\n");
251
        printf("\n\n");
252
    } else {
253
        printf("\n\n");
254
        printf("     Use the three right Switches to run different tests.\n");
255
        printf("     Switch positions and tests:\n\n");
256
        printf("     001  ==> RAM      read/write test\n");
257
        printf("     010  ==> VRAM     read/write test\n");
258
        printf("     011  ==> CharRAM  read/write test (!!will mess screen!!)\n");
259
        printf("     100  ==> CharRAM  character redefinition\n");
260
        printf("     101  ==> LCD      Print text to LCD screen\n");
261
        printf("     110  ==> KBD      Test Keyboard");
262
 
263
        if (platf != S3E) {
264
            printf(" and 7Seg Display");
265
        }
266
 
267
        printf("\n\n\n");
268
        printf("     Set the Switch and press button 0 to start the test\n");
269
        printf("     After test ends, press button 1 to return to main screen\n");
270
        printf("\n\n");
271
 
272
    }
273
        printf("     If green leds are steady, tests passed successfuly.\n");
274
        printf("     If green leds are flashing, test failed.\n");
275
 
276
    // Wait until user press push button 0
277
    // Switch On/Off Green leds from right to left
278
    while (pushButton() != 0b00000001) {
279
        if (LEDCOUNT == 0) LEDCOUNT = 1;
280
        if (platf == O3S) redLedsA(LEDCOUNT); else greenLeds(LEDCOUNT);
281
        delay(1000);
282
        LEDCOUNT=LEDCOUNT*2;
283
    }
284
 
285
    // When user press pushbutton, he has defined what test to run on dip switches
286
    if (platf != O3S) greenLeds(0); else redLedsA(0);
287
 
288
    if (platf != O3S) SW = dipSwitchA(); else SW = pushButton();
289
 
290
     switch (SW) {
291
        case 1:
292
            // test read/write to RAM
293
             cursorxy(5,10);
294
             printf("Testing: RAM");
295
             baseAddress = readMemoryInt(0x57D8);
296
 
297
             // end address leaves 50 bytes for Stack
298
             endAddress = readMemoryInt(0x57DA) - 50;
299
             testram(baseAddress, endAddress);
300
             break;
301
        case 2:
302
            // test read/write to VRAM
303
             cursorxy(5,10);
304
             printf("Testing: VRAM");
305
             baseAddress = readMemoryInt(0x57D4);
306
             endAddress = readMemoryInt(0x57D4) + 4800;
307
             testram(baseAddress, endAddress);
308
             break;
309
         case 3:
310
             // test read/write to CharRAM
311
             cursorxy(5,10);
312
             printf("Testing: CharRAM");
313
             baseAddress = readMemoryInt(0x57D6);
314
             // CharRAM size is 8 bits x 256 characters = 2048 bytes
315
             endAddress = readMemoryInt(0x57D6) + 8 * 256;
316
             testram(baseAddress, endAddress);
317
             break;
318
         case 4:
319
             // redefine characters in CharRAM and display on screen
320
             cursorxy(5,10);
321
             printf("Testing: CharRAM redefinition");
322
             baseAddress = readMemoryInt(0x57D6);
323
             redefineChar(baseAddress);
324
             break;
325
         case 5:
326
             // switch on LCD
327
             lcdonoff(1);
328
             // print text to lcd display
329
             testlcd();
330
             // clear LCD
331
             clslcd();
332
             // switch off lcd
333
             lcdonoff(0);
334
             break;
335
         case 6:
336
             // test keyboard
337
             cursorxy(5,10);
338
             printf("Testing: Keyboard input");
339
             testkbd();
340
             break;
341
     }
342
   }
343
}
344
 
345
 

powered by: WebSVN 2.1.0

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