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

Subversion Repositories z80soc

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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