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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [camera_link/] [sim/] [src/] [camera_link_bfm_pkg.sv] - Blame information for rev 28

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 28 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 camera_link_bfm_pkg;
30
 
31
  // --------------------------------------------------------------------
32
  //
33
  class camera_link_bfm_class #(W = 8);
34
 
35
    string      fifo_name;
36
    fifo_type_t fifo_type;
37
 
38
    virtual fifo_write_if   #(.W(W)) source = null;
39
    virtual fifo_read_if    #(.W(W)) sink = null;
40
    fifo_transaction_class  fifo_tr = new();
41
 
42
 
43
    //--------------------------------------------------------------------
44
    function new
45
      (
46
        virtual fifo_write_if #(.W(W)) source = null,
47
        virtual fifo_read_if  #(.W(W)) sink = null
48
      );
49
 
50
      if(source != null)
51
        this.source = source;
52
 
53
      if(sink != null)
54
        this.sink   = sink;
55
 
56
    endfunction: new
57
 
58
 
59
    // --------------------------------------------------------------------
60
    //
61
    function void
62
      init
63
      (
64
        input string      fifo_name,
65
        input fifo_type_t fifo_type
66
      );
67
 
68
      this.fifo_name  = fifo_name;
69
      this.fifo_type  = fifo_type;
70
 
71
      if(fifo_type == SOURCE)
72
        source.cb_s.wr_en <= 0;
73
      else if(fifo_type == SINK)
74
        sink.cb_s.rd_en   <= 0;
75
      else if(fifo_type == BOTH)
76
        if((this.source == null) | (this.sink == null))
77
        begin
78
          $display("^^^ %16.t | %m | ERROR! %s fifo_type == BOTH with null class", $time, fifo_type.name);
79
          $stop;
80
        end
81
        else
82
        begin
83
          source.cb_s.wr_en <= 0;
84
          sink.cb_s.rd_en   <= 0;
85
        end
86
      else
87
      begin
88
        $display("^^^ %16.t | %m | ERROR! fifo_type %s is invalid", $time, fifo_type.name);
89
        $stop;
90
      end
91
 
92
      $display("^^^ %16.t | %m | initialization of %s for %s", $time, fifo_name, fifo_type.name);
93
 
94
    endfunction: init
95
 
96
 
97
    // --------------------------------------------------------------------
98
    //
99
    task
100
      write
101
      (
102
        input [W-1:0] wr_data,
103
        input int write_delay = 0
104
      );
105
 
106
        source.cb_s.wr_data <= wr_data;
107
        source.cb_s.wr_en <= 0;
108
 
109
        source.zero_cycle_delay();
110
 
111
        if(write_delay != 0)
112
          repeat(write_delay) @(source.cb_s);
113
 
114
        @(source.cb_s iff (source.cb_s.full == 0));
115
        // @(source.cb_s iff (~source.cb_s.full));
116
        source.cb_s.wr_en <= 1;
117
 
118
        @(posedge source.clk);
119
        source.cb_s.wr_en <= 0;
120
 
121
    endtask: write
122
 
123
 
124
    // --------------------------------------------------------------------
125
    //
126
    task
127
      fork_write
128
      (
129
        input [W-1:0] wr_data,
130
        input int write_delay = 0
131
      );
132
 
133
      fork
134
        write(wr_data, write_delay);
135
      join_none
136
 
137
      #0;
138
 
139
    endtask: fork_write
140
 
141
 
142
    // --------------------------------------------------------------------
143
    //
144
    mailbox #(int) rd_data_q  = new();
145
 
146
    task
147
      read
148
      (
149
        input int read_delay = 0
150
      );
151
 
152
        sink.cb_s.rd_en <= 0;
153
 
154
        sink.zero_cycle_delay();
155
 
156
        if(read_delay != 0)
157
          repeat(read_delay) @(sink.cb_s);
158
 
159
        @(sink.cb_s iff (sink.cb_s.empty == 0));
160
        // @(sink.cb_s iff (~sink.cb_s.empty));
161
        sink.cb_s.rd_en <= 1;
162
 
163
        @(posedge sink.clk);
164
 
165
        sink.cb_s.rd_en <= 0;
166
 
167
        rd_data_q.put(sink.cb_s.rd_data);
168
 
169
    endtask: read
170
 
171
 
172
    // --------------------------------------------------------------------
173
    //
174
    task automatic
175
      fork_read
176
      (
177
        input int read_delay = 0
178
      );
179
 
180
      fork
181
        read(read_delay);
182
      join_none
183
 
184
      #0;
185
 
186
    endtask: fork_read
187
 
188
 
189
    // --------------------------------------------------------------------
190
    //
191
    mailbox #(fifo_transaction_class) fifo_tr_q;
192
    semaphore                         fifo_tr_q_semaphore = new(1);
193
 
194
 
195
    // --------------------------------------------------------------------
196
    //
197
    event fifo_write_done;
198
 
199
    task automatic
200
      fifo_write_q;
201
 
202
        if((fifo_type != SOURCE) & (fifo_type == BOTH))
203
        begin
204
          $display("^^^ %16.t | %m | ERROR! wrong fifo_type |", $time);
205
          return;
206
        end
207
 
208
        if(fifo_tr_q_semaphore.try_get() == 0)
209
        begin
210
          $display("^^^ %16.t | %m | ERROR! fifo_tr_q_semaphore.try_get() == 0 |", $time);
211
          return;
212
        end
213
 
214
        $display("^^^ %16.t | %m is active |", $time);
215
 
216
        this.fifo_tr_q = new();
217
 
218
        fifo_write_fork : fork
219
          forever
220
          begin
221
 
222
            fifo_tr_q.get(fifo_tr);
223
            fork_write(fifo_tr.data, fifo_tr.write_delay);
224
 
225
            wait fork;
226
 
227
            ->fifo_write_done;
228
          end
229
        join_none
230
 
231
        #0;
232
 
233
    endtask: fifo_write_q
234
 
235
 
236
    // --------------------------------------------------------------------
237
    //
238
    fifo_transaction_class  fifo_tr_clone;
239
    event                   fifo_read_done;
240
    logic [W - 1:0]         rd_data;
241
    logic [W - 1:0]         rd_result;
242
    int                     compare_result;
243
    int                     compare_errors = 0;
244
 
245
    task automatic
246
      fifo_read_q;
247
 
248
        if((fifo_type != SINK) & (fifo_type == BOTH))
249
        begin
250
          $display("^^^ %16.t | %m | ERROR! wrong fifo_type |", $time);
251
          return;
252
        end
253
 
254
 
255
        if(fifo_tr_q_semaphore.try_get() == 0)
256
        begin
257
          $display("^^^ %16.t | %m | ERROR! fifo_tr_q_semaphore.try_get() == 0 |", $time);
258
          return;
259
        end
260
 
261
        $display("^^^ %16.t | %m is active |", $time);
262
 
263
        this.fifo_tr_q  = new();
264
        fifo_tr_clone   = fifo_tr.clone();
265
 
266
        fifo_read_q_fork : fork
267
          forever
268
          begin
269
 
270
            fifo_tr_q.get(fifo_tr);
271
            fork_read(fifo_tr.read_delay);
272
 
273
            wait fork;
274
 
275
            ->fifo_read_done;
276
 
277
            rd_data_q.get(rd_result);
278
            rd_data = fifo_tr.data;
279
 
280
            if(rd_result != rd_data)
281
            begin
282
              $display("^^^ %16.t | %m | ERROR! rd_result != fifo_tr.data |", $time);
283
              $display("^^^ %16.t | %m | rd_result = %h |", $time, rd_result);
284
              $display("^^^ %16.t | %m | fifo_tr.data = %h |", $time, fifo_tr.data);
285
            end
286
 
287
            // compare_result = avf_in_frame.compare(8, f_h);
288
            // compare_errors += compare_result;
289
 
290
          end
291
        join_none
292
 
293
        #0;
294
 
295
    endtask: fifo_read_q
296
 
297
 
298
    // --------------------------------------------------------------------
299
    //
300
 
301
  endclass: fifo_bfm_class
302
 
303
endpackage: camera_link_bfm_pkg
304
 

powered by: WebSVN 2.1.0

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