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

Subversion Repositories sdr_ctrl

[/] [sdr_ctrl/] [trunk/] [verif/] [tb/] [tb_top.sv] - Blame information for rev 8

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

Line No. Rev Author Line
1 8 dinesha
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////                                                              ////
4
////  This file is part of the SDRAM Controller project           ////
5
////  http://www.opencores.org/cores/sdr_ctrl/                    ////
6
////                                                              ////
7
////  Description                                                 ////
8
////  SDRAM CTRL definitions.                                     ////
9
////                                                              ////
10
////  To Do:                                                      ////
11
////    nothing                                                   ////
12
////                                                              ////
13
////  Author(s):                                                  ////
14
////      - Dinesh Annayya, dinesha@opencores.org                 ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
19
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42
 
43
 
44
`timescale 1ns/1ps
45
 
46
module tb_top;
47
 
48
parameter P_SYS  = 10;     //    100MHz
49
 
50
// General
51
reg            RESETN;
52
reg            sdram_clk;
53
 
54
initial sdram_clk = 0;
55
 
56
always #(P_SYS/2) sdram_clk = !sdram_clk;
57
 
58
parameter      dw              = 32;  // data width
59
parameter      tw              = 8;   // tag id width
60
parameter      bl              = 5;   // burst_lenght_width
61
 
62
//-------------------------------------------
63
// Application Interface bus
64
//-------------------------------------------
65
reg                   app_req            ; // Application Request
66
reg  [8:0]            app_req_len        ; // Burst Request length
67
wire                  app_req_ack        ; // Application Request Ack
68
reg [29:0]            app_req_addr       ; // Application Address
69
reg                   app_req_wr_n       ; // 1 -> Read, 0 -> Write
70
reg [dw-1:0]          app_wr_data        ; // Write Data
71
reg [dw/8-1:0]        app_wr_en_n        ; // Write Enable, Active Low
72
wire                  app_rd_valid       ; // Read Valid
73
wire [dw-1:0]         app_rd_data        ; // Read Data
74
 
75
//--------------------------------------------
76
// SDRAM I/F
77
//--------------------------------------------
78
 
79
`ifdef SDR_32BIT
80
   wire [31:0]           Dq                 ; // SDRAM Read/Write Data Bus
81
   wire [31:0]           sdr_dout           ; // SDRAM Data Out
82
   wire [31:0]           pad_sdr_din        ; // SDRAM Data Input
83
   wire [3:0]            sdr_den_n          ; // SDRAM Data Enable
84
   wire [3:0]            sdr_dqm            ; // SDRAM DATA Mask
85
`else
86
   wire [15:0]           Dq                 ; // SDRAM Read/Write Data Bus
87
   wire [15:0]           sdr_dout           ; // SDRAM Data Out
88
   wire [15:0]           pad_sdr_din        ; // SDRAM Data Input
89
   wire [1:0]            sdr_den_n          ; // SDRAM Data Enable
90
   wire [1:0]            sdr_dqm            ; // SDRAM DATA Mask
91
`endif
92
 
93
wire [1:0]            sdr_ba             ; // SDRAM Bank Select
94
wire [11:0]           sdr_addr           ; // SDRAM ADRESS
95
wire                  sdr_init_done      ; // SDRAM Init Done
96
 
97
// to fix the sdram interface timing issue
98
wire #(1.5) sdram_clk_d = sdram_clk;
99
 
100
`ifdef SDR_32BIT
101
 
102
   sdrc_core #(.SDR_DW(32),.SDR_BW(4)) u_dut(
103
`else
104
   sdrc_core #(.SDR_DW(16),.SDR_BW(2)) u_dut(
105
`endif
106
      // System
107
          .clk                (sdram_clk_d        ),
108
          .reset_n            (RESETN             ),
109
          .pad_clk            (sdram_clk_d        ),
110
`ifdef SDR_32BIT
111
          .sdr_width          (1'b0               ), // 32 BIT SDRAM
112
`else
113
          .sdr_width          (1'b1               ), // 16 BIT SDRAM
114
`endif
115
 
116
 
117
 
118
/* Request from app */
119
          .app_req            (app_req            ),    // Transfer Request
120
          .app_req_addr       (app_req_addr       ),    // SDRAM Address
121
          .app_req_addr_mask  (29'h1FFF_FFFF      ),    // Address mask for queue wrap
122
          .app_req_len        (app_req_len        ),    // Burst Length (in 16 bit words)
123
          .app_req_wrap       (1'b0               ),    // Wrap mode request (xfr_len = 4)
124
          .app_req_wr_n       (app_req_wr_n       ),    // 0 => Write request, 1 => read req
125
          .app_req_ack        (app_req_ack        ),    // Request has been accepted
126
          .sdr_core_busy_n    (                   ),    // OK to arbitrate next request
127
 
128
          .app_wr_data        (app_wr_data        ),
129
          .app_wr_en_n        (app_wr_en_n        ),
130
          .app_rd_data        (app_rd_data        ),
131
          .app_rd_valid       (app_rd_valid       ),
132
          .app_wr_next_req    (app_wr_next_req    ),
133
          .app_req_dma_last   (app_req            ),
134
 
135
/* Interface to SDRAMs */
136
          .sdr_cs_n           (sdr_cs_n           ),
137
          .sdr_cke            (sdr_cke            ),
138
          .sdr_ras_n          (sdr_ras_n          ),
139
          .sdr_cas_n          (sdr_cas_n          ),
140
          .sdr_we_n           (sdr_we_n           ),
141
          .sdr_dqm            (sdr_dqm            ),
142
          .sdr_ba             (sdr_ba             ),
143
          .sdr_addr           (sdr_addr           ),
144
          .pad_sdr_din        (Dq                 ),
145
          .sdr_dout           (sdr_dout           ),
146
          .sdr_den_n          (sdr_den_n          ),
147
 
148
    /* Parameters */
149
          .sdr_init_done      (sdr_init_done      ),
150
          .cfg_req_depth      (2'h2               ),            //how many req. buffer should hold
151
          .cfg_sdr_en         (1'b1               ),
152
          .cfg_sdr_dev_config (2'b0               ),    // using 64M/4bank SDRAMs
153
          .cfg_sdr_mode_reg   (12'h033            ),
154
          .cfg_sdr_tras_d     (4'h4               ),
155
          .cfg_sdr_trp_d      (4'h2               ),
156
          .cfg_sdr_trcd_d     (4'h2               ),
157
          .cfg_sdr_cas        (3'h2               ),
158
          .cfg_sdr_trcar_d    (4'h7               ),
159
          .cfg_sdr_twr_d      (4'h1               ),
160
          .cfg_sdr_rfsh       (12'hC35            ),
161
          .cfg_sdr_rfmax      (3'h6               )
162
 
163
);
164
 
165
 
166
`ifdef SDR_32BIT
167
  assign Dq[7:0]    = (sdr_den_n[0] == 1'b0) ? sdr_dout[7:0]   : 8'hZZ;
168
  assign Dq[15:8]   = (sdr_den_n[1] == 1'b0) ? sdr_dout[15:8]  : 8'hZZ;
169
  assign Dq[23:16]  = (sdr_den_n[2] == 1'b0) ? sdr_dout[23:16] : 8'hZZ;
170
  assign Dq[31:24]  = (sdr_den_n[3] == 1'b0) ? sdr_dout[31:24] : 8'hZZ;
171
mt48lc2m32b2 #(.data_bits(32)) u_sdram32 (
172
          .Dq                 (Dq                 ) ,
173
          .Addr               (sdr_addr           ),
174
          .Ba                 (sdr_ba             ),
175
          .Clk                (sdram_clk          ),
176
          .Cke                (sdr_cke            ),
177
          .Cs_n               (sdr_cs_n           ),
178
          .Ras_n              (sdr_ras_n          ),
179
          .Cas_n              (sdr_cas_n          ),
180
          .We_n               (sdr_we_n           ),
181
          .Dqm                (sdr_dqm            )
182
     );
183
 
184
`else
185
 
186
assign Dq[7:0]  = (sdr_den_n[0] == 1'b0) ? sdr_dout[7:0]  : 8'hZZ;
187
assign Dq[15:8] = (sdr_den_n[1] == 1'b0) ? sdr_dout[15:8] : 8'hZZ;
188
 
189
   IS42VM16400K u_sdram16 (
190
          .dq                 (Dq                 ),
191
          .addr               (sdr_addr           ),
192
          .ba                 (sdr_ba             ),
193
          .clk                (sdram_clk          ),
194
          .cke                (sdr_cke            ),
195
          .csb                (sdr_cs_n           ),
196
          .rasb               (sdr_ras_n          ),
197
          .casb               (sdr_cas_n          ),
198
          .web                (sdr_we_n           ),
199
          .dqm                (sdr_dqm            )
200
    );
201
`endif
202
 
203
//--------------------
204
// Write/Read Burst FIFO
205
//--------------------
206
int wrdfifo[$]; // write data fifo
207
int rddfifo[$]; // read data fifo
208
 
209
reg [31:0] read_data;
210
reg [31:0] ErrCnt;
211
int k;
212
reg [31:0] StartAddr;
213
/////////////////////////////////////////////////////////////////////////
214
// Test Case
215
/////////////////////////////////////////////////////////////////////////
216
 
217
initial begin //{
218
  ErrCnt          = 0;
219
   app_req_addr  = 0;
220
   app_wr_data    = 0;
221
   app_wr_en_n    = 4'hF;
222
   app_req_wr_n   = 0;
223
   app_req        = 0;
224
   app_req_len    = 0;
225
 
226
  RESETN    = 1'h1;
227
 
228
 #100
229
  // Applying reset
230
  RESETN    = 1'h0;
231
  #10000;
232
  // Releasing reset
233
  RESETN    = 1'h1;
234
  #1000;
235
  wait(u_dut.sdr_init_done == 1);
236
 
237
  #1000;
238
 
239
  wrdfifo.push_back(32'h11223344);
240
  wrdfifo.push_back(32'h22334455);
241
  wrdfifo.push_back(32'h33445566);
242
  wrdfifo.push_back(32'h44556677);
243
  wrdfifo.push_back(32'h55667788);
244
 
245
  burst_write(32'h40000);
246
 #1000;
247
  burst_read(32'h40000);
248
 
249
 #1000;
250
  burst_write(32'h7000_0000);
251
 #1000;
252
  burst_read(32'h7000_0000);
253
 
254
  for(k=0; k < 20; k++) begin
255
     StartAddr = $random & 32'h07FFFFFF;
256
     burst_write(StartAddr);
257
    #1000;
258
     burst_read(StartAddr);
259
  end
260
 
261
 
262
  #10000;
263
 
264
        $display("###############################");
265
    if(ErrCnt == 0)
266
        $display("STATUS: SDRAM Write/Read TEST PASSED");
267
    else
268
        $display("ERROR:  SDRAM Write/Read TEST FAILED");
269
        $display("###############################");
270
 
271
    $finish;
272
end
273
 
274
task burst_write;
275
input [31:0] Address;
276
int i;
277
begin
278
   @ (negedge sdram_clk);
279
   app_req        = 1;
280
   app_wr_en_n    = 0;
281
   app_req_wr_n   = 1'b0;
282
   $display("Write Address: %x, Burst Size: %d",Address,wrdfifo.size);
283
   app_req_addr  = Address[31:2];
284
   app_req_len    = wrdfifo.size;
285
 
286
   // wait for app_req_ack == 1
287
   do begin
288
       @ (posedge sdram_clk);
289
   end while(app_req_ack == 1'b0);
290
   @ (negedge sdram_clk);
291
   app_req           = 0;
292
 
293
   for(i=0; i < wrdfifo.size; i++) begin
294
      app_wr_data     = wrdfifo[i];
295
 
296
      do begin
297
          @ (posedge sdram_clk);
298
      end while(app_wr_next_req == 1'b0);
299
          @ (negedge sdram_clk);
300
 
301
       $display("Status: Burst-No: %d  Write Address: %x  WriteData: %x ",i,Address,app_wr_data);
302
   end
303
   app_req           = 0;
304
   app_wr_en_n       = 4'hF;
305
end
306
endtask
307
 
308
task burst_read;
309
input [31:0] Address;
310
 
311
int i,j;
312
reg [31:0]   rd_data;
313
begin
314
   @ (negedge sdram_clk);
315
 
316
      app_req        = 1;
317
      app_wr_en_n    = 0;
318
      app_req_wr_n   = 1;
319
      app_req_addr   = Address[29:2];
320
      app_req_len    = wrdfifo.size;
321
      // wait for app_req_ack == 1
322
      do begin
323
          @ (posedge sdram_clk);
324
      end while(app_req_ack == 1'b0);
325
      @ (negedge sdram_clk);
326
      app_req           = 0;
327
 
328
      for(j=0; j < wrdfifo.size; j++) begin
329
         wait(app_rd_valid == 1);
330
         @ (posedge sdram_clk);
331
         if(app_rd_data != wrdfifo[j]) begin
332
             $display("READ ERROR: Burst-No: %d Addr: %x Rxp: %x Exd: %x",j,Address+(j*2),app_rd_data,wrdfifo[j]);
333
             ErrCnt = ErrCnt+1;
334
         end else begin
335
             $display("READ STATUS: Burst-No: %d Addr: %x Rxd: %x",j,Address+(j*2),app_rd_data);
336
         end
337
         @ (negedge sdram_clk);
338
      end
339
end
340
endtask
341
 
342
 
343
endmodule

powered by: WebSVN 2.1.0

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