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

Subversion Repositories mem_ctrl

[/] [mem_ctrl/] [trunk/] [bench/] [richard/] [verilog/] [bench.v] - Blame information for rev 28

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 25 rherveille
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  OpenCores Memory Controller Testbench                      ////
4
////  Main testbench                                             ////
5
////                                                             ////
6
////  Author: Richard Herveille                                  ////
7
////          richard@asics.ws                                   ////
8
////                                                             ////
9
////                                                             ////
10
////  Downloaded from: http://www.opencores.org/cores/mem_ctrl/  ////
11
////                                                             ////
12
/////////////////////////////////////////////////////////////////////
13
////                                                             ////
14
//// Copyright (C) 2001 Richard Herveille                        ////
15
////                    richard@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
// ToDo:
39
// 1) add power-on configuration
40
// 2) test SSRAM
41
// 3) test synchronous devices ???
42
//
43
 
44
//  CVS Log
45
//
46
//  $Id: bench.v,v 1.1 2002-03-06 15:10:34 rherveille Exp $
47
//
48
//  $Date: 2002-03-06 15:10:34 $
49
//  $Revision: 1.1 $
50
//  $Author: rherveille $
51
//  $Locker:  $
52
//  $State: Exp $
53
//
54
// Change History:
55
//               $Log: not supported by cvs2svn $
56
//
57
 
58
`include "timescale.v"
59
 
60
`define SDRAM_ROWA_HI 12 // row address hi-bit
61
`define SDRAM_COLA_HI 8  // column address hi-bit
62
 
63
`define BA_MASK    32'h0000_00e0 // base address mask
64
`define SDRAM1_LOC 32'h0400_0000 // location of sdram1 in address-space
65
`define SDRAM2_LOC 32'h0800_0000 // location of sdram2 in address-space
66
`define SRAM_LOC   32'h0C00_0000 // location of srams  in address-space
67
`define SSRAM_LOC  32'h1000_0000 // location of ssrams in address-space
68
 
69
module bench_top();
70
 
71
        //
72
        // internal wires
73
        //
74
        reg wb_clk;
75
        reg mc_clk;
76
 
77
        reg  wb_rst;
78
        wire [31:0] wb_dat_i, wb_dat_o;
79
        wire [31:0] wb_adr_o;
80
        wire        wb_cyc_o, wb_stb_o;
81
        wire [ 3:0] wb_sel_o;
82
        wire        wb_ack_i, wb_err_i, wb_rty_i;
83
 
84
        wire        wb_mc_stb;
85
 
86
        wire [23:0] mc_adr_o;
87
        wire [31:0] mc_dq, mc_dq_o;
88
        wire [ 3:0] mc_dp, mc_dp_o, pbus_o, pbus_i;
89
        reg  [ 3:0] set_par;
90
        wire [31:0] par_con;
91
        reg         sel_par, sel_pbus;
92
        wire        par_sdram_cs;
93
        wire        mc_doe_o;
94
        wire [ 3:0] mc_dqm_o;
95
        wire        mc_we_o, mc_oe_o;
96
        wire        mc_ras_o, mc_cas_o, mc_cke_o;
97
        wire [ 7:0] mc_cs_o;
98
        wire        mc_pad_oe;
99
        wire        mc_adsc_o, mc_adv_o, mc_zz_o; // ssram connections
100
 
101
        wire ext_br, ext_bg;
102
 
103
        //
104
        // hookup modules
105
        //
106
 
107
        // hookup watch-dog counter
108
        watch_dog #(1024) wdog (
109
                .clk(wb_clk),
110
                .cyc_i(wb_cyc_o),
111
                .ack_i(wb_ack_i),
112
                .adr_i(wb_adr_o)
113
        );
114
 
115
        // hookup external bus-master model
116
        bm_model ext_bm(
117
                .br(ext_br),
118
                .bg(ext_bg),
119
                .chk(mc_pad_oe)
120
        );
121
 
122
        // hookup ERR checker
123
        err_check err_chk(wb_err_i, sel_par);
124
 
125
        // hookup CSn checker
126
        cs_check cs_chec(mc_cs_o);
127
 
128
        // hookup memory controller
129
        mc_top dut (
130
                // wishbone interface
131
                .clk_i(wb_clk),
132
                .rst_i(wb_rst),
133
                .wb_data_i(wb_dat_o),
134
                .wb_data_o(wb_dat_i),
135
                .wb_addr_i(wb_adr_o),
136
                .wb_sel_i(wb_sel_o),
137
                .wb_we_i(wb_we_o),
138
                .wb_cyc_i(wb_cyc_o),
139
                .wb_stb_i(wb_stb_o),
140
                .wb_ack_o(wb_ack_i),
141
                .wb_err_o(wb_err_i),
142
 
143
                // memory controller
144
                .susp_req_i(1'b0),
145
                .resume_req_i(1'b0),
146
                .suspended_o(),
147
                .poc_o(),
148
                .mc_clk_i(mc_clk),
149
                .mc_br_pad_i(ext_br),
150
                .mc_bg_pad_o(ext_bg),
151
                .mc_ack_pad_i(1'b0),
152
                .mc_addr_pad_o(mc_adr_o),
153
                .mc_data_pad_i(mc_dq),
154
                .mc_data_pad_o(mc_dq_o),
155
                .mc_dp_pad_i(pbus_i), // attach parity bus
156
                .mc_dp_pad_o(mc_dp_o),
157
                .mc_doe_pad_doe_o(mc_doe_o),
158
                .mc_dqm_pad_o(mc_dqm_o),
159
                .mc_oe_pad_o_(mc_oe_o),
160
                .mc_we_pad_o_(mc_we_o),
161
                .mc_cas_pad_o_(mc_cas_o),
162
                .mc_ras_pad_o_(mc_ras_o),
163
                .mc_cke_pad_o_(mc_cke_o),
164
                .mc_cs_pad_o_(mc_cs_o),
165
                .mc_sts_pad_i(1'b0),
166
                .mc_rp_pad_o_(),
167
                .mc_vpen_pad_o(),
168
                .mc_adsc_pad_o_(mc_adsc_o),
169
                .mc_adv_pad_o_(mc_adv_o),
170
                .mc_zz_pad_o(mc_zz_o),
171
                .mc_coe_pad_coe_o(mc_pad_oe)
172
        );
173
 
174
        // assign memory controller stb_signal
175
        assign wb_mc_stb = wb_adr_o[31];
176
 
177
        // generate output buffers for memory controller
178
        assign mc_dq = mc_doe_o ? mc_dq_o : 32'bz;
179
        assign mc_dp = mc_doe_o ? mc_dp_o : 4'bz;
180
 
181
        // hookup ssrams (CHIP SELECT 4)
182
        mt58l1my18d ssram0 (
183
                .Dq( {par_con[24], par_con[16], mc_dq[31:16]} ),
184
                .Addr(mc_adr_o[19:0]),
185
                .Mode(1'b0),       // This input (sometimes called LBO) selects burst order
186
                                   // 1'b0 = linear burst, 1'b1 = interleaved burst
187
                .Adv_n(mc_adv_o),
188
                .Clk(mc_clk),
189
                .Adsc_n(mc_adsc_o),
190
                .Adsp_n(1'b1),
191
                .Bwa_n(mc_dqm_o[3]),
192
                .Bwb_n(mc_dqm_o[2]), // or the otherway around
193
                .Bwe_n(mc_we_o),
194
                .Gw_n(1'b1),       // ??
195
                .Ce_n(mc_cs_o[4]),
196
                .Ce2(1'b1),
197
                .Ce2_n(1'b0),
198
                .Oe_n(mc_oe_o),
199
                .Zz(mc_zz_o)
200
        );
201
 
202
        mt58l1my18d ssram1 (
203
                .Dq( {par_con[8], par_con[0], mc_dq[15:0]} ),
204
                .Addr(mc_adr_o[19:0]),
205
                .Mode(1'b0),       // This input (sometimes called LBO) selects burst order
206
                                   // 1'b0 = linear burst, 1'b1 = interleaved burst
207
                .Adv_n(mc_adv_o),
208
                .Clk(mc_clk),
209
                .Adsc_n(mc_adsc_o),
210
                .Adsp_n(1'b1),
211
                .Bwa_n(mc_dqm_o[1]),
212
                .Bwb_n(mc_dqm_o[0]), // or the otherway around
213
                .Bwe_n(mc_we_o),
214
                .Gw_n(1'b1),
215
                .Ce_n(mc_cs_o[4]),
216
                .Ce2(1'b1),
217
                .Ce2_n(1'b0),
218
                .Oe_n(mc_oe_o),
219
                .Zz(mc_zz_o)
220
        );
221
 
222
 
223
        // hookup sdrams (CHIP SELECT 3)
224
        mt48lc16m16a2 sdram0_3(
225
                .Dq(mc_dq[31:16]),
226
                .Addr(mc_adr_o[12:0]),
227
                .Ba(mc_adr_o[14:13]),
228
                .Clk(mc_clk),
229
                .Cke(mc_cke_o),
230
                .Cs_n(mc_cs_o[3]),
231
                .Ras_n(mc_ras_o),
232
                .Cas_n(mc_cas_o),
233
                .We_n(mc_we_o),
234
                .Dqm(mc_dqm_o[3:2])
235
        );
236
 
237
        mt48lc16m16a2 sdram1_3(
238
                .Dq(mc_dq[15:0]),
239
                .Addr(mc_adr_o[12:0]),
240
                .Ba(mc_adr_o[14:13]),
241
                .Clk(mc_clk),
242
                .Cke(mc_cke_o),
243
                .Cs_n(mc_cs_o[3]),
244
                .Ras_n(mc_ras_o),
245
                .Cas_n(mc_cas_o),
246
                .We_n(mc_we_o),
247
                .Dqm(mc_dqm_o[1:0])
248
        );
249
 
250
        // hookup sdrams (CHIP SELECT 2 or PARITY)
251
        assign pbus_o = sel_pbus ? (sel_par ? mc_dp : set_par) : mc_dq;
252
        assign par_con = {7'bz, pbus_o[3], 7'bz, pbus_o[2], 7'bz, pbus_o[1], 7'bz, pbus_o[0]};
253
        assign pbus_i = {par_con[24], par_con[16], par_con[8], par_con[0]};
254
 
255
        assign par_sdram_cs = sel_pbus ? mc_cs_o[3] : mc_cs_o[2];
256
 
257
        mt48lc16m16a2 sdram0_2(
258
                .Dq(par_con[31:16]),
259
                .Addr(mc_adr_o[12:0]),
260
                .Ba(mc_adr_o[14:13]),
261
                .Clk(mc_clk),
262
                .Cke(mc_cke_o),
263
                .Cs_n(par_sdram_cs),
264
                .Ras_n(mc_ras_o),
265
                .Cas_n(mc_cas_o),
266
                .We_n(mc_we_o),
267
                .Dqm(mc_dqm_o[3:2])
268
        );
269
 
270
        mt48lc16m16a2 sdram1_2(
271
                .Dq(par_con[15:0]),
272
                .Addr(mc_adr_o[12:0]),
273
                .Ba(mc_adr_o[14:13]),
274
                .Clk(mc_clk),
275
                .Cke(mc_cke_o),
276
                .Cs_n(par_sdram_cs),
277
                .Ras_n(mc_ras_o),
278
                .Cas_n(mc_cas_o),
279
                .We_n(mc_we_o),
280
                .Dqm(mc_dqm_o[1:0])
281
        );
282
 
283
        // hookup asynchronous srams (CHIP SELECT 1)
284
        A8Kx8 asram0 (
285
                .Address(mc_adr_o[12:0]),
286
                .dataIO(mc_dq[31:24]),
287
                .OEn(mc_oe_o),
288
                .CE1n(mc_cs_o[1]),
289
                .CE2(1'b1),
290
                .WEn(mc_we_o)
291
        );
292
 
293
        A8Kx8 asram1 (
294
                .Address(mc_adr_o[12:0]),
295
                .dataIO(mc_dq[23:16]),
296
                .OEn(mc_oe_o),
297
                .CE1n(mc_cs_o[1]),
298
                .CE2(1'b1),
299
                .WEn(mc_we_o)
300
        );
301
 
302
        A8Kx8 asram2 (
303
                .Address(mc_adr_o[12:0]),
304
                .dataIO(mc_dq[15: 8]),
305
                .OEn(mc_oe_o),
306
                .CE1n(mc_cs_o[1]),
307
                .CE2(1'b1),
308
                .WEn(mc_we_o)
309
        );
310
 
311
        A8Kx8 asram3 (
312
                .Address(mc_adr_o[12:0]),
313
                .dataIO(mc_dq[ 7: 0]),
314
                .OEn(mc_oe_o),
315
                .CE1n(mc_cs_o[1]),
316
                .CE2(1'b1),
317
                .WEn(mc_we_o)
318
        );
319
 
320
        // hookup wishbone master
321
        wb_master_model wbm(
322
                .clk(wb_clk),
323
                .rst(wb_rst),
324
                .adr(wb_adr_o),
325
                .din(wb_dat_i),
326
                .dout(wb_dat_o),
327
                .cyc(wb_cyc_o),
328
                .stb(wb_stb_o),
329
                .we(wb_we_o),
330
                .sel(wb_sel_o),
331
                .ack(wb_ack_i),
332
                .err(wb_err_i),
333
                .rty(wb_rty_i)
334
        );
335
 
336
 
337
        //
338
        // testbench body
339
        //
340
 
341
        assign wb_rty_i = 1'b0; // no retries from memory controller
342
 
343
        // generate clock
344
        always #2.5 wb_clk <= ~wb_clk;
345
 
346
        always@(posedge wb_clk)
347
//              mc_clk <= #1 ~mc_clk;
348
                mc_clk <= #0 ~mc_clk;
349
 
350
        // initial statements
351
        initial
352
        begin
353
                wb_clk   = 0; // start with low-level clock
354
                wb_rst   = 1; // assert reset
355
                mc_clk   = 0;
356
                sel_par  = 1; // do not modify parity bits
357
                sel_pbus = 1; // use second SDRAMS set as parity sdrams
358
 
359
                repeat(20) @(posedge wb_clk);
360
                wb_rst = 0; // negate reset
361
 
362
                @(posedge wb_clk);
363
                run_tests;
364
 
365
                // show total errors detected
366
                wbm.show_tot_err_cnt;
367
 
368
                $stop;
369
        end
370
 
371
 
372
        //////////////////////
373
        //
374
        // Internal tasks
375
        //
376
 
377
        task run_tests;
378
                begin
379
                        prg_mc;     // program memory controller BA-mask and CSR registers
380
 
381
//                      force sdram0_3.Debug = 1'b1; // turn on  SDRAM debug option
382
                        force sdram0_3.Debug = 1'b0; // turn off SDRAM debug option
383
 
384
                        ///////////////
385
                        // SDRAM tests
386
//                      tst_sdram_memfill;           // test sdrams: Fill entire memory and verify
387
//                      tst_sdram_parity;            // test sdrams: Parity generation
388
//                      tst_sdram_seq;               // test sdrams: Fill-Verify, sequential access
389
//                      tst_sdram_rnd;               // test sdrams: Fill-Verify, random access
390
//                      tst_sdram_rmw_seq;           // test sdrams: Read-Modify-Write test, sequential access
391
//                      tst_sdram_rmw_rnd;           // test sdrams: Read-Modify-Write test, random access
392
//                      tst_sdram_blk_cpy1;          // test sdrams: Perform block copy, different src and dest. address
393
//                      tst_sdram_blk_cpy2;          // test sdrams: Perform block copy, src and dest same address
394
//                      tst_sdram_bytes;             // test sdrams: Peform byte accesses
395
 
396
                        //////////////////////////////
397
                        // ASYNCHRONOUS MEMORIES TEST
398
//                      tst_amem_seq;                // test asynchronous memory
399
                        tst_amem_b2b;                // test asynchronous memory back-2-back
400
 
401
                        ////////////////
402
                        // SSRAMS TESTS
403
                        tst_ssram_seq;
404
 
405
                        //////////////////////
406
                        // MULTI MEMORY TESTS
407
//                      tst_blk_cpy1;                // test block-copy: access sdrams + asrams
408
 
409
                        // The next test (tst_blk_cyp2) is, saddly to say, useless.
410
                        // It tests n-by-n situations for multiple SDRAMS, testing all possible settings for each SDRAM.
411
                        // It is supposed to test the independence for each SDRAM chip-select.
412
                        // However it is to time-consuming; it runs for about a month on an Athlon-XP 1800 system
413
//                      tst_blk_cpy2;                // test block-copy: access multiple sdrams
414
 
415
 
416
                        /////////////////////////////
417
                        // EXTERNAL BUS MASTER TESTS
418
                        // turn on external bus-master and rerun some tests
419
//                      force ext_bm.on_off = 1'b1;
420
//                      tst_sdram_seq;               // test sdrams: Fill-Verify, sequential access
421
//                      tst_amem_seq;                // test asynchronous memory
422
//                      tst_amem_b2b;                // test asynchronous memory back-2-back
423
//                      tst_blk_cpy1;                // test block-copy: access sdrams + asrams
424
 
425
                end
426
        endtask // run_tests
427
 
428
 
429
        task prg_mc;
430
                begin
431
                        wbm.wb_write(0, 0, 32'h6000_0008, `BA_MASK); // program base address register
432
                        wbm.wb_write(0, 0, 32'h6000_0000, 32'h6000_0400); // program CSR
433
 
434
                        // check written data
435
                        wbm.wb_cmp(0, 0, 32'h6000_0008, `BA_MASK);
436
                        wbm.wb_cmp(0, 0, 32'h6000_0000, 32'h6000_0400);
437
                end
438
        endtask //prg_mc
439
 
440
        ////////////////////////////////
441
        // Register test
442
        //
443
        task reg_test;
444
                begin
445
                end
446
        endtask // reg_test
447
 
448
 
449
        /////////////////////////
450
        // include memory tests
451
        //
452
        `include "tst_sdram.v"
453
        `include "tst_asram.v"
454
        `include "tst_ssram.v"
455
        `include "tst_multi_mem.v"
456
 
457
endmodule
458
 

powered by: WebSVN 2.1.0

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