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

Subversion Repositories srdydrdy_lib

[/] [srdydrdy_lib/] [trunk/] [env/] [verilog/] [fifo_b/] [bench_fifo_b.v] - Blame information for rev 29

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

Line No. Rev Author Line
1 6 ghutchis
`timescale 1ns/1ns
2
 
3
module bench_fifo_b;
4
 
5
  reg clk, reset;
6
 
7 22 ghutchis
  localparam width = 16, depth=32, asz=$clog2(depth), usz=$clog2(depth+1);
8 6 ghutchis
 
9
  initial clk = 0;
10
  always #10 clk = ~clk;
11
 
12 14 ghutchis
  reg gen_commit, gen_abort;
13
  reg chk_commit, chk_abort;
14 22 ghutchis
  reg fail;
15 6 ghutchis
  /*AUTOWIRE*/
16
  // Beginning of automatic wires (for undeclared instantiated-module outputs)
17 22 ghutchis
  wire [width-1:0]      chk_data;               // From fifo_s of sd_fifo_b.v
18
  wire                  chk_drdy;               // From chk of sd_seq_check.v
19
  wire                  chk_srdy;               // From fifo_s of sd_fifo_b.v
20
  wire [usz-1:0]        chk_usage;              // From fifo_s of sd_fifo_b.v
21
  wire [width-1:0]      gen_data;               // From gen of sd_seq_gen.v
22
  wire                  gen_drdy;               // From fifo_s of sd_fifo_b.v
23
  wire                  gen_srdy;               // From gen of sd_seq_gen.v
24
  wire [usz-1:0]        gen_usage;              // From fifo_s of sd_fifo_b.v
25 6 ghutchis
  // End of automatics
26
 
27
/* sd_seq_gen AUTO_TEMPLATE
28
 (
29
 .p_\(.*\)   (gen_\1[]),
30
 );
31
 */
32 14 ghutchis
  sd_seq_gen #(width) gen
33 6 ghutchis
    (/*AUTOINST*/
34
     // Outputs
35 22 ghutchis
     .p_srdy                            (gen_srdy),              // Templated
36
     .p_data                            (gen_data[width-1:0]),   // Templated
37 6 ghutchis
     // Inputs
38 22 ghutchis
     .clk                               (clk),
39
     .reset                             (reset),
40
     .p_drdy                            (gen_drdy));              // Templated
41 6 ghutchis
 
42
/* sd_seq_check AUTO_TEMPLATE
43
 (
44
 .c_\(.*\)   (chk_\1[]),
45
 );
46
 */
47 14 ghutchis
  sd_seq_check #(width) chk
48 6 ghutchis
    (/*AUTOINST*/
49
     // Outputs
50 22 ghutchis
     .c_drdy                            (chk_drdy),              // Templated
51 6 ghutchis
     // Inputs
52 22 ghutchis
     .clk                               (clk),
53
     .reset                             (reset),
54
     .c_srdy                            (chk_srdy),              // Templated
55
     .c_data                            (chk_data[width-1:0]));   // Templated
56 6 ghutchis
 
57
/* sd_fifo_b AUTO_TEMPLATE
58
 (
59
     .p_\(.*\)   (chk_\1[]),
60
     .c_\(.*\)   (gen_\1[]),
61
 );
62
 */
63 22 ghutchis
  sd_fifo_b #(width, depth, 1, 1) fifo_b
64 6 ghutchis
    (/*AUTOINST*/
65
     // Outputs
66 22 ghutchis
     .c_drdy                            (gen_drdy),              // Templated
67
     .p_srdy                            (chk_srdy),              // Templated
68
     .p_data                            (chk_data[width-1:0]),   // Templated
69
     .p_usage                           (chk_usage[usz-1:0]),    // Templated
70
     .c_usage                           (gen_usage[usz-1:0]),    // Templated
71 6 ghutchis
     // Inputs
72 22 ghutchis
     .clk                               (clk),
73
     .reset                             (reset),
74
     .c_srdy                            (gen_srdy),              // Templated
75
     .c_commit                          (gen_commit),            // Templated
76
     .c_abort                           (gen_abort),             // Templated
77
     .c_data                            (gen_data[width-1:0]),   // Templated
78
     .p_drdy                            (chk_drdy),              // Templated
79
     .p_commit                          (chk_commit),            // Templated
80
     .p_abort                           (chk_abort));             // Templated
81 6 ghutchis
 
82
  initial
83
    begin
84 22 ghutchis
`ifdef VCS
85
      $vcdpluson;
86
`else
87
      $dumpfile("fifo_b.lxt");
88 6 ghutchis
      $dumpvars;
89 22 ghutchis
`endif
90 6 ghutchis
      reset = 1;
91 14 ghutchis
      gen.rep_count = 0;
92
      gen_commit = 0;
93
      gen_abort  = 0;
94
      chk_commit = 1;
95
      chk_abort  = 0;
96 22 ghutchis
      fail = 0;
97 6 ghutchis
      #100;
98
      reset = 0;
99 14 ghutchis
      repeat (5) @(posedge clk);
100 6 ghutchis
 
101 22 ghutchis
      do_reset();
102
      test1();
103
 
104
      do_reset();
105
      test2();
106
 
107
      do_reset();
108 14 ghutchis
      test3();
109 22 ghutchis
 
110
      if (fail)
111
        $display ("!!!!! TEST FAILED !!!!!");
112
      else
113
        $display ("----- TEST PASSED -----");
114
      $finish;
115 14 ghutchis
    end // initial begin
116
 
117 22 ghutchis
  task do_reset;
118
    begin
119
      gen.rep_count = 0;
120
      gen_commit = 0;
121
      gen_abort  = 0;
122
      chk_commit = 1;
123
      chk_abort  = 0;
124
      reset = 1;
125
      repeat (5) @(posedge clk);
126
      reset = 0;
127
 
128
      repeat (10) @(posedge clk);
129
    end
130
  endtask // do_reset
131
 
132
  task end_check;
133
    begin
134
      if (chk.err_cnt > 0)
135
        fail = 1;
136
    end
137
  endtask
138
 
139
 
140 14 ghutchis
  // test basic overflow/underflow
141
  task test1;
142
    begin
143 22 ghutchis
      $display ("Running test 1");
144 14 ghutchis
      gen_commit = 1;
145 22 ghutchis
      //gen.rep_count = 2000;
146 14 ghutchis
 
147 22 ghutchis
      fork
148
        begin : traffic_gen
149
          gen.send (depth * 2);
150 6 ghutchis
 
151 22 ghutchis
          repeat (5) @(posedge clk);
152
          gen.srdy_pat = 8'h5A;
153
          gen.send (depth * 2);
154
 
155
          repeat (5) @(posedge clk);
156
          chk.drdy_pat = 8'hA5;
157
          gen.send (depth * 2);
158
 
159
          // check FIFO overflow
160
          repeat (5) @(posedge clk);
161
          gen.srdy_pat = 8'hFD;
162
          gen.send (depth * 4);
163 6 ghutchis
 
164 22 ghutchis
          // check FIFO underflow
165
          repeat (5) @(posedge clk);
166
          gen.srdy_pat = 8'h11;
167
          gen.send (depth * 4);
168 6 ghutchis
 
169 22 ghutchis
          repeat (20) @(posedge clk);
170
          disable t1_timeout;
171
        end // block: traffic_gen
172 6 ghutchis
 
173 22 ghutchis
        begin : t1_timeout
174
          repeat (50 * depth)
175
            @(posedge clk);
176
 
177
          fail = 1;
178
          disable traffic_gen;
179
          $display ("%t: ERROR: test1 timeout", $time);
180
        end
181
      join
182 6 ghutchis
 
183 22 ghutchis
      #500;
184
      end_check();
185 6 ghutchis
    end
186 14 ghutchis
  endtask // test1
187 6 ghutchis
 
188 14 ghutchis
  // test of write commit/abort behavior
189
  task test2;
190
    begin
191 22 ghutchis
      $display ("Running test 2");
192 14 ghutchis
      // first fill up entire FIFO
193 22 ghutchis
      //chk.drdy_pat = 0;
194
      gen_commit = 0;
195 14 ghutchis
      gen.send (depth-1);
196
      #50;
197
 
198
      wait (gen_drdy == 0);
199
      @(posedge clk);
200
      gen_abort <= #1 1;
201
 
202
      @(posedge clk);
203
      gen_abort <= #1 0;
204
      #5;
205
      if (gen_drdy !== 1)
206
        begin
207 22 ghutchis
          $display ("%t: ERROR -- drdy should be asserted on empty FIFO", $time);
208
          fail = 1;
209 14 ghutchis
          #100 $finish;
210
        end
211
 
212
 
213
      gen.send (depth-2);
214
      @(posedge clk);
215
      gen_commit <= 1;
216
      gen.send (1);
217
      gen_commit <= 0;
218
 
219
      repeat (depth+10)
220
        @(posedge clk);
221
 
222
      if (chk.last_seq != (depth*2-2))
223
        begin
224 22 ghutchis
          $display ("%t: ERROR -- last sequence number incorrect (%x)", $time, chk.last_seq);
225
          fail = 1;
226 14 ghutchis
          $finish;
227
        end
228
 
229
 
230
      #5000;
231 22 ghutchis
      end_check();
232 14 ghutchis
    end
233
  endtask // test2
234
 
235
  // test read/commit behavior
236
  task test3;
237
    begin
238 22 ghutchis
      $display ("Running test 3");
239 14 ghutchis
      // fill up FIFO
240
      gen_commit <= 1;
241
      chk_commit <= 0;
242
      chk_abort  <= 0;
243
 
244
      @(negedge clk);
245
      chk.drdy_pat = 0;
246
      chk.c_drdy = 0;
247
      chk.nxt_c_drdy = 0;
248
 
249
      repeat (10) @(posedge clk);
250
      gen.send (depth-1);
251
 
252
      // read out contents of FIFO
253
      chk.drdy_pat = 8'h5A;
254
 
255
      repeat (depth*2+2)
256
        @(posedge clk);
257
      chk.drdy_pat = 0;
258
 
259
      // FIFO should be full at this point to write side, and empty to
260
      // read side
261
      if (gen_drdy || chk_srdy)
262
        begin
263
          $display ("ERROR -- c_drdy or p_srdy asserted");
264 22 ghutchis
          fail = 1;
265 14 ghutchis
          #100 $finish;
266
        end
267
 
268
      // reset the read pointer and the expected value
269
      chk.last_seq = 0;
270
      chk_abort <= #1 1;
271
      @(posedge clk);
272
      chk_abort <= #1 0;
273
 
274
      // read out contents of FIFO again
275
      chk.drdy_pat = 8'hFF;
276
 
277
      @(posedge clk);
278
      repeat (depth-3) @(posedge clk);
279
      chk_commit <= #1 1;
280
      repeat (4) @(posedge clk);
281
      chk_commit <= #1 0;
282
 
283
      // All data has been committed, so drdy should be asserted
284 22 ghutchis
      if (gen_drdy !== 1)
285 14 ghutchis
        begin
286 22 ghutchis
          $display ("%t: ERROR -- c_drdy not asserted", $time);
287
          fail = 1;
288 14 ghutchis
          #100 $finish;
289
        end
290
      #500;
291 22 ghutchis
      end_check();
292 14 ghutchis
 
293
    end
294
  endtask
295
 
296 6 ghutchis
endmodule // bench_fifo_s
297
// Local Variables:
298 22 ghutchis
// verilog-library-directories:("." "../common" "../../../rtl/verilog/buffers")
299 6 ghutchis
// End:

powered by: WebSVN 2.1.0

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