1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
|
`timescale 1ns/1ns
module fifo_extram36_tb();
reg clk = 0;
reg sram_clk = 0;
reg rst = 1;
reg clear = 0;
reg Verbose = 0; //
integer ErrorCount = 0;
initial #1000 rst = 0;
// always #125 clk = ~clk;
task task_CLK;
reg [7:0] ran;
begin
while (1) begin
ran = $random;
if (ran[1])
#62 clk = ~clk;
else
#63 clk = !clk;
end
end
endtask // task_CLK
initial task_CLK;
// always #100 sram_clk = ~sram_clk;
task task_SSRAM_clk;
reg [7:0] ran;
begin
while (1) begin
ran = $random;
if (ran[0])
#49 sram_clk = ~sram_clk;
else
#51 sram_clk = ~sram_clk;
end
end
endtask // task_SSRAM_clk
initial task_SSRAM_clk;
reg [31:0] f36_data = 32'hX;
reg [1:0] f36_occ = 0;
reg f36_sof = 0, f36_eof = 0;
wire [35:0] f36_in = {1'b0,f36_occ,f36_eof,f36_sof,f36_data};
reg src_rdy_f36i = 0;
wire dst_rdy_f36i;
wire [35:0] f36_out;
wire src_rdy_f36o;
reg dst_rdy_f36o = 0;
wire [17:0] sram_d;
wire [18:0] sram_a;
wire [1:0] sram_bw;
wire sram_we, sram_adv, sram_ce, sram_oe, sram_mode, sram_zz;
reg [31:0] ScoreBoard [524288:0];
reg [18:0] put_index = 0;
reg [18:0] get_index = 0;
// integer put_index = 0;
// integer get_index = 0;
wire [15:0] DUT_space, DUT_occupied;
fifo_extram36 fifo_extram36
(.clk(clk), .reset(rst), .clear(clear),
.datain(f36_in), .src_rdy_i(src_rdy_f36i), .dst_rdy_o(dst_rdy_f36i), .space(DUT_space),
.dataout(f36_out), .src_rdy_o(src_rdy_f36o), .dst_rdy_i(dst_rdy_f36o), .occupied(DUT_occupied),
.sram_clk(sram_clk), .sram_a(sram_a), .sram_d(sram_d), .sram_we(sram_we),
.sram_bw(sram_bw), .sram_adv(sram_adv), .sram_ce(sram_ce), .sram_oe(sram_oe),
.sram_mode(sram_mode), .sram_zz(sram_zz));
`define idt 1
`ifdef idt
wire [15:0] dummy16;
wire [1:0] dummy2;
idt71v65603s150
ram_model(.A(sram_a[17:0]),
.adv_ld_(sram_adv), // advance (high) / load (low)
.bw1_(0), .bw2_(0), .bw3_(0), .bw4_(0), // byte write enables (low)
.ce1_(0), .ce2(1), .ce2_(0), // chip enables
.cen_(sram_ce), // clock enable (low)
.clk(sram_clk), // clock
.IO({dummy16,sram_d[15:0]}),
.IOP({dummy2,sram_d[17:16]}), // data bus
.lbo_(sram_mode), // linear burst order (low)
.oe_(sram_oe), // output enable (low)
.r_w_(sram_we)); // read (high) / write (low)
`else
cy1356 ram_model(.d(sram_d),.clk(~sram_clk),.a(sram_a),
.bws(2'b00),.we_b(sram_we),.adv_lb(sram_adv),
.ce1b(0),.ce2(1),.ce3b(0),
.oeb(sram_oe),.cenb(sram_ce),.mode(sram_mode) );
`endif
task task_SSRAMMonitor;
reg last_mode;
reg last_clock;
reg last_load;
reg [18:0] sram_addr;
begin
last_mode = 1'bX;
last_clock = 1'bX;
last_load = 1'bX;
@ (posedge Verbose);
$dumpvars(0,fifo_extram36_tb);
$display("%t:%m\t*** Task Started",$time);
while (1) @ (posedge sram_clk) begin
if (sram_mode !== last_mode) begin
$display("%t:%m\tSSRAM mode: %b",$time,sram_mode);
last_mode = sram_mode;
end
if (sram_adv !== last_load) begin
$display("%t:%m\tSSRAM adv/load: %b",$time,sram_adv);
last_load = sram_adv;
end
if (sram_ce !== last_clock) begin
$display("%t:%m\tSSRAM clock enable: %b",$time,sram_ce);
last_clock = sram_ce;
end
if (sram_ce == 1'b0) begin
if (sram_adv == 1'b0) begin
// $display("%t:%m\tSSRAM Address Load A=%h",$time,sram_a);
sram_addr = sram_a;
end else begin
sram_addr = sram_addr + 1;
end
if (sram_oe == 1'b0) begin
$display("%t:%m\tSSRAM Read Cycle A=%h(%h), D=%o",$time,sram_addr-2,sram_a,sram_d);
end
if (sram_we == 1'b0) begin
$display("%t:%m\tSSRAM Write Cycle A=%h(%h), D=%o",$time,sram_addr-2,sram_a,sram_d);
end
if ((sram_we == 1'b0) && (sram_oe == 1'b0)) begin
$display("%t:%m\t*** ERROR: _oe and _we both active",$time);
end
end // if (sram_ce == 1'b0)
end // always @ (posedge sram_clk)
end
endtask // task_SSRAMMonitor
task ReadFromFIFO36;
begin
$display("%t: Read from FIFO36",$time);
#1 dst_rdy_f36o <= 1;
while(1)
begin
while(~src_rdy_f36o)
@(posedge clk);
$display("%t: Read: %h>",$time,f36_out);
@(posedge clk);
end
end
endtask // ReadFromFIFO36
initial dst_rdy_f36o = 0;
task task_ReadFIFO36;
reg [7:0] ran;
begin
$display("%t:%m\t*** Task Started",$time);
while (1) begin
// Read on one of four clocks
#5 dst_rdy_f36o <= 1;
@(posedge clk);
if (src_rdy_f36o) begin
if (f36_out[31:0] != ScoreBoard[get_index]) begin
$display("%t:%m\tFIFO Get Error: R:%h, E:%h (%h)",$time,f36_out[31:0],ScoreBoard[get_index],get_index);
ErrorCount = ErrorCount + 1;
end else begin
if (Verbose)
$display("%t:%m\t(%5h) %o>",$time,get_index,f36_out);
end
get_index = get_index+1;
end else begin
if (ErrorCount >= 192)
$finish;
end // else: !if(src_rdy_f36o)
#10;
ran = $random;
if (ran[2:0] != 3'b000) begin
dst_rdy_f36o <= 0;
if (ran[2] != 1'b0) begin
@(posedge clk);
@(posedge clk);
@(posedge clk);
end
if (ran[1] != 1'b0) begin
@(posedge clk);
@(posedge clk);
end
if (ran[0] != 1'b0) begin
@(posedge clk);
end
end
end // while (1)
end
endtask // task_ReadFIFO36
reg [15:0] count;
task PutPacketInFIFO36;
input [31:0] data_start;
input [31:0] data_len;
begin
count = 4;
src_rdy_f36i = 1;
f36_data = data_start;
f36_sof = 1;
f36_eof = 0;
f36_occ = 0;
$display("%t: Put Packet in FIFO36",$time);
while(~dst_rdy_f36i)
#1; //@(posedge clk);
@(posedge clk);
$display("%t: <%h PPI_FIFO36: Entered First Line",$time,f36_data);
f36_sof <= 0;
while(count+4 < data_len)
begin
f36_data = f36_data + 32'h01010101;
count = count + 4;
while(~dst_rdy_f36i)
#1; //@(posedge clk);
@(posedge clk);
$display("%t: <%h PPI_FIFO36: Entered New Line",$time,f36_data);
end
f36_data <= f36_data + 32'h01010101;
f36_eof <= 1;
if(count + 4 == data_len)
f36_occ <= 0;
else if(count + 3 == data_len)
f36_occ <= 3;
else if(count + 2 == data_len)
f36_occ <= 2;
else
f36_occ <= 1;
while(~dst_rdy_f36i)
@(posedge clk);
@(posedge clk);
f36_occ <= 0;
f36_eof <= 0;
f36_data <= 0;
src_rdy_f36i <= 0;
$display("%t: <%h PPI_FIFO36: Entered Last Line",$time,f36_data);
end
endtask // PutPacketInFIFO36
task task_WriteFIFO36;
integer i;
reg [7:0] ran;
begin
f36_data = 32'bX;
if (rst != 1'b0)
@ (negedge rst);
$display("%t:%m\t*** Task Started",$time);
#10;
src_rdy_f36i = 1;
f36_data = $random;
for (i=0; i<64; i=i+0 ) begin
@ (posedge clk) ;
if (dst_rdy_f36i) begin
if (Verbose)
$display("%t:%m\t(%5h) %o<",$time,put_index,f36_in);
ScoreBoard[put_index] = f36_in[31:0];
put_index = put_index + 1;
#5;
f36_data = $random;
i = i + 1;
end
ran = $random;
if (ran[1:0] != 2'b00) begin
@ (negedge clk);
src_rdy_f36i = 0;
#5;
@ (negedge clk) ;
src_rdy_f36i = 1;
end
end
src_rdy_f36i = 0;
f36_data = 32'bX;
// if (put_index > 19'h3ff00)
// Verbose = 1'b1;
end
endtask // task_WriteFIFO36
initial $dumpfile("fifo_extram36_tb.vcd");
// initial $dumpvars(0,fifo_extram36_tb);
initial $timeformat(-9, 0, " ns", 10);
initial task_SSRAMMonitor;
initial
begin
@(negedge rst);
#40000;
@(posedge clk);
@(posedge clk);
@(posedge clk);
@(posedge clk);
// ReadFromFIFO36;
task_ReadFIFO36;
end
integer i;
initial
begin
@(negedge rst);
@(posedge clk);
@(posedge clk);
@(posedge clk);
task_WriteFIFO36;
@(posedge clk);
@(posedge clk);
@(posedge clk);
// PutPacketInFIFO36(32'hA0B0C0D0,12);
@(posedge clk);
@(posedge clk);
#10000;
@(posedge clk);
// PutPacketInFIFO36(32'hE0F0A0B0,36);
@(posedge clk);
@(posedge clk);
task_WriteFIFO36;
@(posedge clk);
@(posedge clk);
#10000;
@(posedge clk);
@(posedge clk);
task_WriteFIFO36;
// @(posedge clk);
// #30000;
// @(posedge clk);
// @(posedge clk);
task_WriteFIFO36;
// @(posedge clk);
// #30000;
// @(posedge clk);
// @(posedge clk);
task_WriteFIFO36;
// @(posedge clk);
// #30000;
// @(posedge clk);
// @(posedge clk);
task_WriteFIFO36;
@(posedge clk);
#10000;
@(posedge clk);
@(posedge clk);
task_WriteFIFO36;
for (i=0; i<8192; i = i+1) begin
@(posedge clk);
#10000;
@(posedge clk);
@(posedge clk);
task_WriteFIFO36;
@(posedge clk);
end
// $dumpvars(0,fifo_extram36_tb);
@(posedge clk);
task_WriteFIFO36;
@(posedge clk);
#100000000;
$finish;
end
initial
begin
@(negedge rst);
f36_occ <= 0;
repeat (100)
@(posedge clk);
src_rdy_f36i <= 1;
f36_data <= 32'h10203040;
f36_sof <= 1;
f36_eof <= 0;
@(posedge clk);
@(posedge clk);
src_rdy_f36i <= 1;
f36_data <= f36_data + 32'h01010101;
f36_sof <= 0;
f36_eof <= 0;
@(posedge clk);
@(posedge clk);
src_rdy_f36i <= 1;
f36_data <= f36_data + 32'h01010101;
f36_sof <= 0;
f36_eof <= 0;
@(posedge clk);
@(posedge clk);
src_rdy_f36i <= 1;
f36_data <= f36_data + 32'h01010101;
f36_sof <= 0;
f36_eof <= 0;
@(posedge clk);
@(posedge clk);
src_rdy_f36i <= 1;
f36_data <= f36_data + 32'h01010101;
f36_sof <= 0;
f36_eof <= 0;
@(posedge clk);
@(posedge clk);
src_rdy_f36i <= 1;
f36_data <= f36_data + 32'h01010101;
f36_sof <= 0;
f36_eof <= 0;
@(posedge clk);
@(posedge clk);
src_rdy_f36i <= 1;
f36_data <= f36_data + 32'h01010101;
f36_sof <= 0;
f36_eof <= 0;
@(posedge clk);
@(posedge clk);
src_rdy_f36i <= 1;
f36_data <= f36_data + 32'h01010101;
f36_sof <= 0;
f36_eof <= 0;
@(posedge clk);
@(posedge clk);
src_rdy_f36i <= 1;
f36_data <= f36_data + 32'h01010101;
f36_sof <= 0;
f36_eof <= 0;
@(posedge clk);
@(posedge clk);
src_rdy_f36i <= 1;
f36_data <= f36_data + 32'h01010101;
f36_sof <= 0;
f36_eof <= 0;
@(posedge clk);
@(posedge clk);
src_rdy_f36i <= 1;
f36_data <= f36_data + 32'h01010101;
f36_sof <= 0;
f36_eof <= 0;
@(posedge clk);
@(posedge clk);
src_rdy_f36i <= 1;
f36_data <= 32'h1F2F3F4F;
f36_sof <= 0;
f36_eof <= 1;
@(posedge clk);
@(posedge clk);
src_rdy_f36i <= 0;
end
// initial #500000 $finish;
endmodule // fifo_extram_tb
|