1 |
25 |
rherveille |
/////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// OpenCores Memory Controller Testbench ////
|
4 |
|
|
//// SDRAM memory devices tests ////
|
5 |
|
|
//// This file is being included by the main testbench ////
|
6 |
|
|
//// ////
|
7 |
|
|
//// Author: Richard Herveille ////
|
8 |
|
|
//// richard@asics.ws ////
|
9 |
|
|
//// ////
|
10 |
|
|
//// ////
|
11 |
|
|
//// Downloaded from: http://www.opencores.org/cores/mem_ctrl/ ////
|
12 |
|
|
//// ////
|
13 |
|
|
/////////////////////////////////////////////////////////////////////
|
14 |
|
|
//// ////
|
15 |
|
|
//// Copyright (C) 2001, 2002 Richard Herveille ////
|
16 |
|
|
//// richard@asics.ws ////
|
17 |
|
|
//// ////
|
18 |
|
|
//// This source file may be used and distributed without ////
|
19 |
|
|
//// restriction provided that this copyright statement is not ////
|
20 |
|
|
//// removed from the file and that any derivative work contains ////
|
21 |
|
|
//// the original copyright notice and the associated disclaimer.////
|
22 |
|
|
//// ////
|
23 |
|
|
//// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ////
|
24 |
|
|
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ////
|
25 |
|
|
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ////
|
26 |
|
|
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ////
|
27 |
|
|
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ////
|
28 |
|
|
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ////
|
29 |
|
|
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ////
|
30 |
|
|
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ////
|
31 |
|
|
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ////
|
32 |
|
|
//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ////
|
33 |
|
|
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ////
|
34 |
|
|
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ////
|
35 |
|
|
//// POSSIBILITY OF SUCH DAMAGE. ////
|
36 |
|
|
//// ////
|
37 |
|
|
/////////////////////////////////////////////////////////////////////
|
38 |
|
|
|
39 |
|
|
// CVS Log
|
40 |
|
|
//
|
41 |
|
|
// $Id: tst_sdram.v,v 1.1 2002-03-06 15:10:34 rherveille Exp $
|
42 |
|
|
//
|
43 |
|
|
// $Date: 2002-03-06 15:10:34 $
|
44 |
|
|
// $Revision: 1.1 $
|
45 |
|
|
// $Author: rherveille $
|
46 |
|
|
// $Locker: $
|
47 |
|
|
// $State: Exp $
|
48 |
|
|
//
|
49 |
|
|
// Change History:
|
50 |
|
|
// $Log: not supported by cvs2svn $
|
51 |
|
|
//
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
////////////////////////////////
|
55 |
|
|
// SDRAM memory fill test
|
56 |
|
|
//
|
57 |
|
|
|
58 |
|
|
// Test memory contents overwrite
|
59 |
|
|
// 1) Fill entire SDRAM memory
|
60 |
|
|
// 2) Verify memory contents
|
61 |
|
|
// 3) Test for BAS setting
|
62 |
|
|
//
|
63 |
|
|
// THIS IS A FULL MEMORY TEST
|
64 |
|
|
// MAY RUN FOR A FEW DAYS
|
65 |
|
|
task tst_sdram_memfill;
|
66 |
|
|
parameter [31:0] SDRAM_TST_STARTA = `SDRAM1_LOC; // start at address 0
|
67 |
|
|
parameter [ 7:0] SDRAM1_SEL = SDRAM_TST_STARTA[28:21];
|
68 |
|
|
parameter SDRAM_TST_RUN = ( 1<<(`SDRAM_COLA_HI+1)<<(`SDRAM_ROWA_HI+1) ) *4;
|
69 |
|
|
|
70 |
|
|
integer n;
|
71 |
|
|
reg [31:0] my_adr, dest_adr;
|
72 |
|
|
reg [31:0] my_dat;
|
73 |
|
|
|
74 |
|
|
// config register mode bits
|
75 |
|
|
reg [1:0] kro, bas; // a single register doesn't work with the for-loops
|
76 |
|
|
|
77 |
|
|
// SDRAM Mode Register bits
|
78 |
|
|
reg [1:0] wbl; // a single register doesn't work with the for-loops
|
79 |
|
|
reg [2:0] cl, bl;
|
80 |
|
|
|
81 |
|
|
reg [31:0] csc_data, tms_data;
|
82 |
|
|
|
83 |
|
|
integer cyc_delay, stb_delay;
|
84 |
|
|
integer bank_cnt, col_cnt;
|
85 |
|
|
|
86 |
|
|
begin
|
87 |
|
|
|
88 |
|
|
$display("\n\n --- SDRAM MEMORY FILL TEST ---\n\n");
|
89 |
|
|
|
90 |
|
|
// clear Wishbone-Master-model current-error-counter
|
91 |
|
|
wbm.set_cur_err_cnt(0);
|
92 |
|
|
|
93 |
|
|
// choose some settings, other settings will be tested
|
94 |
|
|
// in next tests
|
95 |
|
|
kro = 0;
|
96 |
|
|
bas = 0;
|
97 |
|
|
|
98 |
|
|
wbl = 0; // programmed burst length
|
99 |
|
|
cl = 2; // cas latency = 2
|
100 |
|
|
bl = 2; // burst length = 4
|
101 |
|
|
|
102 |
|
|
// variables for CSC register
|
103 |
|
|
for (bas = 0; bas <= 1; bas = bas +1)
|
104 |
|
|
begin
|
105 |
|
|
csc_data = {
|
106 |
|
|
8'h00, // reserved
|
107 |
|
|
SDRAM1_SEL, // SEL
|
108 |
|
|
4'h0, // reserved
|
109 |
|
|
1'b0, // parity disabled
|
110 |
|
|
kro[0], // KRO
|
111 |
|
|
bas[0], // BAS
|
112 |
|
|
1'b0, // WP
|
113 |
|
|
2'b10, // MS == 256MB
|
114 |
|
|
2'b01, // BW == 16bit bus per device
|
115 |
|
|
3'b000, // MEM_TYPE == SDRAM
|
116 |
|
|
1'b1 // EN == chip select enabled
|
117 |
|
|
};
|
118 |
|
|
|
119 |
|
|
tms_data = {
|
120 |
|
|
4'h0, // reserved
|
121 |
|
|
4'h8, // Trfc == 7 (+1)
|
122 |
|
|
4'h4, // Trp == 2 (+1) ?????
|
123 |
|
|
3'h3, // Trcd == 2 (+1)
|
124 |
|
|
2'b11, // Twr == 2 (+1)
|
125 |
|
|
5'h0, // reserved
|
126 |
|
|
wbl[0], // write burst length
|
127 |
|
|
2'b00, // OM == normal operation
|
128 |
|
|
cl, // cas latency
|
129 |
|
|
1'b0, // BT == sequential burst type
|
130 |
|
|
bl
|
131 |
|
|
};
|
132 |
|
|
|
133 |
|
|
// program chip select registers
|
134 |
|
|
$display("\nProgramming SDRAM chip select register. KRO = %d, BAS = %d", kro, bas);
|
135 |
|
|
wbm.wb_write(0, 0, 32'h6000_0028, csc_data); // program cs3 config register (CSC3)
|
136 |
|
|
|
137 |
|
|
$display("Programming SDRAM timing register. WBL = %d, CL = %d, BL = %d\n", wbl, cl, bl);
|
138 |
|
|
wbm.wb_write(0, 0, 32'h6000_002c, tms_data); // program cs3 timing register (TMS3)
|
139 |
|
|
|
140 |
|
|
// check written data
|
141 |
|
|
wbm.wb_cmp(0, 0, 32'h6000_0028, csc_data);
|
142 |
|
|
wbm.wb_cmp(0, 0, 32'h6000_002c, tms_data);
|
143 |
|
|
|
144 |
|
|
// only select cyc_delay = 0
|
145 |
|
|
// only select stb_delay = 0
|
146 |
|
|
// --> fastest test_run.
|
147 |
|
|
// other possibilities will be tested by next tests
|
148 |
|
|
cyc_delay = 0;
|
149 |
|
|
stb_delay = 0;
|
150 |
|
|
|
151 |
|
|
begin
|
152 |
|
|
|
153 |
|
|
// fill sdrams
|
154 |
|
|
$display("Filling SDRAM memory... (This takes a while)");
|
155 |
|
|
my_dat = 0;
|
156 |
|
|
bank_cnt = 0;
|
157 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+1)
|
158 |
|
|
begin
|
159 |
|
|
my_adr = n<<2;
|
160 |
|
|
dest_adr = SDRAM_TST_RUN -1 - my_adr; // fill backward
|
161 |
|
|
my_dat = my_adr;
|
162 |
|
|
|
163 |
|
|
if (n % (1<<(`SDRAM_COLA_HI+1)<<(`SDRAM_ROWA_HI+1)) == 0)
|
164 |
|
|
begin
|
165 |
|
|
col_cnt = 0;
|
166 |
|
|
bank_cnt = bank_cnt +1;
|
167 |
|
|
end
|
168 |
|
|
|
169 |
|
|
if (n % (1<<(`SDRAM_COLA_HI+1)) == 0)
|
170 |
|
|
begin
|
171 |
|
|
$display("Filling bank %d, column %d", bank_cnt, col_cnt);
|
172 |
|
|
col_cnt = col_cnt +1;
|
173 |
|
|
end
|
174 |
|
|
|
175 |
|
|
wbm.wb_write(cyc_delay, stb_delay, dest_adr, my_dat);
|
176 |
|
|
end
|
177 |
|
|
|
178 |
|
|
// read sdrams
|
179 |
|
|
$display("Verifying SDRAM memory contents...");
|
180 |
|
|
my_dat = 0;
|
181 |
|
|
bank_cnt = 0;
|
182 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+1)
|
183 |
|
|
begin
|
184 |
|
|
my_adr = n<<2;
|
185 |
|
|
dest_adr = SDRAM_TST_STARTA + my_adr;
|
186 |
|
|
my_dat = my_adr;
|
187 |
|
|
|
188 |
|
|
if (n % (1<<(`SDRAM_COLA_HI+1)) == 0)
|
189 |
|
|
begin
|
190 |
|
|
$display("Verifying bank %d", bank_cnt);
|
191 |
|
|
bank_cnt = bank_cnt +1;
|
192 |
|
|
end
|
193 |
|
|
|
194 |
|
|
wbm.wb_cmp(cyc_delay, stb_delay, dest_adr, my_dat);
|
195 |
|
|
end
|
196 |
|
|
end
|
197 |
|
|
|
198 |
|
|
repeat(10) @(posedge wb_clk); //wait a while
|
199 |
|
|
end
|
200 |
|
|
|
201 |
|
|
|
202 |
|
|
// show Wishbone-Master-model current-error-counter
|
203 |
|
|
wbm.show_cur_err_cnt;
|
204 |
|
|
|
205 |
|
|
end
|
206 |
|
|
endtask // test_sdram_memfill
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
////////////////////////////////
|
210 |
|
|
// SDRAM parity test
|
211 |
|
|
//
|
212 |
|
|
|
213 |
|
|
// 1) This is practically the 'SDRAM sequential access test'
|
214 |
|
|
// 2) First check parity operation
|
215 |
|
|
// 3) Then introduce some parity errors
|
216 |
|
|
task tst_sdram_parity;
|
217 |
|
|
|
218 |
|
|
parameter MAX_CYC_DELAY = 5;
|
219 |
|
|
parameter MAX_STB_DELAY = 5;
|
220 |
|
|
|
221 |
|
|
parameter [31:0] SDRAM_TST_STARTA = `SDRAM1_LOC + (1<<`SDRAM_COLA_HI) + (1<<`SDRAM_COLA_HI>>1); // start at 75% of page
|
222 |
|
|
parameter [ 7:0] SDRAM1_SEL = SDRAM_TST_STARTA[28:21];
|
223 |
|
|
parameter SDRAM_TST_RUN = 16; // a few runs
|
224 |
|
|
|
225 |
|
|
integer n;
|
226 |
|
|
reg [31:0] my_adr, dest_adr;
|
227 |
|
|
reg [31:0] my_dat;
|
228 |
|
|
|
229 |
|
|
// config register mode bits
|
230 |
|
|
reg [1:0] kro, bas; // a single register doesn't work with the for-loops
|
231 |
|
|
|
232 |
|
|
// SDRAM Mode Register bits
|
233 |
|
|
reg [1:0] wbl; // a single register doesn't work with the for-loops
|
234 |
|
|
reg [2:0] cl, bl;
|
235 |
|
|
|
236 |
|
|
reg [31:0] csc_data, tms_data;
|
237 |
|
|
|
238 |
|
|
integer cyc_delay, stb_delay;
|
239 |
|
|
|
240 |
|
|
integer mod_par;
|
241 |
|
|
|
242 |
|
|
begin
|
243 |
|
|
|
244 |
|
|
$display("\n\n --- SDRAM PARITY TEST ---\n\n");
|
245 |
|
|
|
246 |
|
|
// clear Wishbone-Master-model current-error-counter
|
247 |
|
|
wbm.set_cur_err_cnt(0);
|
248 |
|
|
|
249 |
|
|
kro = 0;
|
250 |
|
|
bas = 0;
|
251 |
|
|
|
252 |
|
|
wbl = 0; // programmed burst length
|
253 |
|
|
cl = 2; // cas latency = 2
|
254 |
|
|
bl = 1; // burst length = 8
|
255 |
|
|
|
256 |
|
|
// simply set the parity bits to zero, when introducing parity errors
|
257 |
|
|
set_par = 4'b0;
|
258 |
|
|
|
259 |
|
|
// use second SDRAMS set as parity sdrams
|
260 |
|
|
sel_pbus = 1;
|
261 |
|
|
|
262 |
|
|
for(mod_par = 0; mod_par <= 1; mod_par = mod_par +1)
|
263 |
|
|
begin
|
264 |
|
|
|
265 |
|
|
// switch between parity and parity errors
|
266 |
|
|
sel_par = mod_par;
|
267 |
|
|
|
268 |
|
|
if(sel_par)
|
269 |
|
|
$display("\n-- Checking parity generation --");
|
270 |
|
|
else
|
271 |
|
|
$display("\n-- Introducing parity errors --");
|
272 |
|
|
|
273 |
|
|
// variables for TMS register
|
274 |
|
|
|
275 |
|
|
// skip these settings, since they are not relevant to parity
|
276 |
|
|
// for (cl = 2; cl <= 3; cl = cl +1)
|
277 |
|
|
// for (wbl = 0; wbl <= 1; wbl = wbl +1)
|
278 |
|
|
// for (bl = 0; bl <= 3; bl = bl +1)
|
279 |
|
|
|
280 |
|
|
// variables for CSC register
|
281 |
|
|
// for (kro = 0; kro <= 1; kro = kro +1)
|
282 |
|
|
// for (bas = 0; bas <= 1; bas = bas +1)
|
283 |
|
|
|
284 |
|
|
begin
|
285 |
|
|
csc_data = {
|
286 |
|
|
8'h00, // reserved
|
287 |
|
|
SDRAM1_SEL, // SEL
|
288 |
|
|
4'h0, // reserved
|
289 |
|
|
1'b1, // parity enabled
|
290 |
|
|
kro[0], // KRO
|
291 |
|
|
bas[0], // BAS
|
292 |
|
|
1'b0, // WP
|
293 |
|
|
2'b10, // MS == 256MB
|
294 |
|
|
2'b01, // BW == 16bit bus per device
|
295 |
|
|
3'b000, // MEM_TYPE == SDRAM
|
296 |
|
|
1'b1 // EN == chip select enabled
|
297 |
|
|
};
|
298 |
|
|
|
299 |
|
|
tms_data = {
|
300 |
|
|
4'h0, // reserved
|
301 |
|
|
4'h8, // Trfc == 7 (+1)
|
302 |
|
|
4'h4, // Trp == 2 (+1) ?????
|
303 |
|
|
3'h3, // Trcd == 2 (+1)
|
304 |
|
|
2'b11, // Twr == 2 (+1)
|
305 |
|
|
5'h0, // reserved
|
306 |
|
|
wbl[0], // write burst length
|
307 |
|
|
2'b00, // OM == normal operation
|
308 |
|
|
cl, // cas latency
|
309 |
|
|
1'b0, // BT == sequential burst type
|
310 |
|
|
bl
|
311 |
|
|
};
|
312 |
|
|
|
313 |
|
|
// program chip select registers
|
314 |
|
|
$display("\nProgramming SDRAM chip select register. KRO = %d, BAS = %d", kro, bas);
|
315 |
|
|
wbm.wb_write(0, 0, 32'h6000_0028, csc_data); // program cs3 config register (CSC3)
|
316 |
|
|
|
317 |
|
|
$display("Programming SDRAM timing register. WBL = %d, CL = %d, BL = %d\n", wbl, cl, bl);
|
318 |
|
|
wbm.wb_write(0, 0, 32'h6000_002c, tms_data); // program cs3 timing register (TMS3)
|
319 |
|
|
|
320 |
|
|
// check written data
|
321 |
|
|
wbm.wb_cmp(0, 0, 32'h6000_0028, csc_data);
|
322 |
|
|
wbm.wb_cmp(0, 0, 32'h6000_002c, tms_data);
|
323 |
|
|
|
324 |
|
|
cyc_delay = 0;
|
325 |
|
|
stb_delay = 0;
|
326 |
|
|
|
327 |
|
|
// skip cyc_delay and stb_delay.
|
328 |
|
|
// They are not relevant to parity generation
|
329 |
|
|
// for (cyc_delay = 0; cyc_delay <= MAX_CYC_DELAY; cyc_delay = cyc_delay +1)
|
330 |
|
|
// for (stb_delay = 0; stb_delay <= MAX_STB_DELAY; stb_delay = stb_delay +1)
|
331 |
|
|
begin
|
332 |
|
|
|
333 |
|
|
$display("\nSDRAM parity test. CYC-delay = %d, STB-delay = ", cyc_delay, stb_delay);
|
334 |
|
|
|
335 |
|
|
// fill sdrams
|
336 |
|
|
$display("Filling SDRAM memory...");
|
337 |
|
|
my_dat = 0;
|
338 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+1)
|
339 |
|
|
begin
|
340 |
|
|
my_adr = n<<2;
|
341 |
|
|
dest_adr = SDRAM_TST_STARTA + my_adr;
|
342 |
|
|
my_dat = my_adr + my_dat + kro + bas + wbl + cl + bl + cyc_delay + stb_delay;
|
343 |
|
|
|
344 |
|
|
wbm.wb_write(cyc_delay, stb_delay, dest_adr, my_dat);
|
345 |
|
|
end
|
346 |
|
|
|
347 |
|
|
// read sdrams
|
348 |
|
|
$display("Verifying SDRAM memory contents...");
|
349 |
|
|
my_dat = 0;
|
350 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+1)
|
351 |
|
|
begin
|
352 |
|
|
my_adr = n<<2;
|
353 |
|
|
dest_adr = SDRAM_TST_STARTA + my_adr;
|
354 |
|
|
my_dat = my_adr + my_dat + kro + bas + wbl + cl + bl + cyc_delay + stb_delay;
|
355 |
|
|
|
356 |
|
|
wbm.wb_cmp(cyc_delay, stb_delay, dest_adr, my_dat);
|
357 |
|
|
end
|
358 |
|
|
end
|
359 |
|
|
|
360 |
|
|
repeat(10) @(posedge wb_clk); //wait a while
|
361 |
|
|
end
|
362 |
|
|
|
363 |
|
|
end
|
364 |
|
|
|
365 |
|
|
// show Wishbone-Master-model current-error-counter
|
366 |
|
|
wbm.show_cur_err_cnt;
|
367 |
|
|
|
368 |
|
|
end
|
369 |
|
|
endtask // test_sdram_parity
|
370 |
|
|
|
371 |
|
|
////////////////////////////////
|
372 |
|
|
// SDRAM Sequential access test
|
373 |
|
|
//
|
374 |
|
|
|
375 |
|
|
// 1) Tests sdram sequential address access
|
376 |
|
|
// 2) Tests page switch
|
377 |
|
|
// 3) Tests bank-switching using BAS-bit
|
378 |
|
|
// 4) Test burst-action by filling SDRAM backwards (high addresses first)
|
379 |
|
|
// 5) Run test for all possible CS settings for SDRAMS
|
380 |
|
|
task tst_sdram_seq;
|
381 |
|
|
|
382 |
|
|
parameter MAX_CYC_DELAY = 5;
|
383 |
|
|
parameter MAX_STB_DELAY = 5;
|
384 |
|
|
parameter [31:0] SDRAM_TST_STARTA = `SDRAM1_LOC + (1<<`SDRAM_COLA_HI) + (1<<`SDRAM_COLA_HI>>1); // start at 75% of page
|
385 |
|
|
parameter [ 7:0] SDRAM1_SEL = SDRAM_TST_STARTA[28:21];
|
386 |
|
|
parameter SDRAM_TST_RUN = (1<<`SDRAM_COLA_HI>>1); // run for half page length
|
387 |
|
|
|
388 |
|
|
integer n, k;
|
389 |
|
|
reg [31:0] my_adr, dest_adr;
|
390 |
|
|
reg [31:0] my_dat;
|
391 |
|
|
reg [15:0] tmp0, tmp1;
|
392 |
|
|
|
393 |
|
|
// config register mode bits
|
394 |
|
|
reg [1:0] kro, bas; // a single register doesn't work with the for-loops
|
395 |
|
|
|
396 |
|
|
// SDRAM Mode Register bits
|
397 |
|
|
reg [1:0] wbl; // a single register doesn't work with the for-loops
|
398 |
|
|
reg [2:0] cl, bl;
|
399 |
|
|
|
400 |
|
|
reg [31:0] csc_data, tms_data;
|
401 |
|
|
|
402 |
|
|
integer cyc_delay, stb_delay;
|
403 |
|
|
|
404 |
|
|
begin
|
405 |
|
|
|
406 |
|
|
$display("\n\n --- SDRAM SEQUENTIAL ACCESS TEST ---\n\n");
|
407 |
|
|
|
408 |
|
|
// clear Wishbone-Master-model current-error-counter
|
409 |
|
|
wbm.set_cur_err_cnt(0);
|
410 |
|
|
|
411 |
|
|
kro = 0;
|
412 |
|
|
bas = 0;
|
413 |
|
|
|
414 |
|
|
wbl = 0; // programmed burst length
|
415 |
|
|
cl = 2; // cas latency = 2
|
416 |
|
|
bl = 2; // burst length
|
417 |
|
|
|
418 |
|
|
// variables for TMS register
|
419 |
|
|
for (cl = 2; cl <= 3; cl = cl +1)
|
420 |
|
|
for (wbl = 0; wbl <= 1; wbl = wbl +1)
|
421 |
|
|
for (bl = 0; bl <= 3; bl = bl +1)
|
422 |
|
|
|
423 |
|
|
// variables for CSC register
|
424 |
|
|
for (kro = 0; kro <= 1; kro = kro +1)
|
425 |
|
|
for (bas = 0; bas <= 1; bas = bas +1)
|
426 |
|
|
begin
|
427 |
|
|
csc_data = {
|
428 |
|
|
8'h00, // reserved
|
429 |
|
|
SDRAM1_SEL, // SEL
|
430 |
|
|
4'h0, // reserved
|
431 |
|
|
1'b0, // parity disabled
|
432 |
|
|
kro[0], // KRO
|
433 |
|
|
bas[0], // BAS
|
434 |
|
|
1'b0, // WP
|
435 |
|
|
2'b10, // MS == 256MB
|
436 |
|
|
2'b01, // BW == 16bit bus per device
|
437 |
|
|
3'b000, // MEM_TYPE == SDRAM
|
438 |
|
|
1'b1 // EN == chip select enabled
|
439 |
|
|
};
|
440 |
|
|
|
441 |
|
|
tms_data = {
|
442 |
|
|
4'h0, // reserved
|
443 |
|
|
4'h8, // Trfc == 7 (+1)
|
444 |
|
|
4'h4, // Trp == 2 (+1) ?????
|
445 |
|
|
3'h3, // Trcd == 2 (+1)
|
446 |
|
|
2'b11, // Twr == 2 (+1)
|
447 |
|
|
5'h0, // reserved
|
448 |
|
|
wbl[0], // write burst length
|
449 |
|
|
2'b00, // OM == normal operation
|
450 |
|
|
cl, // cas latency
|
451 |
|
|
1'b0, // BT == sequential burst type
|
452 |
|
|
bl
|
453 |
|
|
};
|
454 |
|
|
|
455 |
|
|
// program chip select registers
|
456 |
|
|
$display("\nProgramming SDRAM chip select register. KRO = %d, BAS = %d", kro, bas);
|
457 |
|
|
wbm.wb_write(0, 0, 32'h6000_0028, csc_data); // program cs3 config register (CSC3)
|
458 |
|
|
|
459 |
|
|
$display("Programming SDRAM timing register. WBL = %d, CL = %d, BL = %d\n", wbl, cl, bl);
|
460 |
|
|
wbm.wb_write(0, 0, 32'h6000_002c, tms_data); // program cs3 timing register (TMS3)
|
461 |
|
|
|
462 |
|
|
// check written data
|
463 |
|
|
wbm.wb_cmp(0, 0, 32'h6000_0028, csc_data);
|
464 |
|
|
wbm.wb_cmp(0, 0, 32'h6000_002c, tms_data);
|
465 |
|
|
|
466 |
|
|
cyc_delay = 0;
|
467 |
|
|
stb_delay = 0;
|
468 |
|
|
for (cyc_delay = 0; cyc_delay <= MAX_CYC_DELAY; cyc_delay = cyc_delay +1)
|
469 |
|
|
for (stb_delay = 0; stb_delay <= MAX_STB_DELAY; stb_delay = stb_delay +1)
|
470 |
|
|
begin
|
471 |
|
|
|
472 |
|
|
$display("\nSDRAM sequential test. CYC-delay = %d, STB-delay = ", cyc_delay, stb_delay);
|
473 |
|
|
|
474 |
|
|
// fill sdrams
|
475 |
|
|
$display("Filling SDRAM memory...");
|
476 |
|
|
my_dat = 0;
|
477 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+(1<<bl) )
|
478 |
|
|
begin
|
479 |
|
|
my_adr = SDRAM_TST_STARTA +( (SDRAM_TST_RUN -n -(1<<bl)) <<2);
|
480 |
|
|
for (k=0; k < (1<<bl); k=k+1)
|
481 |
|
|
begin
|
482 |
|
|
// fill destination backwards, but with linear bursts
|
483 |
|
|
dest_adr = my_adr + (k<<2);
|
484 |
|
|
|
485 |
|
|
tmp0 = ~dest_adr[15:0] + kro + bas + wbl + cl + bl + cyc_delay + stb_delay;
|
486 |
|
|
tmp1 = dest_adr[15:0] + kro + bas + wbl + cl + bl + cyc_delay + stb_delay;
|
487 |
|
|
my_dat = {tmp0, tmp1};
|
488 |
|
|
|
489 |
|
|
wbm.wb_write(cyc_delay, stb_delay, dest_adr, my_dat);
|
490 |
|
|
end
|
491 |
|
|
end
|
492 |
|
|
|
493 |
|
|
|
494 |
|
|
// read sdrams
|
495 |
|
|
$display("Verifying SDRAM memory contents...");
|
496 |
|
|
my_dat = 0;
|
497 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+1)
|
498 |
|
|
begin
|
499 |
|
|
my_adr = n<<2;
|
500 |
|
|
dest_adr = SDRAM_TST_STARTA + my_adr;
|
501 |
|
|
|
502 |
|
|
tmp0 = ~dest_adr[15:0] + kro + bas + wbl + cl + bl + cyc_delay + stb_delay;
|
503 |
|
|
tmp1 = dest_adr[15:0] + kro + bas + wbl + cl + bl + cyc_delay + stb_delay;
|
504 |
|
|
my_dat = {tmp0, tmp1};
|
505 |
|
|
|
506 |
|
|
wbm.wb_cmp(cyc_delay, stb_delay, dest_adr, my_dat);
|
507 |
|
|
end
|
508 |
|
|
end
|
509 |
|
|
|
510 |
|
|
repeat(10) @(posedge wb_clk); //wait a while
|
511 |
|
|
end
|
512 |
|
|
|
513 |
|
|
|
514 |
|
|
// show Wishbone-Master-model current-error-counter
|
515 |
|
|
wbm.show_cur_err_cnt;
|
516 |
|
|
|
517 |
|
|
end
|
518 |
|
|
endtask // test_sdram_seq
|
519 |
|
|
|
520 |
|
|
|
521 |
|
|
/////////////////////////////
|
522 |
|
|
// SDRAM Random access test
|
523 |
|
|
//
|
524 |
|
|
|
525 |
|
|
// 1) Tests sdram random address access
|
526 |
|
|
// 2) Run test for all possible CS settings for SDRAMS
|
527 |
|
|
task tst_sdram_rnd;
|
528 |
|
|
|
529 |
|
|
parameter MAX_CYC_DELAY = 5;
|
530 |
|
|
parameter MAX_STB_DELAY = 5;
|
531 |
|
|
|
532 |
|
|
parameter [31:0] SDRAM_TST_STARTA = `SDRAM1_LOC; // start somewhere in memory
|
533 |
|
|
parameter [ 7:0] SDRAM1_SEL = SDRAM_TST_STARTA[28:21];
|
534 |
|
|
parameter SDRAM_TST_RUN = 64; // run a few accesses
|
535 |
|
|
|
536 |
|
|
integer n;
|
537 |
|
|
reg [31:0] my_adr, dest_adr;
|
538 |
|
|
reg [31:0] my_dat;
|
539 |
|
|
|
540 |
|
|
// config register mode bits
|
541 |
|
|
reg [1:0] kro, bas; // a single register doesn't work with the for-loops
|
542 |
|
|
|
543 |
|
|
// SDRAM Mode Register bits
|
544 |
|
|
reg [1:0] wbl; // a single register doesn't work with the for-loops
|
545 |
|
|
reg [2:0] cl, bl;
|
546 |
|
|
|
547 |
|
|
reg [31:0] csc_data, tms_data;
|
548 |
|
|
|
549 |
|
|
integer cyc_delay, stb_delay;
|
550 |
|
|
|
551 |
|
|
begin
|
552 |
|
|
|
553 |
|
|
$display("\n\n --- SDRAM RANDOM ACCESS TEST ---\n\n");
|
554 |
|
|
|
555 |
|
|
// clear Wishbone-Master-model current-error-counter
|
556 |
|
|
wbm.set_cur_err_cnt(0);
|
557 |
|
|
|
558 |
|
|
kro = 0;
|
559 |
|
|
bas = 0;
|
560 |
|
|
|
561 |
|
|
wbl = 0; // programmed burst length
|
562 |
|
|
cl = 2; // cas latency = 2
|
563 |
|
|
bl = 2; // burst length = 4
|
564 |
|
|
|
565 |
|
|
// variables for TMS register
|
566 |
|
|
for (cl = 2; cl <= 3; cl = cl +1)
|
567 |
|
|
for (wbl = 0; wbl <= 1; wbl = wbl +1)
|
568 |
|
|
for (bl = 0; bl <= 3; bl = bl +1)
|
569 |
|
|
|
570 |
|
|
// variables for CSC register
|
571 |
|
|
for (kro = 0; kro <= 1; kro = kro +1)
|
572 |
|
|
for (bas = 0; bas <= 1; bas = bas +1)
|
573 |
|
|
begin
|
574 |
|
|
csc_data = {
|
575 |
|
|
8'h00, // reserved
|
576 |
|
|
SDRAM1_SEL, // SEL
|
577 |
|
|
4'h0, // reserved
|
578 |
|
|
1'b0, // parity disabled
|
579 |
|
|
kro[0], // KRO
|
580 |
|
|
bas[0], // BAS
|
581 |
|
|
1'b0, // WP
|
582 |
|
|
2'b10, // MS == 256MB
|
583 |
|
|
2'b01, // BW == 16bit bus per device
|
584 |
|
|
3'b000, // MEM_TYPE == SDRAM
|
585 |
|
|
1'b1 // EN == chip select enabled
|
586 |
|
|
};
|
587 |
|
|
|
588 |
|
|
tms_data = {
|
589 |
|
|
4'h0, // reserved
|
590 |
|
|
4'h8, // Trfc == 7 (+1)
|
591 |
|
|
4'h4, // Trp == 2 (+1) ?????
|
592 |
|
|
3'h3, // Trcd == 2 (+1)
|
593 |
|
|
2'b11, // Twr == 2 (+1)
|
594 |
|
|
5'h0, // reserved
|
595 |
|
|
wbl[0], // write burst length
|
596 |
|
|
2'b00, // OM == normal operation
|
597 |
|
|
cl, // cas latency
|
598 |
|
|
1'b0, // BT == sequential burst type
|
599 |
|
|
bl
|
600 |
|
|
};
|
601 |
|
|
|
602 |
|
|
// program chip select registers
|
603 |
|
|
$display("\nProgramming SDRAM chip select register. KRO = %d, BAS = %d", kro, bas);
|
604 |
|
|
wbm.wb_write(0, 0, 32'h6000_0028, csc_data); // program cs3 config register (CSC3)
|
605 |
|
|
|
606 |
|
|
$display("\nProgramming SDRAM timing register. WBL = %d, CL = %d, BL = %d\n", wbl, cl, bl);
|
607 |
|
|
wbm.wb_write(0, 0, 32'h6000_002c, tms_data); // program cs3 timing register (TMS3)
|
608 |
|
|
|
609 |
|
|
// check written data
|
610 |
|
|
wbm.wb_cmp(0, 0, 32'h6000_0028, csc_data);
|
611 |
|
|
wbm.wb_cmp(0, 0, 32'h6000_002c, tms_data);
|
612 |
|
|
|
613 |
|
|
// random access requires CYC signal to be broken up (delay >= 1)
|
614 |
|
|
// otherwise MemoryController expects sequential burst
|
615 |
|
|
cyc_delay = 1;
|
616 |
|
|
stb_delay = 0;
|
617 |
|
|
for (cyc_delay = 1; cyc_delay <= MAX_CYC_DELAY; cyc_delay = cyc_delay +1)
|
618 |
|
|
for (stb_delay = 0; stb_delay <= MAX_STB_DELAY; stb_delay = stb_delay +1)
|
619 |
|
|
begin
|
620 |
|
|
|
621 |
|
|
$display("\nSDRAM random test. CYC-delay = %d, STB-delay = ", cyc_delay, stb_delay);
|
622 |
|
|
|
623 |
|
|
// fill sdrams
|
624 |
|
|
$display("Filling SDRAM memory...");
|
625 |
|
|
my_adr = 0;
|
626 |
|
|
my_dat = 0;
|
627 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+1)
|
628 |
|
|
begin
|
629 |
|
|
my_adr = (n << 2) + my_adr;
|
630 |
|
|
dest_adr = SDRAM_TST_STARTA + my_adr;
|
631 |
|
|
my_dat = my_adr + my_dat + kro + bas + wbl + cl + bl + cyc_delay + stb_delay;
|
632 |
|
|
|
633 |
|
|
wbm.wb_write(cyc_delay, stb_delay, dest_adr, my_dat);
|
634 |
|
|
end
|
635 |
|
|
|
636 |
|
|
// read sdrams
|
637 |
|
|
$display("Verifying SDRAM memory contents...\n");
|
638 |
|
|
my_adr = 0;
|
639 |
|
|
my_dat = 0;
|
640 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+1)
|
641 |
|
|
begin
|
642 |
|
|
my_adr = (n << 2) + my_adr;
|
643 |
|
|
dest_adr = SDRAM_TST_STARTA + my_adr;
|
644 |
|
|
my_dat = my_adr + my_dat + kro + bas + wbl + cl + bl + cyc_delay + stb_delay;
|
645 |
|
|
|
646 |
|
|
wbm.wb_cmp(cyc_delay, stb_delay, dest_adr, my_dat);
|
647 |
|
|
end
|
648 |
|
|
end
|
649 |
|
|
end
|
650 |
|
|
|
651 |
|
|
// show Wishbone-Master-model current-error-counter
|
652 |
|
|
wbm.show_cur_err_cnt;
|
653 |
|
|
|
654 |
|
|
end
|
655 |
|
|
endtask //tst_sdram_rnd
|
656 |
|
|
|
657 |
|
|
|
658 |
|
|
/////////////////////////
|
659 |
|
|
// SDRAM seq RMW test
|
660 |
|
|
//
|
661 |
|
|
|
662 |
|
|
// 1) Tests sdram RMW cycle using sequential address accesses
|
663 |
|
|
// 2) Run test for all possible CS settings for SDRAMS
|
664 |
|
|
task tst_sdram_rmw_seq;
|
665 |
|
|
|
666 |
|
|
parameter MAX_CYC_DELAY = 5;
|
667 |
|
|
parameter MAX_STB_DELAY = 5;
|
668 |
|
|
|
669 |
|
|
parameter [31:0] SDRAM_TST_STARTA = `SDRAM1_LOC; // start somewhere in memory (at dword boundary)
|
670 |
|
|
parameter [ 7:0] SDRAM1_SEL = SDRAM_TST_STARTA[28:21];
|
671 |
|
|
parameter SDRAM_TST_RUN = 64; // only do a few runs
|
672 |
|
|
|
673 |
|
|
integer n;
|
674 |
|
|
reg [31:0] my_adr, dest_adr;
|
675 |
|
|
reg [31:0] my_dat;
|
676 |
|
|
|
677 |
|
|
// config register mode bits
|
678 |
|
|
reg [1:0] kro, bas; // a single register doesn't work with the for-loops
|
679 |
|
|
|
680 |
|
|
// SDRAM Mode Register bits
|
681 |
|
|
reg [1:0] wbl; // a single register doesn't work with the for-loops
|
682 |
|
|
reg [2:0] cl, bl;
|
683 |
|
|
|
684 |
|
|
reg [31:0] csc_data, tms_data;
|
685 |
|
|
|
686 |
|
|
integer cyc_delay, stb_delay;
|
687 |
|
|
|
688 |
|
|
begin
|
689 |
|
|
|
690 |
|
|
$display("\n\n --- SDRAM SEQUENTIAL ACCESS READ-MODIFY-WRITE TEST ---\n\n");
|
691 |
|
|
|
692 |
|
|
// clear Wishbone-Master-model current-error-counter
|
693 |
|
|
wbm.set_cur_err_cnt(0);
|
694 |
|
|
|
695 |
|
|
kro = 0;
|
696 |
|
|
bas = 0;
|
697 |
|
|
|
698 |
|
|
wbl = 0; // programmed burst length
|
699 |
|
|
cl = 2; // cas latency = 2
|
700 |
|
|
bl = 1; // burst length = 4
|
701 |
|
|
|
702 |
|
|
// variables for TMS register
|
703 |
|
|
for (cl = 2; cl <= 3; cl = cl +1)
|
704 |
|
|
for (wbl = 0; wbl <= 1; wbl = wbl +1)
|
705 |
|
|
for (bl = 0; bl <= 3; bl = bl +1)
|
706 |
|
|
|
707 |
|
|
// variables for CSC register
|
708 |
|
|
for (kro = 0; kro <= 1; kro = kro +1)
|
709 |
|
|
for (bas = 0; bas <= 1; bas = bas +1)
|
710 |
|
|
begin
|
711 |
|
|
csc_data = {
|
712 |
|
|
8'h00, // reserved
|
713 |
|
|
SDRAM1_SEL, // SEL
|
714 |
|
|
4'h0, // reserved
|
715 |
|
|
1'b0, // parity disabled
|
716 |
|
|
kro[0], // KRO
|
717 |
|
|
bas[0], // BAS
|
718 |
|
|
1'b0, // WP
|
719 |
|
|
2'b10, // MS == 256MB
|
720 |
|
|
2'b01, // BW == 16bit bus per device
|
721 |
|
|
3'b000, // MEM_TYPE == SDRAM
|
722 |
|
|
1'b1 // EN == chip select enabled
|
723 |
|
|
};
|
724 |
|
|
|
725 |
|
|
tms_data = {
|
726 |
|
|
4'h0, // reserved
|
727 |
|
|
4'h8, // Trfc == 7 (+1)
|
728 |
|
|
4'h4, // Trp == 2 (+1) ?????
|
729 |
|
|
3'h3, // Trcd == 2 (+1)
|
730 |
|
|
2'b11, // Twr == 2 (+1)
|
731 |
|
|
5'h0, // reserved
|
732 |
|
|
wbl[0], // write burst length
|
733 |
|
|
2'b00, // OM == normal operation
|
734 |
|
|
cl, // cas latency
|
735 |
|
|
1'b0, // BT == sequential burst type
|
736 |
|
|
bl
|
737 |
|
|
};
|
738 |
|
|
|
739 |
|
|
// program chip select registers
|
740 |
|
|
$display("\nProgramming SDRAM chip select register. KRO = %d, BAS = %d", kro, bas);
|
741 |
|
|
wbm.wb_write(0, 0, 32'h6000_0028, csc_data); // program cs3 config register (CSC3)
|
742 |
|
|
|
743 |
|
|
$display("\nProgramming SDRAM timing register. WBL = %d, CL = %d, BL = %d\n", wbl, cl, bl);
|
744 |
|
|
wbm.wb_write(0, 0, 32'h6000_002c, tms_data); // program cs3 timing register (TMS3)
|
745 |
|
|
|
746 |
|
|
// check written data
|
747 |
|
|
wbm.wb_cmp(0, 0, 32'h6000_0028, csc_data);
|
748 |
|
|
wbm.wb_cmp(0, 0, 32'h6000_002c, tms_data);
|
749 |
|
|
|
750 |
|
|
cyc_delay = 1;
|
751 |
|
|
stb_delay = 0;
|
752 |
|
|
for (cyc_delay = 0; cyc_delay <= MAX_CYC_DELAY; cyc_delay = cyc_delay +1)
|
753 |
|
|
for (stb_delay = 0; stb_delay <= MAX_STB_DELAY; stb_delay = stb_delay +1)
|
754 |
|
|
begin
|
755 |
|
|
|
756 |
|
|
$display("\nSDRAM sequential Read-Modify-Write test. CYC-delay = %d, STB-delay = %d", cyc_delay, stb_delay);
|
757 |
|
|
|
758 |
|
|
// fill sdrams
|
759 |
|
|
$display("Filling SDRAM memory with initial contents ...");
|
760 |
|
|
my_dat = 0;
|
761 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+1)
|
762 |
|
|
begin
|
763 |
|
|
my_adr = (n << 2);
|
764 |
|
|
dest_adr = SDRAM_TST_STARTA + my_adr;
|
765 |
|
|
my_dat = my_adr + my_dat + kro + bas + wbl + cl + bl + cyc_delay + stb_delay;
|
766 |
|
|
|
767 |
|
|
wbm.wb_write(cyc_delay, stb_delay, dest_adr, my_dat);
|
768 |
|
|
end
|
769 |
|
|
|
770 |
|
|
// perform Read-Modify-Write cycle
|
771 |
|
|
$display("Performing RMW cycle ...");
|
772 |
|
|
my_dat = 0;
|
773 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+1)
|
774 |
|
|
begin
|
775 |
|
|
my_adr = (n << 2);
|
776 |
|
|
dest_adr = SDRAM_TST_STARTA + my_adr;
|
777 |
|
|
|
778 |
|
|
// read memory contents
|
779 |
|
|
wbm.wb_read(cyc_delay, stb_delay, dest_adr, my_dat);
|
780 |
|
|
|
781 |
|
|
// modify memory contents
|
782 |
|
|
my_dat = my_dat +1;
|
783 |
|
|
|
784 |
|
|
// write contents back into memory
|
785 |
|
|
wbm.wb_write(cyc_delay, stb_delay, dest_adr, my_dat);
|
786 |
|
|
|
787 |
|
|
end
|
788 |
|
|
|
789 |
|
|
// read sdrams
|
790 |
|
|
$display("Verifying SDRAM memory contents...");
|
791 |
|
|
my_dat = 0;
|
792 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+1)
|
793 |
|
|
begin
|
794 |
|
|
my_adr = (n << 2);
|
795 |
|
|
dest_adr = SDRAM_TST_STARTA + my_adr;
|
796 |
|
|
my_dat = my_adr + my_dat + kro + bas + wbl + cl + bl + cyc_delay + stb_delay;
|
797 |
|
|
|
798 |
|
|
wbm.wb_cmp(cyc_delay, stb_delay, dest_adr, my_dat +1);
|
799 |
|
|
end
|
800 |
|
|
end
|
801 |
|
|
end
|
802 |
|
|
|
803 |
|
|
// show Wishbone-Master-model current-error-counter
|
804 |
|
|
wbm.show_cur_err_cnt;
|
805 |
|
|
|
806 |
|
|
end
|
807 |
|
|
endtask //tst_sdram_rmw_seq
|
808 |
|
|
|
809 |
|
|
/////////////////////////
|
810 |
|
|
// SDRAM Random RMW test
|
811 |
|
|
//
|
812 |
|
|
|
813 |
|
|
// 1) Tests sdram RMW cycle using random address accesses
|
814 |
|
|
// 2) Run test for all possible CS settings for SDRAMS
|
815 |
|
|
task tst_sdram_rmw_rnd;
|
816 |
|
|
|
817 |
|
|
parameter MAX_CYC_DELAY = 5;
|
818 |
|
|
parameter MAX_STB_DELAY = 5;
|
819 |
|
|
|
820 |
|
|
parameter [31:0] SDRAM_TST_STARTA = `SDRAM1_LOC; // start somewhere in memory
|
821 |
|
|
parameter [ 7:0] SDRAM1_SEL = SDRAM_TST_STARTA[28:21];
|
822 |
|
|
parameter SDRAM_TST_RUN = 64; // only do a few runs
|
823 |
|
|
|
824 |
|
|
integer n;
|
825 |
|
|
reg [31:0] my_adr, dest_adr;
|
826 |
|
|
reg [31:0] my_dat;
|
827 |
|
|
|
828 |
|
|
// config register mode bits
|
829 |
|
|
reg [1:0] kro, bas; // a single register doesn't work with the for-loops
|
830 |
|
|
|
831 |
|
|
// SDRAM Mode Register bits
|
832 |
|
|
reg [1:0] wbl; // a single register doesn't work with the for-loops
|
833 |
|
|
reg [2:0] cl, bl;
|
834 |
|
|
|
835 |
|
|
reg [31:0] csc_data, tms_data;
|
836 |
|
|
|
837 |
|
|
integer cyc_delay, stb_delay;
|
838 |
|
|
|
839 |
|
|
begin
|
840 |
|
|
|
841 |
|
|
$display("\n\n --- SDRAM RANDOM ACCESS READ-MODIFY-WRITE TEST ---\n\n");
|
842 |
|
|
|
843 |
|
|
// clear Wishbone-Master-model current-error-counter
|
844 |
|
|
wbm.set_cur_err_cnt(0);
|
845 |
|
|
|
846 |
|
|
kro = 0;
|
847 |
|
|
bas = 0;
|
848 |
|
|
|
849 |
|
|
wbl = 0; // programmed burst length
|
850 |
|
|
cl = 2; // cas latency = 2
|
851 |
|
|
bl = 2; // burst length = 4
|
852 |
|
|
|
853 |
|
|
// variables for TMS register
|
854 |
|
|
for (cl = 2; cl <= 3; cl = cl +1)
|
855 |
|
|
for (wbl = 0; wbl <= 1; wbl = wbl +1)
|
856 |
|
|
for (bl = 0; bl <= 3; bl = bl +1)
|
857 |
|
|
|
858 |
|
|
// variables for CSC register
|
859 |
|
|
for (kro = 0; kro <= 1; kro = kro +1)
|
860 |
|
|
for (bas = 0; bas <= 1; bas = bas +1)
|
861 |
|
|
begin
|
862 |
|
|
csc_data = {
|
863 |
|
|
8'h00, // reserved
|
864 |
|
|
SDRAM1_SEL, // SEL
|
865 |
|
|
4'h0, // reserved
|
866 |
|
|
1'b0, // parity disabled
|
867 |
|
|
kro[0], // KRO
|
868 |
|
|
bas[0], // BAS
|
869 |
|
|
1'b0, // WP
|
870 |
|
|
2'b10, // MS == 256MB
|
871 |
|
|
2'b01, // BW == 16bit bus per device
|
872 |
|
|
3'b000, // MEM_TYPE == SDRAM
|
873 |
|
|
1'b1 // EN == chip select enabled
|
874 |
|
|
};
|
875 |
|
|
|
876 |
|
|
tms_data = {
|
877 |
|
|
4'h0, // reserved
|
878 |
|
|
4'h8, // Trfc == 7 (+1)
|
879 |
|
|
4'h4, // Trp == 2 (+1) ?????
|
880 |
|
|
3'h3, // Trcd == 2 (+1)
|
881 |
|
|
2'b11, // Twr == 2 (+1)
|
882 |
|
|
5'h0, // reserved
|
883 |
|
|
wbl[0], // write burst length
|
884 |
|
|
2'b00, // OM == normal operation
|
885 |
|
|
cl, // cas latency
|
886 |
|
|
1'b0, // BT == sequential burst type
|
887 |
|
|
bl
|
888 |
|
|
};
|
889 |
|
|
|
890 |
|
|
// program chip select registers
|
891 |
|
|
$display("\nProgramming SDRAM chip select register. KRO = %d, BAS = %d", kro, bas);
|
892 |
|
|
wbm.wb_write(0, 0, 32'h6000_0028, csc_data); // program cs3 config register (CSC3)
|
893 |
|
|
|
894 |
|
|
$display("\nProgramming SDRAM timing register. WBL = %d, CL = %d, BL = %d\n", wbl, cl, bl);
|
895 |
|
|
wbm.wb_write(0, 0, 32'h6000_002c, tms_data); // program cs3 timing register (TMS3)
|
896 |
|
|
|
897 |
|
|
// check written data
|
898 |
|
|
wbm.wb_cmp(0, 0, 32'h6000_0028, csc_data);
|
899 |
|
|
wbm.wb_cmp(0, 0, 32'h6000_002c, tms_data);
|
900 |
|
|
|
901 |
|
|
// random access requires CYC signal to be broken up (delay >= 1)
|
902 |
|
|
// otherwise MemoryController expects sequential burst
|
903 |
|
|
cyc_delay = 1;
|
904 |
|
|
stb_delay = 0;
|
905 |
|
|
for (cyc_delay = 1; cyc_delay <= MAX_CYC_DELAY; cyc_delay = cyc_delay +1)
|
906 |
|
|
for (stb_delay = 0; stb_delay <= MAX_STB_DELAY; stb_delay = stb_delay +1)
|
907 |
|
|
begin
|
908 |
|
|
|
909 |
|
|
$display("\nSDRAM random Read-Modify-Write test. CYC-delay = %d, STB-delay = %d", cyc_delay, stb_delay);
|
910 |
|
|
|
911 |
|
|
// fill sdrams
|
912 |
|
|
$display("Filling SDRAM memory with initial contents ...");
|
913 |
|
|
my_adr = 0;
|
914 |
|
|
my_dat = 0;
|
915 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+1)
|
916 |
|
|
begin
|
917 |
|
|
my_adr = (n << 2) + my_adr;
|
918 |
|
|
dest_adr = SDRAM_TST_STARTA + my_adr;
|
919 |
|
|
my_dat = my_adr + my_dat + kro + bas + wbl + cl + bl + cyc_delay + stb_delay;
|
920 |
|
|
|
921 |
|
|
wbm.wb_write(cyc_delay, stb_delay, dest_adr, my_dat);
|
922 |
|
|
end
|
923 |
|
|
|
924 |
|
|
// perform Read-Modify-Write cycle
|
925 |
|
|
$display("Performing RMW cycle ...");
|
926 |
|
|
my_adr = 0;
|
927 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+1)
|
928 |
|
|
begin
|
929 |
|
|
my_adr = (n << 2) + my_adr;
|
930 |
|
|
dest_adr = SDRAM_TST_STARTA + my_adr;
|
931 |
|
|
|
932 |
|
|
// read memory contents
|
933 |
|
|
wbm.wb_read(cyc_delay, stb_delay, dest_adr, my_dat);
|
934 |
|
|
|
935 |
|
|
// modify memory contents
|
936 |
|
|
my_dat = my_dat +1;
|
937 |
|
|
|
938 |
|
|
// write contents back into memory
|
939 |
|
|
wbm.wb_write(cyc_delay, stb_delay, dest_adr, my_dat);
|
940 |
|
|
|
941 |
|
|
end
|
942 |
|
|
|
943 |
|
|
// read sdrams
|
944 |
|
|
$display("Verifying SDRAM memory contents...");
|
945 |
|
|
my_adr = 0;
|
946 |
|
|
my_dat = 0;
|
947 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+1)
|
948 |
|
|
begin
|
949 |
|
|
my_adr = (n << 2) + my_adr;
|
950 |
|
|
dest_adr = SDRAM_TST_STARTA + my_adr;
|
951 |
|
|
my_dat = my_adr + my_dat + kro + bas + wbl + cl + bl + cyc_delay + stb_delay;
|
952 |
|
|
|
953 |
|
|
wbm.wb_cmp(cyc_delay, stb_delay, dest_adr, my_dat +1);
|
954 |
|
|
end
|
955 |
|
|
end
|
956 |
|
|
end
|
957 |
|
|
|
958 |
|
|
// show Wishbone-Master-model current-error-counter
|
959 |
|
|
wbm.show_cur_err_cnt;
|
960 |
|
|
|
961 |
|
|
end
|
962 |
|
|
endtask //tst_sdram_rmw_rnd
|
963 |
|
|
|
964 |
|
|
|
965 |
|
|
//////////////////////////
|
966 |
|
|
// SDRAM Block copy test1
|
967 |
|
|
//
|
968 |
|
|
|
969 |
|
|
// 1) Copy block of memory inside same memory block (chip select)
|
970 |
|
|
// 2) Run test for all possible CS settings for SDRAM
|
971 |
|
|
task tst_sdram_blk_cpy1;
|
972 |
|
|
|
973 |
|
|
parameter MAX_CYC_DELAY = 5;
|
974 |
|
|
parameter MAX_STB_DELAY = 5;
|
975 |
|
|
|
976 |
|
|
parameter [31:0] SDRAM1_STARTA = `SDRAM1_LOC;
|
977 |
|
|
parameter [ 7:0] SDRAM1_SEL = SDRAM1_STARTA[28:21];
|
978 |
|
|
parameter SDRAM_TST_RUN = 64; // only do a few runs
|
979 |
|
|
|
980 |
|
|
parameter MAX_BSIZE = 8;
|
981 |
|
|
|
982 |
|
|
parameter SDRAM_SRC = SDRAM1_STARTA;
|
983 |
|
|
parameter SDRAM_DST = SDRAM1_STARTA + 32'h0001_0000;
|
984 |
|
|
|
985 |
|
|
integer n, wcnt, bsize;
|
986 |
|
|
reg [31:0] my_adr, src_adr, dest_adr;
|
987 |
|
|
reg [31:0] my_dat;
|
988 |
|
|
reg [31:0] tmp [MAX_BSIZE -1 :0];
|
989 |
|
|
|
990 |
|
|
// config register mode bits
|
991 |
|
|
reg [1:0] kro, bas; // a single register doesn't work with the for-loops
|
992 |
|
|
|
993 |
|
|
// SDRAM Mode Register bits
|
994 |
|
|
reg [1:0] wbl; // a single register doesn't work with the for-loops
|
995 |
|
|
reg [2:0] cl, bl;
|
996 |
|
|
|
997 |
|
|
reg [31:0] csc_data, tms_data;
|
998 |
|
|
|
999 |
|
|
integer cyc_delay, stb_delay;
|
1000 |
|
|
|
1001 |
|
|
begin
|
1002 |
|
|
|
1003 |
|
|
$display("\n\n --- SDRAM block copy TEST-1- ---\n\n");
|
1004 |
|
|
|
1005 |
|
|
// clear Wishbone-Master-model current-error-counter
|
1006 |
|
|
wbm.set_cur_err_cnt(0);
|
1007 |
|
|
|
1008 |
|
|
kro = 0;
|
1009 |
|
|
bas = 0;
|
1010 |
|
|
|
1011 |
|
|
wbl = 0; // programmed burst length
|
1012 |
|
|
cl = 2; // cas latency = 2
|
1013 |
|
|
bl = 1; // burst length = 4
|
1014 |
|
|
|
1015 |
|
|
// variables for TMS register
|
1016 |
|
|
for (cl = 2; cl <= 3; cl = cl +1)
|
1017 |
|
|
for (wbl = 0; wbl <= 1; wbl = wbl +1)
|
1018 |
|
|
for (bl = 0; bl <= 3; bl = bl +1)
|
1019 |
|
|
|
1020 |
|
|
// variables for CSC register
|
1021 |
|
|
for (kro = 0; kro <= 1; kro = kro +1)
|
1022 |
|
|
for (bas = 0; bas <= 1; bas = bas +1)
|
1023 |
|
|
begin
|
1024 |
|
|
csc_data = {
|
1025 |
|
|
8'h00, // reserved
|
1026 |
|
|
SDRAM1_SEL, // SEL
|
1027 |
|
|
4'h0, // reserved
|
1028 |
|
|
1'b0, // parity disabled
|
1029 |
|
|
kro[0], // KRO
|
1030 |
|
|
bas[0], // BAS
|
1031 |
|
|
1'b0, // WP
|
1032 |
|
|
2'b10, // MS == 256MB
|
1033 |
|
|
2'b01, // BW == 16bit bus per device
|
1034 |
|
|
3'b000, // MEM_TYPE == SDRAM
|
1035 |
|
|
1'b1 // EN == chip select enabled
|
1036 |
|
|
};
|
1037 |
|
|
|
1038 |
|
|
tms_data = {
|
1039 |
|
|
4'h0, // reserved
|
1040 |
|
|
4'h8, // Trfc == 7 (+1)
|
1041 |
|
|
4'h4, // Trp == 2 (+1) ?????
|
1042 |
|
|
3'h3, // Trcd == 2 (+1)
|
1043 |
|
|
2'b11, // Twr == 2 (+1)
|
1044 |
|
|
5'h0, // reserved
|
1045 |
|
|
wbl[0], // write burst length
|
1046 |
|
|
2'b00, // OM == normal operation
|
1047 |
|
|
cl, // cas latency
|
1048 |
|
|
1'b0, // BT == sequential burst type
|
1049 |
|
|
bl
|
1050 |
|
|
};
|
1051 |
|
|
|
1052 |
|
|
// program chip select registers
|
1053 |
|
|
$display("\nProgramming SDRAM chip select register. KRO = %d, BAS = %d", kro, bas);
|
1054 |
|
|
wbm.wb_write(0, 0, 32'h6000_0028, csc_data); // program cs3 config register (CSC3)
|
1055 |
|
|
|
1056 |
|
|
$display("Programming SDRAM timing register. WBL = %d, CL = %d, BL = %d\n", wbl, cl, bl);
|
1057 |
|
|
wbm.wb_write(0, 0, 32'h6000_002c, tms_data); // program cs3 timing register (TMS3)
|
1058 |
|
|
|
1059 |
|
|
// check written data
|
1060 |
|
|
wbm.wb_cmp(0, 0, 32'h6000_0028, csc_data);
|
1061 |
|
|
wbm.wb_cmp(0, 0, 32'h6000_002c, tms_data);
|
1062 |
|
|
|
1063 |
|
|
cyc_delay = 0;
|
1064 |
|
|
stb_delay = 0;
|
1065 |
|
|
bsize = 2;
|
1066 |
|
|
wcnt = 0;
|
1067 |
|
|
for (cyc_delay = 0; cyc_delay <= MAX_CYC_DELAY; cyc_delay = cyc_delay +1)
|
1068 |
|
|
for (stb_delay = 0; stb_delay <= MAX_STB_DELAY; stb_delay = stb_delay +1)
|
1069 |
|
|
for (bsize = 0; bsize < MAX_BSIZE; bsize = bsize +1)
|
1070 |
|
|
begin
|
1071 |
|
|
|
1072 |
|
|
if (cyc_delay == 0)
|
1073 |
|
|
while ( ((bsize +1) % (1 << bl) != 0) && (bsize < (MAX_BSIZE -1)) )
|
1074 |
|
|
bsize = bsize +1;
|
1075 |
|
|
|
1076 |
|
|
$display("Block copy test-1-. CYC-delay = %d, STB-delay = %d, burst-size = %d", cyc_delay, stb_delay, bsize);
|
1077 |
|
|
|
1078 |
|
|
// fill sdrams
|
1079 |
|
|
my_dat = 0;
|
1080 |
|
|
for (n = 0; n < SDRAM_TST_RUN; n=n+1)
|
1081 |
|
|
begin
|
1082 |
|
|
my_adr = (n << 2);
|
1083 |
|
|
dest_adr = SDRAM_SRC + my_adr;
|
1084 |
|
|
my_dat = my_adr + my_dat + kro + bas + wbl + cl + bl + cyc_delay + stb_delay;
|
1085 |
|
|
|
1086 |
|
|
wbm.wb_write(cyc_delay, stb_delay, dest_adr, my_dat);
|
1087 |
|
|
end
|
1088 |
|
|
|
1089 |
|
|
// perform Read-Modify-Write cycle
|
1090 |
|
|
n = 0;
|
1091 |
|
|
while (n < SDRAM_TST_RUN)
|
1092 |
|
|
begin
|
1093 |
|
|
// read data from sdrams
|
1094 |
|
|
for (wcnt = 0; wcnt <= bsize; wcnt = wcnt +1)
|
1095 |
|
|
begin
|
1096 |
|
|
my_adr = (n + wcnt) << 2;
|
1097 |
|
|
src_adr = SDRAM_SRC + my_adr;
|
1098 |
|
|
|
1099 |
|
|
// read memory contents
|
1100 |
|
|
wbm.wb_read(cyc_delay, stb_delay, src_adr, my_dat);
|
1101 |
|
|
|
1102 |
|
|
// modify memory contents
|
1103 |
|
|
tmp[wcnt] = my_dat +1;
|
1104 |
|
|
end
|
1105 |
|
|
|
1106 |
|
|
// copy data into sdrams; new location
|
1107 |
|
|
for (wcnt = 0; wcnt <= bsize; wcnt = wcnt +1)
|
1108 |
|
|
begin
|
1109 |
|
|
my_adr = (n + wcnt) << 2;
|
1110 |
|
|
dest_adr = SDRAM_DST + my_adr;
|
1111 |
|
|
|
1112 |
|
|
// write contents back into memory
|
1113 |
|
|
wbm.wb_write(cyc_delay, stb_delay, dest_adr, tmp[wcnt]);
|
1114 |
|
|
end
|
1115 |
|
|
|
1116 |
|
|
n = n + bsize +1;
|
1117 |
|
|
end
|
1118 |
|
|
|
1119 |
|
|
// read sdrams
|
1120 |
|
|
my_dat = 0;
|
1121 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+1)
|
1122 |
|
|
begin
|
1123 |
|
|
my_adr = (n << 2);
|
1124 |
|
|
dest_adr = SDRAM_DST + my_adr;
|
1125 |
|
|
my_dat = my_adr + my_dat + kro + bas + wbl + cl + bl + cyc_delay + stb_delay;
|
1126 |
|
|
|
1127 |
|
|
wbm.wb_cmp(cyc_delay, stb_delay, dest_adr, my_dat +1);
|
1128 |
|
|
end
|
1129 |
|
|
end
|
1130 |
|
|
end
|
1131 |
|
|
|
1132 |
|
|
// show Wishbone-Master-model current-error-counter
|
1133 |
|
|
wbm.show_cur_err_cnt;
|
1134 |
|
|
|
1135 |
|
|
$display("\nSDRAM block copy test-1- ended");
|
1136 |
|
|
|
1137 |
|
|
end
|
1138 |
|
|
endtask // tst_sdram_blk_cpy1
|
1139 |
|
|
|
1140 |
|
|
|
1141 |
|
|
|
1142 |
|
|
//////////////////////////
|
1143 |
|
|
// SDRAM Block copy test2
|
1144 |
|
|
//
|
1145 |
|
|
|
1146 |
|
|
// 1) Copy a modified block of memory to the same memory location
|
1147 |
|
|
// 2) Run test for all possible CS settings for SDRAM
|
1148 |
|
|
task tst_sdram_blk_cpy2;
|
1149 |
|
|
|
1150 |
|
|
parameter MAX_CYC_DELAY = 5;
|
1151 |
|
|
parameter MAX_STB_DELAY = 5;
|
1152 |
|
|
|
1153 |
|
|
parameter [31:0] SDRAM1_STARTA = `SDRAM1_LOC;
|
1154 |
|
|
parameter [ 7:0] SDRAM1_SEL = SDRAM1_STARTA[28:21];
|
1155 |
|
|
|
1156 |
|
|
parameter SDRAM_TST_RUN = 64; // only do a few runs
|
1157 |
|
|
|
1158 |
|
|
parameter MAX_BSIZE = 8;
|
1159 |
|
|
|
1160 |
|
|
parameter SDRAM_SRC = SDRAM1_STARTA;
|
1161 |
|
|
|
1162 |
|
|
integer n, wcnt, bsize;
|
1163 |
|
|
reg [31:0] my_adr, src_adr, dest_adr;
|
1164 |
|
|
reg [31:0] my_dat;
|
1165 |
|
|
reg [31:0] tmp [MAX_BSIZE -1 :0];
|
1166 |
|
|
|
1167 |
|
|
// config register mode bits
|
1168 |
|
|
reg [1:0] kro, bas; // a single register doesn't work with the for-loops
|
1169 |
|
|
|
1170 |
|
|
// SDRAM Mode Register bits
|
1171 |
|
|
reg [1:0] wbl; // a single register doesn't work with the for-loops
|
1172 |
|
|
reg [2:0] cl, bl;
|
1173 |
|
|
|
1174 |
|
|
reg [31:0] csc_data, tms_data;
|
1175 |
|
|
|
1176 |
|
|
integer cyc_delay, stb_delay;
|
1177 |
|
|
|
1178 |
|
|
begin
|
1179 |
|
|
|
1180 |
|
|
$display("\n\n --- SDRAM block copy TEST-2- ---\n\n");
|
1181 |
|
|
|
1182 |
|
|
// clear Wishbone-Master-model current-error-counter
|
1183 |
|
|
wbm.set_cur_err_cnt(0);
|
1184 |
|
|
|
1185 |
|
|
kro = 0;
|
1186 |
|
|
bas = 0;
|
1187 |
|
|
|
1188 |
|
|
wbl = 0; // programmed burst length
|
1189 |
|
|
cl = 2; // cas latency = 2
|
1190 |
|
|
bl = 1; // burst length = 4
|
1191 |
|
|
|
1192 |
|
|
// variables for TMS register
|
1193 |
|
|
for (cl = 2; cl <= 3; cl = cl +1)
|
1194 |
|
|
for (wbl = 0; wbl <= 1; wbl = wbl +1)
|
1195 |
|
|
for (bl = 0; bl <= 3; bl = bl +1)
|
1196 |
|
|
|
1197 |
|
|
// variables for CSC register
|
1198 |
|
|
for (kro = 0; kro <= 1; kro = kro +1)
|
1199 |
|
|
for (bas = 0; bas <= 1; bas = bas +1)
|
1200 |
|
|
begin
|
1201 |
|
|
csc_data = {
|
1202 |
|
|
8'h00, // reserved
|
1203 |
|
|
SDRAM1_SEL, // SEL
|
1204 |
|
|
4'h0, // reserved
|
1205 |
|
|
1'b0, // parity disabled
|
1206 |
|
|
kro[0], // KRO
|
1207 |
|
|
bas[0], // BAS
|
1208 |
|
|
1'b0, // WP
|
1209 |
|
|
2'b10, // MS == 256MB
|
1210 |
|
|
2'b01, // BW == 16bit bus per device
|
1211 |
|
|
3'b000, // MEM_TYPE == SDRAM
|
1212 |
|
|
1'b1 // EN == chip select enabled
|
1213 |
|
|
};
|
1214 |
|
|
|
1215 |
|
|
tms_data = {
|
1216 |
|
|
4'h0, // reserved
|
1217 |
|
|
4'h8, // Trfc == 7 (+1)
|
1218 |
|
|
4'h4, // Trp == 2 (+1) ?????
|
1219 |
|
|
3'h3, // Trcd == 2 (+1)
|
1220 |
|
|
2'b11, // Twr == 2 (+1)
|
1221 |
|
|
5'h0, // reserved
|
1222 |
|
|
wbl[0], // write burst length
|
1223 |
|
|
2'b00, // OM == normal operation
|
1224 |
|
|
cl, // cas latency
|
1225 |
|
|
1'b0, // BT == sequential burst type
|
1226 |
|
|
bl
|
1227 |
|
|
};
|
1228 |
|
|
|
1229 |
|
|
// program chip select registers
|
1230 |
|
|
$display("\nProgramming SDRAM chip select register. KRO = %d, BAS = %d", kro, bas);
|
1231 |
|
|
wbm.wb_write(0, 0, 32'h6000_0028, csc_data); // program cs3 config register (CSC3)
|
1232 |
|
|
|
1233 |
|
|
$display("Programming SDRAM timing register. WBL = %d, CL = %d, BL = %d\n", wbl, cl, bl);
|
1234 |
|
|
wbm.wb_write(0, 0, 32'h6000_002c, tms_data); // program cs3 timing register (TMS3)
|
1235 |
|
|
|
1236 |
|
|
// check written data
|
1237 |
|
|
wbm.wb_cmp(0, 0, 32'h6000_0028, csc_data);
|
1238 |
|
|
wbm.wb_cmp(0, 0, 32'h6000_002c, tms_data);
|
1239 |
|
|
|
1240 |
|
|
cyc_delay = 0;
|
1241 |
|
|
stb_delay = 0;
|
1242 |
|
|
bsize = 2;
|
1243 |
|
|
wcnt = 0;
|
1244 |
|
|
for (cyc_delay = 0; cyc_delay <= MAX_CYC_DELAY; cyc_delay = cyc_delay +1)
|
1245 |
|
|
for (stb_delay = 0; stb_delay <= MAX_STB_DELAY; stb_delay = stb_delay +1)
|
1246 |
|
|
for (bsize = 0; bsize < MAX_BSIZE; bsize = bsize +1)
|
1247 |
|
|
begin
|
1248 |
|
|
|
1249 |
|
|
if (cyc_delay == 0)
|
1250 |
|
|
while ( ((bsize +1) % (1 << bl) != 0) && (bsize < (MAX_BSIZE -1)) )
|
1251 |
|
|
bsize = bsize +1;
|
1252 |
|
|
|
1253 |
|
|
$display("Block copy test-2-. CYC-delay = %d, STB-delay = %d, burst-size = %d", cyc_delay, stb_delay, bsize);
|
1254 |
|
|
|
1255 |
|
|
// fill sdrams
|
1256 |
|
|
my_dat = 0;
|
1257 |
|
|
for (n = 0; n < SDRAM_TST_RUN; n=n+1)
|
1258 |
|
|
begin
|
1259 |
|
|
my_adr = (n << 2);
|
1260 |
|
|
dest_adr = SDRAM_SRC + my_adr;
|
1261 |
|
|
my_dat = my_adr + my_dat + kro + bas + wbl + cl + bl + cyc_delay + stb_delay;
|
1262 |
|
|
|
1263 |
|
|
wbm.wb_write(cyc_delay, stb_delay, dest_adr, my_dat);
|
1264 |
|
|
end
|
1265 |
|
|
|
1266 |
|
|
// perform Read-Modify-Write cycle
|
1267 |
|
|
n = 0;
|
1268 |
|
|
while (n < SDRAM_TST_RUN)
|
1269 |
|
|
begin
|
1270 |
|
|
// read data from sdrams
|
1271 |
|
|
for (wcnt = 0; wcnt <= bsize; wcnt = wcnt +1)
|
1272 |
|
|
begin
|
1273 |
|
|
my_adr = (n + wcnt) << 2;
|
1274 |
|
|
src_adr = SDRAM_SRC + my_adr;
|
1275 |
|
|
|
1276 |
|
|
// read memory contents
|
1277 |
|
|
wbm.wb_read(cyc_delay, stb_delay, src_adr, my_dat);
|
1278 |
|
|
|
1279 |
|
|
// modify memory contents
|
1280 |
|
|
tmp[wcnt] = my_dat +1;
|
1281 |
|
|
end
|
1282 |
|
|
|
1283 |
|
|
// copy data into sdrams; new location
|
1284 |
|
|
for (wcnt = 0; wcnt <= bsize; wcnt = wcnt +1)
|
1285 |
|
|
begin
|
1286 |
|
|
my_adr = (n + wcnt) << 2;
|
1287 |
|
|
dest_adr = SDRAM_SRC + my_adr;
|
1288 |
|
|
|
1289 |
|
|
// write contents back into memory
|
1290 |
|
|
wbm.wb_write(cyc_delay, stb_delay, dest_adr, tmp[wcnt]);
|
1291 |
|
|
end
|
1292 |
|
|
|
1293 |
|
|
n = n + bsize +1;
|
1294 |
|
|
end
|
1295 |
|
|
|
1296 |
|
|
// read sdrams
|
1297 |
|
|
my_dat = 0;
|
1298 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+1)
|
1299 |
|
|
begin
|
1300 |
|
|
my_adr = (n << 2);
|
1301 |
|
|
dest_adr = SDRAM_SRC + my_adr;
|
1302 |
|
|
my_dat = my_adr + my_dat + kro + bas + wbl + cl + bl + cyc_delay + stb_delay;
|
1303 |
|
|
|
1304 |
|
|
wbm.wb_cmp(cyc_delay, stb_delay, dest_adr, my_dat +1);
|
1305 |
|
|
end
|
1306 |
|
|
end
|
1307 |
|
|
end
|
1308 |
|
|
|
1309 |
|
|
// show Wishbone-Master-model current-error-counter
|
1310 |
|
|
wbm.show_cur_err_cnt;
|
1311 |
|
|
|
1312 |
|
|
$display("\nSDRAM block copy test-2- ended");
|
1313 |
|
|
|
1314 |
|
|
end
|
1315 |
|
|
endtask // tst_sdram_blk_cpy
|
1316 |
|
|
|
1317 |
|
|
|
1318 |
|
|
/////////////////////////////
|
1319 |
|
|
// SDRAM byte access test
|
1320 |
|
|
//
|
1321 |
|
|
|
1322 |
|
|
// 1) Test byte/word writes (SDRAM DQM lines)
|
1323 |
|
|
// 2) Run for all CS settings for SDRAMS
|
1324 |
|
|
// 3) This test also checks the parity bits
|
1325 |
|
|
task tst_sdram_bytes;
|
1326 |
|
|
|
1327 |
|
|
parameter MAX_CYC_DELAY = 5;
|
1328 |
|
|
parameter MAX_STB_DELAY = 5;
|
1329 |
|
|
|
1330 |
|
|
parameter SDRAM_TST_STARTA = `SDRAM1_LOC; // start at address 0
|
1331 |
|
|
parameter [7:0] SDRAM1_SEL = SDRAM_TST_STARTA[28:21];
|
1332 |
|
|
parameter SDRAM_TST_RUN = 64; // only do a few runs
|
1333 |
|
|
|
1334 |
|
|
integer n;
|
1335 |
|
|
reg [31:0] my_adr, dest_adr;
|
1336 |
|
|
reg [31:0] my_dat;
|
1337 |
|
|
|
1338 |
|
|
// config register mode bits
|
1339 |
|
|
reg [1:0] kro, bas; // a single register doesn't work with the for-loops
|
1340 |
|
|
|
1341 |
|
|
// SDRAM Mode Register bits
|
1342 |
|
|
reg [1:0] wbl; // a single register doesn't work with the for-loops
|
1343 |
|
|
reg [2:0] cl, bl;
|
1344 |
|
|
|
1345 |
|
|
reg [31:0] csc_data, tms_data;
|
1346 |
|
|
|
1347 |
|
|
integer sel;
|
1348 |
|
|
integer cyc_delay, stb_delay;
|
1349 |
|
|
|
1350 |
|
|
begin
|
1351 |
|
|
|
1352 |
|
|
$display("\n\n --- SDRAM BYTE ACCESS TEST ---\n\n");
|
1353 |
|
|
|
1354 |
|
|
// clear Wishbone-Master-model current-error-counter
|
1355 |
|
|
wbm.set_cur_err_cnt(0);
|
1356 |
|
|
|
1357 |
|
|
// use second SDRAMS set as parity sdrams
|
1358 |
|
|
sel_pbus = 1;
|
1359 |
|
|
|
1360 |
|
|
// choose some default settings
|
1361 |
|
|
kro = 0;
|
1362 |
|
|
bas = 0;
|
1363 |
|
|
|
1364 |
|
|
wbl = 0; // programmed burst length
|
1365 |
|
|
cl = 2; // cas latency = 2
|
1366 |
|
|
bl = 2; // burst length = 4
|
1367 |
|
|
|
1368 |
|
|
// variables for TMS register
|
1369 |
|
|
for (cl = 2; cl <= 3; cl = cl +1)
|
1370 |
|
|
for (wbl = 0; wbl <= 1; wbl = wbl +1)
|
1371 |
|
|
for (bl = 0; bl <= 3; bl = bl +1)
|
1372 |
|
|
|
1373 |
|
|
// variables for CSC register
|
1374 |
|
|
for (kro = 0; kro <= 1; kro = kro +1)
|
1375 |
|
|
// for (bas = 0; bas <= 1; bas = bas +1) // ignore BAS for this test
|
1376 |
|
|
begin
|
1377 |
|
|
csc_data = {
|
1378 |
|
|
8'h00, // reserved
|
1379 |
|
|
SDRAM1_SEL, // SEL
|
1380 |
|
|
4'h0, // reserved
|
1381 |
|
|
1'b1, // parity enabled
|
1382 |
|
|
kro[0], // KRO
|
1383 |
|
|
bas[0], // BAS
|
1384 |
|
|
1'b0, // WP
|
1385 |
|
|
2'b10, // MS == 256MB
|
1386 |
|
|
2'b01, // BW == 16bit bus per device
|
1387 |
|
|
3'b000, // MEM_TYPE == SDRAM
|
1388 |
|
|
1'b1 // EN == chip select enabled
|
1389 |
|
|
};
|
1390 |
|
|
|
1391 |
|
|
tms_data = {
|
1392 |
|
|
4'h0, // reserved
|
1393 |
|
|
4'h8, // Trfc == 7 (+1)
|
1394 |
|
|
4'h4, // Trp == 2 (+1) ?????
|
1395 |
|
|
3'h3, // Trcd == 2 (+1)
|
1396 |
|
|
2'b11, // Twr == 2 (+1)
|
1397 |
|
|
5'h0, // reserved
|
1398 |
|
|
wbl[0], // write burst length
|
1399 |
|
|
2'b00, // OM == normal operation
|
1400 |
|
|
cl, // cas latency
|
1401 |
|
|
1'b0, // BT == sequential burst type
|
1402 |
|
|
bl
|
1403 |
|
|
};
|
1404 |
|
|
|
1405 |
|
|
// program chip select registers
|
1406 |
|
|
$display("\nProgramming SDRAM chip select register. KRO = %d, BAS = %d", kro, bas);
|
1407 |
|
|
wbm.wb_write(0, 0, 32'h6000_0028, csc_data); // program cs3 config register (CSC3)
|
1408 |
|
|
|
1409 |
|
|
$display("\nProgramming SDRAM timing register. WBL = %d, CL = %d, BL = %d\n", wbl, cl, bl);
|
1410 |
|
|
wbm.wb_write(0, 0, 32'h6000_002c, tms_data); // program cs3 timing register (TMS3)
|
1411 |
|
|
|
1412 |
|
|
// check written data
|
1413 |
|
|
wbm.wb_cmp(0, 0, 32'h6000_0028, csc_data);
|
1414 |
|
|
wbm.wb_cmp(0, 0, 32'h6000_002c, tms_data);
|
1415 |
|
|
|
1416 |
|
|
cyc_delay = 1;
|
1417 |
|
|
stb_delay = 0;
|
1418 |
|
|
for (cyc_delay = 1; cyc_delay <= MAX_CYC_DELAY; cyc_delay = cyc_delay +1)
|
1419 |
|
|
for (stb_delay = 0; stb_delay <= MAX_STB_DELAY; stb_delay = stb_delay +1)
|
1420 |
|
|
begin
|
1421 |
|
|
|
1422 |
|
|
$display("\nSDRAM byte test. CYC-delay = %d, STB-delay = ", cyc_delay, stb_delay);
|
1423 |
|
|
|
1424 |
|
|
// fill sdrams
|
1425 |
|
|
$display("Filling SDRAM memory...");
|
1426 |
|
|
my_adr = 0;
|
1427 |
|
|
my_dat = 0;
|
1428 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+1)
|
1429 |
|
|
begin
|
1430 |
|
|
my_adr = (n << 2);
|
1431 |
|
|
dest_adr = SDRAM_TST_STARTA + my_adr;
|
1432 |
|
|
my_dat = my_adr + kro + bas + wbl + cl + bl + cyc_delay + stb_delay;
|
1433 |
|
|
my_dat = {my_dat[7:0] +8'd3, my_dat[7:0] +8'd2, my_dat[7:0] +8'd1, my_dat[7:0]};
|
1434 |
|
|
|
1435 |
|
|
wbm.wb_write(cyc_delay, stb_delay, dest_adr, my_dat);
|
1436 |
|
|
end
|
1437 |
|
|
|
1438 |
|
|
// switch memory contents
|
1439 |
|
|
$display("Swapping bytes...");
|
1440 |
|
|
my_adr = 0;
|
1441 |
|
|
my_dat = 0;
|
1442 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+1)
|
1443 |
|
|
for (sel=0; sel < 16; sel=sel+1)
|
1444 |
|
|
begin
|
1445 |
|
|
my_adr = (n << 2);
|
1446 |
|
|
dest_adr = SDRAM_TST_STARTA + my_adr;
|
1447 |
|
|
wbm.wb_read(cyc_delay, stb_delay, dest_adr, my_dat);
|
1448 |
|
|
|
1449 |
|
|
my_dat = {my_dat[31:24] +8'd1, my_dat[23:16] +8'd1, my_dat[15:8] +8'd1, my_dat[7:0] +8'd1};
|
1450 |
|
|
wbm.wb_write_sel(cyc_delay, stb_delay, sel, dest_adr, my_dat);
|
1451 |
|
|
|
1452 |
|
|
end
|
1453 |
|
|
|
1454 |
|
|
// read sdrams
|
1455 |
|
|
$display("Verifying SDRAM memory contents...");
|
1456 |
|
|
my_dat = 0;
|
1457 |
|
|
for (n=0; n < SDRAM_TST_RUN; n=n+1)
|
1458 |
|
|
begin
|
1459 |
|
|
my_adr = (n << 2);
|
1460 |
|
|
dest_adr = SDRAM_TST_STARTA + my_adr;
|
1461 |
|
|
my_dat = my_adr + kro + bas + wbl + cl + bl + cyc_delay + stb_delay;
|
1462 |
|
|
|
1463 |
|
|
my_dat = {my_dat[7:0] +8'd3, my_dat[7:0] +8'd2, my_dat[7:0] +8'd1, my_dat[7:0]};
|
1464 |
|
|
my_dat = {my_dat[31:24] +8'd8, my_dat[23:16] +8'd8, my_dat[15:8] +8'd8, my_dat[7:0] +8'd8};
|
1465 |
|
|
|
1466 |
|
|
wbm.wb_cmp(cyc_delay, stb_delay, dest_adr, my_dat);
|
1467 |
|
|
end
|
1468 |
|
|
end
|
1469 |
|
|
end
|
1470 |
|
|
|
1471 |
|
|
// show Wishbone-Master-model current-error-counter
|
1472 |
|
|
wbm.show_cur_err_cnt;
|
1473 |
|
|
|
1474 |
|
|
end
|
1475 |
|
|
endtask //tst_sdram_bytes
|