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

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [soc/] [rtl/] [altera_ddr_ctrl/] [testbench/] [altera_ddr_example_top_tb.v] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 xianfeng
//------------------------------------------------------------------------------
2
// This confidential and proprietary software may be used only as authorized by
3
// a licensing agreement from Altera Corporation.
4
//
5
// (c) COPYRIGHT 2007 ALTERA CORPORATION
6
// ALL RIGHTS RESERVED
7
//
8
// The entire notice above must be reproduced on all authorized copies and any
9
// such reproduction must be pursuant to a licensing agreement from Altera.
10
//
11
// Title        : Example top level testbench for altera_ddr DDR/2/3 SDRAM High Performance Controller
12
// Project      : DDR/2/3 SDRAM High Performance Controller
13
//
14
// File         : altera_ddr_example_top_tb.v
15
//
16
// Revision     : V9.0
17
//
18
// Abstract:
19
// Automatically generated testbench for the example top level design to allow
20
// functional and timing simulation.
21
//
22
//------------------------------------------------------------------------------
23
//
24
// *************** This is a MegaWizard generated file ****************
25
//
26
// If you need to edit this file make sure the edits are not inside any 'MEGAWIZARD'
27
// text insertion areas.
28
// (between "<< START MEGAWIZARD INSERT" and "<< END MEGAWIZARD INSERT" comments)
29
//
30
// Any edits inside these delimiters will be overwritten by the megawizard if you
31
// re-run it.
32
//
33
// If you really need to make changes inside these delimiters then delete
34
// both 'START' and 'END' delimiters.  This will stop the megawizard updating this
35
// section again.
36
//
37
//----------------------------------------------------------------------------------
38
// << START MEGAWIZARD INSERT PARAMETER_LIST
39
// Parameters:
40
//
41
// Device Family                      : cyclone iii
42
// local Interface Data Width         : 32
43
// MEM_CHIPSELS                       : 1
44
// MEM_BANK_BITS                      : 2
45
// MEM_ROW_BITS                       : 13
46
// MEM_COL_BITS                       : 9
47
// LOCAL_DATA_BITS                    : 32
48
// NUM_CLOCK_PAIRS                    : 1
49
// CLOCK_TICK_IN_PS                   : 6666
50
// REGISTERED_DIMM                    : false
51
// TINIT_CLOCKS                       : 30004
52
// Data_Width_Ratio                   : 2
53
// << END MEGAWIZARD INSERT PARAMETER_LIST
54
//----------------------------------------------------------------------------------
55
// << MEGAWIZARD PARSE FILE DDR9.0
56
 
57
 
58
`timescale 1 ps/1 ps
59
 
60
 
61
 
62
// << START MEGAWIZARD INSERT MODULE
63
module altera_ddr_example_top_tb ();
64
// << END MEGAWIZARD INSERT MODULE
65
 
66
    // << START MEGAWIZARD INSERT PARAMS
67
    parameter gMEM_CHIPSELS     = 1;
68
    parameter gMEM_BANK_BITS    = 2;
69
    parameter gMEM_ROW_BITS     = 13;
70
    parameter gMEM_COL_BITS     = 9;
71
    parameter gMEM_ADDR_BITS    = 13;
72
    parameter gMEM_DQ_PER_DQS   = 8;
73
    parameter DM_DQS_WIDTH      = 2;
74
    parameter gLOCAL_DATA_BITS  = 32;
75
    parameter gLOCAL_IF_DWIDTH_AFTER_ECC  = 32;
76
    parameter gNUM_CLOCK_PAIRS  = 1;
77
    parameter RTL_ROUNDTRIP_CLOCKS  = 0.0;
78
    parameter CLOCK_TICK_IN_PS  = 6666;
79
    parameter REGISTERED_DIMM   = 1'b0;
80
    parameter BOARD_DQS_DELAY   = 0;
81
    parameter BOARD_CLK_DELAY   = 0;
82
    parameter DWIDTH_RATIO      = 2;
83
    parameter TINIT_CLOCKS  = 30004;
84
    parameter REF_CLOCK_TICK_IN_PS  = 20000;
85
 
86
    // Parameters below are for generic memory model
87
    parameter gMEM_TQHS_PS      =       500;
88
    parameter gMEM_TAC_PS       =       700;
89
    parameter gMEM_TDQSQ_PS     =       400;
90
    parameter gMEM_IF_TRCD_NS   =       15.0;
91
    parameter gMEM_IF_TWTR_CK   =       2;
92
    parameter gMEM_TDSS_CK      =       0.2;
93
    parameter gMEM_IF_TRFC_NS   =       70.0;
94
 
95
    parameter gMEM_IF_TRCD_PS   =       gMEM_IF_TRCD_NS * 1000.0;
96
    parameter gMEM_IF_TWTR_PS   =       gMEM_IF_TWTR_CK * CLOCK_TICK_IN_PS;
97
    parameter gMEM_IF_TRFC_PS   =       gMEM_IF_TRFC_NS * 1000.0;
98
    parameter CLOCK_TICK_IN_NS  =       CLOCK_TICK_IN_PS / 1000.0;
99
    parameter gMEM_TDQSQ_NS     =       gMEM_TDQSQ_PS / 1000.0;
100
    parameter gMEM_TDSS_NS      =       gMEM_TDSS_CK * CLOCK_TICK_IN_NS;
101
 
102
 
103
    // << END MEGAWIZARD INSERT PARAMS
104
 
105
    // set to zero for Gatelevel
106
    parameter RTL_DELAYS = 1;
107
    parameter USE_GENERIC_MEMORY_MODEL  = 1'b0;
108
 
109
    // The round trip delay is now modeled inside the datapath (<your core name>_auk_ddr_dqs_group.v/vhd) for RTL simulation.
110
    parameter D90_DEG_DELAY = 0; //RTL only
111
 
112
    parameter GATE_BOARD_DQS_DELAY = BOARD_DQS_DELAY * (RTL_DELAYS ? 0 : 1); // Gate level timing only
113
    parameter GATE_BOARD_CLK_DELAY = BOARD_CLK_DELAY * (RTL_DELAYS ? 0 : 1); // Gate level timing only
114
 
115
    // Below 5 lines for SPR272543: 
116
    // Testbench workaround for tests with "dedicated memory clock phase shift" failing, 
117
    // because dqs delay isnt' being modelled in simulations
118
    parameter gMEM_CLK_PHASE_EN = "false";
119
    parameter real gMEM_CLK_PHASE = 0;
120
    parameter real MEM_CLK_RATIO = ((360.0-gMEM_CLK_PHASE)/360.0);
121
    parameter MEM_CLK_DELAY = MEM_CLK_RATIO*CLOCK_TICK_IN_PS * ((gMEM_CLK_PHASE_EN=="true") ? 1 : 0);
122
    wire clk_to_ram0, clk_to_ram1, clk_to_ram2;
123
 
124
    wire cmd_bus_watcher_enabled;
125
    reg clk;
126
    reg clk_n;
127
    reg reset_n;
128
    wire mem_reset_n;
129
    wire[gMEM_ADDR_BITS - 1:0] a;
130
    wire[gMEM_BANK_BITS - 1:0] ba;
131
    wire[gMEM_CHIPSELS - 1:0] cs_n;
132
    wire[gMEM_CHIPSELS - 1:0] cke;
133
    wire[gMEM_CHIPSELS - 1:0] odt;       //DDR2 only
134
    wire ras_n;
135
    wire cas_n;
136
    wire we_n;
137
    wire[gLOCAL_DATA_BITS / DWIDTH_RATIO / gMEM_DQ_PER_DQS - 1:0] dm;
138
    //wire[gLOCAL_DATA_BITS / DWIDTH_RATIO / gMEM_DQ_PER_DQS - 1:0] dqs;
139
    //wire[gLOCAL_DATA_BITS / DWIDTH_RATIO / gMEM_DQ_PER_DQS - 1:0] dqs_n;
140
 
141
    //wire stratix_dqs_ref_clk;   // only used on stratix to provide external dll reference clock
142
    wire[gNUM_CLOCK_PAIRS - 1:0] clk_to_sdram;
143
    wire[gNUM_CLOCK_PAIRS - 1:0] clk_to_sdram_n;
144
    wire #(GATE_BOARD_CLK_DELAY * 1) clk_to_ram;
145
    wire clk_to_ram_n;
146
    wire[gMEM_ADDR_BITS - 1:0] #(GATE_BOARD_CLK_DELAY * 1 + 1) a_delayed;
147
    wire[gMEM_BANK_BITS - 1:0] #(GATE_BOARD_CLK_DELAY * 1 + 1) ba_delayed;
148
    wire[gMEM_CHIPSELS - 1:0] #(GATE_BOARD_CLK_DELAY * 1 + 1) cke_delayed;
149
    wire[gMEM_CHIPSELS - 1:0] #(GATE_BOARD_CLK_DELAY * 1 + 1) odt_delayed;  //DDR2 only
150
    wire[gMEM_CHIPSELS - 1:0] #(GATE_BOARD_CLK_DELAY * 1 + 1) cs_n_delayed;
151
    wire #(GATE_BOARD_CLK_DELAY * 1 + 1) ras_n_delayed;
152
    wire #(GATE_BOARD_CLK_DELAY * 1 + 1) cas_n_delayed;
153
    wire #(GATE_BOARD_CLK_DELAY * 1 + 1) we_n_delayed;
154
    wire[gLOCAL_DATA_BITS / DWIDTH_RATIO / gMEM_DQ_PER_DQS - 1:0] #(GATE_BOARD_CLK_DELAY * 1 + 1) dm_delayed;
155
 
156
    // pulldown (dm);
157
    assign (weak1, weak0) dm = 0;
158
 
159
    tri [gLOCAL_DATA_BITS / DWIDTH_RATIO - 1:0] mem_dq = 100'bz;
160
    tri [gLOCAL_DATA_BITS / DWIDTH_RATIO / gMEM_DQ_PER_DQS - 1:0] mem_dqs = 100'bz;
161
    tri [gLOCAL_DATA_BITS / DWIDTH_RATIO / gMEM_DQ_PER_DQS - 1:0] mem_dqs_n = 100'bz;
162
        assign (weak1, weak0) mem_dq = 0;
163
        assign (weak1, weak0) mem_dqs = 0;
164
        assign (weak1, weak0) mem_dqs_n = 1;
165
 
166
    wire [gMEM_BANK_BITS - 1:0] zero_one; //"01";
167
    assign zero_one = 1;
168
 
169
    wire test_complete;
170
    wire [7:0] test_status;
171
    // counter to count the number of sucessful read and write loops
172
    integer test_complete_count;
173
    wire pnf;
174
    wire [gLOCAL_IF_DWIDTH_AFTER_ECC / 8 - 1:0] pnf_per_byte;
175
 
176
 
177
    assign cmd_bus_watcher_enabled = 1'b0;
178
 
179
    // Below 5 lines for SPR272543: 
180
    // Testbench workaround for tests with "dedicated memory clock phase shift" failing, 
181
    // because dqs delay isnt' being modelled in simulations
182
    assign #(MEM_CLK_DELAY/4.0) clk_to_ram2 = clk_to_sdram[0];
183
    assign #(MEM_CLK_DELAY/4.0) clk_to_ram1 = clk_to_ram2;
184
    assign #(MEM_CLK_DELAY/4.0) clk_to_ram0 = clk_to_ram1;
185
    assign #((MEM_CLK_DELAY/4.0)) clk_to_ram = clk_to_ram0;
186
    assign clk_to_ram_n = ~clk_to_ram ; // mem model ignores clk_n ?
187
 
188
        // ddr sdram interface
189
 
190
    // << START MEGAWIZARD INSERT ENTITY
191
    altera_ddr_example_top dut (
192
    // << END MEGAWIZARD INSERT ENTITY
193
        .clock_source(clk),
194
        .global_reset_n(reset_n),
195
 
196
        // << START MEGAWIZARD INSERT PORT_MAP
197
        .mem_clk(clk_to_sdram),
198
        .mem_clk_n(clk_to_sdram_n),
199
 
200
        .mem_cke(cke),
201
        .mem_cs_n(cs_n),
202
        .mem_ras_n(ras_n),
203
        .mem_cas_n(cas_n),
204
        .mem_we_n(we_n),
205
        .mem_ba(ba),
206
        .mem_addr(a),
207
        .mem_dq(mem_dq),
208
        .mem_dqs(mem_dqs),
209
        .mem_dm(dm),
210
 
211
        // << END MEGAWIZARD INSERT PORT_MAP
212
 
213
        .test_complete(test_complete),
214
        .test_status(test_status),
215
        .pnf_per_byte(pnf_per_byte),
216
        .pnf(pnf)
217
    );
218
 
219
 
220
    // << START MEGAWIZARD INSERT MEMORY_ARRAY
221
    // This will need updating to match the memory models you are using.
222
 
223
    // Instantiate a generated DDR memory model to match the datawidth & chipselect requirements
224
 
225
    altera_ddr_mem_model mem (
226
        .mem_dq    (mem_dq),
227
        .mem_dqs   (mem_dqs),
228
        .mem_addr  (a_delayed),
229
        .mem_ba    (ba_delayed),
230
        .mem_clk   (clk_to_ram),
231
        .mem_clk_n (clk_to_ram_n),
232
        .mem_cke   (cke_delayed),
233
        .mem_cs_n  (cs_n_delayed),
234
        .mem_ras_n (ras_n_delayed),
235
        .mem_cas_n (cas_n_delayed),
236
        .mem_we_n  (we_n_delayed),
237
        .mem_dm    (dm_delayed),
238
        .global_reset_n ()
239
    );
240
 
241
    // << END MEGAWIZARD INSERT MEMORY_ARRAY
242
 
243
 
244
    always
245
    begin
246
        clk <= 1'b0 ;
247
        clk_n <= 1'b1 ;
248
        while (1'b1)
249
        begin
250
            #((REF_CLOCK_TICK_IN_PS / 2) * 1);
251
            clk <= ~clk ;
252
            clk_n <= ~clk_n ;
253
        end
254
    end
255
 
256
 
257
    initial
258
    begin
259
        reset_n <= 1'b1 ;
260
        @(clk);
261
        @(clk);
262
        @(clk);
263
        @(clk);
264
        @(clk);
265
        @(clk);
266
        reset_n <= 1'b0 ;
267
        @(clk);
268
        @(clk);
269
        @(clk);
270
        @(clk);
271
        @(clk);
272
        @(clk);
273
        reset_n <= 1'b1 ;
274
    end
275
 
276
    // control and data lines = 3 inches
277
    assign a_delayed = a ;
278
    assign ba_delayed = ba ;
279
    assign cke_delayed = cke ;
280
    assign odt_delayed = odt ;
281
    assign cs_n_delayed = cs_n ;
282
    assign ras_n_delayed = ras_n ;
283
    assign cas_n_delayed = cas_n ;
284
    assign we_n_delayed = we_n ;
285
    assign dm_delayed = dm ;
286
 
287
    // ---------------------------------------------------------------
288
    initial
289
    begin : endit
290
        integer count;
291
        reg ln;
292
        count = 0;
293
 
294
        // Stop simulation after test_complete or TINIT + 600000 clocks
295
        while ((count < (TINIT_CLOCKS + 600000)) & (test_complete !== 1))
296
        begin
297
            count = count + 1;
298
            @(negedge clk_to_sdram[0]);
299
        end
300
        if (test_complete === 1)
301
        begin
302
            if (pnf)
303
            begin
304
                $write($time);
305
                $write("          --- SIMULATION PASSED --- ");
306
                $stop;
307
            end
308
            else
309
            begin
310
                $write($time);
311
                $write("          --- SIMULATION FAILED --- ");
312
                $stop;
313
            end
314
        end
315
        else
316
        begin
317
            $write($time);
318
            $write("          --- SIMULATION FAILED, DID NOT COMPLETE --- ");
319
            $stop;
320
        end
321
    end
322
 
323
    always @(clk_to_sdram[0] or reset_n)
324
    begin
325
        if (!reset_n)
326
        begin
327
            test_complete_count <= 0 ;
328
        end
329
        else if ((clk_to_sdram[0]))
330
        begin
331
            if (test_complete)
332
            begin
333
                test_complete_count <= test_complete_count + 1 ;
334
            end
335
        end
336
    end
337
 
338
 
339
 
340
    reg[2:0] cmd_bus;
341
 
342
 
343
    //***********************************************************
344
    // Watch the SDRAM command bus
345
    always @(clk_to_ram)
346
    begin
347
        if (clk_to_ram)
348
        begin
349
            if (1'b1)
350
            begin
351
                cmd_bus = {ras_n_delayed, cas_n_delayed, we_n_delayed};
352
                case (cmd_bus)
353
                    3'b000 :
354
                        begin
355
                            // LMR command
356
                            $write($time);
357
                            if (ba_delayed == zero_one)
358
                            begin
359
                                $write("          ELMR     settings = ");
360
                                if (!(a_delayed[0]))
361
                                begin
362
                                    $write("DLL enable");
363
                                end
364
                            end
365
                            else
366
                            begin
367
                                                        $write("          LMR      settings = ");
368
 
369
                                        case (a_delayed[1:0])
370
                                                        3'b01 : $write("BL = 2,");
371
                                                3'b10 : $write("BL = 4,");
372
                                                3'b11 : $write("BL = 8,");
373
                                                default : $write("BL = ??,");
374
                                                endcase
375
 
376
                                                case (a_delayed[6:4])
377
                                                        3'b010 : $write(" CL = 2.0,");
378
                                                        3'b011 : $write(" CL = 3.0,");
379
                                                        3'b101 : $write(" CL = 1.5,");
380
                                                3'b110 : $write(" CL = 2.5,");
381
                                                        default : $write(" CL = ??,");
382
                                                endcase
383
 
384
                                                if ((a_delayed[8])) $write(" DLL reset");
385
 
386
                            end
387
                            $write("\n");
388
                        end
389
                    3'b001 :
390
                        begin
391
                            // ARF command
392
                            $write($time);
393
                            $write("          ARF\n");
394
                        end
395
                    3'b010 :
396
                        begin
397
                            // PCH command
398
                            $write($time);
399
                            $write("          PCH");
400
                            if ((a_delayed[10]))
401
                            begin
402
                                $write(" all banks \n");
403
                            end
404
                            else
405
                            begin
406
                                $write(" bank ");
407
                                $write("%H\n", ba_delayed);
408
                            end
409
                        end
410
                    3'b011 :
411
                        begin
412
                            // ACT command
413
                            $write($time);
414
                            $write("          ACT     row address ");
415
                            $write("%H", a_delayed);
416
                            $write(" bank ");
417
                            $write("%H\n", ba_delayed);
418
                        end
419
                   3'b100 :
420
                        begin
421
                            // WR command
422
                            $write($time);
423
                            $write("          WR to   col address ");
424
                            $write("%H", a_delayed);
425
                            $write(" bank ");
426
                            $write("%H\n", ba_delayed);
427
                        end
428
                   3'b101 :
429
                        begin
430
                            // RD command
431
                            $write($time);
432
                            $write("          RD from col address ");
433
                            $write("%H", a_delayed);
434
                            $write(" bank ");
435
                            $write("%H\n", ba_delayed);
436
                        end
437
                   3'b110 :
438
                        begin
439
                            // BT command
440
                            $write($time);
441
                            $write("          BT ");
442
                        end
443
                   3'b111 :
444
                        begin
445
                            // NOP command
446
                        end
447
                endcase
448
            end
449
            else
450
            begin
451
            end // if enabled
452
        end
453
    end
454
 
455
endmodule
456
 

powered by: WebSVN 2.1.0

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