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

Subversion Repositories mem_ctrl

[/] [mem_ctrl/] [trunk/] [bench/] [verilog/] [tests.v] - Blame information for rev 10

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

Line No. Rev Author Line
1 4 rudi
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  Top Level Test Bench                                       ////
4
////                                                             ////
5
////                                                             ////
6
////  Author: Rudolf Usselmann                                   ////
7
////          rudi@asics.ws                                      ////
8
////                                                             ////
9
////                                                             ////
10
////  Downloaded from: http://www.opencores.org/cores/mem_ctrl/  ////
11
////                                                             ////
12
/////////////////////////////////////////////////////////////////////
13
////                                                             ////
14
//// Copyright (C) 2000 Rudolf Usselmann                         ////
15
////                    rudi@asics.ws                            ////
16
////                                                             ////
17
//// This source file may be used and distributed without        ////
18
//// restriction provided that this copyright statement is not   ////
19
//// removed from the file and that any derivative work contains ////
20
//// the original copyright notice and the associated disclaimer.////
21
////                                                             ////
22
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
23
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
24
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
25
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
26
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
27
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
28
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
29
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
30
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
31
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
32
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
33
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
34
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
35
////                                                             ////
36
/////////////////////////////////////////////////////////////////////
37
 
38
//  CVS Log
39
//
40 10 rudi
//  $Id: tests.v,v 1.3 2001-09-02 02:29:43 rudi Exp $
41 4 rudi
//
42 10 rudi
//  $Date: 2001-09-02 02:29:43 $
43
//  $Revision: 1.3 $
44 4 rudi
//  $Author: rudi $
45
//  $Locker:  $
46
//  $State: Exp $
47
//
48
// Change History:
49
//               $Log: not supported by cvs2svn $
50 10 rudi
//               Revision 1.2  2001/08/10 08:16:21  rudi
51
//
52
//               - Changed IO names to be more clear.
53
//               - Uniquifyed define names to be core specific.
54
//               - Removed "Refresh Early" configuration
55
//
56 8 rudi
//               Revision 1.1  2001/07/29 07:34:40  rudi
57
//
58
//
59
//               1) Changed Directory Structure
60
//               2) Fixed several minor bugs
61
//
62 4 rudi
//               Revision 1.1.1.1  2001/05/13 09:36:38  rudi
63
//               Created Directory Structure
64
//
65
//
66
//
67
//                        
68
 
69
 
70
task sdram_rd1;
71
input           quick;
72
 
73
integer         quick;
74
integer         n;
75
integer         del, size;
76
reg     [7:0]    mode;
77
reg     [2:0]    bs;
78
integer         sz_inc;
79
integer         sz_max, del_max;
80
integer         write;
81
 
82
begin
83
$display("\n\n");
84
$display("*****************************************************");
85
$display("*** SDRAM Size, Delay & Mode Read test 1 ...      ***");
86
$display("*****************************************************\n");
87
 
88
m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
89
m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
90
 
91 10 rudi
m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
92
                                        4'd0,           // RESERVED [31:28]
93
                                        4'd7,           // Trfc [27:24]
94
                                        4'd2,           // Trp [23:20]
95
                                        3'd2,           // Trcd [19:17]
96
                                        2'd1,           // Twr [16:15]
97
                                        5'd0,           // RESERVED [14:10]
98
 
99 4 rudi
                                        1'd0,   // Wr. Burst Len (1=Single)
100
                                        2'd0,   // Op Mode
101
                                        3'd2,   // CL
102
                                        1'b0,   // Burst Type (0=Seq;1=Inter)
103
                                        3'd3    // Burst Length
104
                                        });
105
 
106 10 rudi
//m0.wb_wr1(`REG_BASE + `CSC0,  4'hf, 32'h0000_0821);
107
m0.wb_wr1(`REG_BASE + `CSC0,    4'hf, 32'h0000_0021);
108 4 rudi
 
109
case(quick)
110
 0: sz_max = 64;
111
 1: sz_max = 32;
112
 2: sz_max = 16;
113
endcase
114
 
115
case(quick)
116
 0: del_max = 16;
117
 1: del_max = 8;
118
 2: del_max = 4;
119
endcase
120
 
121 10 rudi
size = 4;
122
del = 1;
123
mode = 2;
124
write = 0;
125 4 rudi
//force sdram0.Debug = 1;
126
 
127
for(mode=0;mode<10;mode=mode+1)
128
begin
129
        sdram0.mem_fill(1024);
130 10 rudi
        //sdram0p.mem_fill(1024);
131 4 rudi
 
132
        case(mode[3:1])
133
           0: bs = 0;
134
           1: bs = 1;
135
           2: bs = 2;
136
           3: bs = 3;
137
           4: bs = 7;
138
        endcase
139
 
140
        case(mode[3:1])
141
           0: sz_inc = 1;
142
           1: sz_inc = 2;
143
           2: sz_inc = 4;
144
           3: sz_inc = 8;
145
           4: sz_inc = 1;
146
        endcase
147
 
148 10 rudi
        m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
149
                                        4'd0,           // RESERVED [31:28]
150
                                        4'd7,           // Trfc [27:24]
151
                                        4'd2,           // Trp [23:20]
152
                                        3'd2,           // Trcd [19:17]
153
                                        2'd1,           // Twr [16:15]
154
                                        5'd0,           // RESERVED [14:10]
155 4 rudi
                                        1'd0,           // Wr. Burst Len (1=Single)
156
                                        2'd0,           // Op Mode
157
                                        3'd2+mode[0],    // CL
158
                                        1'b0,           // Burst Type (0=Seq;1=Inter)
159
                                        3'd0+bs         // Burst Length
160
                                        });
161
 
162
if(!verbose)    $display("Mode: %b", mode);
163
for(del=0;del<del_max;del=del+1)
164
for(size=sz_inc;size<sz_max;size=size+sz_inc)
165
   begin
166
        m0.mem_fill;
167
 
168
        if(verbose)     $display("Mode: %b, Size: %0d, Delay: %0d", mode,  size, del);
169
 
170
        if(write)       m0.wb_wr_mult(`MEM_BASE +        0, 4'hf, del, size);
171
        m0.wb_rd_mult(`MEM_BASE +        0, 4'hf, del, size);
172
 
173
        if(write)       m0.wb_wr_mult(`MEM_BASE + size*1*4, 4'hf, del, size);
174
        m0.wb_rd_mult(`MEM_BASE + size*1*4, 4'hf, del, size);
175
 
176
        if(write)       m0.wb_wr_mult(`MEM_BASE + size*2*4, 4'hf, del, size);
177
        m0.wb_rd_mult(`MEM_BASE + size*2*4, 4'hf, del, size);
178
 
179
        if(write)       m0.wb_wr_mult(`MEM_BASE + size*3*4, 4'hf, del, size);
180
        m0.wb_rd_mult(`MEM_BASE + size*3*4, 4'hf, del, size);
181
 
182
        for(n=0;n<(size*4);n=n+1)
183
           begin
184
                if((sdram0.Bank0[n] !== m0.rd_mem[n]) |
185
                        (|sdram0.Bank0[n] === 1'bx) |
186
                        (|m0.rd_mem[n] === 1'bx)         )
187
                   begin
188
                        $display("ERROR: Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
189
                        n, sdram0.Bank0[n], m0.rd_mem[n],  $time);
190
                        error_cnt = error_cnt + 1;
191
                   end
192
           end
193
   end
194
 
195
end
196
 
197
show_errors;
198
$display("*****************************************************");
199
$display("*** Test DONE ...                                 ***");
200
$display("*****************************************************\n\n");
201
end
202
endtask
203
 
204
 
205
 
206
task sdram_wr1;
207
input           quick;
208
 
209
integer         quick;
210
integer         n;
211
integer         del, size;
212
reg     [7:0]    mode;
213
reg     [2:0]    bs;
214
integer         sz_inc;
215
integer         sz_max, del_max;
216
integer         read;
217
 
218
begin
219
$display("\n\n");
220
$display("*****************************************************");
221
$display("*** SDRAM Size, Delay & Mode Write test 1 ...     ***");
222
$display("*****************************************************\n");
223
 
224
m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
225
m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
226
 
227 10 rudi
m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
228
                                        4'd0,           // RESERVED [31:28]
229
                                        4'd7,           // Trfc [27:24]
230
                                        4'd2,           // Trp [23:20]
231
                                        3'd2,           // Trcd [19:17]
232
                                        2'd1,           // Twr [16:15]
233
                                        5'd0,           // RESERVED [14:10]
234 4 rudi
                                        1'd0,   // Wr. Burst Len (1=Single)
235
                                        2'd0,   // Op Mode
236
                                        3'd2,   // CL
237
                                        1'b0,   // Burst Type (0=Seq;1=Inter)
238
                                        3'd3    // Burst Length
239
                                        });
240
 
241
m0.wb_wr1(`REG_BASE + `CSC0,    4'hf, 32'h0000_0821);
242
 
243
case(quick)
244
 0: sz_max = 64;
245
 1: sz_max = 32;
246
 2: sz_max = 16;
247
endcase
248
 
249
case(quick)
250
 0: del_max = 16;
251
 1: del_max = 8;
252
 2: del_max = 4;
253
endcase
254
 
255 10 rudi
size = 1;
256
del = 0;
257 4 rudi
mode = 0;
258
read = 1;
259
//force sdram0.Debug = 1;
260
 
261
for(mode=0;mode<20;mode=mode+1)
262
begin
263
        sdram0.mem_fill(1024);
264
 
265
        case(mode[4:2])
266
           0: bs = 0;
267
           1: bs = 1;
268
           2: bs = 2;
269
           3: bs = 3;
270
           4: bs = 7;
271
        endcase
272
 
273
        if(mode[1])
274
           sz_inc = 1;
275
        else
276
                case(mode[4:2])
277
                   0: sz_inc = 1;
278
                   1: sz_inc = 2;
279
                   2: sz_inc = 4;
280
                   3: sz_inc = 8;
281
                   4: sz_inc = 1;
282
                endcase
283
 
284 10 rudi
        m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
285
                                        4'd0,           // RESERVED [31:28]
286
                                        4'd7,           // Trfc [27:24]
287
                                        4'd2,           // Trp [23:20]
288
                                        3'd2,           // Trcd [19:17]
289
                                        2'd1,           // Twr [16:15]
290
                                        5'd0,           // RESERVED [14:10]
291 4 rudi
                                        1'd0+mode[1],   // Wr. Burst Len (1=Single)
292
                                        2'd0,           // Op Mode
293
                                        3'd2+mode[0],    // CL
294
                                        1'b0,           // Burst Type (0=Seq;1=Inter)
295
                                        3'd0+bs         // Burst Length
296
                                        });
297
 
298
if(!verbose)    $display("Mode: %b", mode);
299
 
300
for(del=0;del<del_max;del=del+1)
301
for(size=sz_inc;size<sz_max;size=size+sz_inc)
302
   begin
303
        m0.mem_fill;
304
 
305
        if(verbose)     $display("Mode: %b, Size: %0d, Delay: %0d", mode,  size, del);
306
 
307
        m0.wb_wr_mult(`MEM_BASE +        0, 4'hf, del, size);
308
        if(read)        m0.wb_rd_mult(`MEM_BASE +        0, 4'hf, del, size);
309
 
310
        m0.wb_wr_mult(`MEM_BASE + size*1*4, 4'hf, del, size);
311
        if(read)        m0.wb_rd_mult(`MEM_BASE + size*1*4, 4'hf, del, size);
312
 
313
        m0.wb_wr_mult(`MEM_BASE + size*2*4, 4'hf, del, size);
314
        if(read)        m0.wb_rd_mult(`MEM_BASE + size*2*4, 4'hf, del, size);
315
 
316
        m0.wb_wr_mult(`MEM_BASE + size*3*4, 4'hf, del, size);
317
        if(read)        m0.wb_rd_mult(`MEM_BASE + size*3*4, 4'hf, del, size);
318
 
319
        repeat(10)      @(posedge clk);
320
 
321
        for(n=0;n< (size*4);n=n+1)
322
           begin
323
                if((sdram0.Bank0[n] !== m0.wr_mem[n]) |
324
                        (|sdram0.Bank0[n] === 1'bx) |
325
                        (|m0.wr_mem[n] === 1'bx)         )
326
                   begin
327
                        $display("ERROR: WR Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
328
                        n, sdram0.Bank0[n], m0.wr_mem[n],  $time);
329
                        error_cnt = error_cnt + 1;
330
                   end
331
           end
332
   end
333
 
334
end
335
 
336
show_errors;
337
$display("*****************************************************");
338
$display("*** Test DONE ...                                 ***");
339
$display("*****************************************************\n\n");
340
end
341
endtask
342
 
343
 
344
task sdram_rd2;
345
input           quick;
346
 
347
integer         quick;
348
integer         n,m,adr;
349
integer         del, size;
350
reg     [7:0]    mode;
351
reg     [2:0]    bs;
352
integer         sz_inc;
353
integer         sz_max, del_max;
354
reg     [2:0]    bas;
355
reg     [31:0]   data;
356
integer         page_size;
357
 
358
begin
359
 
360
$display("\n\n");
361
$display("*****************************************************");
362
$display("*** SDRAM Size, Delay & Mode Read test 2 ...      ***");
363
$display("*** Different Row and Bank                        ***");
364
$display("*****************************************************\n");
365
 
366
page_size = 256; // 64 mbit x 32 SDRAM
367
 
368
case(quick)
369
 0: sz_max = 32;
370
 1: sz_max = 32;
371
 2: sz_max = 16;
372
endcase
373
 
374
case(quick)
375
 0: del_max = 16;
376
 1: del_max = 8;
377
 2: del_max = 4;
378
endcase
379
 
380
m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
381
m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
382
 
383 10 rudi
m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
384
                                        4'd0,           // RESERVED [31:28]
385
                                        4'd7,           // Trfc [27:24]
386
                                        4'd2,           // Trp [23:20]
387
                                        3'd2,           // Trcd [19:17]
388
                                        2'd1,           // Twr [16:15]
389
                                        5'd0,           // RESERVED [14:10]
390 4 rudi
                                        1'd0,   // Wr. Burst Len (1=Single)
391
                                        2'd0,   // Op Mode
392
                                        3'd2,   // CL
393
                                        1'b0,   // Burst Type (0=Seq;1=Inter)
394
                                        3'd3    // Burst Length
395
                                        });
396
 
397
bas = 0;
398
for(bas=0;bas<2;bas=bas+1)
399
begin
400
m0.wb_wr1(`REG_BASE + `CSC0,    4'hf, 32'h0000_0821 | (bas[0]<<9));
401
 
402
size = 33;
403
del = 0;
404
mode = 0;
405
 
406
//force sdram0.Debug = 1;
407
 
408
for(mode=0;mode<10;mode=mode+1)
409
begin
410
        sdram0.mem_fill(1024);
411
 
412
        case(mode[3:1])
413
           0: bs = 0;
414
           1: bs = 1;
415
           2: bs = 2;
416
           3: bs = 3;
417
           4: bs = 7;
418
        endcase
419
 
420
        case(mode[3:1])
421
           0: sz_inc = 1;
422
           1: sz_inc = 2;
423
           2: sz_inc = 4;
424
           3: sz_inc = 8;
425
           4: sz_inc = 1;
426
        endcase
427
 
428 10 rudi
        m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
429
                                        4'd0,           // RESERVED [31:28]
430
                                        4'd7,           // Trfc [27:24]
431
                                        4'd2,           // Trp [23:20]
432
                                        3'd2,           // Trcd [19:17]
433
                                        2'd1,           // Twr [16:15]
434
                                        5'd0,           // RESERVED [14:10]
435 4 rudi
                                        1'd0,           // Wr. Burst Len (1=Single)
436
                                        2'd0,           // Op Mode
437
                                        3'd2+mode[0],    // CL
438
                                        1'b0,           // Burst Type (0=Seq;1=Inter)
439
                                        3'd0+bs         // Burst Length
440
                                        });
441
 
442
if(!verbose)    $display("BAS: %0d, Mode: %b", bas, mode);
443
 
444
for(del=0;del<del_max;del=del+1)
445
for(size=sz_inc;size<sz_max;size=size+sz_inc)
446
   begin
447
        m0.mem_fill;
448
 
449
        if(verbose)     $display("BAS: %0d, Mode: %b, Size: %0d, Delay: %0d",
450
                                bas, mode,  size, del);
451
 
452
        m0.wb_wr_mult(`MEM_BASE + (page_size*0*4) + size*0*4, 4'hf, del, size);
453
        m0.wb_rd_mult(`MEM_BASE + (page_size*0*4) + size*0*4, 4'hf, del, size);
454
        m0.wb_wr_mult(`MEM_BASE + (page_size*0*4) + size*1*4, 4'hf, del, size);
455
        m0.wb_rd_mult(`MEM_BASE + (page_size*0*4) + size*1*4, 4'hf, del, size);
456
 
457
        m0.wb_wr_mult(`MEM_BASE + (page_size*1*4) + size*2*4, 4'hf, del, size);
458
        m0.wb_rd_mult(`MEM_BASE + (page_size*1*4) + size*2*4, 4'hf, del, size);
459
        m0.wb_wr_mult(`MEM_BASE + (page_size*1*4) + size*3*4, 4'hf, del, size);
460
        m0.wb_rd_mult(`MEM_BASE + (page_size*1*4) + size*3*4, 4'hf, del, size);
461
 
462
        m0.wb_wr_mult(`MEM_BASE + (page_size*2*4) + size*4*4, 4'hf, del, size);
463
        m0.wb_rd_mult(`MEM_BASE + (page_size*2*4) + size*4*4, 4'hf, del, size);
464
        m0.wb_wr_mult(`MEM_BASE + (page_size*2*4) + size*5*4, 4'hf, del, size);
465
        m0.wb_rd_mult(`MEM_BASE + (page_size*2*4) + size*5*4, 4'hf, del, size);
466
 
467
        m0.wb_wr_mult(`MEM_BASE + (page_size*3*4) + size*6*4, 4'hf, del, size);
468
        m0.wb_rd_mult(`MEM_BASE + (page_size*3*4) + size*6*4, 4'hf, del, size);
469
        m0.wb_wr_mult(`MEM_BASE + (page_size*3*4) + size*7*4, 4'hf, del, size);
470
        m0.wb_rd_mult(`MEM_BASE + (page_size*3*4) + size*7*4, 4'hf, del, size);
471
 
472
        for(m=0;m<4;m=m+1)
473
        for(n=0;n<(size*2);n=n+1)
474
           begin
475
                adr = (m * page_size) + (m*size*2) + n;
476
 
477
                if(bas[0])       data = sdram0.Bank0[adr];
478
                else
479
                case(m)
480
                   0: data = sdram0.Bank0[n];
481
                   1: data = sdram0.Bank1[n+1*size*2];
482
                   2: data = sdram0.Bank2[n+2*size*2];
483
                   3: data = sdram0.Bank3[n+3*size*2];
484
                endcase
485
 
486
                if((data !== m0.rd_mem[(m*size*2)+n]) | (|data === 1'bx) |
487
                        (|m0.rd_mem[(m*size*2)+n] === 1'bx) )
488
                   begin
489
                        $display("ERROR: Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
490
                        (m*size*2)+n, data, m0.rd_mem[(m*size*2)+n],  $time);
491
                        error_cnt = error_cnt + 1;
492
                   end
493
 
494
           end
495
   end
496
 
497
end
498
end
499
 
500
show_errors;
501
$display("*****************************************************");
502
$display("*** Test DONE ...                                 ***");
503
$display("*****************************************************\n\n");
504
end
505
endtask
506
 
507
 
508
 
509
 
510
task sdram_wr2;
511
input           quick;
512
 
513
integer         quick;
514
integer         n,m,adr;
515
integer         del, size;
516
reg     [7:0]    mode;
517
reg     [2:0]    bs;
518
integer         sz_inc;
519
integer         sz_max, del_max;
520
integer         read;
521
reg     [2:0]    bas;
522
reg     [31:0]   data;
523
integer         page_size;
524
 
525
begin
526
$display("\n\n");
527
$display("*****************************************************");
528
$display("*** SDRAM Size, Delay & Mode Write test 2 ...     ***");
529
$display("*** Different Row and Bank                        ***");
530
$display("*****************************************************\n");
531
 
532
page_size = 256; // 64 mbit x 32 SDRAM
533
 
534
m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
535
m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
536
 
537 10 rudi
m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
538
                                        4'd0,           // RESERVED [31:28]
539
                                        4'd7,           // Trfc [27:24]
540
                                        4'd2,           // Trp [23:20]
541
                                        3'd2,           // Trcd [19:17]
542
                                        2'd1,           // Twr [16:15]
543
                                        5'd0,           // RESERVED [14:10]
544 4 rudi
                                        1'd0,   // Wr. Burst Len (1=Single)
545
                                        2'd0,   // Op Mode
546
                                        3'd2,   // CL
547
                                        1'b0,   // Burst Type (0=Seq;1=Inter)
548
                                        3'd3    // Burst Length
549
                                        });
550
 
551
bas = 0;
552
for(bas=0;bas<2;bas=bas+1)
553
begin
554
 
555 10 rudi
//m0.wb_wr1(`REG_BASE + `CSC0,  4'hf, 32'h0000_0821 | (bas[0]<<9));
556
m0.wb_wr1(`REG_BASE + `CSC0,    4'hf, 32'h0000_0021 | (bas[0]<<9));
557 4 rudi
 
558
case(quick)
559
 0: sz_max = 32;
560
 1: sz_max = 32;
561
 2: sz_max = 16;
562
endcase
563
 
564
case(quick)
565
 0: del_max = 16;
566
 1: del_max = 8;
567
 2: del_max = 4;
568
endcase
569
 
570 10 rudi
size = 3;
571
del = 0;
572
mode = 10;
573 4 rudi
read = 1;
574
//force sdram0.Debug = 1;
575
 
576
for(mode=0;mode<20;mode=mode+1)
577
begin
578
        sdram0.mem_fill(1024);
579
 
580
        case(mode[4:2])
581 10 rudi
           0: bs = 0;     // 1 Transfer
582
           1: bs = 1;   // 2 Transfers
583
           2: bs = 2;   // 4 Transfers
584
           3: bs = 3;   // 8 Transfers
585
           4: bs = 7;   // Page Size Transfer
586 4 rudi
        endcase
587
 
588
        if(mode[1])
589 10 rudi
           begin
590
                sz_inc = 1;
591
           end
592 4 rudi
        else
593 10 rudi
           begin
594 4 rudi
                case(mode[4:2])
595
                   0: sz_inc = 1;
596
                   1: sz_inc = 2;
597
                   2: sz_inc = 4;
598
                   3: sz_inc = 8;
599
                   4: sz_inc = 1;
600
                endcase
601 10 rudi
           end
602 4 rudi
 
603
        m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {         // 22'h3fff_ff,
604
 
605
                                        4'd0,           // RESERVED [31:28]
606
                                        4'd7,           // Trfc [27:24]
607
                                        4'd2,           // Trp [23:20]
608
                                        3'd2,           // Trcd [19:17]
609 10 rudi
                                        2'd1,           // Twr [16:15]
610 4 rudi
                                        5'd0,           // RESERVED [14:10]
611
 
612
                                        1'd0+mode[1],   // Wr. Burst Len (1=Single)
613
                                        2'd0,           // Op Mode
614
                                        3'd2+mode[0],    // CL
615
                                        1'b0,           // Burst Type (0=Seq;1=Inter)
616
                                        3'd0+bs         // Burst Length
617
                                        });
618
 
619
if(!verbose)    $display("BAS: %0d, Mode: %b", bas, mode);
620
 
621
for(del=0;del<del_max;del=del+1)
622
for(size=sz_inc;size<sz_max;size=size+sz_inc)
623
   begin
624
        m0.mem_fill;
625
 
626
        if(verbose)     $display("BAS: %0d, Mode: %b, Size: %0d, Delay: %0d",
627
                                bas, mode,  size, del);
628
 
629
                        m0.wb_wr_mult(`MEM_BASE + (page_size*0*4) + size*0*4, 4'hf, del, size);
630
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*0*4) + size*0*4, 4'hf, del, size);
631
                        m0.wb_wr_mult(`MEM_BASE + (page_size*0*4) + size*1*4, 4'hf, del, size);
632
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*0*4) + size*1*4, 4'hf, del, size);
633
 
634
                        m0.wb_wr_mult(`MEM_BASE + (page_size*1*4) + size*2*4, 4'hf, del, size);
635
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*1*4) + size*2*4, 4'hf, del, size);
636
                        m0.wb_wr_mult(`MEM_BASE + (page_size*1*4) + size*3*4, 4'hf, del, size);
637
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*1*4) + size*3*4, 4'hf, del, size);
638
 
639
                        m0.wb_wr_mult(`MEM_BASE + (page_size*2*4) + size*4*4, 4'hf, del, size);
640
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*2*4) + size*4*4, 4'hf, del, size);
641
                        m0.wb_wr_mult(`MEM_BASE + (page_size*2*4) + size*5*4, 4'hf, del, size);
642
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*2*4) + size*5*4, 4'hf, del, size);
643
 
644
                        m0.wb_wr_mult(`MEM_BASE + (page_size*3*4) + size*6*4, 4'hf, del, size);
645
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*3*4) + size*6*4, 4'hf, del, size);
646
                        m0.wb_wr_mult(`MEM_BASE + (page_size*3*4) + size*7*4, 4'hf, del, size);
647
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*3*4) + size*7*4, 4'hf, del, size);
648
 
649
        repeat(10)      @(posedge clk);
650
 
651
        for(m=0;m<4;m=m+1)
652
        for(n=0;n<size*2;n=n+1)
653
           begin
654
                adr = (m * page_size) + (m*size*2) + n;
655
 
656
                if(bas[0])       data = sdram0.Bank0[adr];
657
                else
658
                case(m)
659
                   0: data = sdram0.Bank0[n];
660
                   1: data = sdram0.Bank1[n+1*size*2];
661
                   2: data = sdram0.Bank2[n+2*size*2];
662
                   3: data = sdram0.Bank3[n+3*size*2];
663
                endcase
664
 
665 10 rudi
 
666
                if(read & 0)
667
                if((data !== m0.rd_mem[(m*size*2)+n]) | (|data === 1'bx) |
668
                        (|m0.rd_mem[(m*size*2)+n] === 1'bx) )
669
                   begin
670
                        $display("ERROR: RD Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
671
                        (m*size*2)+n, data, m0.rd_mem[(m*size*2)+n],  $time);
672
                        error_cnt = error_cnt + 1;
673
                   end
674
 
675 4 rudi
                if((data !== m0.wr_mem[(m*size*2)+n]) | (|data === 1'bx) |
676
                        (|m0.wr_mem[(m*size*2)+n] === 1'bx) )
677
                   begin
678
                        $display("ERROR: WR Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
679
                        (m*size*2)+n, data, m0.wr_mem[(m*size*2)+n],  $time);
680
                        error_cnt = error_cnt + 1;
681
                   end
682
 
683
           end
684
 
685
   end
686
end
687
end
688
 
689
show_errors;
690
$display("*****************************************************");
691
$display("*** Test DONE ...                                 ***");
692
$display("*****************************************************\n\n");
693
end
694
endtask
695
 
696
 
697
 
698
task sdram_rd3;
699
input           quick;
700
 
701
integer         quick;
702
integer         n;
703
integer         del, size;
704
reg     [7:0]    mode;
705
reg     [2:0]    bs;
706
integer         sz_inc;
707
integer         sz_max, del_max;
708
integer         sbs, write;
709
 
710
begin
711
 
712
$display("\n\n");
713
$display("*****************************************************");
714
$display("*** SDRAM Size, Delay & Mode Read test 3 ...      ***");
715
$display("*** Keep Row Open Active                          ***");
716
$display("*****************************************************\n");
717
 
718
m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
719
m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
720
 
721 10 rudi
m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
722
                                        4'd0,           // RESERVED [31:28]
723
                                        4'd7,           // Trfc [27:24]
724
                                        4'd2,           // Trp [23:20]
725
                                        3'd2,           // Trcd [19:17]
726
                                        2'd1,           // Twr [16:15]
727
                                        5'd0,           // RESERVED [14:10]
728 4 rudi
                                        1'd0,   // Wr. Burst Len (1=Single)
729
                                        2'd0,   // Op Mode
730
                                        3'd2,   // CL
731
                                        1'b0,   // Burst Type (0=Seq;1=Inter)
732
                                        3'd3    // Burst Length
733
                                        });
734
 
735
m0.wb_wr1(`REG_BASE + `CSC0,    4'hf, 32'h0000_0421);
736
 
737
case(quick)
738
 0: sz_max = 65;
739
 1: sz_max = 33;
740
 2: sz_max = 17;
741
endcase
742
 
743
case(quick)
744
 0: del_max = 16;
745
 1: del_max = 8;
746
 2: del_max = 4;
747
endcase
748
 
749
size = 4;
750
del = 0;
751
mode = 8;
752
write = 1;
753
//force sdram0.Debug = 1;
754
 
755
for(mode=0;mode<10;mode=mode+1)
756
begin
757
        sdram0.mem_fill(1024);
758
 
759
        case(mode[3:1])
760
           0: bs = 0;
761
           1: bs = 1;
762
           2: bs = 2;
763
           3: bs = 3;
764
           4: bs = 7;
765
        endcase
766
 
767
        case(mode[3:1])
768
           0: sbs = 1;
769
           1: sbs = 2;
770
           2: sbs = 4;
771
           3: sbs = 8;
772
           4: sbs = 1024;
773
        endcase
774
 
775
        case(mode[3:1])
776
           0: sz_inc = 1;
777
           1: sz_inc = 2;
778
           2: sz_inc = 4;
779
           3: sz_inc = 8;
780
           4: sz_inc = 1;
781
        endcase
782
 
783
        m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
784
 
785
                                        4'd0,           // RESERVED [31:28]
786
                                        4'd5,           // Trfc [27:24]
787
                                        4'd1,           // Trp [23:20]
788
                                        3'd1,           // Trcd [19:17]
789
                                        2'd1,           // Twr [16:15]
790
                                        5'd0,           // RESERVED [14:10]
791
 
792
                                        1'd0,           // Wr. Burst Len (1=Single)
793
                                        2'd0,           // Op Mode
794
                                        3'd2+mode[0],    // CL
795
                                        1'b0,           // Burst Type (0=Seq;1=Inter)
796
                                        3'd0+bs         // Burst Length
797
                                        });
798
 
799
 
800
if(!verbose)    $display("Mode: %b", mode);
801
 
802
for(del=0;del<del_max;del=del+1)
803
for(size=sz_inc;size<sz_max;size=size+sz_inc)
804
   begin
805
        m0.mem_fill;
806
 
807
        if(verbose)     $display("Mode: %b, Size: %0d, Delay: %0d", mode,  size, del);
808
 
809
//bw_clear;
810
        if(write)       m0.wb_wr_mult(`MEM_BASE +        0, 4'hf, del, size);
811
        m0.wb_rd_mult(`MEM_BASE +        0, 4'hf, del, size);
812
 
813
        if(write)       m0.wb_wr_mult(`MEM_BASE + size*1*4, 4'hf, del, size);
814
        m0.wb_rd_mult(`MEM_BASE + size*1*4, 4'hf, del, size);
815
 
816
        if(write)       m0.wb_wr_mult(`MEM_BASE + size*2*4, 4'hf, del, size);
817
        m0.wb_rd_mult(`MEM_BASE + size*2*4, 4'hf, del, size);
818
 
819
        if(write)       m0.wb_wr_mult(`MEM_BASE + size*3*4, 4'hf, del, size);
820
        m0.wb_rd_mult(`MEM_BASE + size*3*4, 4'hf, del, size);
821
 
822
//bw_report;
823
 
824
        for(n=0;n<(size*4);n=n+1)
825
           begin
826
                if((sdram0.Bank0[n] !== m0.rd_mem[n]) |
827
                        (|sdram0.Bank0[n] === 1'bx) |
828
                        (|m0.rd_mem[n] === 1'bx)         )
829
                   begin
830
                        $display("ERROR: Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
831
                        n, sdram0.Bank0[n], m0.rd_mem[n],  $time);
832
                        error_cnt = error_cnt + 1;
833
                   end
834
 
835
           end
836
   end
837
 
838
end
839
 
840
show_errors;
841
$display("*****************************************************");
842
$display("*** Test DONE ...                                 ***");
843
$display("*****************************************************\n\n");
844
end
845
endtask
846
 
847
 
848
 
849
task sdram_wr3;
850
input           quick;
851
 
852
integer         quick;
853
integer         n;
854
integer         del, size;
855
reg     [7:0]    mode;
856
reg     [2:0]    bs;
857
integer         sz_inc;
858
integer         sz_max, del_max;
859
integer         sbs, read;
860
 
861
begin
862
$display("\n\n");
863
$display("*****************************************************");
864
$display("*** SDRAM Size, Delay & Mode Write test 3 ...     ***");
865
$display("*** Keep Row Open Active                          ***");
866
$display("*****************************************************\n");
867
 
868
m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
869
m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
870
 
871 10 rudi
m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
872
                                        4'd0,           // RESERVED [31:28]
873
                                        4'd7,           // Trfc [27:24]
874
                                        4'd2,           // Trp [23:20]
875
                                        3'd2,           // Trcd [19:17]
876
                                        2'd1,           // Twr [16:15]
877
                                        5'd0,           // RESERVED [14:10]
878 4 rudi
                                        1'd0,   // Wr. Burst Len (1=Single)
879
                                        2'd0,   // Op Mode
880
                                        3'd2,   // CL
881
                                        1'b0,   // Burst Type (0=Seq;1=Inter)
882
                                        3'd3    // Burst Length
883
                                        });
884
 
885
m0.wb_wr1(`REG_BASE + `CSC0,    4'hf, 32'h0000_0421);
886
 
887
case(quick)
888
 0: sz_max = 64;
889
 1: sz_max = 32;
890
 2: sz_max = 16;
891
endcase
892
 
893
case(quick)
894
 0: del_max = 16;
895
 1: del_max = 8;
896
 2: del_max = 4;
897
endcase
898
 
899
size = 8;
900
del = 0;
901
mode = 16;
902
read = 0;
903
//force sdram0.Debug = 1;
904
 
905
for(mode=0;mode<20;mode=mode+1)
906
begin
907
 
908
        sdram0.mem_fill(1024);
909
 
910
        case(mode[4:2])
911
           0: bs = 0;
912
           1: bs = 1;
913
           2: bs = 2;
914
           3: bs = 3;
915
           4: bs = 7;
916
        endcase
917
 
918
        case(mode[4:2])
919
           0: sbs = 1;
920
           1: sbs = 2;
921
           2: sbs = 4;
922
           3: sbs = 8;
923
           4: sbs = 1024;
924
        endcase
925
 
926
        if(mode[1])
927
           sz_inc = 1;
928
        else
929
                case(mode[4:2])
930
                   0: sz_inc = 1;
931
                   1: sz_inc = 2;
932
                   2: sz_inc = 4;
933
                   3: sz_inc = 8;
934
                   4: sz_inc = 1;
935
                endcase
936
 
937
        m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
938
 
939
                                        4'd0,           // RESERVED [31:28]
940
                                        4'd5,           // Trfc [27:24]
941
                                        4'd1,           // Trp [23:20]
942
                                        3'd1,           // Trcd [19:17]
943
                                        2'd1,           // Twr [16:15]
944
                                        5'd0,           // RESERVED [14:10]
945
 
946
                                        1'd0+mode[1],   // Wr. Burst Len (1=Single)
947
                                        2'd0,           // Op Mode
948
                                        3'd2+mode[0],    // CL
949
                                        1'b0,           // Burst Type (0=Seq;1=Inter)
950
                                        3'd0+bs         // Burst Length
951
                                        });
952
 
953
if(!verbose)    $display("Mode: %b", mode);
954
 
955
for(del=0;del<del_max;del=del+1)
956
for(size=sz_inc;size<sz_max;size=size+sz_inc)
957
   begin
958
        m0.mem_fill;
959
//bw_clear;
960
        if(verbose)     $display("Mode: %b, Size: %0d, Delay: %0d", mode,  size, del);
961
 
962
        m0.wb_wr_mult(`MEM_BASE +        0, 4'hf, del, size);
963
        if(read)        m0.wb_rd_mult(`MEM_BASE +        0, 4'hf, del, size);
964
 
965
        m0.wb_wr_mult(`MEM_BASE + size*1*4, 4'hf, del, size);
966
        if(read)        m0.wb_rd_mult(`MEM_BASE + size*1*4, 4'hf, del, size);
967
 
968
        m0.wb_wr_mult(`MEM_BASE + size*2*4, 4'hf, del, size);
969
        if(read)        m0.wb_rd_mult(`MEM_BASE + size*2*4, 4'hf, del, size);
970
 
971
        m0.wb_wr_mult(`MEM_BASE + size*3*4, 4'hf, del, size);
972
        if(read)        m0.wb_rd_mult(`MEM_BASE + size*3*4, 4'hf, del, size);
973
 
974
//bw_report;
975
        repeat(10)      @(posedge clk);
976
 
977
        for(n=0;n< (size*4);n=n+1)
978
           begin
979
                if((sdram0.Bank0[n] !== m0.wr_mem[n]) |
980
                        (|sdram0.Bank0[n] === 1'bx) |
981
                        (|m0.wr_mem[n] === 1'bx)         )
982
                   begin
983
                        $display("ERROR: WR Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
984
                        n, sdram0.Bank0[n], m0.wr_mem[n],  $time);
985
                        error_cnt = error_cnt + 1;
986
                   end
987
           end
988
   end
989
 
990
end
991
 
992
show_errors;
993
$display("*****************************************************");
994
$display("*** Test DONE ...                                 ***");
995
$display("*****************************************************\n\n");
996
end
997
endtask
998
 
999
 
1000
 
1001
task sdram_rd4;
1002
input           quick;
1003
 
1004
integer         quick;
1005
integer         n,m,adr;
1006
integer         del, size;
1007
reg     [7:0]    mode;
1008
reg     [2:0]    bs;
1009
integer         sz_inc;
1010
integer         sz_max, del_max;
1011
reg     [2:0]    bas;
1012
reg     [31:0]   data;
1013
integer         page_size;
1014
integer         write;
1015
 
1016
begin
1017
 
1018
$display("\n\n");
1019
$display("*****************************************************");
1020
$display("*** SDRAM Size, Delay & Mode Read test 4 ...      ***");
1021
$display("*** KRO & Different Row and Bank                  ***");
1022
$display("*****************************************************\n");
1023
 
1024
page_size = 256; // 64 mbit x 32 SDRAM
1025
 
1026
case(quick)
1027
 0: sz_max = 32;
1028
 1: sz_max = 32;
1029
 2: sz_max = 16;
1030
endcase
1031
 
1032
case(quick)
1033
 0: del_max = 16;
1034
 1: del_max = 8;
1035
 2: del_max = 4;
1036
endcase
1037
 
1038
m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
1039
m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
1040
 
1041 10 rudi
m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
1042
                                        4'd0,           // RESERVED [31:28]
1043
                                        4'd7,           // Trfc [27:24]
1044
                                        4'd2,           // Trp [23:20]
1045
                                        3'd2,           // Trcd [19:17]
1046
                                        2'd1,           // Twr [16:15]
1047
                                        5'd0,           // RESERVED [14:10]
1048 4 rudi
                                        1'd0,   // Wr. Burst Len (1=Single)
1049
                                        2'd0,   // Op Mode
1050
                                        3'd2,   // CL
1051
                                        1'b0,   // Burst Type (0=Seq;1=Inter)
1052
                                        3'd3    // Burst Length
1053
                                        });
1054
 
1055
bas = 0;
1056
for(bas=0;bas<2;bas=bas+1)
1057
begin
1058
m0.wb_wr1(`REG_BASE + `CSC0,    4'hf, 32'h0000_0421 | (bas[0]<<9));
1059
 
1060
size = 2;
1061
del = 0;
1062
mode = 8;
1063
write = 1;
1064
//force sdram0.Debug = 1;
1065
 
1066
for(mode=0;mode<10;mode=mode+1)
1067
begin
1068
        sdram0.mem_fill(1024);
1069
 
1070
        case(mode[3:1])
1071
           0: bs = 0;
1072
           1: bs = 1;
1073
           2: bs = 2;
1074
           3: bs = 3;
1075
           4: bs = 7;
1076
        endcase
1077
 
1078
        case(mode[3:1])
1079
           0: sz_inc = 1;
1080
           1: sz_inc = 2;
1081
           2: sz_inc = 4;
1082
           3: sz_inc = 8;
1083
           4: sz_inc = 1;
1084
        endcase
1085
 
1086 10 rudi
        m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
1087
                                        4'd0,           // RESERVED [31:28]
1088
                                        4'd7,           // Trfc [27:24]
1089
                                        4'd2,           // Trp [23:20]
1090
                                        3'd2,           // Trcd [19:17]
1091
                                        2'd1,           // Twr [16:15]
1092
                                        5'd0,           // RESERVED [14:10]
1093 4 rudi
                                        1'd0,           // Wr. Burst Len (1=Single)
1094
                                        2'd0,           // Op Mode
1095
                                        3'd2+mode[0],    // CL
1096
                                        1'b0,           // Burst Type (0=Seq;1=Inter)
1097
                                        3'd0+bs         // Burst Length
1098
                                        });
1099
 
1100
if(!verbose)    $display("BAS: %0d, Mode: %b", bas, mode);
1101
 
1102
for(del=0;del<del_max;del=del+1)
1103
for(size=sz_inc;size<sz_max;size=size+sz_inc)
1104
   begin
1105
        m0.mem_fill;
1106
        if(verbose)     $display("BAS: %0d, Mode: %b, Size: %0d, Delay: %0d",
1107
                                bas, mode,  size, del);
1108
 
1109
        if(write)
1110
        m0.wb_wr_mult(`MEM_BASE + (page_size*0*4) + size*0*4, 4'hf, del, size);
1111
        m0.wb_rd_mult(`MEM_BASE + (page_size*0*4) + size*0*4, 4'hf, del, size);
1112
        if(write)
1113
        m0.wb_wr_mult(`MEM_BASE + (page_size*0*4) + size*1*4, 4'hf, del, size);
1114
        m0.wb_rd_mult(`MEM_BASE + (page_size*0*4) + size*1*4, 4'hf, del, size);
1115
 
1116
        if(write)
1117
        m0.wb_wr_mult(`MEM_BASE + (page_size*1*4) + size*2*4, 4'hf, del, size);
1118
        m0.wb_rd_mult(`MEM_BASE + (page_size*1*4) + size*2*4, 4'hf, del, size);
1119
        if(write)
1120
        m0.wb_wr_mult(`MEM_BASE + (page_size*1*4) + size*3*4, 4'hf, del, size);
1121
        m0.wb_rd_mult(`MEM_BASE + (page_size*1*4) + size*3*4, 4'hf, del, size);
1122
 
1123
        if(write)
1124
        m0.wb_wr_mult(`MEM_BASE + (page_size*2*4) + size*4*4, 4'hf, del, size);
1125
        m0.wb_rd_mult(`MEM_BASE + (page_size*2*4) + size*4*4, 4'hf, del, size);
1126
        if(write)
1127
        m0.wb_wr_mult(`MEM_BASE + (page_size*2*4) + size*5*4, 4'hf, del, size);
1128
        m0.wb_rd_mult(`MEM_BASE + (page_size*2*4) + size*5*4, 4'hf, del, size);
1129
 
1130
        if(write)
1131
        m0.wb_wr_mult(`MEM_BASE + (page_size*3*4) + size*6*4, 4'hf, del, size);
1132
        m0.wb_rd_mult(`MEM_BASE + (page_size*3*4) + size*6*4, 4'hf, del, size);
1133
        if(write)
1134
        m0.wb_wr_mult(`MEM_BASE + (page_size*3*4) + size*7*4, 4'hf, del, size);
1135
        m0.wb_rd_mult(`MEM_BASE + (page_size*3*4) + size*7*4, 4'hf, del, size);
1136
 
1137
        for(m=0;m<4;m=m+1)
1138
        for(n=0;n<(size*2);n=n+1)
1139
           begin
1140
                adr = (m * page_size) + (m*(size*2)) + n;
1141
 
1142
                if(bas[0])       data = sdram0.Bank0[adr];
1143
                else
1144
                case(m)
1145
                   0: data = sdram0.Bank0[n];
1146
                   1: data = sdram0.Bank1[n+1*size*2];
1147
                   2: data = sdram0.Bank2[n+2*size*2];
1148
                   3: data = sdram0.Bank3[n+3*size*2];
1149
                endcase
1150
 
1151
                if((data !== m0.rd_mem[(m*size*2)+n]) | (|data === 1'bx) |
1152
                        (|m0.rd_mem[(m*size*2)+n] === 1'bx) )
1153
                   begin
1154
                        $display("ERROR: Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
1155
                        (m*size*2)+n, data, m0.rd_mem[(m*size*2)+n],  $time);
1156
                        error_cnt = error_cnt + 1;
1157
                   end
1158
 
1159
           end
1160
   end
1161
end
1162
 
1163
end
1164
 
1165
show_errors;
1166
$display("*****************************************************");
1167
$display("*** Test DONE ...                                 ***");
1168
$display("*****************************************************\n\n");
1169
end
1170
endtask
1171
 
1172
 
1173
 
1174
 
1175
task sdram_wr4;
1176
input           quick;
1177
 
1178
integer         quick;
1179
integer         n,m,adr;
1180
integer         del, size;
1181
reg     [7:0]    mode;
1182
reg     [2:0]    bs;
1183
integer         sz_inc;
1184
integer         sz_max, del_max;
1185
integer         read;
1186
reg     [2:0]    bas;
1187
reg     [31:0]   data;
1188
integer         page_size;
1189
 
1190
begin
1191
$display("\n\n");
1192
$display("*****************************************************");
1193
$display("*** SDRAM Size, Delay & Mode Write test 4 ...     ***");
1194
$display("*** KRO & Different Row and Bank                  ***");
1195
$display("*****************************************************\n");
1196
 
1197
//force sdram0.Debug = 1;
1198
 
1199
page_size = 256; // 64 mbit x 32 SDRAM
1200
 
1201
m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
1202
m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
1203
 
1204 10 rudi
m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
1205
                                        4'd0,           // RESERVED [31:28]
1206
                                        4'd7,           // Trfc [27:24]
1207
                                        4'd2,           // Trp [23:20]
1208
                                        3'd2,           // Trcd [19:17]
1209
                                        2'd1,           // Twr [16:15]
1210
                                        5'd0,           // RESERVED [14:10]
1211 4 rudi
                                        1'd0,   // Wr. Burst Len (1=Single)
1212
                                        2'd0,   // Op Mode
1213
                                        3'd2,   // CL
1214
                                        1'b0,   // Burst Type (0=Seq;1=Inter)
1215
                                        3'd3    // Burst Length
1216
                                        });
1217
 
1218
bas = 0;
1219
for(bas=0;bas<2;bas=bas+1)
1220
begin
1221
 
1222
m0.wb_wr1(`REG_BASE + `CSC0,    4'hf, 32'h0000_0421 | (bas[0]<<9));
1223
 
1224
case(quick)
1225
 0: sz_max = 32;
1226
 1: sz_max = 32;
1227
 2: sz_max = 16;
1228
endcase
1229
 
1230
case(quick)
1231
 0: del_max = 16;
1232
 1: del_max = 8;
1233
 2: del_max = 4;
1234
endcase
1235
 
1236
size = 15;
1237
del = 0;
1238
mode = 19;
1239
read = 1;
1240
 
1241
for(mode=0;mode<20;mode=mode+1)
1242
begin
1243
 
1244
        sdram0.mem_fill(1024);
1245
 
1246
        case(mode[4:2])
1247
           0: bs = 0;
1248
           1: bs = 1;
1249
           2: bs = 2;
1250
           3: bs = 3;
1251
           4: bs = 7;
1252
        endcase
1253
 
1254
        if(mode[1])
1255
           sz_inc = 1;
1256
        else
1257
                case(mode[4:2])
1258
                   0: sz_inc = 1;
1259
                   1: sz_inc = 2;
1260
                   2: sz_inc = 4;
1261
                   3: sz_inc = 8;
1262
                   4: sz_inc = 1;
1263
                endcase
1264
 
1265 10 rudi
        m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
1266
                                        4'd0,           // RESERVED [31:28]
1267
                                        4'd7,           // Trfc [27:24]
1268
                                        4'd2,           // Trp [23:20]
1269
                                        3'd2,           // Trcd [19:17]
1270
                                        2'd1,           // Twr [16:15]
1271
                                        5'd0,           // RESERVED [14:10]
1272 4 rudi
                                        1'd0+mode[1],   // Wr. Burst Len (1=Single)
1273
                                        2'd0,           // Op Mode
1274
                                        3'd2+mode[0],    // CL
1275
                                        1'b0,           // Burst Type (0=Seq;1=Inter)
1276
                                        3'd0+bs         // Burst Length
1277
                                        });
1278
 
1279
if(!verbose)    $display("BAS: %0d, Mode: %b", bas, mode);
1280
 
1281
for(del=0;del<del_max;del=del+1)
1282
for(size=sz_inc;size<sz_max;size=size+sz_inc)
1283
   begin
1284
        m0.mem_fill;
1285
        if(verbose)     $display("BAS: %0d, Mode: %b, Size: %0d, Delay: %0d",
1286
                                bas, mode,  size, del);
1287
 
1288
                        m0.wb_wr_mult(`MEM_BASE + (page_size*0*4) + size*0*4, 4'hf, del, size);
1289
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*0*4) + size*0*4, 4'hf, del, size);
1290
                        m0.wb_wr_mult(`MEM_BASE + (page_size*0*4) + size*1*4, 4'hf, del, size);
1291
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*0*4) + size*1*4, 4'hf, del, size);
1292
 
1293
                        m0.wb_wr_mult(`MEM_BASE + (page_size*1*4) + size*2*4, 4'hf, del, size);
1294
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*1*4) + size*2*4, 4'hf, del, size);
1295
                        m0.wb_wr_mult(`MEM_BASE + (page_size*1*4) + size*3*4, 4'hf, del, size);
1296
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*1*4) + size*3*4, 4'hf, del, size);
1297
 
1298
                        m0.wb_wr_mult(`MEM_BASE + (page_size*2*4) + size*4*4, 4'hf, del, size);
1299
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*2*4) + size*4*4, 4'hf, del, size);
1300
                        m0.wb_wr_mult(`MEM_BASE + (page_size*2*4) + size*5*4, 4'hf, del, size);
1301
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*2*4) + size*5*4, 4'hf, del, size);
1302
 
1303
                        m0.wb_wr_mult(`MEM_BASE + (page_size*3*4) + size*6*4, 4'hf, del, size);
1304
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*3*4) + size*6*4, 4'hf, del, size);
1305
                        m0.wb_wr_mult(`MEM_BASE + (page_size*3*4) + size*7*4, 4'hf, del, size);
1306
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*3*4) + size*6*4, 4'hf, del, size);
1307
 
1308
        repeat(20)      @(posedge clk);
1309
 
1310
        for(m=0;m<4;m=m+1)
1311
        for(n=0;n<(size*2);n=n+1)
1312
           begin
1313
                adr = (m * page_size) + (m*size*2) + n;
1314
 
1315
                if(bas[0])       data = sdram0.Bank0[adr];
1316
                else
1317
                case(m)
1318
                   0: data = sdram0.Bank0[n];
1319
                   1: data = sdram0.Bank1[n+1*size*2];
1320
                   2: data = sdram0.Bank2[n+2*size*2];
1321
                   3: data = sdram0.Bank3[n+3*size*2];
1322
                endcase
1323
 
1324
                if((data !== m0.wr_mem[(m*size*2)+n]) | (|data === 1'bx) |
1325
                        (|m0.wr_mem[(m*size*2)+n] === 1'bx) )
1326
                   begin
1327
                        $display("ERROR: WR Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
1328
                        (m*size*2)+n, data, m0.wr_mem[(m*size*2)+n],  $time);
1329
                        error_cnt = error_cnt + 1;
1330
                   end
1331
 
1332
           end
1333
 
1334
   end
1335
 
1336
end
1337
end
1338
 
1339
show_errors;
1340
$display("*****************************************************");
1341
$display("*** Test DONE ...                                 ***");
1342
$display("*****************************************************\n\n");
1343
end
1344
endtask
1345
 
1346
 
1347
 
1348
`ifdef MULTI_SDRAM
1349
 
1350
task sdram_rd5;
1351
input           quick;
1352
 
1353
integer         quick;
1354
integer         s,n,m,adr;
1355
integer         del, size;
1356
reg     [7:0]    mode;
1357
reg     [2:0]    bs;
1358
integer         sz_inc;
1359
integer         sz_max, del_max;
1360
reg     [2:0]    bas;
1361
reg     [31:0]   data;
1362
integer         page_size;
1363
integer         write;
1364
 
1365
begin
1366
 
1367
$display("\n\n");
1368
$display("*****************************************************");
1369
$display("*** SDRAM Size, Delay & Mode Read test 5 ...      ***");
1370
$display("*** KRO & Different Row and Bank and CS           ***");
1371
$display("*****************************************************\n");
1372
 
1373
page_size = 256; // 64 mbit x 32 SDRAM
1374
 
1375
case(quick)
1376
 0: sz_max = 32;
1377
 1: sz_max = 32;
1378
 2: sz_max = 16;
1379
endcase
1380
 
1381
case(quick)
1382
 0: del_max = 16;
1383
 1: del_max = 8;
1384 10 rudi
 2: del_max = 8;
1385 4 rudi
endcase
1386
 
1387
m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
1388
m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
1389
 
1390 10 rudi
m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
1391
                                        4'd0,           // RESERVED [31:28]
1392
                                        4'd7,           // Trfc [27:24]
1393
                                        4'd2,           // Trp [23:20]
1394
                                        3'd2,           // Trcd [19:17]
1395
                                        2'd1,           // Twr [16:15]
1396
                                        5'd0,           // RESERVED [14:10]
1397 4 rudi
                                        1'd0,   // Wr. Burst Len (1=Single)
1398
                                        2'd0,   // Op Mode
1399
                                        3'd2,   // CL
1400
                                        1'b0,   // Burst Type (0=Seq;1=Inter)
1401
                                        3'd3    // Burst Length
1402
                                        });
1403
 
1404 10 rudi
m0.wb_wr1(`REG_BASE + `TMS1,    4'hf, {
1405
                                        4'd0,           // RESERVED [31:28]
1406
                                        4'd7,           // Trfc [27:24]
1407
                                        4'd2,           // Trp [23:20]
1408
                                        3'd2,           // Trcd [19:17]
1409
                                        2'd1,           // Twr [16:15]
1410
                                        5'd0,           // RESERVED [14:10]
1411 4 rudi
                                        1'd0,   // Wr. Burst Len (1=Single)
1412
                                        2'd0,   // Op Mode
1413
                                        3'd2,   // CL
1414
                                        1'b0,   // Burst Type (0=Seq;1=Inter)
1415
                                        3'd3    // Burst Length
1416
                                        });
1417
 
1418 10 rudi
m0.wb_wr1(`REG_BASE + `TMS2,    4'hf, {
1419
                                        4'd0,           // RESERVED [31:28]
1420
                                        4'd7,           // Trfc [27:24]
1421
                                        4'd2,           // Trp [23:20]
1422
                                        3'd2,           // Trcd [19:17]
1423
                                        2'd1,           // Twr [16:15]
1424
                                        5'd0,           // RESERVED [14:10]
1425 4 rudi
                                        1'd0,   // Wr. Burst Len (1=Single)
1426
                                        2'd0,   // Op Mode
1427
                                        3'd2,   // CL
1428
                                        1'b0,   // Burst Type (0=Seq;1=Inter)
1429
                                        3'd3    // Burst Length
1430
                                        });
1431
 
1432 10 rudi
bas = 0;
1433 4 rudi
for(bas=0;bas<2;bas=bas+1)
1434
begin
1435
m0.wb_wr1(`REG_BASE + `CSC0,    4'hf, 32'h0000_0421 | (bas[0]<<9));
1436
m0.wb_wr1(`REG_BASE + `CSC1,    4'hf, 32'h0020_0021 | (bas[0]<<9));
1437
m0.wb_wr1(`REG_BASE + `CSC2,    4'hf, 32'h0040_0421 | (bas[0]<<9));
1438
 
1439 10 rudi
size = 15;
1440
del = 3;
1441
mode = 9;
1442 4 rudi
write = 1;
1443
if(0)
1444
   begin
1445
        force sdram0.Debug = 1;
1446
        force sdram1.Debug = 1;
1447
        force sdram2.Debug = 1;
1448
   end
1449
 
1450 10 rudi
//for(mode=0;mode<10;mode=mode+1)
1451 4 rudi
for(mode=0;mode<10;mode=mode+1)
1452
begin
1453
        sdram0.mem_fill(1024);
1454
        sdram1.mem_fill(1024);
1455
        sdram2.mem_fill(1024);
1456
 
1457
        case(mode[3:1])
1458
           0: bs = 0;
1459
           1: bs = 1;
1460
           2: bs = 2;
1461
           3: bs = 3;
1462
           4: bs = 7;
1463
        endcase
1464 10 rudi
 
1465 4 rudi
        case(mode[3:1])
1466
           0: sz_inc = 1;
1467
           1: sz_inc = 2;
1468
           2: sz_inc = 4;
1469
           3: sz_inc = 8;
1470
           4: sz_inc = 1;
1471
        endcase
1472
 
1473 10 rudi
        m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
1474
                                        4'd0,           // RESERVED [31:28]
1475
                                        4'd7,           // Trfc [27:24]
1476
                                        4'd2,           // Trp [23:20]
1477
                                        3'd2,           // Trcd [19:17]
1478
                                        2'd1,           // Twr [16:15]
1479
                                        5'd0,           // RESERVED [14:10]
1480 4 rudi
                                        1'd0,           // Wr. Burst Len (1=Single)
1481
                                        2'd0,           // Op Mode
1482
                                        3'd2+mode[0],    // CL
1483
                                        1'b0,           // Burst Type (0=Seq;1=Inter)
1484
                                        3'd0+bs         // Burst Length
1485
                                        });
1486
 
1487 10 rudi
        m0.wb_wr1(`REG_BASE + `TMS1,    4'hf, {
1488
                                        4'd0,           // RESERVED [31:28]
1489
                                        4'd7,           // Trfc [27:24]
1490
                                        4'd2,           // Trp [23:20]
1491
                                        3'd2,           // Trcd [19:17]
1492
                                        2'd1,           // Twr [16:15]
1493
                                        5'd0,           // RESERVED [14:10]
1494 4 rudi
                                        1'd0,           // Wr. Burst Len (1=Single)
1495
                                        2'd0,           // Op Mode
1496
                                        3'd2+mode[0],    // CL
1497
                                        1'b0,           // Burst Type (0=Seq;1=Inter)
1498
                                        3'd0+bs         // Burst Length
1499
                                        });
1500
 
1501 10 rudi
        m0.wb_wr1(`REG_BASE + `TMS2,    4'hf, {
1502
                                        4'd0,           // RESERVED [31:28]
1503
                                        4'd7,           // Trfc [27:24]
1504
                                        4'd2,           // Trp [23:20]
1505
                                        3'd2,           // Trcd [19:17]
1506
                                        2'd1,           // Twr [16:15]
1507
                                        5'd0,           // RESERVED [14:10]
1508 4 rudi
                                        1'd0,           // Wr. Burst Len (1=Single)
1509
                                        2'd0,           // Op Mode
1510
                                        3'd3-mode[0],    // CL
1511
                                        1'b0,           // Burst Type (0=Seq;1=Inter)
1512
                                        3'd0+bs         // Burst Length
1513
                                        });
1514
 
1515
 
1516
if(!verbose)    $display("BAS: %0d, Mode: %b", bas, mode);
1517
 
1518
for(del=0;del<del_max;del=del+1)
1519
for(size=sz_inc;size<sz_max;size=size+sz_inc)
1520
   begin
1521
        m0.mem_fill;
1522
        if(verbose)     $display("BAS: %0d, Mode: %b, Size: %0d, Delay: %0d",
1523
                                bas, mode,  size, del);
1524
 
1525
        if(write)
1526
        m0.wb_wr_mult(`MEM_BASE + (page_size*0*4) + size*0*4, 4'hf, del, size);
1527
        m0.wb_rd_mult(`MEM_BASE + (page_size*0*4) + size*0*4, 4'hf, del, size);
1528
        if(write)
1529
        m0.wb_wr_mult(`MEM_BASE + (page_size*0*4) + size*1*4, 4'hf, del, size);
1530
        m0.wb_rd_mult(`MEM_BASE + (page_size*0*4) + size*1*4, 4'hf, del, size);
1531
        if(write)
1532
        m0.wb_wr_mult(`MEM_BASE1 + (page_size*0*4) + size*0*4, 4'hf, del, size);
1533
        m0.wb_rd_mult(`MEM_BASE1 + (page_size*0*4) + size*0*4, 4'hf, del, size);
1534
        if(write)
1535
        m0.wb_wr_mult(`MEM_BASE1 + (page_size*0*4) + size*1*4, 4'hf, del, size);
1536
        m0.wb_rd_mult(`MEM_BASE1 + (page_size*0*4) + size*1*4, 4'hf, del, size);
1537
        if(write)
1538
        m0.wb_wr_mult(`MEM_BASE2 + (page_size*0*4) + size*0*4, 4'hf, del, size);
1539
        m0.wb_rd_mult(`MEM_BASE2 + (page_size*0*4) + size*0*4, 4'hf, del, size);
1540
        if(write)
1541
        m0.wb_wr_mult(`MEM_BASE2 + (page_size*0*4) + size*1*4, 4'hf, del, size);
1542
        m0.wb_rd_mult(`MEM_BASE2 + (page_size*0*4) + size*1*4, 4'hf, del, size);
1543
 
1544
        if(write)
1545
        m0.wb_wr_mult(`MEM_BASE + (page_size*1*4) + size*2*4, 4'hf, del, size);
1546
        m0.wb_rd_mult(`MEM_BASE + (page_size*1*4) + size*2*4, 4'hf, del, size);
1547
        if(write)
1548
        m0.wb_wr_mult(`MEM_BASE + (page_size*1*4) + size*3*4, 4'hf, del, size);
1549
        m0.wb_rd_mult(`MEM_BASE + (page_size*1*4) + size*3*4, 4'hf, del, size);
1550
        if(write)
1551
        m0.wb_wr_mult(`MEM_BASE1 + (page_size*1*4) + size*2*4, 4'hf, del, size);
1552
        m0.wb_rd_mult(`MEM_BASE1 + (page_size*1*4) + size*2*4, 4'hf, del, size);
1553
        if(write)
1554
        m0.wb_wr_mult(`MEM_BASE1 + (page_size*1*4) + size*3*4, 4'hf, del, size);
1555
        m0.wb_rd_mult(`MEM_BASE1 + (page_size*1*4) + size*3*4, 4'hf, del, size);
1556
        if(write)
1557
        m0.wb_wr_mult(`MEM_BASE2 + (page_size*1*4) + size*2*4, 4'hf, del, size);
1558
        m0.wb_rd_mult(`MEM_BASE2 + (page_size*1*4) + size*2*4, 4'hf, del, size);
1559
        if(write)
1560
        m0.wb_wr_mult(`MEM_BASE2 + (page_size*1*4) + size*3*4, 4'hf, del, size);
1561
        m0.wb_rd_mult(`MEM_BASE2 + (page_size*1*4) + size*3*4, 4'hf, del, size);
1562
 
1563
        if(write)
1564
        m0.wb_wr_mult(`MEM_BASE + (page_size*2*4) + size*4*4, 4'hf, del, size);
1565
        m0.wb_rd_mult(`MEM_BASE + (page_size*2*4) + size*4*4, 4'hf, del, size);
1566
        if(write)
1567
        m0.wb_wr_mult(`MEM_BASE + (page_size*2*4) + size*5*4, 4'hf, del, size);
1568
        m0.wb_rd_mult(`MEM_BASE + (page_size*2*4) + size*5*4, 4'hf, del, size);
1569
        if(write)
1570
        m0.wb_wr_mult(`MEM_BASE1 + (page_size*2*4) + size*4*4, 4'hf, del, size);
1571
        m0.wb_rd_mult(`MEM_BASE1 + (page_size*2*4) + size*4*4, 4'hf, del, size);
1572
        if(write)
1573
        m0.wb_wr_mult(`MEM_BASE1 + (page_size*2*4) + size*5*4, 4'hf, del, size);
1574
        m0.wb_rd_mult(`MEM_BASE1 + (page_size*2*4) + size*5*4, 4'hf, del, size);
1575
        if(write)
1576
        m0.wb_wr_mult(`MEM_BASE2 + (page_size*2*4) + size*4*4, 4'hf, del, size);
1577
        m0.wb_rd_mult(`MEM_BASE2 + (page_size*2*4) + size*4*4, 4'hf, del, size);
1578
        if(write)
1579
        m0.wb_wr_mult(`MEM_BASE2 + (page_size*2*4) + size*5*4, 4'hf, del, size);
1580
        m0.wb_rd_mult(`MEM_BASE2 + (page_size*2*4) + size*5*4, 4'hf, del, size);
1581
 
1582
        if(write)
1583
        m0.wb_wr_mult(`MEM_BASE + (page_size*3*4) + size*6*4, 4'hf, del, size);
1584
        m0.wb_rd_mult(`MEM_BASE + (page_size*3*4) + size*6*4, 4'hf, del, size);
1585
        if(write)
1586
        m0.wb_wr_mult(`MEM_BASE + (page_size*3*4) + size*7*4, 4'hf, del, size);
1587
        m0.wb_rd_mult(`MEM_BASE + (page_size*3*4) + size*7*4, 4'hf, del, size);
1588
        if(write)
1589
        m0.wb_wr_mult(`MEM_BASE1 + (page_size*3*4) + size*6*4, 4'hf, del, size);
1590
        m0.wb_rd_mult(`MEM_BASE1 + (page_size*3*4) + size*6*4, 4'hf, del, size);
1591
        if(write)
1592
        m0.wb_wr_mult(`MEM_BASE1 + (page_size*3*4) + size*7*4, 4'hf, del, size);
1593
        m0.wb_rd_mult(`MEM_BASE1 + (page_size*3*4) + size*7*4, 4'hf, del, size);
1594
        if(write)
1595
        m0.wb_wr_mult(`MEM_BASE2 + (page_size*3*4) + size*6*4, 4'hf, del, size);
1596
        m0.wb_rd_mult(`MEM_BASE2 + (page_size*3*4) + size*6*4, 4'hf, del, size);
1597
        if(write)
1598
        m0.wb_wr_mult(`MEM_BASE2 + (page_size*3*4) + size*7*4, 4'hf, del, size);
1599
        m0.wb_rd_mult(`MEM_BASE2 + (page_size*3*4) + size*7*4, 4'hf, del, size);
1600
 
1601
        for(m=0;m<4;m=m+1)
1602
        for(s=0;s<3;s=s+1)
1603
        for(n=0;n<(size*2);n=n+1)
1604
           begin
1605
                adr = (m * page_size) + (m*(size*2)) + n;
1606
 
1607
                case(s)
1608
                   0:    if(bas[0])       data = sdram0.Bank0[adr];
1609
                        else
1610
                        case(m)
1611
                           0: data = sdram0.Bank0[n];
1612
                           1: data = sdram0.Bank1[n+1*size*2];
1613
                           2: data = sdram0.Bank2[n+2*size*2];
1614
                           3: data = sdram0.Bank3[n+3*size*2];
1615
                        endcase
1616
                   1:   if(bas[0])       data = sdram1.Bank0[adr];
1617
                        else
1618
                        case(m)
1619
                           0: data = sdram1.Bank0[n];
1620
                           1: data = sdram1.Bank1[n+1*size*2];
1621
                           2: data = sdram1.Bank2[n+2*size*2];
1622
                           3: data = sdram1.Bank3[n+3*size*2];
1623
                        endcase
1624
                   2:   if(bas[0])       data = sdram2.Bank0[adr];
1625
                        else
1626
                        case(m)
1627
                           0: data = sdram2.Bank0[n];
1628
                           1: data = sdram2.Bank1[n+1*size*2];
1629
                           2: data = sdram2.Bank2[n+2*size*2];
1630
                           3: data = sdram2.Bank3[n+3*size*2];
1631
                        endcase
1632
                endcase
1633
 
1634
                if((data !== m0.rd_mem[(m*size*6)+(s*size*2)+n]) | (|data === 1'bx) |
1635
                        (|m0.rd_mem[(m*size*6)+(s*size*2)+n] === 1'bx) )
1636
                   begin
1637
                        $display("ERROR: Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
1638
                        (m*size*2)+n, data, m0.rd_mem[(m*size*2)+n],  $time);
1639
                        error_cnt = error_cnt + 1;
1640 10 rudi
                        if(error_cnt > 25)      $finish;
1641 4 rudi
                   end
1642
 
1643
           end
1644
   end
1645
end
1646
 
1647
end
1648
 
1649
show_errors;
1650
$display("*****************************************************");
1651
$display("*** Test DONE ...                                 ***");
1652
$display("*****************************************************\n\n");
1653
end
1654
endtask
1655
 
1656
 
1657
 
1658
 
1659
task sdram_wr5;
1660
input           quick;
1661
 
1662
integer         quick;
1663
integer         s,n,m,adr;
1664
integer         del, size;
1665
reg     [7:0]    mode;
1666
reg     [2:0]    bs;
1667
integer         sz_inc;
1668
integer         sz_max, del_max;
1669
integer         read;
1670
reg     [2:0]    bas;
1671
reg     [31:0]   data;
1672
integer         page_size;
1673
 
1674
begin
1675
$display("\n\n");
1676
$display("*****************************************************");
1677
$display("*** SDRAM Size, Delay & Mode Write test 5 ...     ***");
1678
$display("*** KRO & Different Row and Bank and CS           ***");
1679
$display("*****************************************************\n");
1680
 
1681
page_size = 256; // 64 mbit x 32 SDRAM
1682
 
1683 10 rudi
m0.wb_wr1(`REG_BASE + `CSC0,    4'hf, 32'h0000_0000);
1684
m0.wb_wr1(`REG_BASE + `CSC1,    4'hf, 32'h0000_0000);
1685
m0.wb_wr1(`REG_BASE + `CSC2,    4'hf, 32'h0000_0000);
1686
repeat(10)      @(posedge clk);
1687
 
1688 4 rudi
m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
1689
m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
1690
 
1691 10 rudi
m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
1692
                                        4'd0,           // RESERVED [31:28]
1693
                                        4'd7,           // Trfc [27:24]
1694
                                        4'd2,           // Trp [23:20]
1695
                                        3'd2,           // Trcd [19:17]
1696
                                        2'd1,           // Twr [16:15]
1697
                                        5'd0,           // RESERVED [14:10]
1698 4 rudi
                                        1'd0,   // Wr. Burst Len (1=Single)
1699
                                        2'd0,   // Op Mode
1700
                                        3'd2,   // CL
1701
                                        1'b0,   // Burst Type (0=Seq;1=Inter)
1702
                                        3'd3    // Burst Length
1703
                                        });
1704
 
1705 10 rudi
m0.wb_wr1(`REG_BASE + `TMS1,    4'hf, {
1706
                                        4'd0,           // RESERVED [31:28]
1707
                                        4'd7,           // Trfc [27:24]
1708
                                        4'd2,           // Trp [23:20]
1709
                                        3'd2,           // Trcd [19:17]
1710
                                        2'd1,           // Twr [16:15]
1711
                                        5'd0,           // RESERVED [14:10]
1712 4 rudi
                                        1'd0,   // Wr. Burst Len (1=Single)
1713
                                        2'd0,   // Op Mode
1714
                                        3'd2,   // CL
1715
                                        1'b0,   // Burst Type (0=Seq;1=Inter)
1716
                                        3'd3    // Burst Length
1717
                                        });
1718
 
1719 10 rudi
m0.wb_wr1(`REG_BASE + `TMS2,    4'hf, {
1720
                                        4'd0,           // RESERVED [31:28]
1721
                                        4'd7,           // Trfc [27:24]
1722
                                        4'd2,           // Trp [23:20]
1723
                                        3'd2,           // Trcd [19:17]
1724
                                        2'd1,           // Twr [16:15]
1725
                                        5'd0,           // RESERVED [14:10]
1726 4 rudi
                                        1'd0,   // Wr. Burst Len (1=Single)
1727
                                        2'd0,   // Op Mode
1728
                                        3'd2,   // CL
1729
                                        1'b0,   // Burst Type (0=Seq;1=Inter)
1730
                                        3'd3    // Burst Length
1731
                                        });
1732
 
1733 10 rudi
bas = 0;
1734 4 rudi
for(bas=0;bas<2;bas=bas+1)
1735
begin
1736
 
1737
m0.wb_wr1(`REG_BASE + `CSC0,    4'hf, 32'h0000_0421 | (bas[0]<<9));
1738
m0.wb_wr1(`REG_BASE + `CSC1,    4'hf, 32'h0020_0421 | (bas[0]<<9));
1739
m0.wb_wr1(`REG_BASE + `CSC2,    4'hf, 32'h0040_0421 | (bas[0]<<9));
1740
 
1741
case(quick)
1742
 0: sz_max = 32;
1743
 1: sz_max = 32;
1744
 2: sz_max = 16;
1745
endcase
1746
 
1747
case(quick)
1748
 0: del_max = 16;
1749
 1: del_max = 8;
1750 10 rudi
 2: del_max = 8;
1751 4 rudi
endcase
1752
 
1753
size = 5;
1754
del = 0;
1755
mode = 0;
1756
read = 1;
1757
 
1758
if(0)
1759
   begin
1760
        force sdram0.Debug = 1;
1761
        force sdram1.Debug = 1;
1762
        force sdram2.Debug = 1;
1763
   end
1764
 
1765
for(mode=0;mode<20;mode=mode+1)
1766
begin
1767
 
1768
        sdram0.mem_fill(1024);
1769
        sdram1.mem_fill(1024);
1770
        sdram2.mem_fill(1024);
1771
 
1772
        case(mode[4:2])
1773
           0: bs = 0;
1774
           1: bs = 1;
1775
           2: bs = 2;
1776
           3: bs = 3;
1777
           4: bs = 7;
1778
        endcase
1779
 
1780
        if(mode[1])
1781
           sz_inc = 1;
1782
        else
1783
                case(mode[4:2])
1784
                   0: sz_inc = 1;
1785
                   1: sz_inc = 2;
1786
                   2: sz_inc = 4;
1787
                   3: sz_inc = 8;
1788
                   4: sz_inc = 1;
1789
                endcase
1790
 
1791 10 rudi
        m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
1792
                                        4'd0,           // RESERVED [31:28]
1793
                                        4'd7,           // Trfc [27:24]
1794
                                        4'd2,           // Trp [23:20]
1795
                                        3'd2,           // Trcd [19:17]
1796
                                        2'd1,           // Twr [16:15]
1797
                                        5'd0,           // RESERVED [14:10]
1798 4 rudi
                                        1'd0+mode[1],   // Wr. Burst Len (1=Single)
1799
                                        2'd0,           // Op Mode
1800
                                        3'd2+mode[0],    // CL
1801
                                        1'b0,           // Burst Type (0=Seq;1=Inter)
1802
                                        3'd0+bs         // Burst Length
1803
                                        });
1804
 
1805
 
1806 10 rudi
        m0.wb_wr1(`REG_BASE + `TMS1,    4'hf, {
1807
                                        4'd0,           // RESERVED [31:28]
1808
                                        4'd7,           // Trfc [27:24]
1809
                                        4'd2,           // Trp [23:20]
1810
                                        3'd2,           // Trcd [19:17]
1811
                                        2'd1,           // Twr [16:15]
1812
                                        5'd0,           // RESERVED [14:10]
1813 4 rudi
                                        1'd0+mode[1],   // Wr. Burst Len (1=Single)
1814
                                        2'd0,           // Op Mode
1815
                                        3'd3-mode[0],    // CL
1816
                                        1'b0,           // Burst Type (0=Seq;1=Inter)
1817
                                        3'd0+bs         // Burst Length
1818
                                        });
1819
 
1820
 
1821 10 rudi
        m0.wb_wr1(`REG_BASE + `TMS2,    4'hf, {
1822
                                        4'd0,           // RESERVED [31:28]
1823
                                        4'd7,           // Trfc [27:24]
1824
                                        4'd2,           // Trp [23:20]
1825
                                        3'd2,           // Trcd [19:17]
1826
                                        2'd1,           // Twr [16:15]
1827
                                        5'd0,           // RESERVED [14:10]
1828 4 rudi
                                        1'd0+mode[1],   // Wr. Burst Len (1=Single)
1829
                                        2'd0,           // Op Mode
1830
                                        3'd2+mode[0],    // CL
1831
                                        1'b0,           // Burst Type (0=Seq;1=Inter)
1832
                                        3'd0+bs         // Burst Length
1833
                                        });
1834
 
1835
if(!verbose)    $display("BAS: %0d, Mode: %b", bas, mode);
1836
 
1837 10 rudi
for(del=0;del<del_max;del=del+1)
1838 4 rudi
for(size=sz_inc;size<sz_max;size=size+sz_inc)
1839
   begin
1840
        m0.mem_fill;
1841
        if(verbose)     $display("BAS: %0d, Mode: %b, Size: %0d, Delay: %0d",
1842
                                bas, mode,  size, del);
1843
 
1844
                        m0.wb_wr_mult(`MEM_BASE + (page_size*0*4) + size*0*4, 4'hf, del, size);
1845
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*0*4) + size*0*4, 4'hf, del, size);
1846
                        m0.wb_wr_mult(`MEM_BASE + (page_size*0*4) + size*1*4, 4'hf, del, size);
1847
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*0*4) + size*1*4, 4'hf, del, size);
1848
                        m0.wb_wr_mult(`MEM_BASE1 + (page_size*0*4) + size*0*4, 4'hf, del, size);
1849
        if(read)        m0.wb_rd_mult(`MEM_BASE1 + (page_size*0*4) + size*0*4, 4'hf, del, size);
1850
                        m0.wb_wr_mult(`MEM_BASE1 + (page_size*0*4) + size*1*4, 4'hf, del, size);
1851
        if(read)        m0.wb_rd_mult(`MEM_BASE1 + (page_size*0*4) + size*1*4, 4'hf, del, size);
1852
                        m0.wb_wr_mult(`MEM_BASE2 + (page_size*0*4) + size*0*4, 4'hf, del, size);
1853
        if(read)        m0.wb_rd_mult(`MEM_BASE2 + (page_size*0*4) + size*0*4, 4'hf, del, size);
1854
                        m0.wb_wr_mult(`MEM_BASE2 + (page_size*0*4) + size*1*4, 4'hf, del, size);
1855
        if(read)        m0.wb_rd_mult(`MEM_BASE2 + (page_size*0*4) + size*1*4, 4'hf, del, size);
1856
 
1857
                        m0.wb_wr_mult(`MEM_BASE + (page_size*1*4) + size*2*4, 4'hf, del, size);
1858
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*1*4) + size*2*4, 4'hf, del, size);
1859
                        m0.wb_wr_mult(`MEM_BASE + (page_size*1*4) + size*3*4, 4'hf, del, size);
1860
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*1*4) + size*3*4, 4'hf, del, size);
1861
                        m0.wb_wr_mult(`MEM_BASE1 + (page_size*1*4) + size*2*4, 4'hf, del, size);
1862
        if(read)        m0.wb_rd_mult(`MEM_BASE1 + (page_size*1*4) + size*2*4, 4'hf, del, size);
1863
                        m0.wb_wr_mult(`MEM_BASE1 + (page_size*1*4) + size*3*4, 4'hf, del, size);
1864
        if(read)        m0.wb_rd_mult(`MEM_BASE1 + (page_size*1*4) + size*3*4, 4'hf, del, size);
1865
                        m0.wb_wr_mult(`MEM_BASE2 + (page_size*1*4) + size*2*4, 4'hf, del, size);
1866
        if(read)        m0.wb_rd_mult(`MEM_BASE2 + (page_size*1*4) + size*2*4, 4'hf, del, size);
1867
                        m0.wb_wr_mult(`MEM_BASE2 + (page_size*1*4) + size*3*4, 4'hf, del, size);
1868
        if(read)        m0.wb_rd_mult(`MEM_BASE2 + (page_size*1*4) + size*3*4, 4'hf, del, size);
1869
 
1870
                        m0.wb_wr_mult(`MEM_BASE + (page_size*2*4) + size*4*4, 4'hf, del, size);
1871
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*2*4) + size*4*4, 4'hf, del, size);
1872
                        m0.wb_wr_mult(`MEM_BASE + (page_size*2*4) + size*5*4, 4'hf, del, size);
1873
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*2*4) + size*5*4, 4'hf, del, size);
1874
                        m0.wb_wr_mult(`MEM_BASE1 + (page_size*2*4) + size*4*4, 4'hf, del, size);
1875
        if(read)        m0.wb_rd_mult(`MEM_BASE1 + (page_size*2*4) + size*4*4, 4'hf, del, size);
1876
                        m0.wb_wr_mult(`MEM_BASE1 + (page_size*2*4) + size*5*4, 4'hf, del, size);
1877
        if(read)        m0.wb_rd_mult(`MEM_BASE1 + (page_size*2*4) + size*5*4, 4'hf, del, size);
1878
                        m0.wb_wr_mult(`MEM_BASE2 + (page_size*2*4) + size*4*4, 4'hf, del, size);
1879
        if(read)        m0.wb_rd_mult(`MEM_BASE2 + (page_size*2*4) + size*4*4, 4'hf, del, size);
1880
                        m0.wb_wr_mult(`MEM_BASE2 + (page_size*2*4) + size*5*4, 4'hf, del, size);
1881
        if(read)        m0.wb_rd_mult(`MEM_BASE2 + (page_size*2*4) + size*5*4, 4'hf, del, size);
1882
 
1883
                        m0.wb_wr_mult(`MEM_BASE + (page_size*3*4) + size*6*4, 4'hf, del, size);
1884
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*3*4) + size*6*4, 4'hf, del, size);
1885
                        m0.wb_wr_mult(`MEM_BASE + (page_size*3*4) + size*7*4, 4'hf, del, size);
1886
        if(read)        m0.wb_rd_mult(`MEM_BASE + (page_size*3*4) + size*7*4, 4'hf, del, size);
1887
                        m0.wb_wr_mult(`MEM_BASE1 + (page_size*3*4) + size*6*4, 4'hf, del, size);
1888
        if(read)        m0.wb_rd_mult(`MEM_BASE1 + (page_size*3*4) + size*6*4, 4'hf, del, size);
1889
                        m0.wb_wr_mult(`MEM_BASE1 + (page_size*3*4) + size*7*4, 4'hf, del, size);
1890
        if(read)        m0.wb_rd_mult(`MEM_BASE1 + (page_size*3*4) + size*7*4, 4'hf, del, size);
1891
                        m0.wb_wr_mult(`MEM_BASE2 + (page_size*3*4) + size*6*4, 4'hf, del, size);
1892
        if(read)        m0.wb_rd_mult(`MEM_BASE2 + (page_size*3*4) + size*6*4, 4'hf, del, size);
1893
                        m0.wb_wr_mult(`MEM_BASE2 + (page_size*3*4) + size*7*4, 4'hf, del, size);
1894
        if(read)        m0.wb_rd_mult(`MEM_BASE2 + (page_size*3*4) + size*7*4, 4'hf, del, size);
1895
 
1896
 
1897
 
1898
        repeat(20)      @(posedge clk);
1899
 
1900
        for(m=0;m<4;m=m+1)
1901
        for(s=0;s<3;s=s+1)
1902
        for(n=0;n<(size*2);n=n+1)
1903
           begin
1904
                adr = (m * page_size) + (m*size*2) + n;
1905
 
1906
                case(s)
1907
                   0:    if(bas[0])       data = sdram0.Bank0[adr];
1908
                        else
1909
                        case(m)
1910
                           0: data = sdram0.Bank0[n];
1911
                           1: data = sdram0.Bank1[n+1*size*2];
1912
                           2: data = sdram0.Bank2[n+2*size*2];
1913
                           3: data = sdram0.Bank3[n+3*size*2];
1914
                        endcase
1915
                   1:   if(bas[0])       data = sdram1.Bank0[adr];
1916
                        else
1917
                        case(m)
1918
                           0: data = sdram1.Bank0[n];
1919
                           1: data = sdram1.Bank1[n+1*size*2];
1920
                           2: data = sdram1.Bank2[n+2*size*2];
1921
                           3: data = sdram1.Bank3[n+3*size*2];
1922
                        endcase
1923
                   2:   if(bas[0])       data = sdram2.Bank0[adr];
1924
                        else
1925
                        case(m)
1926
                           0: data = sdram2.Bank0[n];
1927
                           1: data = sdram2.Bank1[n+1*size*2];
1928
                           2: data = sdram2.Bank2[n+2*size*2];
1929
                           3: data = sdram2.Bank3[n+3*size*2];
1930
                        endcase
1931
                endcase
1932
 
1933
                if((data !== m0.wr_mem[(m*size*6)+(s*size*2)+n]) | (|data === 1'bx) |
1934
                        (|m0.wr_mem[(m*size*6)+(s*size*2)+n] === 1'bx) )
1935
                   begin
1936
                        $display("ERROR: WR Data[%0d-%0d] Mismatch: Expected: %x, Got: %x (%0t)",
1937
                        s, (m*size*2)+n, data, m0.wr_mem[(m*size*2)+n],  $time);
1938
                        error_cnt = error_cnt + 1;
1939 10 rudi
 
1940
                        if(error_cnt > 25)      $finish;
1941 4 rudi
                   end
1942
 
1943
           end
1944
 
1945
   end
1946
 
1947
end
1948
end
1949
 
1950
show_errors;
1951
$display("*****************************************************");
1952
$display("*** Test DONE ...                                 ***");
1953
$display("*****************************************************\n\n");
1954
end
1955
endtask
1956
 
1957
`endif
1958
 
1959
 
1960
task    asc_rdwr1;
1961
input           quick;
1962
 
1963
integer         quick;
1964
integer         x,s,n,m,adr;
1965
integer         del, size;
1966
reg     [7:0]    mode;
1967
reg     [2:0]    bs;
1968
integer         sz_inc;
1969
integer         sz_max, del_max;
1970
integer         read;
1971
reg     [2:0]    bas;
1972 10 rudi
reg     [31:0]   data, exp;
1973 4 rudi
 
1974
begin
1975
$display("\n\n");
1976
$display("*****************************************************");
1977
$display("*** ASC Read/Write Test 1 ...                     ***");
1978
$display("*****************************************************\n");
1979
 
1980
        m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
1981
        m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
1982
 
1983
        m0.wb_wr1(`REG_BASE + `TMS3,    4'hf, 32'hffff_f40a);
1984
 
1985
case(quick)
1986
 0: sz_max = 32;
1987
 1: sz_max = 32;
1988
 2: sz_max = 16;
1989
endcase
1990
 
1991
case(quick)
1992
 0: del_max = 16;
1993
 1: del_max = 8;
1994
 2: del_max = 4;
1995
endcase
1996
 
1997
size = 1;
1998
del = 0;
1999
mode = 0;
2000
read = 1;
2001
write = 0;
2002
 
2003
 
2004
for(mode=0;mode<3;mode=mode+1)
2005
begin
2006
 
2007
repeat(1)       @(posedge clk);
2008
 
2009
case(mode)
2010
   0:    m0.wb_wr1(`REG_BASE + `CSC3,    4'hf, 32'h0060_0025);   // 32 bit bus
2011
   1:   m0.wb_wr1(`REG_BASE + `CSC3,    4'hf, 32'h0060_0005);   // 8 bit bus
2012
   2:   m0.wb_wr1(`REG_BASE + `CSC3,    4'hf, 32'h0060_0015);   // 16 bit bus
2013
endcase
2014
 
2015
repeat(10)      @(posedge clk);
2016
if(!verbose)    $display("Mode: %b", mode);
2017
 
2018 10 rudi
for(del=0;del<del_max;del=del+1)
2019
for(size=1;size<sz_max;size=size+1)
2020 4 rudi
   begin
2021
        m0.mem_fill;
2022
        for(n=0;n<1024;n=n+1)
2023
                m0.wr_mem[n] = 32'hffff_ffff;
2024
 
2025
        if(verbose)     $display("Mode: %0d, Size: %0d, Delay: %0d", mode,  size, del);
2026
 
2027
        if(write)       m0.wb_wr_mult(`MEM_BASE3 + size*0*4, 4'hf, del, size);
2028
        if(read)        m0.wb_rd_mult(`MEM_BASE3 + size*0*4, 4'hf, del, size);
2029
 
2030
        if(write)       m0.wb_wr_mult(`MEM_BASE3 + size*1*4, 4'hf, del, size);
2031
        if(read)        m0.wb_rd_mult(`MEM_BASE3 + size*1*4, 4'hf, del, size);
2032
 
2033
        if(write)       m0.wb_wr_mult(`MEM_BASE3 + size*2*4, 4'hf, del, size);
2034
        if(read)        m0.wb_rd_mult(`MEM_BASE3 + size*2*4, 4'hf, del, size);
2035
 
2036
        if(write)       m0.wb_wr_mult(`MEM_BASE3 + size*3*4, 4'hf, del, size);
2037
        if(read)        m0.wb_rd_mult(`MEM_BASE3 + size*3*4, 4'hf, del, size);
2038
 
2039
        repeat(10)      @(posedge clk);
2040
 
2041
        x = 0;
2042
        for(n=0;n<(size*4);n=n+1)
2043
           begin
2044
 
2045
                case(mode)
2046 10 rudi
                   0:    data = {16'hxxxx, n[15:0]};
2047 4 rudi
                   1:
2048
                        begin
2049
                                data[31:24] = x[7:0]+3;
2050
                                data[23:16] = x[7:0]+2;
2051
                                data[15:08] = x[7:0]+1;
2052
                                data[07:00] = x[7:0]+0;
2053
                        end
2054
                   2:   begin
2055
                                data[31:16] = x[15:0]+1;
2056
                                data[15:00] = x[15:0]+0;
2057
                        end
2058
                endcase
2059
 
2060
                case(mode)
2061
                   0:    x = x + 1;
2062
                   1:   x = x + 4;
2063
                   2:   x = x + 2;
2064
                endcase
2065
 
2066 10 rudi
                exp = m0.rd_mem[n];
2067
                if(mode==0)      exp[31:16] = data[31:16];
2068 4 rudi
 
2069 10 rudi
                if(data !== exp)
2070 4 rudi
                   begin
2071
                        $display("ERROR: Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
2072 10 rudi
                        n, data, exp,  $time);
2073 4 rudi
                        error_cnt = error_cnt + 1;
2074
                   end
2075
           end
2076
 
2077
   end
2078
 
2079
end
2080
 
2081
show_errors;
2082
$display("*****************************************************");
2083
$display("*** Test DONE ...                                 ***");
2084
$display("*****************************************************\n\n");
2085
 
2086
end
2087
endtask
2088
 
2089
 
2090
task    asc_rdwr1_x;
2091
input           quick;
2092
 
2093
integer         quick;
2094
integer         x,s,n,m,adr;
2095
integer         del, size;
2096
reg     [7:0]    mode;
2097
reg     [2:0]    bs;
2098
integer         sz_inc;
2099
integer         sz_max, del_max;
2100
integer         read;
2101
reg     [2:0]    bas;
2102
reg     [31:0]   data;
2103
 
2104
begin
2105
 
2106
$display("\n\n");
2107
$display("*****************************************************");
2108
$display("*** ASC Read/Write Test 1 X ...                   ***");
2109
$display("*****************************************************\n");
2110
 
2111
        m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
2112
        m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
2113
 
2114
        m0.wb_wr1(`REG_BASE + `TMS3,    4'hf, 32'h0005_2004);
2115
        m0.wb_wr1(`REG_BASE + `CSC3,    4'hf, 32'h0060_0005);
2116
 
2117
case(quick)
2118
 0: sz_max = 32;
2119
 1: sz_max = 32;
2120
 2: sz_max = 16;
2121
endcase
2122
 
2123
case(quick)
2124
 0: del_max = 16;
2125
 1: del_max = 8;
2126
 2: del_max = 4;
2127
endcase
2128
 
2129
size = 1;
2130
del = 0;
2131
mode = 1;
2132
read = 1;
2133
write = 0;
2134
 
2135
 
2136
//for(mode=0;mode<8;mode=mode+1)
2137
begin
2138
 
2139
repeat(1)       @(posedge clk);
2140
 
2141
 
2142
//m0.wb_wr1(`REG_BASE + `CSC3,  4'hf, 32'h0081_0005);
2143
 
2144
        //m0.wb_wr1(`REG_BASE + `TMS3,  4'hf, 32'h0000_2004 + (mode<<16));
2145
        m0.wb_wr1(`REG_BASE + `TMS3,    4'hf, 32'h0001_200a);
2146
 
2147
repeat(10)      @(posedge clk);
2148
if(!verbose)    $display("Mode: %b", mode);
2149
 
2150
//for(del=0;del<del_max;del=del+1)
2151
//for(size=1;size<sz_max;size=size+1)
2152
   begin
2153
        m0.mem_fill;
2154
        for(n=0;n<1024;n=n+1)
2155
                m0.wr_mem[n] = 32'hffff_ffff;
2156
 
2157
        if(verbose)     $display("Mode: %b, Size: %0d, Delay: %0d", mode,  size, del);
2158
 
2159
        if(write)       m0.wb_wr_mult(`MEM_BASE3 + size*0*4, 4'hf, del, size);
2160
        if(read)        m0.wb_rd_mult(`MEM_BASE3 + size*0*4, 4'hf, del, size);
2161
 
2162
        if(write)       m0.wb_wr_mult(`MEM_BASE3 + size*1*4, 4'hf, del, size);
2163
        if(read)        m0.wb_rd_mult(`MEM_BASE3 + size*1*4, 4'hf, del, size);
2164
 
2165
        if(write)       m0.wb_wr_mult(`MEM_BASE3 + size*2*4, 4'hf, del, size);
2166
        if(read)        m0.wb_rd_mult(`MEM_BASE3 + size*2*4, 4'hf, del, size);
2167
 
2168
        if(write)       m0.wb_wr_mult(`MEM_BASE3 + size*3*4, 4'hf, del, size);
2169
        if(read)        m0.wb_rd_mult(`MEM_BASE3 + size*3*4, 4'hf, del, size);
2170
 
2171
        repeat(10)      @(posedge clk);
2172
 
2173
        x = 0;
2174
 
2175
        for(n=0;n<(size*4);n=n+1)
2176
           begin
2177
 
2178
                case(mode)
2179
                   0:    data = {16'hzzzz, n[15:0]};
2180
                   1:
2181
                        begin
2182
                                data[31:24] = x[7:0]+3;
2183
                                data[23:16] = x[7:0]+2;
2184
                                data[15:08] = x[7:0]+1;
2185
                                data[07:00] = x[7:0]+0;
2186
                        end
2187
 
2188
                   2:   begin
2189
                                data[31:16] = x[15:0]+1;
2190
                                data[15:00] = x[15:0]+0;
2191
                        end
2192
                endcase
2193
 
2194
                case(mode)
2195
                   0:    x = x + 1;
2196
                   1:   x = x + 4;
2197
                   2:   x = x + 2;
2198
                endcase
2199
 
2200
                //$display("INFO: Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
2201
                //      n, data, m0.rd_mem[n],  $time);
2202
 
2203
                if(data !== m0.rd_mem[n])
2204
                   begin
2205
                        $display("ERROR: Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
2206
                        n, data, m0.rd_mem[n],  $time);
2207
                        error_cnt = error_cnt + 1;
2208
                   end
2209
           end
2210
 
2211
 
2212
   end
2213
 
2214
end
2215
 
2216
show_errors;
2217
$display("*****************************************************");
2218
$display("*** Test DONE ...                                 ***");
2219
$display("*****************************************************\n\n");
2220
 
2221
end
2222
endtask
2223
 
2224
 
2225
task    boot;
2226
input           quick;
2227
 
2228
integer         quick;
2229
integer         x,s,n,m,adr;
2230
integer         del, size;
2231
reg     [7:0]    mode;
2232
reg     [2:0]    bs;
2233
integer         sz_inc;
2234
integer         sz_max, del_max;
2235
integer         read;
2236
reg     [2:0]    bas;
2237 10 rudi
reg     [31:0]   data, exp;
2238 4 rudi
 
2239
begin
2240
$display("\n\n");
2241
$display("*****************************************************");
2242
$display("*** ASC Boot Test 1 ...                           ***");
2243
$display("*****************************************************\n");
2244
 
2245
case(quick)
2246
 0: sz_max = 32;
2247
 1: sz_max = 32;
2248
 2: sz_max = 16;
2249
endcase
2250
 
2251
case(quick)
2252
 0: del_max = 16;
2253
 1: del_max = 8;
2254
 2: del_max = 4;
2255
endcase
2256
 
2257
size = 1;
2258
del = 0;
2259
mode = 0;
2260
read = 1;
2261
write = 1;
2262
 
2263
for(mode=0;mode<3;mode=mode+1)
2264
begin
2265
 
2266
repeat(1)       @(posedge clk);
2267
 
2268
case(mode)
2269
   0: begin
2270
        poc_mode = 2;
2271
        mc_reset;
2272
      end
2273
   1: begin
2274
        poc_mode = 0;
2275
        mc_reset;
2276
      end
2277
   2: begin
2278
        poc_mode = 1;
2279
        mc_reset;
2280
      end
2281
endcase
2282
 
2283
repeat(5)       @(posedge clk);
2284
if(!verbose)    $display("Mode: %b", mode);
2285
 
2286
for(del=0;del<del_max;del=del+1)
2287
for(size=1;size<sz_max;size=size+1)
2288
   begin
2289
        m0.mem_fill;
2290
        for(n=0;n<1024;n=n+1)
2291
                m0.wr_mem[n] = 32'hffff_ffff;
2292
 
2293
        if(verbose)     $display("Mode: %b, Size: %0d, Delay: %0d", mode,  size, del);
2294
 
2295
        if(write)       m0.wb_wr_mult(`MEM_BASE + size*0*4, 4'hf, del, size);
2296
        if(read)        m0.wb_rd_mult(`MEM_BASE + size*0*4, 4'hf, del, size);
2297
 
2298
        if(write)       m0.wb_wr_mult(`MEM_BASE + size*1*4, 4'hf, del, size);
2299
        if(read)        m0.wb_rd_mult(`MEM_BASE + size*1*4, 4'hf, del, size);
2300
 
2301
        if(write)       m0.wb_wr_mult(`MEM_BASE + size*2*4, 4'hf, del, size);
2302
        if(read)        m0.wb_rd_mult(`MEM_BASE + size*2*4, 4'hf, del, size);
2303
 
2304
        if(write)       m0.wb_wr_mult(`MEM_BASE + size*3*4, 4'hf, del, size);
2305
        if(read)        m0.wb_rd_mult(`MEM_BASE + size*3*4, 4'hf, del, size);
2306
 
2307
        repeat(10)      @(posedge clk);
2308
 
2309
        x = 0;
2310
        for(n=0;n<(size*4);n=n+1)
2311
           begin
2312
 
2313
                case(mode)
2314 10 rudi
                   0:    data = {16'hxxxx, n[15:0]};
2315 4 rudi
                   1:
2316
                        begin
2317
                                data[31:24] = x[7:0]+3;
2318
                                data[23:16] = x[7:0]+2;
2319
                                data[15:08] = x[7:0]+1;
2320
                                data[07:00] = x[7:0]+0;
2321
                        end
2322
 
2323
                   2:   begin
2324
                                data[31:16] = x[15:0]+1;
2325
                                data[15:00] = x[15:0]+0;
2326
                        end
2327
                endcase
2328
 
2329
                case(mode)
2330
                   0:    x = x + 1;
2331
                   1:   x = x + 4;
2332
                   2:   x = x + 2;
2333
                endcase
2334
 
2335 10 rudi
                exp = m0.rd_mem[n];
2336
                if(mode==0)      exp[31:16] = data[31:16];
2337 4 rudi
 
2338 10 rudi
                if(data !== exp)
2339 4 rudi
                   begin
2340
                        $display("ERROR: Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
2341 10 rudi
                        n, data, exp,  $time);
2342 4 rudi
                        error_cnt = error_cnt + 1;
2343
                   end
2344
           end
2345
   end
2346
end
2347
show_errors;
2348
$display("*****************************************************");
2349
$display("*** Test DONE ...                                 ***");
2350
$display("*****************************************************\n\n");
2351
 
2352
end
2353
endtask
2354
 
2355
 
2356
task sram_rd1;
2357
 
2358
integer         n,m,read,write;
2359 8 rudi
integer         d2, del, size;
2360 4 rudi
reg     [31:0]   data;
2361
begin
2362
 
2363
$display("\n\n");
2364
$display("*****************************************************");
2365
$display("*** SRAM Size & Delay Read Test 1 ...             ***");
2366
$display("*****************************************************\n");
2367
 
2368
        m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
2369
        m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
2370
 
2371
        m0.wb_wr1(`REG_BASE + `TMS4,    4'hf, 32'hffff_ffff);
2372
        m0.wb_wr1(`REG_BASE + `CSC4,    4'hf, 32'h0080_0003);
2373
 
2374 8 rudi
size = 4;
2375 4 rudi
del = 0;
2376
read = 1;
2377
write = 0;
2378
 
2379
sram0a.mem_fill( 256 );
2380
sram0b.mem_fill( 256 );
2381
 
2382
repeat(1)       @(posedge clk);
2383
 
2384
for(del=0;del<16;del=del+1)
2385
for(size=1;size<18;size=size+1)
2386
   begin
2387
        m0.mem_fill;
2388
 
2389
        $display("Size: %0d, Delay: %0d", size, del);
2390
//bw_clear;
2391
 
2392
        if(write)       m0.wb_wr_mult(`MEM_BASE4 + 0*4, 4'hf, del, size);
2393
        if(read)        m0.wb_rd_mult(`MEM_BASE4 + 0*4, 4'hf, del, size);
2394
        if(write)       m0.wb_wr_mult(`MEM_BASE4 + 4*4, 4'hf, del, size);
2395
        if(read)        m0.wb_rd_mult(`MEM_BASE4 + 4*4, 4'hf, del, size);
2396
        if(write)       m0.wb_wr_mult(`MEM_BASE4 + 8*4, 4'hf, del, size);
2397
        if(read)        m0.wb_rd_mult(`MEM_BASE4 + 8*4, 4'hf, del, size);
2398
        if(write)       m0.wb_wr_mult(`MEM_BASE4 + 12*4, 4'hf, del, size);
2399
        if(read)        m0.wb_rd_mult(`MEM_BASE4 + 12*4, 4'hf, del, size);
2400
 
2401
//bw_report;
2402
 
2403
        for(m=0;m< 4;m=m+1)
2404
        for(n=0;n< size;n=n+1)
2405
           begin
2406
 
2407
`ifdef MICRON
2408
                data[07:00] = sram0a.bank0[(m*4)+n];
2409
                data[15:08] = sram0a.bank1[(m*4)+n];
2410
                data[23:16] = sram0b.bank0[(m*4)+n];
2411
                data[31:24] = sram0b.bank1[(m*4)+n];
2412
`else
2413
                data[07:00] = sram0a.memb1[(m*4)+n];
2414
                data[15:08] = sram0a.memb2[(m*4)+n];
2415
                data[23:16] = sram0b.memb1[(m*4)+n];
2416
                data[31:24] = sram0b.memb2[(m*4)+n];
2417
`endif
2418
 
2419
                if(data !== m0.rd_mem[(m*size)+n])
2420
                   begin
2421
                        $display("ERROR: Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
2422
                        (m*4)+n, data, m0.rd_mem[(m*size)+n],  $time);
2423
                        error_cnt = error_cnt + 1;
2424
                   end
2425
 
2426
           end
2427
 
2428
   end
2429
 
2430
show_errors;
2431
$display("*****************************************************");
2432
$display("*** Test DONE ...                                 ***");
2433
$display("*****************************************************\n\n");
2434
 
2435
end
2436
endtask
2437
 
2438
task sram_wr1;
2439
 
2440
integer         n,m,read,write;
2441
integer         del, size;
2442
reg     [31:0]   data;
2443
begin
2444
 
2445
$display("\n\n");
2446
$display("*****************************************************");
2447
$display("*** SRAM Size & Delay Write Test 1 ...            ***");
2448
$display("*****************************************************\n");
2449
 
2450
        m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
2451
        m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
2452
 
2453
        m0.wb_wr1(`REG_BASE + `TMS4,    4'hf, 32'hffff_ffff);
2454
        m0.wb_wr1(`REG_BASE + `CSC4,    4'hf, 32'h0080_0803);
2455
 
2456
size = 4;
2457 10 rudi
del = 26;
2458 4 rudi
mode = 0;
2459
read = 1;
2460
write = 1;
2461
 
2462
sram0a.mem_fill( 256 );
2463
sram0b.mem_fill( 256 );
2464
 
2465
repeat(1)       @(posedge clk);
2466
 
2467
for(del=0;del<16;del=del+1)
2468
for(size=1;size<18;size=size+1)
2469
   begin
2470
        m0.mem_fill;
2471
 
2472
        $display("Size: %0d, Delay: %0d", size, del);
2473
//bw_clear;
2474
 
2475
        if(write)       m0.wb_wr_mult(`MEM_BASE4 + 0*4, 4'hf, del, size);
2476
        if(read)        m0.wb_rd_mult(`MEM_BASE4 + 0*4, 4'hf, del, size);
2477
        if(write)       m0.wb_wr_mult(`MEM_BASE4 + 32*4, 4'hf, del, size);
2478
        if(read)        m0.wb_rd_mult(`MEM_BASE4 + 32*4, 4'hf, del, size);
2479
        if(write)       m0.wb_wr_mult(`MEM_BASE4 + 64*4, 4'hf, del, size);
2480
        if(read)        m0.wb_rd_mult(`MEM_BASE4 + 64*4, 4'hf, del, size);
2481
        if(write)       m0.wb_wr_mult(`MEM_BASE4 + 96*4, 4'hf, del, size);
2482
        if(read)        m0.wb_rd_mult(`MEM_BASE4 + 96*4, 4'hf, del, size);
2483
 
2484
//bw_report;
2485
 
2486
repeat(10)      @(posedge clk);
2487
 
2488
for(m=0;m< 4;m=m+1)
2489
   for(n=0;n< size;n=n+1)
2490
           begin
2491
 
2492
`ifdef MICRON
2493
                data[07:00] = sram0a.bank0[(m*32)+n];
2494
                data[15:08] = sram0a.bank1[(m*32)+n];
2495
                data[23:16] = sram0b.bank0[(m*32)+n];
2496
                data[31:24] = sram0b.bank1[(m*32)+n];
2497
`else
2498
                data[07:00] = sram0a.memb1[(m*32)+n];
2499
                data[15:08] = sram0a.memb2[(m*32)+n];
2500
                data[23:16] = sram0b.memb1[(m*32)+n];
2501
                data[31:24] = sram0b.memb2[(m*32)+n];
2502
`endif
2503
 
2504
                if(data !== m0.wr_mem[(m*size)+n])
2505
                   begin
2506
                        $display("ERROR: Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
2507
                        (m*32)+n, data, m0.wr_mem[(m*size)+n],  $time);
2508
                        error_cnt = error_cnt + 1;
2509
                   end
2510
 
2511
           end
2512
 
2513
 
2514
   end
2515
 
2516
show_errors;
2517
$display("*****************************************************");
2518
$display("*** Test DONE ...                                 ***");
2519
$display("*****************************************************\n\n");
2520
 
2521
end
2522
endtask
2523
 
2524
 
2525
 
2526
task    scs_rdwr1;
2527
input           quick;
2528
 
2529
integer         quick;
2530
integer         x,s,n,m,adr;
2531
integer         del, size;
2532
reg     [7:0]    mode;
2533
reg     [2:0]    bs;
2534
integer         sz_inc;
2535
integer         sz_max, del_max;
2536
integer         read;
2537
reg     [2:0]    bas;
2538
reg     [31:0]   data;
2539
 
2540
begin
2541
 
2542
$display("\n\n");
2543
$display("*****************************************************");
2544
$display("*** SCS Read/Write Test 1 ...                     ***");
2545
$display("*****************************************************\n");
2546
 
2547
        m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
2548
        m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
2549
 
2550
        m0.wb_wr1(`REG_BASE + `TMS5,    4'hf, 32'hf03f_4104);
2551
        m0.wb_wr1(`REG_BASE + `CSC5,    4'hf, 32'h00a0_0027);
2552
 
2553
 
2554
case(quick)
2555
 0: sz_max = 32;
2556
 1: sz_max = 32;
2557
 2: sz_max = 16;
2558
endcase
2559
 
2560
case(quick)
2561
 0: del_max = 16;
2562
 1: del_max = 8;
2563
 2: del_max = 4;
2564
endcase
2565
 
2566
size = 1;
2567
del = 0;
2568
mode = 1;
2569
read = 1;
2570
write = 0;
2571
 
2572
s0.mem_fill;
2573
 
2574
repeat(5)       @(posedge clk);
2575
 
2576
for(del=0;del<del_max;del=del+1)
2577
for(size=1;size<sz_max;size=size+1)
2578
   begin
2579
        m0.mem_fill;
2580
 
2581
        if(verbose)     $display("Mode: %b, Size: %0d, Delay: %0d", mode,  size, del);
2582
 
2583
        if(write)       m0.wb_wr_mult(`MEM_BASE5 + size*0*4, 4'hf, del, size);
2584
        if(read)        m0.wb_rd_mult(`MEM_BASE5 + size*0*4, 4'hf, del, size);
2585
 
2586
        if(write)       m0.wb_wr_mult(`MEM_BASE5 + size*1*4, 4'hf, del, size);
2587
        if(read)        m0.wb_rd_mult(`MEM_BASE5 + size*1*4, 4'hf, del, size);
2588
 
2589
        if(write)       m0.wb_wr_mult(`MEM_BASE5 + size*2*4, 4'hf, del, size);
2590
        if(read)        m0.wb_rd_mult(`MEM_BASE5 + size*2*4, 4'hf, del, size);
2591
 
2592
        if(write)       m0.wb_wr_mult(`MEM_BASE5 + size*3*4, 4'hf, del, size);
2593
        if(read)        m0.wb_rd_mult(`MEM_BASE5 + size*3*4, 4'hf, del, size);
2594
 
2595
        repeat(10)      @(posedge clk);
2596
 
2597
        x = 0;
2598
        for(n=0;n<(size*4);n=n+1)
2599
           begin
2600
 
2601
                data = s0.mem[n];
2602
 
2603
                if(data !== m0.rd_mem[n])
2604
                   begin
2605
                        $display("ERROR: Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
2606
                        n, data, m0.rd_mem[n],  $time);
2607
                        error_cnt = error_cnt + 1;
2608
                   end
2609
           end
2610
 
2611
   end
2612
 
2613
 
2614
show_errors;
2615
$display("*****************************************************");
2616
$display("*** Test DONE ...                                 ***");
2617
$display("*****************************************************\n\n");
2618
 
2619
end
2620
endtask
2621
 
2622
 
2623
task sdram_wp;
2624
input           quick;
2625
 
2626
integer         quick;
2627
integer         n;
2628
integer         del, size;
2629
reg     [7:0]    mode;
2630
reg     [2:0]    bs;
2631
integer         sz_inc;
2632
integer         sz_max, del_max;
2633
integer         read;
2634
 
2635
begin
2636
$display("\n\n");
2637
$display("*****************************************************");
2638
$display("*** SDRAM Write Protect Test 1 ...                ***");
2639
$display("*****************************************************\n");
2640
 
2641
m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6020_0200);
2642
m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
2643
 
2644 10 rudi
m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
2645
                                        4'd0,           // RESERVED [31:28]
2646
                                        4'd7,           // Trfc [27:24]
2647
                                        4'd2,           // Trp [23:20]
2648
                                        3'd2,           // Trcd [19:17]
2649
                                        2'd1,           // Twr [16:15]
2650
                                        5'd0,           // RESERVED [14:10]
2651 4 rudi
                                        1'd0,   // Wr. Burst Len (1=Single)
2652
                                        2'd0,   // Op Mode
2653
                                        3'd2,   // CL
2654
                                        1'b0,   // Burst Type (0=Seq;1=Inter)
2655
                                        3'd3    // Burst Length
2656
                                        });
2657
 
2658
//m0.wb_wr1(`REG_BASE + `CSC0,  4'hf, 32'h0000_0921);
2659
m0.wb_wr1(`REG_BASE + `CSC0,    4'hf, 32'h0000_0121);
2660
 
2661
wb_err_check_dis=1;
2662
case(quick)
2663
 0: sz_max = 64;
2664
 1: sz_max = 32;
2665
 2: sz_max = 16;
2666
endcase
2667
 
2668
case(quick)
2669
 0: del_max = 16;
2670
 1: del_max = 8;
2671
 2: del_max = 4;
2672
endcase
2673
 
2674 10 rudi
size = 4;
2675
del = 4;
2676 4 rudi
mode = 0;
2677
read = 1;
2678
//force sdram0.Debug = 1;
2679
 
2680
for(mode=0;mode<20;mode=mode+1)
2681
begin
2682
        sdram0.mem_fill(1024);
2683
 
2684
        case(mode[4:2])
2685
           0: bs = 0;
2686
           1: bs = 1;
2687
           2: bs = 2;
2688
           3: bs = 3;
2689
           4: bs = 7;
2690
        endcase
2691
 
2692
        if(mode[1])
2693
           sz_inc = 1;
2694
        else
2695
                case(mode[4:2])
2696
                   0: sz_inc = 1;
2697
                   1: sz_inc = 2;
2698
                   2: sz_inc = 4;
2699
                   3: sz_inc = 8;
2700
                   4: sz_inc = 1;
2701
                endcase
2702
 
2703 10 rudi
        m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
2704
                                        4'd0,           // RESERVED [31:28]
2705
                                        4'd7,           // Trfc [27:24]
2706
                                        4'd2,           // Trp [23:20]
2707
                                        3'd2,           // Trcd [19:17]
2708
                                        2'd1,           // Twr [16:15]
2709
                                        5'd0,           // RESERVED [14:10]
2710 4 rudi
                                        1'd0+mode[1],   // Wr. Burst Len (1=Single)
2711
                                        2'd0,           // Op Mode
2712
                                        3'd2+mode[0],    // CL
2713
                                        1'b0,           // Burst Type (0=Seq;1=Inter)
2714
                                        3'd0+bs         // Burst Length
2715
                                        });
2716
 
2717
if(!verbose)    $display("Mode: %b", mode);
2718
 
2719
for(del=0;del<del_max;del=del+1)
2720
for(size=sz_inc;size<sz_max;size=size+sz_inc)
2721
   begin
2722
        m0.mem_fill;
2723
 
2724
        if(verbose)     $display("Mode: %b, Size: %0d, Delay: %0d", mode,  size, del);
2725
 
2726
        m0.wb_wr_mult(`MEM_BASE +        0, 4'hf, del, size);
2727
        if(read)        m0.wb_rd_mult(`MEM_BASE +        0, 4'hf, del, size);
2728
 
2729
        m0.wb_wr_mult(`MEM_BASE + size*1*4, 4'hf, del, size);
2730
        if(read)        m0.wb_rd_mult(`MEM_BASE + size*1*4, 4'hf, del, size);
2731
 
2732
        m0.wb_wr_mult(`MEM_BASE + size*2*4, 4'hf, del, size);
2733
        if(read)        m0.wb_rd_mult(`MEM_BASE + size*2*4, 4'hf, del, size);
2734
 
2735
        m0.wb_wr_mult(`MEM_BASE + size*3*4, 4'hf, del, size);
2736
        if(read)        m0.wb_rd_mult(`MEM_BASE + size*3*4, 4'hf, del, size);
2737
 
2738
        repeat(10)      @(posedge clk);
2739
 
2740
        for(n=0;n< (size*4);n=n+1)
2741
           begin
2742
                if((sdram0.Bank0[n] == m0.wr_mem[n]) |
2743
                        (|sdram0.Bank0[n] === 1'bx) |
2744
                        (|m0.wr_mem[n] === 1'bx)         )
2745
                   begin
2746
                        $display("ERROR: WR Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
2747
                        n, sdram0.Bank0[n], m0.wr_mem[n],  $time);
2748
                        error_cnt = error_cnt + 1;
2749
                   end
2750
           end
2751
   end
2752
 
2753
end
2754
 
2755
wb_err_check_dis=0;
2756
show_errors;
2757
$display("*****************************************************");
2758
$display("*** Test DONE ...                                 ***");
2759
$display("*****************************************************\n\n");
2760
end
2761
endtask
2762
 
2763
 
2764
task sram_wp;
2765
 
2766
integer         n,m,read,write;
2767
integer         del, size;
2768
reg     [31:0]   data;
2769
begin
2770
 
2771
$display("\n\n");
2772
$display("*****************************************************");
2773
$display("*** SRAM Write Protect Test 1 ...                 ***");
2774
$display("*****************************************************\n");
2775
 
2776
        m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
2777
        m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
2778
 
2779
        m0.wb_wr1(`REG_BASE + `TMS4,    4'hf, 32'hffff_ffff);
2780
        m0.wb_wr1(`REG_BASE + `CSC4,    4'hf, 32'h0080_0903);
2781
 
2782 10 rudi
size = 17;
2783
del = 15;
2784 4 rudi
mode = 0;
2785
read = 1;
2786
write = 1;
2787
 
2788
sram0a.mem_fill( 256 );
2789
sram0b.mem_fill( 256 );
2790
 
2791
wb_err_check_dis=1;
2792
repeat(1)       @(posedge clk);
2793
 
2794
for(del=0;del<16;del=del+1)
2795
for(size=1;size<18;size=size+1)
2796
   begin
2797
        m0.mem_fill;
2798
 
2799
        $display("Size: %0d, Delay: %0d", size, del);
2800
//bw_clear;
2801
 
2802
        if(write)       m0.wb_wr_mult(`MEM_BASE4 + 0*4, 4'hf, del, size);
2803
        if(read)        m0.wb_rd_mult(`MEM_BASE4 + 0*4, 4'hf, del, size);
2804
        if(write)       m0.wb_wr_mult(`MEM_BASE4 + 32*4, 4'hf, del, size);
2805
        if(read)        m0.wb_rd_mult(`MEM_BASE4 + 32*4, 4'hf, del, size);
2806
        if(write)       m0.wb_wr_mult(`MEM_BASE4 + 64*4, 4'hf, del, size);
2807
        if(read)        m0.wb_rd_mult(`MEM_BASE4 + 64*4, 4'hf, del, size);
2808
        if(write)       m0.wb_wr_mult(`MEM_BASE4 + 96*4, 4'hf, del, size);
2809
        if(read)        m0.wb_rd_mult(`MEM_BASE4 + 96*4, 4'hf, del, size);
2810
 
2811
//bw_report;
2812
 
2813
repeat(10)      @(posedge clk);
2814
 
2815
for(m=0;m< 4;m=m+1)
2816
   for(n=0;n< size;n=n+1)
2817
           begin
2818
 
2819
`ifdef MICRON
2820
                data[07:00] = sram0a.bank0[(m*32)+n];
2821
                data[15:08] = sram0a.bank1[(m*32)+n];
2822
                data[23:16] = sram0b.bank0[(m*32)+n];
2823
                data[31:24] = sram0b.bank1[(m*32)+n];
2824
`else
2825
                data[07:00] = sram0a.memb1[(m*32)+n];
2826
                data[15:08] = sram0a.memb2[(m*32)+n];
2827
                data[23:16] = sram0b.memb1[(m*32)+n];
2828
                data[31:24] = sram0b.memb2[(m*32)+n];
2829
`endif
2830
 
2831
                if(data == m0.wr_mem[(m*size)+n])
2832
                   begin
2833
                        $display("ERROR: Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
2834
                        (m*32)+n, data, m0.wr_mem[(m*size)+n],  $time);
2835
                        error_cnt = error_cnt + 1;
2836
                   end
2837
 
2838
           end
2839
 
2840
 
2841
   end
2842
 
2843
wb_err_check_dis=0;
2844
show_errors;
2845
$display("*****************************************************");
2846
$display("*** Test DONE ...                                 ***");
2847
$display("*****************************************************\n\n");
2848
 
2849
end
2850
endtask
2851
 
2852
 
2853
task sdram_rmw1;
2854
input           quick;
2855
 
2856
integer         quick;
2857
integer         n,m,adr;
2858
integer         del, size;
2859
reg     [7:0]    mode;
2860
reg     [2:0]    bs;
2861
integer         sz_inc;
2862
integer         sz_max, del_max;
2863
reg     [2:0]    kro;
2864
reg     [31:0]   data;
2865
integer         page_size;
2866
reg     [31:0]   mem0[0:1024];
2867
reg     [31:0]   mem1[0:1024];
2868
reg     [31:0]   mem2[0:1024];
2869
reg     [31:0]   mem3[0:1024];
2870
 
2871
begin
2872
 
2873
$display("\n\n");
2874
$display("*****************************************************");
2875
$display("*** SDRAM Size, Delay & Mode RMW test 1 ...       ***");
2876
$display("*** Different Row and Bank                        ***");
2877
$display("*****************************************************\n");
2878
 
2879
page_size = 256; // 64 mbit x 32 SDRAM
2880
 
2881
case(quick)
2882
 0: sz_max = 32;
2883
 1: sz_max = 32;
2884
 2: sz_max = 16;
2885
endcase
2886
 
2887
case(quick)
2888
 0: del_max = 16;
2889
 1: del_max = 8;
2890
 2: del_max = 4;
2891
endcase
2892
 
2893
m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
2894
m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
2895
 
2896 10 rudi
m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
2897
                                        4'd0,           // RESERVED [31:28]
2898
                                        4'd7,           // Trfc [27:24]
2899
                                        4'd2,           // Trp [23:20]
2900
                                        3'd2,           // Trcd [19:17]
2901
                                        2'd1,           // Twr [16:15]
2902
                                        5'd0,           // RESERVED [14:10]
2903 4 rudi
                                        1'd0,   // Wr. Burst Len (1=Single)
2904
                                        2'd0,   // Op Mode
2905
                                        3'd2,   // CL
2906
                                        1'b0,   // Burst Type (0=Seq;1=Inter)
2907
                                        3'd3    // Burst Length
2908
                                        });
2909
 
2910
kro = 0;
2911
for(kro=0;kro<2;kro=kro+1)       // Don't Need this for this test
2912
begin
2913
m0.wb_wr1(`REG_BASE + `CSC0,    4'hf, 32'h0000_0821 | (kro[0]<<10));
2914
 
2915
size = 4;
2916
del = 0;
2917 10 rudi
mode = 0;
2918 4 rudi
 
2919
//force sdram0.Debug = 1;
2920
 
2921
for(mode=0;mode<10;mode=mode+1)
2922
begin
2923
 
2924
        case(mode[3:1])
2925
           0: bs = 0;
2926
           1: bs = 1;
2927
           2: bs = 2;
2928
           3: bs = 3;
2929
           4: bs = 7;
2930
        endcase
2931
 
2932
        case(mode[3:1])
2933
           0: sz_inc = 1;
2934
           1: sz_inc = 2;
2935
           2: sz_inc = 4;
2936
           3: sz_inc = 8;
2937
           4: sz_inc = 1;
2938
        endcase
2939
 
2940 10 rudi
        m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
2941
                                        4'd0,           // RESERVED [31:28]
2942
                                        4'd7,           // Trfc [27:24]
2943
                                        4'd2,           // Trp [23:20]
2944
                                        3'd2,           // Trcd [19:17]
2945
                                        2'd1,           // Twr [16:15]
2946
                                        5'd0,           // RESERVED [14:10]
2947 4 rudi
                                        1'd0+mode[0],    // Wr. Burst Len (1=Single)
2948
                                        2'd0,           // Op Mode
2949
                                        3'd2,           // CL
2950
                                        1'b0,           // Burst Type (0=Seq;1=Inter)
2951
                                        3'd0+bs         // Burst Length
2952
                                        });
2953
 
2954
repeat(50)      @(posedge clk);
2955
 
2956
if(!verbose)    $display("KRO: %0d, Mode: %b", kro, mode);
2957
 
2958
for(del=0;del<del_max;del=del+1)
2959
for(size=sz_inc;size<sz_max;size=size+sz_inc)
2960
   begin
2961
        m0.mem_fill;
2962
        fill_mem(1024);
2963
        for(m=0;m<4;m=m+1)
2964
        for(n=0;n<(size*2)+1;n=n+1)
2965
                case(m)
2966
                   0: mem0[n] = sdram0.Bank0[n];
2967
                   1: mem1[n] = sdram0.Bank1[n+1*size*2];
2968
                   2: mem2[n] = sdram0.Bank2[n+2*size*2];
2969
                   3: mem3[n] = sdram0.Bank3[n+3*size*2];
2970
                endcase
2971
 
2972
        if(verbose)     $display("KRO: %0d, Mode: %b, Size: %0d, Delay: %0d",
2973
                                kro, mode,  size, del);
2974
 
2975
        m0.wb_rmw(`MEM_BASE + (page_size*0*4) + size*0*4, 4'hf, del, size, size);
2976
        m0.wb_rmw(`MEM_BASE + (page_size*0*4) + size*1*4, 4'hf, del, size, size);
2977
 
2978
        m0.wb_rmw(`MEM_BASE + (page_size*1*4) + size*2*4, 4'hf, del, size, size);
2979
        m0.wb_rmw(`MEM_BASE + (page_size*1*4) + size*3*4, 4'hf, del, size, size);
2980
 
2981
        m0.wb_rmw(`MEM_BASE + (page_size*2*4) + size*4*4, 4'hf, del, size, size);
2982
        m0.wb_rmw(`MEM_BASE + (page_size*2*4) + size*5*4, 4'hf, del, size, size);
2983
 
2984
        m0.wb_rmw(`MEM_BASE + (page_size*3*4) + size*6*4, 4'hf, del, size, size);
2985
        m0.wb_rmw(`MEM_BASE + (page_size*3*4) + size*7*4, 4'hf, del, size, size);
2986
 
2987
        for(m=0;m<4;m=m+1)
2988
        for(n=0;n<(size*2);n=n+1)
2989
           begin
2990
 
2991
                case(m)
2992
                   0: data = mem0[n];
2993
                   1: data = mem1[n];
2994
                   2: data = mem2[n];
2995
                   3: data = mem3[n];
2996
                endcase
2997
 
2998
                if((data !== m0.rd_mem[(m*size*2)+n]) | (|data === 1'bx) |
2999
                        (|m0.rd_mem[(m*size*2)+n] === 1'bx) )
3000
                   begin
3001
                        $display("ERROR: RD Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
3002
                        (m*size*2)+n, data, m0.rd_mem[(m*size*2)+n],  $time);
3003
                        error_cnt = error_cnt + 1;
3004
                   end
3005
 
3006
           end
3007
 
3008
        repeat(10)      @(posedge clk);
3009
 
3010
        for(m=0;m<4;m=m+1)
3011
        for(n=0;n<size*2;n=n+1)
3012
           begin
3013
 
3014
                case(m)
3015
                   0: data = sdram0.Bank0[n];
3016
                   1: data = sdram0.Bank1[n+1*size*2];
3017
                   2: data = sdram0.Bank2[n+2*size*2];
3018
                   3: data = sdram0.Bank3[n+3*size*2];
3019
                endcase
3020
 
3021
                if((data !== m0.wr_mem[(m*size*2)+n]) | (|data === 1'bx) |
3022
                        (|m0.wr_mem[(m*size*2)+n] === 1'bx) )
3023
                   begin
3024
                        $display("ERROR: WR Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
3025
                        (m*size*2)+n, data, m0.wr_mem[(m*size*2)+n],  $time);
3026
                        error_cnt = error_cnt + 1;
3027
                   end
3028
           end
3029
   end
3030
 
3031
end
3032
end
3033
 
3034
show_errors;
3035
$display("*****************************************************");
3036
$display("*** Test DONE ...                                 ***");
3037
$display("*****************************************************\n\n");
3038
end
3039
endtask
3040
 
3041
 
3042
 
3043
 
3044
task sdram_rmw2;
3045
input           quick;
3046
 
3047
integer         quick;
3048
integer         n,m,adr;
3049
integer         del, size;
3050
reg     [7:0]    mode;
3051
reg     [2:0]    bs;
3052
integer         sz_inc;
3053
integer         sz_max, del_max;
3054
reg     [2:0]    kro;
3055
reg     [31:0]   data, data1;
3056
integer         page_size;
3057
 
3058
begin
3059
 
3060
$display("\n\n");
3061
$display("*****************************************************");
3062
$display("*** SDRAM Size, Delay & Mode RMW test 2 ...       ***");
3063
$display("*** Different Row and Bank                        ***");
3064
$display("*****************************************************\n");
3065
 
3066
page_size = 256; // 64 mbit x 32 SDRAM
3067
 
3068
case(quick)
3069
 0: sz_max = 32;
3070
 1: sz_max = 32;
3071
 2: sz_max = 16;
3072
endcase
3073
 
3074
case(quick)
3075
 0: del_max = 16;
3076
 1: del_max = 8;
3077
 2: del_max = 4;
3078
endcase
3079
 
3080
m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
3081
m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
3082
 
3083 10 rudi
m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
3084
                                        4'd0,   // RESERVED [31:28]
3085
                                        4'd7,   // Trfc [27:24]
3086
                                        4'd2,   // Trp [23:20]
3087
                                        3'd2,   // Trcd [19:17]
3088
                                        2'd1,   // Twr [16:15]
3089
                                        5'd0,   // RESERVED [14:10]
3090 4 rudi
                                        1'd0,   // Wr. Burst Len (1=Single)
3091
                                        2'd0,   // Op Mode
3092
                                        3'd2,   // CL
3093
                                        1'b0,   // Burst Type (0=Seq;1=Inter)
3094
                                        3'd3    // Burst Length
3095
                                        });
3096
 
3097
kro = 0;
3098
for(kro=0;kro<2;kro=kro+1)       // Don't Need this for this test
3099
begin
3100
m0.wb_wr1(`REG_BASE + `CSC0,    4'hf, 32'h0000_0821 | (kro[0]<<10));
3101
 
3102 10 rudi
size = 1;
3103
del = 0;
3104
mode = 0;
3105 4 rudi
 
3106
//force sdram0.Debug = 1;
3107
 
3108
for(mode=0;mode<10;mode=mode+1)
3109
begin
3110
 
3111
        case(mode[3:1])
3112
           0: bs = 0;
3113
           1: bs = 1;
3114
           2: bs = 2;
3115
           3: bs = 3;
3116
           4: bs = 7;
3117
        endcase
3118
 
3119
        case(mode[3:1])
3120
           0: sz_inc = 1;
3121
           1: sz_inc = 2;
3122
           2: sz_inc = 4;
3123
           3: sz_inc = 8;
3124
           4: sz_inc = 1;
3125
        endcase
3126
 
3127 10 rudi
        m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, {
3128
 
3129
                                        4'd0,           // RESERVED [31:28]
3130
                                        4'd7,           // Trfc [27:24]
3131
                                        4'd2,           // Trp [23:20]
3132
                                        3'd2,           // Trcd [19:17]
3133
                                        2'd1,           // Twr [16:15]
3134
                                        5'd0,           // RESERVED [14:10]
3135
 
3136 4 rudi
                                        1'd0+mode[0],    // Wr. Burst Len (1=Single)
3137
                                        2'd0,           // Op Mode
3138
                                        3'd2,           // CL
3139
                                        1'b0,           // Burst Type (0=Seq;1=Inter)
3140
                                        3'd0+bs         // Burst Length
3141
                                        });
3142
 
3143
repeat(50)      @(posedge clk);
3144
 
3145
if(!verbose)    $display("KRO: %0d, Mode: %b", kro, mode);
3146
 
3147
for(del=0;del<del_max;del=del+1)
3148
for(size=sz_inc;size<sz_max;size=size+sz_inc)
3149
   begin
3150
        m0.mem_fill;
3151
        fill_mem(1024);
3152
 
3153
 
3154
        if(verbose)     $display("KRO: %0d, Mode: %b, Size: %0d, Delay: %0d",
3155
                                kro, mode,  size, del);
3156
 
3157
        m0.wb_wmr(`MEM_BASE + (page_size*0*4) + size*0*4, 4'hf, del, size, size);
3158
        m0.wb_wmr(`MEM_BASE + (page_size*0*4) + size*1*4, 4'hf, del, size, size);
3159
 
3160
        m0.wb_wmr(`MEM_BASE + (page_size*1*4) + size*2*4, 4'hf, del, size, size);
3161
        m0.wb_wmr(`MEM_BASE + (page_size*1*4) + size*3*4, 4'hf, del, size, size);
3162
 
3163
        m0.wb_wmr(`MEM_BASE + (page_size*2*4) + size*4*4, 4'hf, del, size, size);
3164
        m0.wb_wmr(`MEM_BASE + (page_size*2*4) + size*5*4, 4'hf, del, size, size);
3165
 
3166
        m0.wb_wmr(`MEM_BASE + (page_size*3*4) + size*6*4, 4'hf, del, size, size);
3167
        m0.wb_wmr(`MEM_BASE + (page_size*3*4) + size*7*4, 4'hf, del, size, size);
3168
 
3169
        for(n=0;n<(size*2);n=n+1)
3170
           begin
3171
 
3172
                data = m0.wr_mem[n];
3173
                data1 = m0.rd_mem[n];
3174
 
3175
                if((data !== data1) | (|data === 1'bx) |
3176
                        (|data1 === 1'bx) )
3177
                   begin
3178
                        $display("ERROR: WMR Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
3179
                        (m*size*2)+n, data, m0.rd_mem[(m*size*2)+n],  $time);
3180
                        error_cnt = error_cnt + 1;
3181
                   end
3182
 
3183
           end
3184
 
3185
   end
3186
 
3187
end
3188
end
3189
 
3190
show_errors;
3191
$display("*****************************************************");
3192
$display("*** Test DONE ...                                 ***");
3193
$display("*****************************************************\n\n");
3194
end
3195
endtask
3196
 
3197
 
3198
 
3199
task sram_rmw1;
3200
 
3201
integer         n,m,read,write;
3202
integer         del, size;
3203
reg     [31:0]   data;
3204
reg     [31:0]   mem[0:1024];
3205
begin
3206
 
3207
$display("\n\n");
3208
$display("*****************************************************");
3209
$display("*** SRAM Size & Delay RMW Test 1 ...              ***");
3210 10 rudi
$display("*** Time: %t", $time);
3211 4 rudi
$display("*****************************************************\n");
3212
 
3213
        m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
3214
        m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
3215
 
3216
        m0.wb_wr1(`REG_BASE + `TMS4,    4'hf, 32'hffff_ffff);
3217
        m0.wb_wr1(`REG_BASE + `CSC4,    4'hf, 32'h0080_0003);
3218
 
3219
size = 1;
3220
del = 0;
3221
 
3222
repeat(1)       @(posedge clk);
3223
 
3224
for(del=0;del<16;del=del+1)
3225
for(size=1;size<18;size=size+1)
3226
   begin
3227
        m0.mem_fill;
3228
        sram0a.mem_fill( 256 );
3229
        sram0b.mem_fill( 256 );
3230
        for(m=0;m<4;m=m+1)
3231
        for(n=0;n<(size*2)+1;n=n+1)
3232
           begin
3233
`ifdef MICRON
3234
                data[07:00] = sram0a.bank0[(m*32)+n];
3235
                data[15:08] = sram0a.bank1[(m*32)+n];
3236
                data[23:16] = sram0b.bank0[(m*32)+n];
3237
                data[31:24] = sram0b.bank1[(m*32)+n];
3238
`else
3239
                data[07:00] = sram0a.memb1[(m*32)+n];
3240
                data[15:08] = sram0a.memb2[(m*32)+n];
3241
                data[23:16] = sram0b.memb1[(m*32)+n];
3242
                data[31:24] = sram0b.memb2[(m*32)+n];
3243
`endif
3244
                mem[(m*32)+n] = data;
3245
           end
3246
 
3247
 
3248
        $display("Size: %0d, Delay: %0d", size, del);
3249
//bw_clear;
3250
 
3251
        m0.wb_rmw(`MEM_BASE4 + 00*4, 4'hf, del, size, size);
3252
        m0.wb_rmw(`MEM_BASE4 + 32*4, 4'hf, del, size, size);
3253
        m0.wb_rmw(`MEM_BASE4 + 64*4, 4'hf, del, size, size);
3254
        m0.wb_rmw(`MEM_BASE4 + 96*4, 4'hf, del, size, size);
3255
 
3256
//bw_report;
3257
 
3258
repeat(10)      @(posedge clk);
3259
 
3260
for(m=0;m< 4;m=m+1)
3261
   for(n=0;n< size;n=n+1)
3262
           begin
3263
 
3264
                data = mem[(m*32)+n];
3265
 
3266
                if(data !== m0.rd_mem[(m*size)+n])
3267
                   begin
3268
                        $display("ERROR: RD Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
3269
                        (m*32)+n, data, m0.rd_mem[(m*size)+n],  $time);
3270
                        error_cnt = error_cnt + 1;
3271 10 rudi
                        if(error_cnt > 10)      $finish;
3272 4 rudi
                   end
3273
 
3274
`ifdef MICRON
3275
                data[07:00] = sram0a.bank0[(m*32)+n];
3276
                data[15:08] = sram0a.bank1[(m*32)+n];
3277
                data[23:16] = sram0b.bank0[(m*32)+n];
3278
                data[31:24] = sram0b.bank1[(m*32)+n];
3279
`else
3280
                data[07:00] = sram0a.memb1[(m*32)+n];
3281
                data[15:08] = sram0a.memb2[(m*32)+n];
3282
                data[23:16] = sram0b.memb1[(m*32)+n];
3283
                data[31:24] = sram0b.memb2[(m*32)+n];
3284
`endif
3285
 
3286
                if(data !== m0.wr_mem[(m*size)+n])
3287
                   begin
3288
                        $display("ERROR: WR Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
3289
                        (m*32)+n, data, m0.wr_mem[(m*size)+n],  $time);
3290
                        error_cnt = error_cnt + 1;
3291 10 rudi
                        if(error_cnt > 10)      $finish;
3292 4 rudi
                   end
3293
 
3294
           end
3295
 
3296
   end
3297
 
3298
show_errors;
3299
$display("*****************************************************");
3300
$display("*** Test DONE ...                                 ***");
3301
$display("*****************************************************\n\n");
3302
 
3303
end
3304
endtask
3305
 
3306
 
3307
 
3308
task sram_rmw2;
3309
 
3310
integer         n,m,read,write;
3311
integer         del, size;
3312
reg     [31:0]   data;
3313
reg     [31:0]   mem[0:1024];
3314
begin
3315
 
3316
$display("\n\n");
3317
$display("*****************************************************");
3318
$display("*** SRAM Size & Delay RMW Test 2 ...              ***");
3319
$display("*****************************************************\n");
3320
 
3321
        m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'h6030_0300);
3322
        m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'h0000_00f0);
3323
 
3324
        m0.wb_wr1(`REG_BASE + `TMS4,    4'hf, 32'hffff_ffff);
3325
        m0.wb_wr1(`REG_BASE + `CSC4,    4'hf, 32'h0080_0003);
3326
 
3327
size = 4;
3328
del = 2;
3329
 
3330
repeat(1)       @(posedge clk);
3331
 
3332
for(del=0;del<16;del=del+1)
3333
for(size=1;size<18;size=size+1)
3334
   begin
3335
        m0.mem_fill;
3336
        sram0a.mem_fill( 256 );
3337
        sram0b.mem_fill( 256 );
3338
        for(m=0;m<4;m=m+1)
3339
        for(n=0;n<(size*2)+1;n=n+1)
3340
           begin
3341
`ifdef MICRON
3342
                data[07:00] = sram0a.bank0[(m*32)+n];
3343
                data[15:08] = sram0a.bank1[(m*32)+n];
3344
                data[23:16] = sram0b.bank0[(m*32)+n];
3345
                data[31:24] = sram0b.bank1[(m*32)+n];
3346
`else
3347
                data[07:00] = sram0a.memb1[(m*32)+n];
3348
                data[15:08] = sram0a.memb2[(m*32)+n];
3349
                data[23:16] = sram0b.memb1[(m*32)+n];
3350
                data[31:24] = sram0b.memb2[(m*32)+n];
3351
`endif
3352
                mem[(m*32)+n] = data;
3353
           end
3354
 
3355
 
3356
        $display("Size: %0d, Delay: %0d", size, del);
3357
//bw_clear;
3358
 
3359
        m0.wb_wmr(`MEM_BASE4 + 00*4, 4'hf, del, size, size);
3360
        m0.wb_wmr(`MEM_BASE4 + 32*4, 4'hf, del, size, size);
3361
        m0.wb_wmr(`MEM_BASE4 + 64*4, 4'hf, del, size, size);
3362
        m0.wb_wmr(`MEM_BASE4 + 96*4, 4'hf, del, size, size);
3363
 
3364
//bw_report;
3365
 
3366
repeat(10)      @(posedge clk);
3367
 
3368
 
3369
for(m=0;m< 4;m=m+1)
3370
   for(n=0;n< size;n=n+1)
3371
           begin
3372
 
3373
                data = m0.wr_mem[(m*size)+n];
3374
 
3375
                if(data !== m0.rd_mem[(m*size)+n])
3376
                   begin
3377
                        $display("ERROR: RD Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",
3378
                        (m*32)+n, data, m0.rd_mem[(m*size)+n],  $time);
3379
                        error_cnt = error_cnt + 1;
3380
                   end
3381
 
3382
           end
3383
 
3384
   end
3385
 
3386
show_errors;
3387
$display("*****************************************************");
3388
$display("*** Test DONE ...                                 ***");
3389
$display("*****************************************************\n\n");
3390
 
3391
end
3392
endtask
3393
 
3394
 

powered by: WebSVN 2.1.0

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