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

Subversion Repositories mem_ctrl

[/] [mem_ctrl/] [trunk/] [bench/] [verilog/] [test_bench_top.v] - Blame information for rev 15

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 15 rudi
//  $Id: test_bench_top.v,v 1.5 2001-11-13 00:45:15 rudi Exp $
41 4 rudi
//
42 15 rudi
//  $Date: 2001-11-13 00:45:15 $
43
//  $Revision: 1.5 $
44 4 rudi
//  $Author: rudi $
45
//  $Locker:  $
46
//  $State: Exp $
47
//
48
// Change History:
49
//               $Log: not supported by cvs2svn $
50 15 rudi
//               Revision 1.4  2001/11/11 01:52:02  rudi
51
//
52
//               Minor fixes to testbench ...
53
//
54 14 rudi
//               Revision 1.3  2001/09/02 02:29:43  rudi
55
//
56
//               Fixed the TMS register setup to be tight and correct.
57
//
58 10 rudi
//               Revision 1.2  2001/08/10 08:16:21  rudi
59
//
60
//               - Changed IO names to be more clear.
61
//               - Uniquifyed define names to be core specific.
62
//               - Removed "Refresh Early" configuration
63
//
64 8 rudi
//               Revision 1.1  2001/07/29 07:34:40  rudi
65
//
66
//
67
//               1) Changed Directory Structure
68
//               2) Fixed several minor bugs
69
//
70 4 rudi
//               Revision 1.2  2001/06/03 11:34:18  rudi
71
//               *** empty log message ***
72
//
73
//               Revision 1.1.1.1  2001/05/13 09:36:32  rudi
74
//               Created Directory Structure
75
//
76
//
77
//
78
//                        
79
 
80
`include "mc_defines.v"
81
 
82
module test;
83
 
84
reg             clk;
85
reg             rst;
86
 
87
// IO Prototypes
88
 
89
wire    [31:0]   wb_data_i;
90
wire    [31:0]   wb_data_o;
91
wire    [31:0]   wb_addr_i;
92
wire    [3:0]    wb_sel_i;
93
wire            wb_we_i;
94
wire            wb_cyc_i;
95
wire            wb_stb_i;
96
wire            wb_ack_o;
97
wire            wb_err_o;
98
wire            wb_rty_o;
99
 
100
reg             susp_req, resume_req;
101
wire            suspended;
102
wire    [31:0]   poc;
103
 
104
reg             mc_clk;
105
reg             mc_br;
106
wire            mc_bg;
107
wire            mc_ack;
108
wire    [23:0]   mc_addr;
109
wire    [31:0]   mc_data_i;
110
wire    [31:0]   mc_data_o;
111
wire    [3:0]    mc_dp_i;
112
wire    [3:0]    mc_dp_o;
113
wire            mc_data_oe;
114
wire    [3:0]    mc_dqm;
115
wire            mc_oe_;
116
wire            mc_we_;
117
wire            mc_cas_;
118
wire            mc_ras_;
119
wire            mc_cke_;
120
wire    [7:0]    mc_cs_;
121
wire            mc_sts;
122
wire            mc_rp_;
123
wire            mc_vpen;
124
wire            mc_adsc_;
125
wire            mc_adv_;
126
wire            mc_zz;
127
wire            mc_c_oe;
128
 
129
 
130
// Test Bench Variables
131
reg     [31:0]   wd_cnt;
132
integer         error_cnt;
133
integer         verbose;
134
integer         poc_mode;
135
reg             wb_err_check_dis;
136 10 rudi
integer         LVL;
137 4 rudi
 
138
integer cyc_cnt;
139
integer ack_cnt;
140
 
141
// Misc Variables
142
 
143
integer         n,m;
144
 
145
reg     [31:0]   data;
146
 
147
reg     [31:0]   buffer32;
148
integer         del, size;
149
reg     [7:0]    mode;
150
reg     [2:0]    bs;
151
integer         sz_inc;
152
integer         read, write;
153
integer         done;
154
integer         adr;
155
 
156
/////////////////////////////////////////////////////////////////////
157
//
158
// Defines 
159
//
160
 
161
`define MEM_BASE        32'h0000_0000
162
`define MEM_BASE1       32'h0400_0000
163
`define MEM_BASE2       32'h0800_0000
164
`define MEM_BASE3       32'h0c00_0000
165
`define MEM_BASE4       32'h1000_0000
166
`define MEM_BASE5       32'h1400_0000
167
`define MEM_BASE6       32'h1800_0000
168 14 rudi
`define REG_BASE        32'h6000_0000
169 4 rudi
 
170
`define CSR             8'h00
171
`define POC             8'h04
172
`define BA_MASK         8'h08
173
 
174
`define CSC0            8'h10
175
`define TMS0            8'h14
176
`define CSC1            8'h18
177
`define TMS1            8'h1c
178
`define CSC2            8'h20
179
`define TMS2            8'h24
180
`define CSC3            8'h28
181
`define TMS3            8'h2c
182
`define CSC4            8'h30
183
`define TMS4            8'h34
184
`define CSC5            8'h38
185
`define TMS5            8'h3c
186
`define CSC6            8'h40
187
`define TMS6            8'h44
188
`define CSC7            8'h48
189
`define TMS7            8'h4c
190
 
191
/////////////////////////////////////////////////////////////////////
192
//
193
// Simulation Initialization and Start up Section
194
//
195
 
196
`define SDRAM0          1
197
`define SRAM            1
198
`define MULTI_SDRAM     1
199
`define FLASH           1
200
`define MICRON          1
201
 
202
initial
203
   begin
204
        $display("\n\n");
205
        $display("*****************************************************");
206
        $display("* WISHBONE Memory Controller Simulation started ... *");
207
        $display("*****************************************************");
208
        $display("\n");
209
`ifdef WAVES
210
        $shm_open("waves");
211
        $shm_probe("AS",test,"AS");
212
        $display("INFO: Signal dump enabled ...\n\n");
213
`endif
214
        poc_mode = 1;
215
        #1;
216
        poc_mode = 0;
217
        wb_err_check_dis=0;
218
        cyc_cnt = 0;
219
        ack_cnt = 0;
220
        wd_cnt = 0;
221
        error_cnt = 0;
222
        clk = 1;
223
        mc_clk = 0;
224 14 rudi
        rst = 1;
225 4 rudi
        susp_req = 0;
226
        resume_req = 0;
227
        verbose = 1;
228
        mc_br = 0;
229
 
230 10 rudi
        repeat(11)      @(posedge clk);
231
        #1;
232 14 rudi
        rst = 0;
233 4 rudi
        repeat(10)      @(posedge clk);
234
 
235
        // HERE IS WHERE THE TEST CASES GO ...
236
 
237 15 rudi
if(1)   // Full Regression Run
238 4 rudi
   begin
239
$display(" ......................................................");
240
$display(" :                                                    :");
241
$display(" :    Long Regression Run ...                         :");
242
$display(" :....................................................:");
243
        verbose = 0;
244
`ifdef FLASH
245
        boot(0);
246
`endif
247
 
248
        m0.wb_wr1(`REG_BASE + `CSC3,    4'hf, 32'h0000_0000);
249
        sdram_wr1(0);
250
        sdram_rd1(0);
251
        sdram_rd2(0);
252
        sdram_wr2(0);
253
        sdram_rd3(0);
254
        sdram_wr3(0);
255
        sdram_rd4(0);
256
        sdram_wr4(0);
257
        sdram_wp(0);
258
        sdram_rmw1(0);
259
        sdram_rmw2(0);
260
 
261
`ifdef MULTI_SDRAM
262
        sdram_rd5(0);
263
        sdram_wr5(0);
264
`endif
265
 
266
`ifdef FLASH
267
        asc_rdwr1(0);
268
`endif
269
 
270
`ifdef SRAM
271
        sram_rd1;
272
        sram_wr1;
273
        sram_wp;
274
        sram_rmw1;
275
        sram_rmw2;
276
`endif
277
 
278
        scs_rdwr1(0);
279
 
280
   end
281
else
282 15 rudi
if(1)   // Quick Regression Run
283 4 rudi
   begin
284
$display(" ......................................................");
285
$display(" :                                                    :");
286
$display(" :    Short Regression Run ...                        :");
287
$display(" :....................................................:");
288
        verbose = 0;
289
`ifdef FLASH
290
        boot(2);
291
`endif
292
        m0.wb_wr1(`REG_BASE + `CSC3,    4'hf, 32'h0000_0000);
293 8 rudi
 
294 4 rudi
        sdram_rd1(2);
295
        sdram_wr1(2);
296
 
297
        sdram_rd2(2);
298
        sdram_wr2(2);
299
 
300
        sdram_rd3(2);
301
        sdram_wr3(2);
302
 
303
        sdram_rd4(2);
304
        sdram_wr4(2);
305
 
306
        sdram_wp(2);
307
        sdram_rmw1(2);
308
        sdram_rmw2(2);
309
 
310
`ifdef MULTI_SDRAM
311
        sdram_rd5(2);
312
        sdram_wr5(2);
313
`endif
314
 
315 10 rudi
 
316 4 rudi
`ifdef FLASH
317
        asc_rdwr1(2);
318
`endif
319
 
320
`ifdef SRAM
321
        sram_rd1;
322
        sram_wr1;
323
        sram_wp;
324
        sram_rmw1;
325
        sram_rmw2;
326
`endif
327 14 rudi
        //scs_rdwr1(2);
328 4 rudi
 
329 14 rudi
        mc_reset;
330 4 rudi
   end
331 14 rudi
//else
332 8 rudi
if(1)   // Suspend resume testing
333 4 rudi
begin
334
$display(" ......................................................");
335
$display(" :                                                    :");
336
$display(" :    Suspend Resume Testing ...                      :");
337
$display(" :....................................................:");
338
 
339
        verbose = 0;
340
        done = 0;
341 14 rudi
        LVL = 2;
342 10 rudi
 
343 4 rudi
        fork
344
 
345
           begin
346 10 rudi
 
347 4 rudi
`ifdef FLASH
348 10 rudi
                boot(LVL);
349 4 rudi
`endif
350
                m0.wb_wr1(`REG_BASE + `CSC3,    4'hf, 32'h0000_0000);
351 10 rudi
 
352 4 rudi
                while(susp_req | suspended)     @(posedge clk);
353 10 rudi
                sdram_rd1(LVL);
354 4 rudi
                while(susp_req | suspended)     @(posedge clk);
355 10 rudi
                sdram_wr1(LVL);
356 4 rudi
                while(susp_req | suspended)     @(posedge clk);
357 10 rudi
                sdram_rd2(LVL);
358
 
359
 
360 4 rudi
                while(susp_req | suspended)     @(posedge clk);
361 10 rudi
                sdram_wr2(LVL);
362
 
363 4 rudi
                while(susp_req | suspended)     @(posedge clk);
364 10 rudi
                sdram_rd3(LVL);
365 4 rudi
                while(susp_req | suspended)     @(posedge clk);
366 10 rudi
                sdram_wr3(LVL);
367 4 rudi
                while(susp_req | suspended)     @(posedge clk);
368 10 rudi
                sdram_rd4(LVL);
369 4 rudi
                while(susp_req | suspended)     @(posedge clk);
370 10 rudi
                sdram_wr4(LVL);
371 4 rudi
 
372
                while(susp_req | suspended)     @(posedge clk);
373 10 rudi
                sdram_wp(LVL);
374 4 rudi
                while(susp_req | suspended)     @(posedge clk);
375 10 rudi
                sdram_rmw1(LVL);
376 4 rudi
                while(susp_req | suspended)     @(posedge clk);
377 10 rudi
                sdram_rmw2(LVL);
378 4 rudi
 
379
`ifdef MULTI_SDRAM
380
                while(susp_req | suspended)     @(posedge clk);
381 10 rudi
                sdram_rd5(LVL);
382 4 rudi
                while(susp_req | suspended)     @(posedge clk);
383 10 rudi
                sdram_wr5(LVL);
384 4 rudi
`endif
385
 
386 14 rudi
 
387 4 rudi
`ifdef FLASH
388
                while(susp_req | suspended)     @(posedge clk);
389 10 rudi
                asc_rdwr1(LVL);
390 4 rudi
`endif
391
 
392
`ifdef SRAM
393 14 rudi
 
394 4 rudi
                while(susp_req | suspended)     @(posedge clk);
395
                sram_rd1;
396
                while(susp_req | suspended)     @(posedge clk);
397
                sram_wr1;
398
                while(susp_req | suspended)     @(posedge clk);
399
                sram_wp;
400
                while(susp_req | suspended)     @(posedge clk);
401 10 rudi
                sram_wp;
402
                while(susp_req | suspended)     @(posedge clk);
403 4 rudi
                sram_rmw1;
404 10 rudi
 
405 4 rudi
                while(susp_req | suspended)     @(posedge clk);
406 10 rudi
                sram_rmw1;
407
                while(susp_req | suspended)     @(posedge clk);
408 4 rudi
                sram_rmw2;
409
`endif
410 14 rudi
                //while(susp_req | suspended)   @(posedge clk);
411
                //scs_rdwr1(LVL);
412 4 rudi
 
413 10 rudi
 
414 4 rudi
                done = 1;
415
           end
416
 
417
           begin
418
                repeat(50)      @(posedge clk);
419
                while(!done)
420
                   begin
421
                        repeat(40)      @(posedge clk);
422
                        susp_res;
423
                   end
424
           end
425
        join
426 14 rudi
 
427
        mc_reset;
428 4 rudi
end
429 10 rudi
//else
430 15 rudi
if(1)   // Bus Request testing
431 4 rudi
begin
432
$display(" ......................................................");
433
$display(" :                                                    :");
434
$display(" :    Bus Request/Grant Testing ...                   :");
435
$display(" :....................................................:");
436
        verbose = 0;
437
        done = 0;
438 14 rudi
        LVL = 2;
439 4 rudi
        fork
440
 
441
           begin
442
`ifdef FLASH
443 10 rudi
                boot(LVL);
444 4 rudi
`endif
445
                m0.wb_wr1(`REG_BASE + `CSC3,    4'hf, 32'h0000_0000);
446 10 rudi
                sdram_rd1(LVL);
447
                sdram_wr1(LVL);
448
                sdram_rd1(LVL);
449
                sdram_wr1(LVL);
450
                sdram_rd3(LVL);
451
                sdram_wr3(LVL);
452
                sdram_rd4(LVL);
453
                sdram_wr4(LVL);
454
                sdram_wp(LVL);
455
                sdram_rmw1(LVL);
456
                sdram_rmw2(LVL);
457 4 rudi
 
458
`ifdef MULTI_SDRAM
459 10 rudi
                sdram_rd5(LVL);
460
                sdram_wr5(LVL);
461 4 rudi
`endif
462
 
463
`ifdef FLASH
464 10 rudi
                asc_rdwr1(LVL);
465 4 rudi
`endif
466
 
467
`ifdef SRAM
468
                sram_rd1;
469
                sram_wr1;
470
                sram_wp;
471
                sram_rmw1;
472
                sram_rmw2;
473
`endif
474 14 rudi
                //scs_rdwr1(LVL);
475 4 rudi
 
476
                done = 1;
477
           end
478
 
479
           begin
480
                repeat(50)      @(posedge clk);
481
                while(!done)
482
                   begin
483
                        repeat(40)      @(posedge clk);
484
                        bus_req;
485
                   end
486
           end
487
 
488
        join
489
end
490
else
491
if(1)   // Debug Tests
492
   begin
493
$display(" ......................................................");
494
$display(" :                                                    :");
495
$display(" :    Test Debug Testing ...                          :");
496
$display(" :....................................................:");
497 10 rudi
        //verbose = 0;
498 4 rudi
        //boot(2);
499 15 rudi
/*
500 4 rudi
 
501
`define CSR             8'h00
502
`define POC             8'h04
503
`define BA_MASK         8'h08
504
 
505 14 rudi
`define CSR_MASK        32'hff00_07fe
506
`define BAM_MASK        32'h0000_07ff
507
`define CSC_MASK        32'hffff_ffff
508
`define TMS_MASK        32'hffff_ffff
509
 
510
        m0.wb_wr1(`REG_BASE + `CSR,     4'hf, 32'hffff_ffff);
511
        m0.wb_wr1(`REG_BASE + `BA_MASK, 4'hf, 32'hffff_ffff);
512
        m0.wb_wr1(`REG_BASE + `CSC0,    4'hf, 32'hffff_ffff);
513
        m0.wb_wr1(`REG_BASE + `TMS0,    4'hf, 32'hffff_ffff);
514
        m0.wb_wr1(`REG_BASE + `CSC1,    4'hf, 32'hffff_ffff);
515
        m0.wb_wr1(`REG_BASE + `TMS1,    4'hf, 32'hffff_ffff);
516
        m0.wb_wr1(`REG_BASE + `CSC2,    4'hf, 32'hffff_ffff);
517
        m0.wb_wr1(`REG_BASE + `TMS2,    4'hf, 32'hffff_ffff);
518
        m0.wb_wr1(`REG_BASE + `CSC3,    4'hf, 32'hffff_ffff);
519
        m0.wb_wr1(`REG_BASE + `TMS3,    4'hf, 32'hffff_ffff);
520
 
521
        m0.wb_rd1(`REG_BASE + `CSR,     4'hf, data);
522
        m0.wb_rd1(`REG_BASE + `BA_MASK, 4'hf, data);
523
        m0.wb_rd1(`REG_BASE + `CSC0,    4'hf, data);
524
        m0.wb_rd1(`REG_BASE + `TMS0,    4'hf, data);
525
        m0.wb_rd1(`REG_BASE + `CSC1,    4'hf, data);
526
        m0.wb_rd1(`REG_BASE + `TMS1,    4'hf, data);
527
        m0.wb_rd1(`REG_BASE + `CSC2,    4'hf, data);
528
        m0.wb_rd1(`REG_BASE + `TMS2,    4'hf, data);
529
        m0.wb_rd1(`REG_BASE + `CSC3,    4'hf, data);
530
        m0.wb_rd1(`REG_BASE + `TMS3,    4'hf, data);
531 15 rudi
*/
532 14 rudi
 
533
 
534
 
535
 
536 4 rudi
        m0.wb_wr1(`REG_BASE + `CSC3,    4'hf, 32'h0000_0000);
537 14 rudi
        //sdram_rd1(2);
538
        //sdram_wr1(2);
539
        //asc_rdwr1(2);
540 8 rudi
        //sram_rd1;
541 14 rudi
        //sram_wr1;
542 8 rudi
        //sram_rmw1;
543 4 rudi
        //sram_rmw2;
544 8 rudi
        //sram_wp;
545 4 rudi
 
546
        //scs_rdwr1(2);
547
 
548
        //asc_rdwr1(2);
549
        //asc_rdwr1_x(2);
550
 
551 10 rudi
        //sdram_wp(2);
552
        //sdram_rmw1(2);
553 8 rudi
        //sdram_rmw2(2);
554
 
555 10 rudi
        //sdram_rd2(2);
556
        //sdram_wr2(2);
557 14 rudi
 
558
        //sdram_bo;
559
        //sdram_rd1b(2);
560
 
561
        //sdram_rd1(2);
562
        //sdram_wr1(2);
563
 
564
        //sdram_rd5(2);
565
        //sdram_wr5(2);
566 15 rudi
        sdram_wr4(2);
567 4 rudi
/*
568
        sdram_rd1(2);
569 10 rudi
        sdram_wr1(2);
570
        sdram_rd2(2);
571
        sdram_wr2(2);
572
        sdram_rd3(2);
573
        sdram_wr3(2);
574
        sdram_rd4(2);
575
        sdram_wr4(2);
576
        sdram_rd5(2);
577
        sdram_wr5(2);
578 14 rudi
 
579 10 rudi
        sdram_wp(2);
580
        sdram_rmw1(2);
581 14 rudi
        sdram_rmw2(2);
582
 
583 10 rudi
*/
584 4 rudi
 
585
 
586 14 rudi
 
587 4 rudi
        repeat(100)     @(posedge clk);
588
        $finish;
589
   end
590 14 rudi
else
591 4 rudi
   begin
592
 
593
        //
594
        // TEST DEVELOPMENT AREA
595
        //
596 10 rudi
        $display("\n\n");
597
        $display("*****************************************************");
598
        $display("*** Test Development ...                          ***");
599 14 rudi
        $display("*****************************************************\n"                                                             );
600 4 rudi
 
601
 
602 10 rudi
        show_errors;
603
        $display("*****************************************************");
604
        $display("*** Test DONE ...                                 ***");
605
        $display("*****************************************************\n\n");
606
   end
607 4 rudi
 
608 10 rudi
        repeat(100)     @(posedge clk);
609
        $finish;
610 4 rudi
 
611 10 rudi
end     // End of Initial
612 4 rudi
 
613
 
614 10 rudi
/////////////////////////////////////////////////////////////////////
615
//
616
// Clock Generation
617
//
618 4 rudi
 
619 10 rudi
always #2.5     clk = ~clk;
620 4 rudi
 
621 10 rudi
always @(posedge clk)
622
        mc_clk <= ~mc_clk;
623 4 rudi
 
624 10 rudi
/////////////////////////////////////////////////////////////////////
625
//
626
// IO Monitors
627
//
628 4 rudi
 
629 10 rudi
`define STD     10
630
always @(posedge clk)
631
        if((wb_ack_o === 1'bx) & ($time > `STD) )
632
           begin
633
                $display("ERROR: Wishbone ACK unknown (%t)", $time);
634
                error_cnt = error_cnt + 1;
635
           end
636 4 rudi
 
637 10 rudi
always @(posedge clk)
638
        if( (wb_err_o === 1'bx) & ($time > `STD) )
639 4 rudi
 
640 10 rudi
           begin
641
                $display("ERROR: Wishbone ERR unknown (%t)", $time);
642
                error_cnt = error_cnt + 1;
643
           end
644 4 rudi
 
645 10 rudi
always @(posedge clk)
646
        if( (mc_ras_ === 1'bx) & ($time > `STD) )
647 4 rudi
 
648 10 rudi
           begin
649
                $display("ERROR: MC RAS unknown (%t)", $time);
650
                error_cnt = error_cnt + 1;
651
           end
652 4 rudi
 
653 10 rudi
always @(posedge clk)
654
        if( (mc_cas_ === 1'bx) & ($time > `STD) )
655 4 rudi
 
656
           begin
657 10 rudi
                $display("ERROR: MC CAS unknown (%t)", $time);
658
                error_cnt = error_cnt + 1;
659
           end
660 4 rudi
 
661 10 rudi
always @(posedge clk)
662
        if( (mc_we_ === 1'bx) & ($time > `STD) )
663 4 rudi
 
664 10 rudi
           begin
665
                $display("ERROR: MC WE unknown (%t)", $time);
666
                error_cnt = error_cnt + 1;
667
           end
668 4 rudi
 
669 10 rudi
always @(posedge clk)
670
        if( ((|mc_cs_) === 1'bx) & ($time > `STD) )
671 4 rudi
 
672 10 rudi
           begin
673
                $display("ERROR: MC CS unknown (%t)", $time);
674
                error_cnt = error_cnt + 1;
675 4 rudi
           end
676
 
677 10 rudi
always @(error_cnt)
678
        if(error_cnt > 25)      #500 $finish;
679 4 rudi
 
680
/////////////////////////////////////////////////////////////////////
681
//
682
// IO Buffers
683
//
684
 
685
wire    [31:0]   mc_dq;
686
wire    [3:0]    mc_dqp;
687
wire    [23:0]   _mc_addr;
688
wire    [3:0]    _mc_dqm;
689
wire            _mc_oe_;
690
wire            _mc_we_;
691
wire            _mc_cas_;
692
wire            _mc_ras_;
693
wire            _mc_cke_;
694
wire    [7:0]    _mc_cs_;
695
wire            _mc_rp_;
696
wire            _mc_vpen;
697
wire            _mc_adsc_;
698
wire            _mc_adv_;
699
wire            _mc_zz;
700
reg     [31:0]   rst_dq_val;
701
 
702
always @(poc_mode)
703
        case(poc_mode)
704
           0: rst_dq_val = {28'hzzz_zzzz, 2'b10, 2'b00};
705
           1: rst_dq_val = {28'hzzz_zzzz, 2'b10, 2'b01};
706
           2: rst_dq_val = {28'hzzz_zzzz, 2'b10, 2'b10};
707
         //  3: rst_dq_val = {28'hzzzz_zzzz, 2'b10, 2'b11};
708
           default: rst_dq_val = 32'hzzzz_zzzz;
709
        endcase
710
 
711 14 rudi
/*
712
assign #1 mc_dq = mc_data_oe ? mc_data_o : (rst ? rst_dq_val : 32'hzzzz_zzzz);
713 10 rudi
assign #1 mc_data_i = mc_dq;
714 4 rudi
 
715 10 rudi
assign #1 mc_dqp = mc_data_oe ? mc_dp_o : 4'hz;
716
assign #1 mc_dp_i = mc_dqp;
717 4 rudi
 
718 10 rudi
assign #1 mc_addr = mc_c_oe ? _mc_addr : 24'bz;
719
assign #1 mc_dqm = mc_c_oe ? _mc_dqm : 4'bz;
720
assign #1 mc_oe_ = mc_c_oe ? _mc_oe_ : 1'bz;
721
assign #1 mc_we_ = mc_c_oe ? _mc_we_ : 1'bz;
722
assign #1 mc_cas_ = mc_c_oe ? _mc_cas_ : 1'bz;
723
assign #1 mc_ras_ = mc_c_oe ? _mc_ras_ : 1'bz;
724
assign #1 mc_cke_ = mc_c_oe ? _mc_cke_ : 1'bz;
725
assign #1 mc_cs_ = mc_c_oe ? _mc_cs_ : 8'bz;
726
assign #1 mc_rp_ = mc_c_oe ? _mc_rp_ : 1'bz;
727
assign #1 mc_vpen = mc_c_oe ? _mc_vpen : 1'bz;
728
assign #1 mc_adsc_ = mc_c_oe ? _mc_adsc_ : 1'bz;
729
assign #1 mc_adv_ = mc_c_oe ? _mc_adv_ : 1'bz;
730
assign #1 mc_zz = mc_c_oe ? _mc_zz : 1'bz;
731 14 rudi
*/
732 4 rudi
 
733 14 rudi
 
734
assign  mc_dq = mc_data_oe ? mc_data_o : (rst ? rst_dq_val : 32'hzzzz_zzzz);
735
assign  mc_data_i = mc_dq;
736
 
737
assign  mc_dqp = mc_data_oe ? mc_dp_o : 4'hz;
738
assign  mc_dp_i = mc_dqp;
739
 
740
assign  mc_addr = mc_c_oe ? _mc_addr : 24'bz;
741
assign  mc_dqm = mc_c_oe ? _mc_dqm : 4'bz;
742
assign  mc_oe_ = mc_c_oe ? _mc_oe_ : 1'bz;
743
assign  mc_we_ = mc_c_oe ? _mc_we_ : 1'bz;
744
assign  mc_cas_ = mc_c_oe ? _mc_cas_ : 1'bz;
745
assign  mc_ras_ = mc_c_oe ? _mc_ras_ : 1'bz;
746
assign  #1.5 mc_cke_ = mc_c_oe ? _mc_cke_ : 1'bz;
747
assign  mc_cs_ = mc_c_oe ? _mc_cs_ : 8'bz;
748
assign  mc_rp_ = mc_c_oe ? _mc_rp_ : 1'bz;
749
assign  mc_vpen = mc_c_oe ? _mc_vpen : 1'bz;
750
assign  mc_adsc_ = mc_c_oe ? _mc_adsc_ : 1'bz;
751
assign  mc_adv_ = mc_c_oe ? _mc_adv_ : 1'bz;
752
assign  mc_zz = mc_c_oe ? _mc_zz : 1'bz;
753
 
754
 
755
 
756
 
757 4 rudi
pullup p0(mc_cas_);
758
pullup p1(mc_ras_);
759
pullup p2(mc_oe_);
760
pullup p3(mc_we_);
761
pullup p4(mc_cke_);
762
pullup p5(mc_adsc_);
763
pullup p6(mc_adv_);
764
pullup p70(mc_cs_[0]);
765
pullup p71(mc_cs_[1]);
766
pullup p72(mc_cs_[2]);
767
pullup p73(mc_cs_[3]);
768
pullup p74(mc_cs_[4]);
769
pullup p75(mc_cs_[5]);
770
pullup p76(mc_cs_[6]);
771
pullup p77(mc_cs_[7]);
772
pullup p8(mc_rp_);
773
 
774
 
775
/////////////////////////////////////////////////////////////////////
776
//
777
// WISHBONE Memory Controller IP Core
778
//
779
mc_top  u0(
780 8 rudi
                .clk_i(         clk             ),
781
                .rst_i(         rst             ),
782 4 rudi
                .wb_data_i(     wb_data_i       ),
783
                .wb_data_o(     wb_data_o       ),
784
                .wb_addr_i(     wb_addr_i       ),
785
                .wb_sel_i(      wb_sel_i        ),
786
                .wb_we_i(       wb_we_i         ),
787
                .wb_cyc_i(      wb_cyc_i        ),
788
                .wb_stb_i(      wb_stb_i        ),
789
                .wb_ack_o(      wb_ack_o        ),
790
                .wb_err_o(      wb_err_o        ),
791 8 rudi
                .susp_req_i(    susp_req        ),
792
                .resume_req_i(  resume_req      ),
793
                .suspended_o(   suspended       ),
794
                .poc_o(         poc             ),
795
                .mc_clk_i(      mc_clk          ),
796
                .mc_br_pad_i(   mc_br           ),
797
                .mc_bg_pad_o(   mc_bg           ),
798
                .mc_ack_pad_i(  mc_ack          ),
799
                .mc_addr_pad_o( _mc_addr        ),
800
                .mc_data_pad_i( mc_data_i       ),
801
                .mc_data_pad_o( mc_data_o       ),
802
                .mc_dp_pad_i(   mc_dp_i         ),
803
                .mc_dp_pad_o(   mc_dp_o         ),
804
                .mc_doe_pad_doe_o(mc_data_oe    ),
805
                .mc_dqm_pad_o(  _mc_dqm         ),
806
                .mc_oe_pad_o_(  _mc_oe_         ),
807
                .mc_we_pad_o_(  _mc_we_         ),
808
                .mc_cas_pad_o_( _mc_cas_        ),
809
                .mc_ras_pad_o_( _mc_ras_        ),
810
                .mc_cke_pad_o_( _mc_cke_        ),
811
                .mc_cs_pad_o_(  _mc_cs_         ),
812
                .mc_sts_pad_i(  mc_sts          ),
813
                .mc_rp_pad_o_(  _mc_rp_         ),
814
                .mc_vpen_pad_o( _mc_vpen        ),
815
                .mc_adsc_pad_o_(_mc_adsc_       ),
816
                .mc_adv_pad_o_( _mc_adv_        ),
817
                .mc_zz_pad_o(   _mc_zz          ),
818
                .mc_coe_pad_coe_o(mc_c_oe       )
819 4 rudi
                );
820
 
821
/////////////////////////////////////////////////////////////////////
822
//
823
// WISHBONE Master Model
824
//
825
 
826
wb_mast m0(     .clk(           clk             ),
827 14 rudi
                .rst(           ~rst            ),
828 4 rudi
                .adr(           wb_addr_i       ),
829
                .din(           wb_data_o       ),
830
                .dout(          wb_data_i       ),
831
                .cyc(           wb_cyc_i        ),
832
                .stb(           wb_stb_i        ),
833
                .sel(           wb_sel_i        ),
834
                .we(            wb_we_i         ),
835
                .ack(           wb_ack_o        ),
836
                .err(           wb_err_o        ),
837
                .rty(           wb_rty_o        )
838
                );
839
 
840
/////////////////////////////////////////////////////////////////////
841
//
842
// Sync. CS Device Model
843
//
844
 
845
sync_cs_dev s0(
846
                .clk(           mc_clk          ),
847
                .addr(          mc_addr[15:0]    ),
848
                .dq(            mc_dq           ),
849
                .cs_(           mc_cs_[5]       ),
850
                .we_(           mc_we_          ),
851
                .oe_(           mc_oe_          ),
852
                .ack_(          mc_ack          )
853
                );
854
 
855
 
856
/////////////////////////////////////////////////////////////////////
857
//
858
// Memory Models
859
//
860
 
861
`ifdef SDRAM0
862
//      Model:  MT48LC2M32B2 (2Meg x 32 x 4 Banks)
863
mt48lc2m32b2 sdram0(
864
                .Dq(            mc_dq           ),
865
                .Addr(          mc_addr[10:0]    ),
866
                .Ba(            mc_addr[14:13]  ),
867
                .Clk(           mc_clk          ),
868
                .Cke(           mc_cke_         ),
869
                .Cs_n(          mc_cs_[0]        ),
870
                .Ras_n(         mc_ras_         ),
871
                .Cas_n(         mc_cas_         ),
872
                .We_n(          mc_we_          ),
873
                .Dqm(           mc_dqm          )
874
                );
875
 
876
wire    [27:0]   dq_tmp;
877
mt48lc2m32b2 sdram0p(
878
                .Dq(            {dq_tmp, mc_dqp}),
879
                .Addr(          mc_addr[10:0]    ),
880
                .Ba(            mc_addr[14:13]  ),
881
                .Clk(           mc_clk          ),
882
                .Cke(           mc_cke_         ),
883
                .Cs_n(          mc_cs_[0]        ),
884
                .Ras_n(         mc_ras_         ),
885
                .Cas_n(         mc_cas_         ),
886
                .We_n(          mc_we_          ),
887
                .Dqm(           mc_dqm          )
888
                );
889
 
890
task fill_mem;
891
input   size;
892
 
893
integer         size, n;
894
reg     [31:0]   data;
895
 
896
begin
897
sdram0.mem_fill(size);
898
 
899
for(n=0;n<size;n=n+1)
900
   begin
901
        data = sdram0.Bank0[n];
902
        sdram0p.Bank0[n] = {28'h0, ^data[31:24], ^data[23:16], ^data[15:8], ^data[7:0] };
903
        data = sdram0.Bank1[n];
904
        sdram0p.Bank1[n] = {28'h0, ^data[31:24], ^data[23:16], ^data[15:8], ^data[7:0] };
905
        data = sdram0.Bank2[n];
906
        sdram0p.Bank2[n] = {28'h0, ^data[31:24], ^data[23:16], ^data[15:8], ^data[7:0] };
907
        data = sdram0.Bank3[n];
908
        sdram0p.Bank3[n] = {28'h0, ^data[31:24], ^data[23:16], ^data[15:8], ^data[7:0] };
909
   end
910
 
911
 
912
end
913
endtask
914
 
915
 
916
`endif
917
 
918
 
919
`ifdef MULTI_SDRAM
920
//      Model:  MT48LC2M32B2 (2Meg x 32 x 4 Banks)
921
 
922
mt48lc2m32b2 sdram1(
923
                .Dq(            mc_dq           ),
924
                .Addr(          mc_addr[10:0]    ),
925
                .Ba(            mc_addr[14:13]  ),
926
                .Clk(           mc_clk          ),
927
                .Cke(           mc_cke_         ),
928
                .Cs_n(          mc_cs_[1]       ),
929
                .Ras_n(         mc_ras_         ),
930
                .Cas_n(         mc_cas_         ),
931
                .We_n(          mc_we_          ),
932
                .Dqm(           mc_dqm          )
933
                );
934
 
935
//      Model:  MT48LC2M32B2 (2Meg x 32 x 4 Banks)
936
mt48lc2m32b2 sdram2(
937
                .Dq(            mc_dq           ),
938
                .Addr(          mc_addr[10:0]    ),
939
                .Ba(            mc_addr[14:13]  ),
940
                .Clk(           mc_clk          ),
941
                .Cke(           mc_cke_         ),
942
                .Cs_n(          mc_cs_[2]       ),
943
                .Ras_n(         mc_ras_         ),
944
                .Cas_n(         mc_cas_         ),
945
                .We_n(          mc_we_          ),
946
                .Dqm(           mc_dqm          )
947
                );
948
 
949
 
950 14 rudi
mt48lc16m16a2 sdram1a(
951 4 rudi
                .Dq(            mc_dq[15:0]      ),
952 14 rudi
                .Addr(          mc_addr[12:0]    ),
953 4 rudi
                .Ba(            mc_addr[14:13]  ),
954
                .Clk(           mc_clk          ),
955
                .Cke(           mc_cke_         ),
956 14 rudi
                .Cs_n(          mc_cs_[5]       ),
957 4 rudi
                .Ras_n(         mc_ras_         ),
958
                .Cas_n(         mc_cas_         ),
959
                .We_n(          mc_we_          ),
960
                .Dqm(           mc_dqm[1:0]      )
961
                );
962
 
963 14 rudi
mt48lc16m16a2 sdram1b(
964 4 rudi
                .Dq(            mc_dq[31:16]    ),
965 14 rudi
                .Addr(          mc_addr[12:0]    ),
966 4 rudi
                .Ba(            mc_addr[14:13]  ),
967
                .Clk(           mc_clk          ),
968
                .Cke(           mc_cke_         ),
969 14 rudi
                .Cs_n(          mc_cs_[5]       ),
970 4 rudi
                .Ras_n(         mc_ras_         ),
971
                .Cas_n(         mc_cas_         ),
972
                .We_n(          mc_we_          ),
973
                .Dqm(           mc_dqm[3:2]     )
974
                );
975
 
976 14 rudi
/*
977 4 rudi
mt48lc8m8a2 sdram2a(
978
                .Dq(            mc_dq[07:00]    ),
979
                .Addr(          mc_addr[11:0]   ),
980
                .Ba(            mc_addr[14:13]  ),
981
                .Clk(           mc_clk          ),
982
                .Cke(           mc_cke_         ),
983
                .Cs_n(          mc_cs_[2]       ),
984
                .Ras_n(         mc_ras_         ),
985
                .Cas_n(         mc_cas_         ),
986
                .We_n(          mc_we_          ),
987
                .Dqm(           mc_dqm[0]       )
988
                );
989
 
990
mt48lc8m8a2 sdram2b(
991
                .Dq(            mc_dq[15:08]    ),
992
                .Addr(          mc_addr[11:0]   ),
993
                .Ba(            mc_addr[14:13]  ),
994
                .Clk(           mc_clk          ),
995
                .Cke(           mc_cke_         ),
996
                .Cs_n(          mc_cs_[2]       ),
997
                .Ras_n(         mc_ras_         ),
998
                .Cas_n(         mc_cas_         ),
999
                .We_n(          mc_we_          ),
1000
                .Dqm(           mc_dqm[1]       )
1001
                );
1002
 
1003
mt48lc8m8a2 sdram2c(
1004
                .Dq(            mc_dq[23:16]    ),
1005
                .Addr(          mc_addr[11:0]   ),
1006
                .Ba(            mc_addr[14:13]  ),
1007
                .Clk(           mc_clk          ),
1008
                .Cke(           mc_cke_         ),
1009
                .Cs_n(          mc_cs_[2]       ),
1010
                .Ras_n(         mc_ras_         ),
1011
                .Cas_n(         mc_cas_         ),
1012
                .We_n(          mc_we_          ),
1013
                .Dqm(           mc_dqm[2]       )
1014
                );
1015
 
1016
mt48lc8m8a2 sdram2d(
1017
                .Dq(            mc_dq[31:24]    ),
1018
                .Addr(          mc_addr[11:0]   ),
1019
                .Ba(            mc_addr[14:13]  ),
1020
                .Clk(           mc_clk          ),
1021
                .Cke(           mc_cke_         ),
1022
                .Cs_n(          mc_cs_[2]       ),
1023
                .Ras_n(         mc_ras_         ),
1024
                .Cas_n(         mc_cas_         ),
1025
                .We_n(          mc_we_          ),
1026
                .Dqm(           mc_dqm[3]       )
1027
                );
1028
*/
1029
 
1030
`endif
1031
 
1032
`ifdef FLASH
1033
IntelAdvBoot f1(
1034
                .dq(    mc_dq[15:0]      ),
1035
                .addr(  mc_addr[19:0]    ),
1036
                .ceb(   mc_cs_[3]       ),
1037
                .oeb(   mc_oe_          ),
1038
                .web(   mc_we_          ),
1039
                .rpb(   mc_rp_          ),
1040
                .wpb(   1'b0            ),
1041
                .vpp(   3300            ),
1042
                .vcc(   3300            )
1043
                );
1044
`endif
1045
 
1046
 
1047
`ifdef SRAM
1048
 
1049
`ifdef MICRON
1050
mt58l1my18d sram0a(
1051
                .Dq(            {mc_dqp[1],
1052
                                mc_dq[15:8],
1053
                                mc_dqp[0],
1054
                                mc_dq[7:0]}      ),
1055
 
1056
                .Addr(          mc_addr[19:0]    ),
1057
                .Mode(          1'b0            ),
1058
                .Adv_n(         mc_adv_         ),
1059
                .Clk(           mc_clk          ),
1060
                .Adsc_n(        mc_adsc_        ),
1061
                .Adsp_n(        1'b1            ),
1062
 
1063
                .Bwa_n(         mc_dqm[0]        ),
1064
                .Bwb_n(         mc_dqm[1]       ),
1065
                .Bwe_n(         mc_we_          ),
1066
                .Gw_n(          1'b1            ),
1067
 
1068
                .Ce_n(          mc_cs_[4]       ),
1069
                .Ce2(           1'b1            ),
1070
                .Ce2_n(         1'b0            ),
1071
                .Oe_n(          mc_oe_          ),
1072
                .Zz(            mc_zz           )
1073
                );
1074
 
1075
 
1076
mt58l1my18d sram0b(
1077
                .Dq(            {mc_dqp[3],
1078
                                mc_dq[31:24],
1079
                                mc_dqp[2],
1080
                                mc_dq[23:16]}   ),
1081
 
1082
                .Addr(          mc_addr[19:0]    ),
1083
                .Mode(          1'b0            ),
1084
                .Adv_n(         mc_adv_         ),
1085
                .Clk(           mc_clk          ),
1086
                .Adsc_n(        mc_adsc_        ),
1087
                .Adsp_n(        1'b1            ),
1088
 
1089
                .Bwa_n(         mc_dqm[2]       ),
1090
                .Bwb_n(         mc_dqm[3]       ),
1091
                .Bwe_n(         mc_we_          ),
1092
                .Gw_n(          1'b1            ),
1093
 
1094
                .Ce_n(          mc_cs_[4]       ),
1095
                .Ce2(           1'b1            ),
1096
                .Ce2_n(         1'b0            ),
1097
                .Oe_n(          mc_oe_          ),
1098
                .Zz(            mc_zz           )
1099
                );
1100
 
1101
`else
1102
 
1103
idt71t67802s133 sram0a(
1104
                .A(     mc_addr[18:0]    ),
1105
                .D(     mc_dq[15:0]      ),
1106
                .DP(    mc_dqp[1:0]      ),
1107
                .oe_(   mc_oe_          ),
1108
                .ce_(   mc_cs_[4]       ),
1109
                .cs0(   1'b1            ),
1110
                .cs1_(  1'b0            ),
1111
                .lbo_(  1'b0            ),
1112
 
1113
                .gw_(   1'b1            ),
1114
                .bwe_(  mc_we_          ),
1115
                .bw2_(  mc_dqm[1]       ),
1116
                .bw1_(  mc_dqm[0]        ),
1117
 
1118
                .adsp_( 1'b1            ),
1119
                .adsc_( mc_adsc_        ),
1120
                .adv_(  mc_adv_         ),
1121
                .clk(   mc_clk          )
1122
                );
1123
 
1124
idt71t67802s133 sram0b(
1125
                .A(     mc_addr[18:0]    ),
1126
                .D(     mc_dq[31:16]    ),
1127
                .DP(    mc_dqp[3:2]     ),
1128
                .oe_(   mc_oe_          ),
1129
                .ce_(   mc_cs_[4]       ),
1130
                .cs0(   1'b1            ),
1131
                .cs1_(  1'b0            ),
1132
                .lbo_(  1'b0            ),
1133
 
1134
                .gw_(   1'b1            ),
1135
                .bwe_(  mc_we_          ),
1136
                .bw2_(  mc_dqm[3]       ),
1137
                .bw1_(  mc_dqm[2]       ),
1138
 
1139
                .adsp_( 1'b1            ),
1140
                .adsc_( mc_adsc_        ),
1141
                .adv_(  mc_adv_         ),
1142
                .clk(   mc_clk          )
1143
                );
1144
`endif
1145
 
1146
`endif
1147
 
1148
`include "tests.v"
1149
`include "test_lib.v"
1150
 
1151
endmodule
1152
 

powered by: WebSVN 2.1.0

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