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

Subversion Repositories dmt_tx

[/] [dmt_tx/] [trunk/] [const_encoder/] [tb/] [tb_fifo.v] - Blame information for rev 32

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

Line No. Rev Author Line
1 13 dannori
/* *****************************************************************
2
 *
3 15 dannori
 *  This file is part of the
4
 *
5
 *   Tone Order and Constellation Encoder Core.
6
 *
7 13 dannori
 *  Copyright (C) 2007 Guenter Dannoritzer
8
 *
9
 *   This source is free software; you can redistribute it
10
 *   and/or modify it under the terms of the
11
 *             GNU General Public License
12
 *   as published by the Free Software Foundation;
13
 *   either version 3 of the License,
14
 *   or (at your option) any later version.
15
 *
16
 *   This source is distributed in the hope
17
 *   that it will be useful, but WITHOUT ANY WARRANTY;
18
 *   without even the implied warranty of MERCHANTABILITY
19
 *   or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 *   GNU General Public License for more details.
21
 *
22
 *   You should have received a copy of the
23 15 dannori
 *   GNU General Public License along with this source.
24 13 dannori
 *   If not, see <http://www.gnu.org/licenses/>.
25
 *
26
 * *****************************************************************/
27 12 dannori
module tb_fifo;
28
 
29
parameter AWIDTH = 2;
30
parameter DWIDTH = 8;
31
parameter TW=10;
32
 
33
 
34
 
35
//
36
// to interface the dut
37
// 
38
reg                 clk;
39
reg                 reset;
40
reg   [DWIDTH-1:0]  data_i;
41
reg                 re_i;
42
wire                empty_o;
43
wire                full_o;
44
wire                one_available_o;
45
wire                two_available_o;
46
reg                 we_i;
47
reg   [DWIDTH-1:0]  data_i;
48
reg                 re_i;
49
wire  [DWIDTH-1:0]  data_o;
50
 
51
 
52
 
53
//
54
// instantiate the DUT
55
//
56
fifo #(.AWIDTH(AWIDTH), .DWIDTH(DWIDTH))
57
 
58
      dut ( .clk(clk),
59
            .reset(reset),
60
            .empty_o(empty_o),
61
            .full_o(full_o),
62
            .one_available_o(one_available_o),
63
            .two_available_o(two_available_o),
64
            .we_i(we_i),
65
            .data_i(data_i),
66
            .re_i(re_i),
67
            .data_o(data_o));
68
 
69
 
70
//
71
// local reg/wires
72
//
73
reg [DWIDTH-1:0] got_data;
74
 
75
//
76
// main tests
77
// 
78
 
79
initial begin
80
  clk = 0;
81
  we_i = 0;
82
  re_i = 0;
83
  reset = 0;
84
end
85
 
86
always begin
87
  #TW clk = ~clk;
88
end
89
 
90
//
91
// dump signals
92
//
93
initial begin
94
  $dumpfile("tb_fifo.vcd");
95
  $dumpvars;
96
end
97
 
98
 
99
initial begin
100 15 dannori
  $display("=== Verifing FIFO ===");
101 12 dannori
 
102 15 dannori
  $display("- reset test");
103 12 dannori
  test_reset;
104
  check_control(5'b0001);
105
 
106 15 dannori
  $display("- verify write followed by read");
107 12 dannori
  write_data(8'haa);
108
  check_control(5'b0100);
109
 
110
  read_data(got_data);
111
  check_result(got_data, 8'haa);
112
  check_control(5'b0001);
113
 
114
  // fifo is empty again
115
 
116
  // fill it and only expect after the 4th write a full signal
117
 
118 15 dannori
  $display("- fill FIFO up");
119 12 dannori
  // #1
120
  write_data(8'h70);
121
  check_control(5'b0100);
122
  // #2
123
  write_data(8'h71);
124
  check_control(5'b1100);
125
  // #3
126
  write_data(8'h72);
127
  check_control(5'b1100);
128
  // #4
129
  write_data(8'h73);
130
  check_control(5'b1110);
131 15 dannori
 
132
  $display("- FIFO is full, another write should not have an affect");
133 12 dannori
  write_data(8'hab);
134
  check_control(5'b1110);
135
 
136 15 dannori
  $display("- verify reading the data from the full FIFO back");
137 12 dannori
  // #1  
138
  read_data(got_data);
139
  check_result(got_data, 8'h70);
140
  check_control(5'b1100);
141
  // #2  
142
  read_data(got_data);
143
  check_result(got_data, 8'h71);
144
  check_control(5'b1100);
145
  // #3  
146
  read_data(got_data);
147
  check_result(got_data, 8'h72);
148
  check_control(5'b0100);
149
  // #4  
150
  read_data(got_data);
151
  check_result(got_data, 8'h73);
152
  check_control(5'b0001);
153
 
154 15 dannori
 
155
  $display("= Now test a read/write at the same clock =");
156 12 dannori
 
157 15 dannori
 
158
  $display("- First have an empty FIFO and do the read/write");
159
  // read should fail but write should succeed
160
  fork
161
    read_data(got_data);
162
    write_data(8'h80);
163
  join
164
  check_control(5'b0100);
165
  read_data(got_data);
166
  check_result(got_data, 8'h80);
167
 
168
 
169 13 dannori
  //
170 15 dannori
  $display("- Now have one entry in the FIFO and do a read/write");
171
  // read should bring the first value back and the written value
172
  // should stay
173
  write_data(8'h90);
174
  fork
175
    read_data(got_data);
176
    write_data(8'hA0);
177
  join
178
  check_control(5'b0100);
179
  check_result(got_data, 8'h90);
180 13 dannori
 
181 15 dannori
  read_data(got_data);
182
  check_result(got_data, 8'hA0);
183
  check_control(5'b0001);
184 13 dannori
 
185 15 dannori
 
186
 
187
  $display("- Finally fill up the FIFO and to the read/write");
188
  // #1
189
  write_data(8'h10);
190
  check_control(5'b0100);
191
  // #2
192
  write_data(8'h11);
193
  check_control(5'b1100);
194
  // #3
195
  write_data(8'h12);
196
  check_control(5'b1100);
197
  // #4
198
  write_data(8'h13);
199
  check_control(5'b1110);
200 13 dannori
 
201 15 dannori
  // doing the read/write, as the FIFO is full the written value should
202
  // not end up in the FIFO
203
  fork
204
    read_data(got_data);
205
    write_data(8'h20);
206
  join
207
 
208
  check_control(5'b1100);
209
  check_result(got_data, 8'h10);
210
 
211
  // doing a read/write with one empty spot, the read should return the
212
  // last but one value and the write should end up in the FIFO
213
  fork
214
    read_data(got_data);
215
    write_data(8'h21);
216
  join
217
 
218
  check_control(5'b1100);
219
  check_result(got_data, 8'h11);
220
 
221
 
222
  // so reading back the values, should return the 3 remaining values
223
  // #1  
224
  read_data(got_data);
225
  check_result(got_data, 8'h12);
226
  check_control(5'b1100);
227
  // #2  
228
  read_data(got_data);
229
  check_result(got_data, 8'h13);
230
  check_control(5'b0100);
231
  // #3  
232
  read_data(got_data);
233
  check_result(got_data, 8'h21);
234
  check_control(5'b0001);
235
 
236
  $display("FIFO verification done!");
237
 
238 12 dannori
  $finish();
239
 
240
end
241
 
242
 
243
 
244
 
245 16 dannori
// //////////////////////////////////////////////////////////////////// 
246
// 
247 12 dannori
// bus functional models
248 16 dannori
// 
249
// //////////////////////////////////////////////////////////////////// 
250
 
251 12 dannori
task test_reset;
252
  begin
253 15 dannori
  //$display("Testing reset");
254 12 dannori
  reset = 0;
255
  #10 reset = 1;
256
  #20 reset = 0;
257
 
258
end
259
endtask
260
 
261
 
262
// =====================================================================
263
// check the expected control line status
264
//
265
// exp_ctrl[4:0] == {two_available, one_available, full, empty}
266
//
267
task check_control(input [4:0]exp_ctrl);
268
  begin
269
 
270 15 dannori
    //$display("# %d expCtrl: %d", $time, exp_ctrl);
271 12 dannori
 
272
  if(empty_o !== exp_ctrl[0])
273
    $display("ERROR! => Expected empty_o == %d, got %d", exp_ctrl[0], empty_o);
274
 
275
  if(full_o !== exp_ctrl[1])
276
    $display("ERROR! => Expected full_o == %d, got %d", exp_ctrl[1], full_o);
277
 
278
  if(one_available_o !== exp_ctrl[2])
279
    $display("ERROR! => Expected one_available_o == %d, got %d", exp_ctrl[3], one_available_o);
280
 
281
  if(two_available_o !== exp_ctrl[3])
282
    $display("ERROR! => Expected two_available_o == %d, got %d", exp_ctrl[4], two_available_o);
283
 
284
  end
285
endtask
286
 
287
 
288
// =====================================================================
289
//
290
// write data to the fifo
291
// 
292
task write_data(input [DWIDTH-1:0]data);
293
  begin
294 15 dannori
    //$display("# %d Writing data", $time);
295 12 dannori
    @(negedge clk);
296
    data_i = data;
297
    we_i = 1;
298
    @(negedge clk);
299
    we_i = 0;
300
 
301
  end
302
endtask
303
 
304
// =====================================================================
305
//
306
// read data from the fifo
307
// 
308
// 
309
task read_data(output [DWIDTH-1:0]data);
310
  begin
311
 
312 15 dannori
    //$display("# %d Reading data", $time);
313 12 dannori
    @(negedge clk);
314
    re_i = 1;
315
    @(negedge clk);
316
    data = data_o;
317
    re_i = 0;
318
 
319
  end
320
endtask
321
 
322
 
323
// =====================================================================
324
//
325
// check result
326
// 
327
// 
328
task check_result(input [DWIDTH-1:0]got, input [DWIDTH-1:0]expected);
329
  begin
330
    if(got !== expected)
331
      $display("ERROR! => Result does not match! Got: %d (%x) expected: %d (%x)", got, got, expected, expected);
332
  end
333
endtask
334
 
335
endmodule
336
 

powered by: WebSVN 2.1.0

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