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

Subversion Repositories z80soc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 46 rrred
#include <o3s.h>
2
#include <de2115.h>
3
#include <z80soc.h>
4
#include <string.h>
5
#include <stdio.h>
6
#include <stdlib.h>
7
#include <time.h>
8
 
9
void delay(int count) {
10
        if (count > 0) {
11
                for (count; count>0; count--) {
12
                        readMemory(0x0000);
13
                }
14
        }
15
}
16
 
17
// blink leds until pushbutton 0 is pressed
18
void waitToExit(void) {
19
    while (pushButton() != 0b00000001) {
20
 
21
        greenLeds(0xFF);
22
        delay(5000);
23
        greenLeds(0x00);
24
        delay(5000);
25
    }
26
}
27
 
28
unsigned char testmodule(unsigned int baseAddress, unsigned int endAddress, short int baseAddressL, short int baseAddressH) {
29
 
30
    unsigned char currdip = dipSwitchA();
31
    unsigned char mychar  = 0;
32
 
33
    while (baseAddress < endAddress) {
34
        hexlsb0(baseAddressL);
35
        hexmsb0(baseAddressH);
36
 
37
        mychar = 0x41;
38
        hexmsb1(mychar);
39
        writeMemory(baseAddress, mychar);
40
 
41
        mychar = 0xAA;
42
        mychar = readMemory(baseAddress);
43
        hexlsb1(mychar);
44
 
45
        if ( mychar == 0x41) {
46
            greenLeds(readMemory(baseAddress));
47
            baseAddressL++;
48
            baseAddress++;
49
            if (baseAddressL > 0xFF) {
50
                baseAddressL = 0x00;
51
                baseAddressH++;
52
            }
53
        } else {
54
            waitToExit();
55
            return 0xFF;
56
        }
57
    }
58
 
59
    waitToExit();
60
    return 0xAA;
61
}
62
 
63
unsigned char testvram(void) {
64
    unsigned char nchar = 0;
65
    unsigned int addr = readMemoryInt(0x57D4);
66
    unsigned int endaddr = addr + 4800;
67
 
68
    hexlsb0(readMemory(0x57D4));
69
    hexmsb0(readMemory(0x57D5));
70
    while (addr < endaddr) {
71
        writeMemory(addr,nchar);
72
        nchar++;
73
        if (nchar == 255) nchar = 0;
74
        addr++;
75
    }
76
    waitToExit();
77
    return 0xAA;
78
}
79
 
80
unsigned char testlcd(void) {
81
    unsigned char nchar = 0;
82
    unsigned int addr = readMemoryInt(0x57DC);
83
 
84
    hexlsb0(readMemory(0x57DC));
85
    hexmsb0(readMemory(0x57DD));
86
 
87
    printlcd(0,"**** Z80SoC ****");
88
    printlcd(16,"  Retro-CPU.run ");
89
 
90
    waitToExit();
91
    return 0xAA;
92
}
93
 
94
unsigned char lcdcls(void) {
95
    unsigned char nchar = 0;
96
    unsigned int addr = readMemoryInt(0x57DC);
97
 
98
    hexlsb0(readMemory(0x57DC));
99
    hexmsb0(readMemory(0x57DD));
100
    while (nchar < 32) {
101
        writeMemory(addr,32);
102
        nchar++;
103
        addr++;
104
    }
105
    return 0xAA;
106
}
107
 
108
unsigned char testCharRam(void) {
109
    // will redefine char with ascii codes 1 to 4
110
    unsigned int baseAddress = readMemoryInt(0x57D6) + 8;
111
    short int i;
112
    unsigned char hero_bits[] = {
113
        0x01,0x01,0x03,0x13,0x13,0x97,0x97,0x9e,
114
        0x80,0x80,0xc0,0xc8,0xc8,0xe9,0xe9,0x79,
115
        0xbc,0xbd,0xff,0xff,0xfb,0xf3,0xe1,0xc1,
116
        0x3d,0xbd,0xff,0xff,0xdf,0xcf,0x87,0x83
117
    };
118
 
119
    for (i = 0; i < 32; i++) {
120
        writeMemory(baseAddress + i, hero_bits[i]);
121
    }
122
 
123
    writeMemory(readMemoryInt(0x57D4) + 10*80 + 31,1);
124
    writeMemory(readMemoryInt(0x57D4) + 10*80 + 32,2);
125
    writeMemory(readMemoryInt(0x57D4) + 11*80 + 31,3);
126
    writeMemory(readMemoryInt(0x57D4) + 11*80 + 32,4);
127
 
128
    waitToExit();
129
    return 0xAA;
130
}
131
 
132
unsigned char testprintf(char s[]) {
133
    // set device output to video
134
    writeMemory(0x57CD,0);
135
 
136
    hexlsb0(readMemory(0x57D0));
137
    hexmsb0(readMemory(0x57D1));
138
 
139
    printf(s);
140
 
141
    return 0xAA;
142
}
143
 
144
 
145
void main(void) {
146
 
147
    unsigned char SW = 0;
148
    char LEDCOUNT = 0;
149
    short int baseAddressL;
150
    short int baseAddressH;
151
    unsigned int baseAddress = 0;
152
    unsigned int endAddress = 0;
153
    unsigned int myvramaddr;
154
    int i;
155
    int direction;
156
 
157
    myvramaddr = readMemoryInt(0x57D4) + (5 * 32);
158
    writeMemoryInt(0x57D0, myvramaddr);
159
 
160
    cls();
161
    lcdonoff(1);
162
    redLedsA(6);
163
 
164
    if (readMemory(0x57DF) > 0) {
165
        printlcd(0,"TestSys Z80SoC  ");
166
        if (readMemory(0x57DF) == 1) {
167
            printlcd(16,"  running on S3E");
168
        } else if (readMemory(0x57DF) == 2) {
169
            printlcd(16,"  running on DE2");
170
        } else if (readMemory(0x57DF) == 3) {
171
            printlcd(16,"  running on O3S");
172
        }
173
    }
174
 
175
    while (1) {
176
 
177
    cursorxy(15,3);
178
    printf("TestSys - A hardware test program for the Z80SoC");
179
 
180
    redLedsA(LEDCOUNT);
181
    LEDCOUNT++;
182
 
183
    SW = dipSwitchA();
184
 
185
     switch (SW) {
186
        case 1:
187
            // test sram
188
            printf("\n\n\n      Testing RAM. Check the address being tested on the 7SEG Display");
189
            baseAddressL = readMemory(0x57D8);
190
            baseAddressH = readMemory(0x57D9);
191
            baseAddress = readMemoryInt(0x57D8);
192
            endAddress = readMemoryInt(0x57DA) - 0x100;
193
            hexmsb1(testmodule(baseAddress, endAddress, baseAddressL, baseAddressH));
194
            waitToExit();
195
            break;
196
        case 2:
197
            // test vram
198
            //hexmsb1(testvram());
199
             baseAddressL = readMemory(0x57D4);
200
             baseAddressH = readMemory(0x57D5);
201
             baseAddress = readMemoryInt(0x57D4);
202
             endAddress = readMemoryInt(0x57D8);
203
             hexmsb1(testmodule(baseAddress, endAddress, baseAddressL, baseAddressH));
204
             waitToExit();
205
             cls();
206
            break;
207
        case 4:
208
             // test lcd
209
             if (readMemory(0x57DF) == 0) {
210
                 printf("\n\n\n     DE1 platform don't have LCD display");
211
                 waitToExit();
212
                 cls();
213
             } else {
214
                     printf("\n\n\n      Check the LCD display");
215
                     lcdonoff(0);
216
                     waitToExit();
217
                     lcdonoff(1);
218
                    }
219
             break;
220
        case 8:
221
             // test lcd
222
             if (readMemory(0x57DF) == 0) {
223
                 printf("\n\n\n     DE1 platform don't have LCD display");
224
                 waitToExit();
225
                 cls();
226
             } else {
227
                     printf("\n\n\n      Check the LCD display");
228
                     hexmsb1(testlcd());
229
                     waitToExit();
230
                     printlcd(0,"TestSys Z80SoC  ");
231
 
232
                    if (readMemory(0x57DF) == 1) {
233
                        printlcd(16,"  running on S3E");
234
                    } else if (readMemory(0x57DF) == 2) {
235
                              printlcd(16,"  running on DE2");
236
                           }
237
              }
238
             break;
239
        case 16:
240
            // test charram
241
            hexlsb0(readMemory(0x57D6));
242
            hexmsb0(readMemory(0x57D7));
243
            hexmsb1(testCharRam());
244
            waitToExit();
245
            cls();
246
            break;
247
         case 32:
248
             printf("\n\n\n              Testing the printf C function and newlines \\n");
249
             cursorxy(10,10);
250
             printf("1******************** Z80SoC ********************");
251
             cursorxy(10,11);
252
             printf("2******************** Z80SoC ********************");
253
             cursorxy(10,12);
254
             printf("3******************** Z80SoC ********************");
255
             printf("<< end>>");
256
 
257
             printf("\n>>>printing after\n\n\n\n>>>four new lines\n");
258
 
259
             hexlsb0(readMemory(0x57D0));
260
             hexmsb0(readMemory(0x57D1));
261
 
262
             printf("    1\n");
263
             printf("    2\n");
264
             printf("    3\n\n");
265
             printf("    4\n");
266
 
267
             waitToExit();
268
             cls();
269
             break;
270
         case 64:
271
             cls();
272
             cursorxy(5,2);
273
             printf("Testing char type storage and retrieve using writeMemory() function\n");
274
             cursorxy(5,3);
275
             printf("Confirms that a single byte is being written");
276
             baseAddress = readMemoryInt(0x57D8);
277
             for (i=0; i<10; i++) {
278
                 writeMemory(baseAddress + i, i);
279
                 writeMemory(baseAddress + 20 + 9 - i, 9 - i);
280
             }
281
 
282
             cursorxy(5,5);
283
             printf("written up down");
284
             cursorxy(40,5);
285
             printf("written down up");
286
 
287
             for (i=0; i<10; i++) {
288
                 cursorxy(5,6+i);
289
                 printf("%d",readMemory(baseAddress + i));
290
                 cursorxy(40,6+i);
291
                 printf("%d",readMemory(baseAddress + 20 + i));
292
             }
293
 
294
             waitToExit();
295
             cls();
296
             break;
297
         case 128:
298
             // random number generator test
299
             printf("\n    Testing the random integer number generator implemented inside thr FPGA (0xFFCA)");
300
             cursorxy(5,5);
301
             for (i=0; i<2000; i++) {
302
                 direction = readMemoryInt(0x57C9); // get a rumdom number - integer
303
                 printf("%i ",direction);
304
             }
305
             waitToExit();
306
             cls();
307
             break;
308
     }
309
   }
310
}
311
 
312
 

powered by: WebSVN 2.1.0

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