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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [PCIe/] [sim/] [src/] [riffa_bfm_class_pkg.sv] - Blame information for rev 39

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 32 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2017 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 riffa_bfm_class_pkg;
30
 
31
  // --------------------------------------------------------------------
32
  //
33
  import q_pkg::*;
34
 
35
 
36
  // --------------------------------------------------------------------
37
  //
38
  class riffa_transaction_class #(N);
39
 
40
    rand logic [31:0] len;
41
    rand logic [30:0] off;
42
    rand logic last;
43
    rand logic [(8*N)-1:0] data[];
44
 
45
 
46
    //--------------------------------------------------------------------
47
    //
48
    function int get_data_size(int len);
49 39 qaztronic
      int words = ((len * 4) % N == 0) ? ((len * 4) / N) : ((len * 4) / N) + 1;
50
      // $display("^^^ %16.t | N     = %d", $time, N);
51
      // $display("^^^ %16.t | len   = %d", $time, len);
52
      // $display("^^^ %16.t | mod   = %d", $time, (len * 4) % N);
53 32 qaztronic
      // $display("^^^ %16.t | words = %d", $time, words);
54
      return(words);
55
    endfunction: get_data_size
56
 
57
 
58
    //--------------------------------------------------------------------
59
    //
60 35 qaztronic
    function void constant(int len, int off, bit last, logic [(8*N)-1:0] value);
61
      this.data = new[get_data_size(len)];
62
      this.len = len;
63
      this.off = off;
64
      this.last = last;
65
      foreach(this.data[i])
66
        this.data[i] = value;
67
    endfunction: constant
68
 
69
 
70
    //--------------------------------------------------------------------
71
    //
72
    function void counting(int len, int off, bit last);
73
      this.data = new[get_data_size(len)];
74
      this.len = len;
75
      this.off = off;
76
      this.last = last;
77
      foreach(this.data[i])
78
        this.data[i] = i;
79
    endfunction: counting
80
 
81
 
82
    //--------------------------------------------------------------------
83
    //
84 39 qaztronic
    function void hex(string str, int off, bit last);
85
      string rev_str;
86
      string char;
87
      int w, c;
88
      this.len  = (str.len() % (2 * 4)) == 0
89
                ? (str.len() / (2 * 4))
90
                : (str.len() / (2 * 4)) + 1;
91
      this.data = new[get_data_size(this.len)];
92
      this.off = off;
93
      this.last = last;
94
      rev_str = {<<8{str}}; // reverse string
95
      for(w = 0; w < rev_str.len(); w += (N * 2))
96
        for(c = 0; c < (N * 2); c++)
97
        begin
98
          char = string'(rev_str.getc(w + c));
99
          if(char == "")
100
            this.data[w / (N * 2)][(c * 4) +: 4] = 0;
101
          else
102
            this.data[w / (N * 2)][(c * 4) +: 4] = char.atohex();
103
        end
104
    endfunction: hex
105
 
106
 
107
    //--------------------------------------------------------------------
108
    //
109 32 qaztronic
    function void random(int len, int off, bit last);
110
      this.data = new[get_data_size(len)];
111
      assert(this.randomize() with
112
      {
113
        this.len == len;  // why not working?
114
        this.off == off;
115
        this.last == last;
116
      });
117
      this.len = len;
118
      this.off = off;
119
      this.last = last;
120
    endfunction: random
121
 
122
 
123 35 qaztronic
    //--------------------------------------------------------------------
124
    //
125
    function void compare(riffa_transaction_class #(N) to, int max_mismatches = 8);
126
      int error_count = 0;
127
      $display("!!! %16.t | %m", $time);
128
      if(this.len != to.len)
129
        $display("!!! %16.t | ERROR! len mismatch", $time);
130
 
131
      if(this.off != to.off)
132
        $display("!!! %16.t | ERROR! off mismatch", $time);
133
 
134
      if(this.last != to.last)
135
        $display("!!! %16.t | ERROR! last mismatch", $time);
136
 
137
      foreach(this.data[i])
138
      begin
139
        if(error_count > max_mismatches)
140
          break;
141 37 qaztronic
        if(this.data[i] !== to.data[i])
142 35 qaztronic
        begin
143
          $display("!!! %16.t | ERROR! | 0x%x | this != to | 0x%x != 0x%x", $time, i, this.data[i], to.data[i]);
144
          error_count++;
145
        end
146
      end
147
    endfunction: compare
148
 
149
 
150 32 qaztronic
    // // --------------------------------------------------------------------
151
    // //
152
    // function void copy(ref riffa_transaction_class #(N) from);
153
      // this.len = from.len;
154
      // this.off = from.off;
155
      // this.last = from.last;
156
    // endfunction: copy
157
 
158
 
159
    // // --------------------------------------------------------------------
160
    // //
161
    // function riffa_transaction_class #(N) clone();
162
      // clone = new(0, 0, 0);
163
      // clone.copy(this);
164
    // endfunction: clone
165
 
166
 
167
    //--------------------------------------------------------------------
168
    function new(int len, int off, bit last);
169
      this.data = new[get_data_size(len)];
170
      this.len  = len;
171
      this.off  = off;
172
      this.last = last;
173
    endfunction: new
174
 
175
 
176
  // --------------------------------------------------------------------
177
  //
178
  endclass: riffa_transaction_class
179
 
180
 
181
  // --------------------------------------------------------------------
182
  // root port tx
183
  class rp_tx_bfm_class #(N)
184
    extends blocking_transmission_q_class #(riffa_transaction_class #(N));
185
 
186
    virtual riffa_chnl_if #(.N(N)) chnl_bus;
187
 
188
    // --------------------------------------------------------------------
189
    //
190
    task set_default;
191
 
192
      chnl_bus.cb_rp_tx.rx <= 0;
193
      chnl_bus.cb_rp_tx.rx_last <= 'bx;
194
      chnl_bus.cb_rp_tx.rx_len <= 'bx;
195
      chnl_bus.cb_rp_tx.rx_off <= 'bx;
196
      chnl_bus.cb_rp_tx.rx_data <= 'bx;
197
      chnl_bus.cb_rp_tx.rx_data_valid <= 0;
198
 
199
    endtask: set_default
200
 
201
 
202
    // --------------------------------------------------------------------
203
    //
204
    event tx_done;
205
 
206
    task transmit(ref Q_T tr_h);
207
 
208
      @(chnl_bus.cb_rp_tx);
209
      chnl_bus.cb_rp_tx.rx_len <= tr_h.len;  // must be => 4
210
      chnl_bus.cb_rp_tx.rx_off <= tr_h.off;
211
      chnl_bus.cb_rp_tx.rx_last <= tr_h.last;
212
      chnl_bus.cb_rp_tx.rx <= 1;
213
 
214
      @(chnl_bus.cb_rp_tx iff chnl_bus.cb_rp_tx.rx_ack);
215
      chnl_bus.cb_rp_tx.rx_data_valid <= 1;
216
 
217
      foreach(tr_h.data[i])
218
      begin
219
        chnl_bus.cb_rp_tx.rx_data <= tr_h.data[i];
220
        @(chnl_bus.cb_rp_tx iff chnl_bus.cb_rp_tx.rx_data_ren);
221
      end
222
 
223
      set_default();
224
      ->tx_done;
225
    endtask: transmit
226
 
227
 
228
    //--------------------------------------------------------------------
229
    //
230
    function new(virtual riffa_chnl_if #(.N(N)) chnl_bus);
231
      this.chnl_bus = chnl_bus;
232
      fork
233
        set_default();
234
      join_none
235
    endfunction: new
236
 
237
 
238
    // --------------------------------------------------------------------
239
    //
240
  endclass: rp_tx_bfm_class
241
 
242
 
243
  // --------------------------------------------------------------------
244
  // root port rx
245
  class rp_rx_bfm_class #(N)
246
    extends blocking_transmission_q_class #(riffa_transaction_class #(N));
247
 
248
    virtual riffa_chnl_if #(.N(N)) chnl_bus;
249
    mailbox #(riffa_transaction_class #(N)) rx_q;
250
 
251
 
252
    // --------------------------------------------------------------------
253
    //
254
    task set_default;
255
 
256
      chnl_bus.cb_rp_rx.tx_ack <= 0;
257
      chnl_bus.cb_rp_rx.tx_data_ren <= 0;
258
 
259
    endtask: set_default
260
 
261
 
262
    // --------------------------------------------------------------------
263
    //
264
    event rx_done;
265
 
266
    task automatic transmit(ref Q_T tr_h);
267
      int last;
268
      int len;
269
      int off;
270
 
271
      @(chnl_bus.cb_rp_rx iff chnl_bus.cb_rp_rx.tx);
272
 
273
      last = chnl_bus.cb_rp_rx.tx_last;
274
      len = chnl_bus.cb_rp_rx.tx_len; // must be => 4
275
      off = chnl_bus.cb_rp_rx.tx_off;
276
      tr_h = new(len, off, last);
277
 
278
      chnl_bus.cb_rp_rx.tx_ack <= 1;
279
      chnl_bus.cb_rp_rx.tx_data_ren <= 1;
280 35 qaztronic
 
281 32 qaztronic
      fork
282 39 qaztronic
        @(chnl_bus.cb_rp_rx)
283 32 qaztronic
          chnl_bus.cb_rp_rx.tx_ack <= 0;
284
      join_none
285 35 qaztronic
 
286 32 qaztronic
      foreach(tr_h.data[i])
287 39 qaztronic
      begin
288
        @(chnl_bus.cb_rp_rx iff chnl_bus.cb_rp_rx.tx_data_valid)
289 35 qaztronic
          tr_h.data[i] <= chnl_bus.cb_rp_rx.tx_data;
290 39 qaztronic
        // $display("^^^ %16.t | %d | %h", $time, i, chnl_bus.cb_rp_rx.tx_data);
291
      end
292 32 qaztronic
 
293
      rx_q.put(tr_h);
294
      set_default();
295
      ->rx_done;
296
    endtask: transmit
297
 
298
 
299
    //--------------------------------------------------------------------
300
    //
301
    function new(virtual riffa_chnl_if  #(.N(N)) chnl_bus);
302
      this.chnl_bus = chnl_bus;
303
      this.rx_q = new();
304
      fork
305
        set_default();
306
      join_none
307
    endfunction: new
308
 
309
 
310
    // --------------------------------------------------------------------
311
    //
312
  endclass: rp_rx_bfm_class
313
 
314
// --------------------------------------------------------------------
315
//
316
endpackage: riffa_bfm_class_pkg
317
 

powered by: WebSVN 2.1.0

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