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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [stdalone/] [memtest/] [main.c] - Blame information for rev 262

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 213 hellwig
/*
2
 * main.c -- ECO32 memory test
3
 */
4
 
5
 
6
#include "types.h"
7
#include "stdarg.h"
8
#include "iolib.h"
9
 
10
 
11
#define K               1024
12
#define M               (K * K)
13
#define MEM_ADDR        ((void *) (0xC0000000 + 0x10000 + 0x3000))
14
#define MEM_SIZE        (32 * M - (0x10000 + 0x3000))
15
#define PASSES          3
16
 
17
 
18
/**************************************************************/
19
 
20
 
21
unsigned int randomNumber;
22
 
23
 
24
void setRandomNumber(unsigned int seed) {
25
  randomNumber = seed;
26
}
27
 
28
 
29
unsigned int getRandomNumber(void) {
30
  randomNumber = randomNumber * (unsigned) 1103515245 + (unsigned) 12345;
31
  return randomNumber;
32
}
33
 
34
 
35
/**************************************************************/
36
 
37
 
38
void writeWords(void *start,
39
                unsigned int numWords,
40
                unsigned int seed) {
41
  unsigned int *addr;
42
  unsigned int rn;
43
 
44
  setRandomNumber(seed);
45
  addr = (unsigned int *) start;
46
  while (numWords -= 1) {
47
    rn = getRandomNumber();
48
    *addr++ = rn;
49
  }
50
}
51
 
52
 
53
void writeHalfs(void *start,
54
                unsigned int numHalfs,
55
                unsigned int seed) {
56
  unsigned short *addr;
57
  unsigned int rn;
58
 
59
  setRandomNumber(seed);
60
  addr = (unsigned short *) start;
61
  while (numHalfs -= 2) {
62
    rn = getRandomNumber();
63
    *addr++ = (rn >> 16) & 0x0000FFFF;
64
    *addr++ = (rn >>  0) & 0x0000FFFF;
65
  }
66
}
67
 
68
 
69
void writeBytes(void *start,
70
                unsigned int numBytes,
71
                unsigned int seed) {
72
  unsigned char *addr;
73
  unsigned int rn;
74
 
75
  setRandomNumber(seed);
76
  addr = (unsigned char *) start;
77
  while (numBytes -= 4) {
78
    rn = getRandomNumber();
79
    *addr++ = (rn >> 24) & 0x000000FF;
80
    *addr++ = (rn >> 16) & 0x000000FF;
81
    *addr++ = (rn >>  8) & 0x000000FF;
82
    *addr++ = (rn >>  0) & 0x000000FF;
83
  }
84
}
85
 
86
 
87
unsigned int readWords(void *start,
88
                       unsigned int numWords,
89
                       unsigned int seed) {
90
  unsigned int errors;
91
  unsigned int *addr;
92
  unsigned int rn;
93
 
94
  errors = 0;
95
  setRandomNumber(seed);
96
  addr = (unsigned int *) start;
97
  while (numWords -= 1) {
98
    rn = getRandomNumber();
99
    if (*addr++ != rn) {
100
      errors++;
101
    }
102
  }
103
  return errors;
104
}
105
 
106
 
107
unsigned int readHalfs(void *start,
108
                       unsigned int numHalfs,
109
                       unsigned int seed) {
110
  unsigned int errors;
111
  unsigned short *addr;
112
  unsigned int rn;
113
 
114
  errors = 0;
115
  setRandomNumber(seed);
116
  addr = (unsigned short *) start;
117
  while (numHalfs -= 2) {
118
    rn = getRandomNumber();
119
    if (*addr++ != ((rn >> 16) & 0x0000FFFF)) {
120
      errors++;
121
    }
122
    if (*addr++ != ((rn >>  0) & 0x0000FFFF)) {
123
      errors++;
124
    }
125
  }
126
  return errors;
127
}
128
 
129
 
130
unsigned int readBytes(void *start,
131
                       unsigned int numBytes,
132
                       unsigned int seed) {
133
  unsigned int errors;
134
  unsigned char *addr;
135
  unsigned int rn;
136
 
137
  errors = 0;
138
  setRandomNumber(seed);
139
  addr = (unsigned char *) start;
140
  while (numBytes -= 4) {
141
    rn = getRandomNumber();
142
    if (*addr++ != ((rn >> 24) & 0x000000FF)) {
143
      errors++;
144
    }
145
    if (*addr++ != ((rn >> 16) & 0x000000FF)) {
146
      errors++;
147
    }
148
    if (*addr++ != ((rn >>  8) & 0x000000FF)) {
149
      errors++;
150
    }
151
    if (*addr++ != ((rn >>  0) & 0x000000FF)) {
152
      errors++;
153
    }
154
  }
155
  return errors;
156
}
157
 
158
 
159
/**************************************************************/
160
 
161
 
162
void memtest(void *start, unsigned int size, int passes) {
163
  int i;
164
  int j;
165
  unsigned int seed;
166
 
167
  setRandomNumber(10007);
168
  for (i = 1; i <= passes; i++) {
169
    printf("Pass %d\n", i);
170
    /* -------------------- */
171
    printf("  writing words...\n");
172
    for (j = 0; j < i; j++) {
173
      getRandomNumber();
174
    }
175
    seed = getRandomNumber();
176
    writeWords(start, size / 4, seed);
177
    printf("    reading words: ");
178
    printf("%d", readWords(start, size / 4, seed));
179
    printf(" errors\n");
180
    printf("    reading halfs: ");
181
    printf("%d", readHalfs(start, size / 2, seed));
182
    printf(" errors\n");
183
    printf("    reading bytes: ");
184
    printf("%d", readBytes(start, size / 1, seed));
185
    printf(" errors\n");
186
    /* -------------------- */
187
    printf("  writing halfs...\n");
188
    for (j = 0; j < i; j++) {
189
      getRandomNumber();
190
    }
191
    seed = getRandomNumber();
192
    writeHalfs(start, size / 2, seed);
193
    printf("    reading words: ");
194
    printf("%d", readWords(start, size / 4, seed));
195
    printf(" errors\n");
196
    printf("    reading halfs: ");
197
    printf("%d", readHalfs(start, size / 2, seed));
198
    printf(" errors\n");
199
    printf("    reading bytes: ");
200
    printf("%d", readBytes(start, size / 1, seed));
201
    printf(" errors\n");
202
    /* -------------------- */
203
    printf("  writing bytes...\n");
204
    for (j = 0; j < i; j++) {
205
      getRandomNumber();
206
    }
207
    seed = getRandomNumber();
208
    writeBytes(start, size / 1, seed);
209
    printf("    reading words: ");
210
    printf("%d", readWords(start, size / 4, seed));
211
    printf(" errors\n");
212
    printf("    reading halfs: ");
213
    printf("%d", readHalfs(start, size / 2, seed));
214
    printf(" errors\n");
215
    printf("    reading bytes: ");
216
    printf("%d", readBytes(start, size / 1, seed));
217
    printf(" errors\n");
218
  }
219
}
220
 
221
 
222
/**************************************************************/
223
 
224
 
225
int main(void) {
226
  printf("\nECO32 memory test started\n\n");
227
  memtest(MEM_ADDR, MEM_SIZE, PASSES);
228
  printf("\nECO32 memory test finished\n");
229
  return 0;
230
}

powered by: WebSVN 2.1.0

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