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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [basal/] [sim/] [src/] [legacy/] [fifo_bfm_pkg.sv] - Blame information for rev 50

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 50 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2015 Authors and OPENCORES.ORG                 ////
4
////                                                              ////
5
//// This source file may be used and distributed without         ////
6
//// restriction provided that this copyright statement is not    ////
7
//// removed from the file and that any derivative work contains  ////
8
//// the original copyright notice and the associated disclaimer. ////
9
////                                                              ////
10
//// This source file is free software; you can redistribute it   ////
11
//// and/or modify it under the terms of the GNU Lesser General   ////
12
//// Public License as published by the Free Software Foundation; ////
13
//// either version 2.1 of the License, or (at your option) any   ////
14
//// later version.                                               ////
15
////                                                              ////
16
//// This source is distributed in the hope that it will be       ////
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
19
//// PURPOSE.  See the GNU Lesser General Public License for more ////
20
//// details.                                                     ////
21
////                                                              ////
22
//// You should have received a copy of the GNU Lesser General    ////
23
//// Public License along with this source; if not, download it   ////
24
//// from http://www.opencores.org/lgpl.shtml                     ////
25
////                                                              ////
26
//////////////////////////////////////////////////////////////////////
27
 
28
 
29
package fifo_bfm_pkg;
30
 
31
  typedef enum
32
  {
33
    SOURCE,
34
    SINK,
35
    BOTH
36
  } fifo_type_t;
37
 
38
  // --------------------------------------------------------------------
39
  //
40
  class fifo_transaction_class;
41
 
42
    rand int data;
43
    rand int write_delay = 0;
44
    rand int read_delay = 0;
45
 
46
    constraint default_write_delay
47
    {
48
      write_delay >= 0 && write_delay <= 4;
49
      write_delay dist {0 := 60, [1:4] :=40 };
50
    }
51
 
52
    constraint default_read_delay
53
    {
54
      read_delay >= 0 && read_delay <= 4;
55
      read_delay dist {0 := 60, [1:4] :=40 };
56
    }
57
 
58
 
59
    // --------------------------------------------------------------------
60
    //
61
    function void copy
62
    (
63
      ref fifo_transaction_class from
64
    );
65
 
66
      // $display("^^^ %16.t | %m", $time);
67
 
68
      this.data         = from.data;
69
      this.write_delay  = from.write_delay;
70
      this.read_delay   = from.read_delay;
71
 
72
    endfunction: copy
73
 
74
 
75
    // --------------------------------------------------------------------
76
    //
77
    extern virtual function fifo_transaction_class clone();
78
    // virtual function fifo_transaction_class clone();
79
 
80
      // $display("^^^ %16.t | %m", $time);
81
 
82
      // clone = new();
83
      // clone.copy(this);
84
      // return(clone);
85
 
86
    // endfunction: clone
87
 
88
 
89
    // --------------------------------------------------------------------
90
    //
91
 
92
  endclass: fifo_transaction_class
93
 
94
 
95
  // --------------------------------------------------------------------
96
  //
97
  function fifo_transaction_class fifo_transaction_class::clone();
98
 
99
    // $display("^^^ %16.t | %m", $time);
100
 
101
    clone = new();
102
    clone.copy(this);
103
 
104
  endfunction: clone
105
 
106
 
107
  // --------------------------------------------------------------------
108
  //
109
  class fifo_bfm_class #(W = 8);
110
 
111
    string      fifo_name;
112
    fifo_type_t fifo_type;
113
 
114
    virtual fifo_write_if   #(.W(W)) source = null;
115
    virtual fifo_read_if    #(.W(W)) sink = null;
116
    fifo_transaction_class  fifo_tr = new();
117
 
118
 
119
    //--------------------------------------------------------------------
120
    function new
121
      (
122
        virtual fifo_write_if #(.W(W)) source = null,
123
        virtual fifo_read_if  #(.W(W)) sink = null
124
      );
125
 
126
      if(source != null)
127
        this.source = source;
128
 
129
      if(sink != null)
130
        this.sink   = sink;
131
 
132
    endfunction: new
133
 
134
 
135
    // --------------------------------------------------------------------
136
    //
137
    function void
138
      init
139
      (
140
        input string      fifo_name,
141
        input fifo_type_t fifo_type
142
      );
143
 
144
      this.fifo_name  = fifo_name;
145
      this.fifo_type  = fifo_type;
146
 
147
      if(fifo_type == SOURCE)
148
        source.cb_s.wr_en <= 0;
149
      else if(fifo_type == SINK)
150
        sink.cb_s.rd_en   <= 0;
151
      else if(fifo_type == BOTH)
152
        if((this.source == null) | (this.sink == null))
153
        begin
154
          $display("^^^ %16.t | %m | ERROR! %s fifo_type == BOTH with null class", $time, fifo_type.name);
155
          $stop;
156
        end
157
        else
158
        begin
159
          source.cb_s.wr_en <= 0;
160
          sink.cb_s.rd_en   <= 0;
161
        end
162
      else
163
      begin
164
        $display("^^^ %16.t | %m | ERROR! fifo_type %s is invalid", $time, fifo_type.name);
165
        $stop;
166
      end
167
 
168
      $display("^^^ %16.t | %m | initialization of %s for %s", $time, fifo_name, fifo_type.name);
169
 
170
    endfunction: init
171
 
172
 
173
    // --------------------------------------------------------------------
174
    //
175
    task
176
      write
177
      (
178
        input [W-1:0] wr_data,
179
        input int write_delay = 0
180
      );
181
 
182
        source.cb_s.wr_data <= wr_data;
183
        source.cb_s.wr_en <= 0;
184
 
185
        source.zero_cycle_delay();
186
 
187
        if(write_delay != 0)
188
          repeat(write_delay) @(source.cb_s);
189
 
190
        @(source.cb_s iff (source.cb_s.full == 0));
191
        // @(source.cb_s iff (~source.cb_s.full));
192
        source.cb_s.wr_en <= 1;
193
 
194
        @(posedge source.clk);
195
        source.cb_s.wr_en <= 0;
196
 
197
    endtask: write
198
 
199
 
200
    // --------------------------------------------------------------------
201
    //
202
    task
203
      fork_write
204
      (
205
        input [W-1:0] wr_data,
206
        input int write_delay = 0
207
      );
208
 
209
      fork
210
        write(wr_data, write_delay);
211
      join_none
212
 
213
      #0;
214
 
215
    endtask: fork_write
216
 
217
 
218
    // --------------------------------------------------------------------
219
    //
220
    mailbox #(int) rd_data_q  = new();
221
 
222
    task
223
      read
224
      (
225
        input int read_delay = 0
226
      );
227
 
228
        sink.cb_s.rd_en <= 0;
229
 
230
        sink.zero_cycle_delay();
231
 
232
        if(read_delay != 0)
233
          repeat(read_delay) @(sink.cb_s);
234
 
235
        @(sink.cb_s iff (sink.cb_s.empty == 0));
236
        // @(sink.cb_s iff (~sink.cb_s.empty));
237
        sink.cb_s.rd_en <= 1;
238
 
239
        @(posedge sink.clk);
240
 
241
        sink.cb_s.rd_en <= 0;
242
 
243
        rd_data_q.put(sink.cb_s.rd_data);
244
 
245
    endtask: read
246
 
247
 
248
    // --------------------------------------------------------------------
249
    //
250
    task automatic
251
      fork_read
252
      (
253
        input int read_delay = 0
254
      );
255
 
256
      fork
257
        read(read_delay);
258
      join_none
259
 
260
      #0;
261
 
262
    endtask: fork_read
263
 
264
 
265
    // --------------------------------------------------------------------
266
    //
267
    mailbox #(fifo_transaction_class) fifo_tr_q;
268
    semaphore                         fifo_tr_q_semaphore = new(1);
269
 
270
 
271
    // --------------------------------------------------------------------
272
    //
273
    event fifo_write_done;
274
 
275
    task automatic
276
      fifo_write_q;
277
 
278
        if((fifo_type != SOURCE) & (fifo_type == BOTH))
279
        begin
280
          $display("^^^ %16.t | %m | ERROR! wrong fifo_type |", $time);
281
          return;
282
        end
283
 
284
        if(fifo_tr_q_semaphore.try_get() == 0)
285
        begin
286
          $display("^^^ %16.t | %m | ERROR! fifo_tr_q_semaphore.try_get() == 0 |", $time);
287
          return;
288
        end
289
 
290
        $display("^^^ %16.t | %m is active |", $time);
291
 
292
        this.fifo_tr_q = new();
293
 
294
        fifo_write_fork : fork
295
          forever
296
          begin
297
 
298
            fifo_tr_q.get(fifo_tr);
299
            fork_write(fifo_tr.data, fifo_tr.write_delay);
300
 
301
            wait fork;
302
 
303
            ->fifo_write_done;
304
          end
305
        join_none
306
 
307
        #0;
308
 
309
    endtask: fifo_write_q
310
 
311
 
312
    // --------------------------------------------------------------------
313
    //
314
    fifo_transaction_class  fifo_tr_clone;
315
    event                   fifo_read_done;
316
    logic [W - 1:0]         rd_data;
317
    logic [W - 1:0]         rd_result;
318
    int                     compare_result;
319
    int                     compare_errors = 0;
320
 
321
    task automatic
322
      fifo_read_q;
323
 
324
        if((fifo_type != SINK) & (fifo_type == BOTH))
325
        begin
326
          $display("^^^ %16.t | %m | ERROR! wrong fifo_type |", $time);
327
          return;
328
        end
329
 
330
 
331
        if(fifo_tr_q_semaphore.try_get() == 0)
332
        begin
333
          $display("^^^ %16.t | %m | ERROR! fifo_tr_q_semaphore.try_get() == 0 |", $time);
334
          return;
335
        end
336
 
337
        $display("^^^ %16.t | %m is active |", $time);
338
 
339
        this.fifo_tr_q  = new();
340
        fifo_tr_clone   = fifo_tr.clone();
341
 
342
        fifo_read_q_fork : fork
343
          forever
344
          begin
345
 
346
            fifo_tr_q.get(fifo_tr);
347
            fork_read(fifo_tr.read_delay);
348
 
349
            wait fork;
350
 
351
            ->fifo_read_done;
352
 
353
            rd_data_q.get(rd_result);
354
            rd_data = fifo_tr.data;
355
 
356
            if(rd_result != rd_data)
357
            begin
358
              $display("^^^ %16.t | %m | ERROR! rd_result != fifo_tr.data |", $time);
359
              $display("^^^ %16.t | %m | rd_result = %h |", $time, rd_result);
360
              $display("^^^ %16.t | %m | fifo_tr.data = %h |", $time, fifo_tr.data);
361
            end
362
 
363
            // compare_result = avf_in_frame.compare(8, f_h);
364
            // compare_errors += compare_result;
365
 
366
          end
367
        join_none
368
 
369
        #0;
370
 
371
    endtask: fifo_read_q
372
 
373
 
374
    // --------------------------------------------------------------------
375
    //
376
 
377
  endclass: fifo_bfm_class
378
 
379
endpackage: fifo_bfm_pkg
380
 

powered by: WebSVN 2.1.0

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