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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [stdalone/] [dskchk/] [main.c] - Blame information for rev 272

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

Line No. Rev Author Line
1 18 hellwig
/*
2
 * main.c -- start the ball rolling
3
 */
4
 
5
 
6
#include "stdarg.h"
7
#include "start.h"
8
#include "idedsk.h"
9
 
10
 
11
#define NUM_SECTORS     500
12
#define SECTOR_RANGE    8000
13
 
14
#define NUM_BLOCKS      300
15
#define BLOCK_RANGE     1000
16
 
17
 
18
/**************************************************************/
19
 
20
 
21
#define RAND_MAX        0x7FFF
22
 
23
 
24 259 hellwig
static unsigned int randomNumber = 1;
25 18 hellwig
 
26
 
27
void srand(int seed) {
28
  randomNumber = seed;
29
}
30
 
31
 
32
int rand(void) {
33
  randomNumber = randomNumber * 1103515245 + 12345;
34
  return (unsigned int)(randomNumber >> 16) & RAND_MAX;
35
}
36
 
37
 
38
/**************************************************************/
39
 
40
 
41
void putchar(char c) {
42
  unsigned int *base;
43
 
44
  if (c == '\n') {
45
    putchar('\r');
46
  }
47
  base = (unsigned int *) 0xF0300000;
48
  while ((*(base + 2) & 1) == 0) ;
49
  *(base + 3) = c;
50
}
51
 
52
 
53
void puts(char *s) {
54
  char c;
55
 
56
  while ((c = *s++) != '\0') {
57
    putchar(c);
58
  }
59
}
60
 
61
 
62
void printn(int n) {
63
  int a;
64
 
65
  if (n < 0) {
66
    putchar('-');
67
    n = -n;
68
  }
69
  a = n / 10;
70
  if (a != 0) {
71
    printn(a);
72
  }
73
  putchar(n % 10 + '0');
74
}
75
 
76
 
77
void printu(unsigned int n, unsigned int b) {
78
  unsigned int a;
79
 
80
  a = n / b;
81
  if (a != 0) {
82
    printu(a, b);
83
  }
84
  putchar("0123456789ABCDEF"[n % b]);
85
}
86
 
87
 
88
void printf(char *fmt, ...) {
89
  va_list ap;
90
  char c;
91
  int n;
92
  unsigned int u;
93
  char *s;
94
 
95
  va_start(ap, fmt);
96
  while (1) {
97
    while ((c = *fmt++) != '%') {
98
      if (c == '\0') {
99
        va_end(ap);
100
        return;
101
      }
102
      putchar(c);
103
    }
104
    c = *fmt++;
105
    if (c == 'd') {
106
      n = va_arg(ap, int);
107
      printn(n);
108
    } else
109
    if (c == 'u' || c == 'o' || c == 'x') {
110
      u = va_arg(ap, int);
111
      printu(u, c == 'o' ? 8 : (c == 'x' ? 16 : 10));
112
    } else
113
    if (c == 's') {
114
      s = va_arg(ap, char *);
115
      puts(s);
116
    } else {
117
      putchar(c);
118
    }
119
  }
120
}
121
 
122
 
123
/**************************************************************/
124
 
125
 
126
static char *exceptionCause[32] = {
127
  /* 00 */  "terminal 0 transmitter interrupt",
128
  /* 01 */  "terminal 0 receiver interrupt",
129
  /* 02 */  "terminal 1 transmitter interrupt",
130
  /* 03 */  "terminal 1 receiver interrupt",
131
  /* 04 */  "keyboard interrupt",
132
  /* 05 */  "unknown interrupt",
133
  /* 06 */  "unknown interrupt",
134
  /* 07 */  "unknown interrupt",
135
  /* 08 */  "disk interrupt",
136
  /* 09 */  "unknown interrupt",
137
  /* 10 */  "unknown interrupt",
138
  /* 11 */  "unknown interrupt",
139
  /* 12 */  "unknown interrupt",
140
  /* 13 */  "unknown interrupt",
141 38 hellwig
  /* 14 */  "timer 0 interrupt",
142
  /* 15 */  "timer 1 interrupt",
143 18 hellwig
  /* 16 */  "bus timeout exception",
144
  /* 17 */  "illegal instruction exception",
145
  /* 18 */  "privileged instruction exception",
146
  /* 19 */  "divide instruction exception",
147
  /* 20 */  "trap instruction exception",
148
  /* 21 */  "TLB miss exception",
149
  /* 22 */  "TLB write exception",
150
  /* 23 */  "TLB invalid exception",
151
  /* 24 */  "illegal address exception",
152
  /* 25 */  "privileged address exception",
153
  /* 26 */  "unknown exception",
154
  /* 27 */  "unknown exception",
155
  /* 28 */  "unknown exception",
156
  /* 29 */  "unknown exception",
157
  /* 30 */  "unknown exception",
158
  /* 31 */  "unknown exception"
159
};
160
 
161
 
162
int defaultISR(int irq) {
163
  printf("\n%s\n", exceptionCause[irq]);
164
  return 0;  /* do not skip any instruction */
165
}
166
 
167
 
168
void initInterrupts(void) {
169
  int i;
170
 
171
  for (i = 0; i < 32; i++) {
172
    setISR(i, defaultISR);
173
  }
174
}
175
 
176
 
177
/**************************************************************/
178
 
179
 
180
#define TIMER_CTRL      ((unsigned *) 0xF0000000)
181
#define TIMER_DIV       ((unsigned *) 0xF0000004)
182
 
183
 
184
int hundredth = 0;
185
 
186
 
187
int clockISR(int irq) {
188
  *TIMER_CTRL = 2;
189
  hundredth++;
190
  return 0;
191
}
192
 
193
 
194
void initClock(void) {
195
  setISR(14, clockISR);
196 38 hellwig
  *TIMER_DIV = 500000;
197 18 hellwig
  *TIMER_CTRL = 2;
198
  setMask(1 << 14);
199
  enable();
200
}
201
 
202
 
203
/**************************************************************/
204
 
205
 
206
void checkDisk1(void) {
207
  unsigned res;
208
 
209
  printf("\nIs the disk present?\n");
210
  res = *DISK_CTRL;
211
  printf("yes, CTRL = 0x%x\n", res);
212
}
213
 
214
 
215
void checkDisk2(void) {
216
  int start;
217
  int ready;
218
 
219
  printf("\nDoes the disk get ready?\n");
220
  start = hundredth;
221
  ready = 0;
222
  while (start + 10 * 100 > hundredth) {
223
    if (*DISK_CTRL & DISK_CTRL_READY) {
224
      ready = hundredth;
225
      break;
226
    }
227
  }
228
  if (ready == 0) {
229
    printf("disk did not get ready\n");
230
  } else {
231
    printf("disk got ready after %d/100 seconds\n", ready - start);
232
  }
233
}
234
 
235
 
236
void checkDisk3(void) {
237
  int errors;
238
  int seed;
239
  unsigned int *p;
240
  int i, j;
241
 
242
  printf("\nDisk sector buffer read/write\n");
243
  errors = 0;
244
  srand(321);
245
  for (i = 0; i < NUM_SECTORS; i++) {
246
    seed = rand();
247
    srand(seed);
248
    p = DISK_BUFFER;
249
    for (j = 0; j < WPS; j++) {
250
      *p++ = rand();
251
    }
252
    srand(seed);
253
    p = DISK_BUFFER;
254
    for (j = 0; j < WPS; j++) {
255
      if (*p++ != rand()) {
256
        errors++;
257
        break;
258
      }
259
    }
260
  }
261
  printf("%d errors in %d sectors\n", errors, NUM_SECTORS);
262
}
263
 
264
 
265
void checkDisk4(void) {
266
  int sector;
267
  unsigned int *p;
268
  int i, j;
269
  int start, done;
270
  int errors;
271
 
272
  printf("\nRandom sector read/write, polled\n");
273
  printf("writing...\n");
274
  srand(321);
275
  for (i = 0; i < NUM_SECTORS; i++) {
276
    sector = rand() % SECTOR_RANGE;
277
    p = DISK_BUFFER;
278
    for (j = 0; j < WPS; j++) {
279
      *p++ = sector + j;
280
    }
281
    *DISK_SCT = sector;
282
    *DISK_CNT = 1;
283
    *DISK_CTRL = *DISK_CTRL
284
                 & ~(DISK_CTRL_DONE | DISK_CTRL_ERR)
285
                 | (DISK_CTRL_WRT | DISK_CTRL_STRT);
286
    start = hundredth;
287
    done = 0;
288
    while (start + 2 * 100 > hundredth) {
289
      if (*DISK_CTRL & DISK_CTRL_DONE) {
290
        done = hundredth;
291
        break;
292
      }
293
    }
294
    if (done == 0) {
295
      printf("disk did not complete a sector write command\n");
296
      return;
297
    }
298
  }
299
  printf("reading...\n");
300
  errors = 0;
301
  srand(321);
302
  for (i = 0; i < NUM_SECTORS; i++) {
303
    sector = rand() % SECTOR_RANGE;
304
    *DISK_SCT = sector;
305
    *DISK_CNT = 1;
306
    *DISK_CTRL = *DISK_CTRL
307
                 & ~(DISK_CTRL_DONE | DISK_CTRL_ERR | DISK_CTRL_WRT)
308
                 | DISK_CTRL_STRT;
309
    start = hundredth;
310
    done = 0;
311
    while (start + 2 * 100 > hundredth) {
312
      if (*DISK_CTRL & DISK_CTRL_DONE) {
313
        done = hundredth;
314
        break;
315
      }
316
    }
317
    if (done == 0) {
318
      printf("disk did not complete a sector read command\n");
319
      return;
320
    }
321
    p = DISK_BUFFER;
322
    for (j = 0; j < WPS; j++) {
323
      if (*p++ != sector + j) {
324
        errors++;
325
        break;
326
      }
327
    }
328
  }
329
  printf("%d errors in %d sectors (range 0..%d)\n",
330
         errors, NUM_SECTORS, SECTOR_RANGE);
331
}
332
 
333
 
334
void checkDisk5(void) {
335
  int errors;
336
  int seed;
337
  unsigned int *p;
338
  int i, j;
339
 
340
  printf("\nDisk block buffer read/write\n");
341
  errors = 0;
342
  srand(321);
343
  for (i = 0; i < NUM_BLOCKS; i++) {
344
    seed = rand();
345
    srand(seed);
346
    p = DISK_BUFFER;
347
    for (j = 0; j < WPB; j++) {
348
      *p++ = rand();
349
    }
350
    srand(seed);
351
    p = DISK_BUFFER;
352
    for (j = 0; j < WPB; j++) {
353
      if (*p++ != rand()) {
354
        errors++;
355
        break;
356
      }
357
    }
358
  }
359
  printf("%d errors in %d blocks\n", errors, NUM_BLOCKS);
360
}
361
 
362
 
363
void checkDisk6(void) {
364
  int block;
365
  unsigned int *p;
366
  int i, j;
367
  int start, done;
368
  int errors;
369
 
370
  printf("\nRandom block read/write, polled\n");
371
  printf("writing...\n");
372
  srand(321);
373
  for (i = 0; i < NUM_BLOCKS; i++) {
374
    block = rand() % BLOCK_RANGE;
375
    p = DISK_BUFFER;
376
    for (j = 0; j < WPB; j++) {
377
      *p++ = block + j;
378
    }
379
    *DISK_SCT = 8 * block;
380
    *DISK_CNT = 8;
381
    *DISK_CTRL = *DISK_CTRL
382
                 & ~(DISK_CTRL_DONE | DISK_CTRL_ERR)
383
                 | (DISK_CTRL_WRT | DISK_CTRL_STRT);
384
    start = hundredth;
385
    done = 0;
386
    while (start + 2 * 100 > hundredth) {
387
      if (*DISK_CTRL & DISK_CTRL_DONE) {
388
        done = hundredth;
389
        break;
390
      }
391
    }
392
    if (done == 0) {
393
      printf("disk did not complete a block write command\n");
394
      return;
395
    }
396
  }
397
  printf("reading...\n");
398
  errors = 0;
399
  srand(321);
400
  for (i = 0; i < NUM_BLOCKS; i++) {
401
    block = rand() % BLOCK_RANGE;
402
    *DISK_SCT = 8 * block;
403
    *DISK_CNT = 8;
404
    *DISK_CTRL = *DISK_CTRL
405
                 & ~(DISK_CTRL_DONE | DISK_CTRL_ERR | DISK_CTRL_WRT)
406
                 | DISK_CTRL_STRT;
407
    start = hundredth;
408
    done = 0;
409
    while (start + 2 * 100 > hundredth) {
410
      if (*DISK_CTRL & DISK_CTRL_DONE) {
411
        done = hundredth;
412
        break;
413
      }
414
    }
415
    if (done == 0) {
416
      printf("disk did not complete a block read command\n");
417
      return;
418
    }
419
    p = DISK_BUFFER;
420
    for (j = 0; j < WPB; j++) {
421
      if (*p++ != block + j) {
422
        errors++;
423
        break;
424
      }
425
    }
426
  }
427
  printf("%d errors in %d blocks (range 0..%d)\n",
428
         errors, NUM_BLOCKS, BLOCK_RANGE);
429
}
430
 
431
 
432
/**************************************************************/
433
 
434
 
435
void main(void) {
436
  initInterrupts();
437
  initClock();
438
  checkDisk1();
439
  checkDisk2();
440
  checkDisk3();
441
  checkDisk4();
442
  checkDisk5();
443
  checkDisk6();
444
  printf("\nHalting...\n");
445
}

powered by: WebSVN 2.1.0

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