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 32

Go to most recent revision | 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
      // int words = $ceil(len/(N/4));  // need to fix
50
      int words = len/(N/4);
51
      // $display("^^^ %16.t | words = %d", $time, words);
52
      return(words);
53
    endfunction: get_data_size
54
 
55
 
56
    //--------------------------------------------------------------------
57
    //
58
    function void random(int len, int off, bit last);
59
      this.data = new[get_data_size(len)];
60
      assert(this.randomize() with
61
      {
62
        this.len == len;  // why not working?
63
        this.off == off;
64
        this.last == last;
65
      });
66
      this.len = len;
67
      this.off = off;
68
      this.last = last;
69
    endfunction: random
70
 
71
 
72
    // // --------------------------------------------------------------------
73
    // //
74
    // function void copy(ref riffa_transaction_class #(N) from);
75
      // this.len = from.len;
76
      // this.off = from.off;
77
      // this.last = from.last;
78
    // endfunction: copy
79
 
80
 
81
    // // --------------------------------------------------------------------
82
    // //
83
    // function riffa_transaction_class #(N) clone();
84
      // clone = new(0, 0, 0);
85
      // clone.copy(this);
86
    // endfunction: clone
87
 
88
 
89
    //--------------------------------------------------------------------
90
    function new(int len, int off, bit last);
91
      this.data = new[get_data_size(len)];
92
      this.len  = len;
93
      this.off  = off;
94
      this.last = last;
95
    endfunction: new
96
 
97
 
98
  // --------------------------------------------------------------------
99
  //
100
  endclass: riffa_transaction_class
101
 
102
 
103
  // --------------------------------------------------------------------
104
  // root port tx
105
  class rp_tx_bfm_class #(N)
106
    extends blocking_transmission_q_class #(riffa_transaction_class #(N));
107
 
108
    virtual riffa_chnl_if #(.N(N)) chnl_bus;
109
 
110
    // --------------------------------------------------------------------
111
    //
112
    task set_default;
113
 
114
      chnl_bus.cb_rp_tx.rx <= 0;
115
      chnl_bus.cb_rp_tx.rx_last <= 'bx;
116
      chnl_bus.cb_rp_tx.rx_len <= 'bx;
117
      chnl_bus.cb_rp_tx.rx_off <= 'bx;
118
      chnl_bus.cb_rp_tx.rx_data <= 'bx;
119
      chnl_bus.cb_rp_tx.rx_data_valid <= 0;
120
 
121
    endtask: set_default
122
 
123
 
124
    // --------------------------------------------------------------------
125
    //
126
    event tx_done;
127
 
128
    task transmit(ref Q_T tr_h);
129
 
130
      @(chnl_bus.cb_rp_tx);
131
      chnl_bus.cb_rp_tx.rx_len <= tr_h.len;  // must be => 4
132
      chnl_bus.cb_rp_tx.rx_off <= tr_h.off;
133
      chnl_bus.cb_rp_tx.rx_last <= tr_h.last;
134
      chnl_bus.cb_rp_tx.rx <= 1;
135
 
136
      @(chnl_bus.cb_rp_tx iff chnl_bus.cb_rp_tx.rx_ack);
137
      chnl_bus.cb_rp_tx.rx_data_valid <= 1;
138
 
139
      foreach(tr_h.data[i])
140
      begin
141
        chnl_bus.cb_rp_tx.rx_data <= tr_h.data[i];
142
        @(chnl_bus.cb_rp_tx iff chnl_bus.cb_rp_tx.rx_data_ren);
143
      end
144
 
145
      set_default();
146
      ->tx_done;
147
    endtask: transmit
148
 
149
 
150
    //--------------------------------------------------------------------
151
    //
152
    function new(virtual riffa_chnl_if #(.N(N)) chnl_bus);
153
      this.chnl_bus = chnl_bus;
154
      fork
155
        set_default();
156
      join_none
157
    endfunction: new
158
 
159
 
160
    // --------------------------------------------------------------------
161
    //
162
  endclass: rp_tx_bfm_class
163
 
164
 
165
  // --------------------------------------------------------------------
166
  // root port rx
167
  class rp_rx_bfm_class #(N)
168
    extends blocking_transmission_q_class #(riffa_transaction_class #(N));
169
 
170
    virtual riffa_chnl_if #(.N(N)) chnl_bus;
171
    mailbox #(riffa_transaction_class #(N)) rx_q;
172
 
173
 
174
    // --------------------------------------------------------------------
175
    //
176
    task set_default;
177
 
178
      chnl_bus.cb_rp_rx.tx_ack <= 0;
179
      chnl_bus.cb_rp_rx.tx_data_ren <= 0;
180
 
181
    endtask: set_default
182
 
183
 
184
    // --------------------------------------------------------------------
185
    //
186
    event rx_done;
187
 
188
    task automatic transmit(ref Q_T tr_h);
189
      int last;
190
      int len;
191
      int off;
192
 
193
      @(chnl_bus.cb_rp_rx iff chnl_bus.cb_rp_rx.tx);
194
 
195
      last = chnl_bus.cb_rp_rx.tx_last;
196
      len = chnl_bus.cb_rp_rx.tx_len; // must be => 4
197
      off = chnl_bus.cb_rp_rx.tx_off;
198
      tr_h = new(len, off, last);
199
 
200
      chnl_bus.cb_rp_rx.tx_ack <= 1;
201
      chnl_bus.cb_rp_rx.tx_data_ren <= 1;
202
 
203
      fork
204
        @(chnl_bus.cb_rp_tx)
205
          chnl_bus.cb_rp_rx.tx_ack <= 0;
206
      join_none
207
 
208
      foreach(tr_h.data[i])
209
        @(chnl_bus.cb_rp_tx)
210
          if(~chnl_bus.cb_rp_rx.tx)
211
            break;
212
          else if(chnl_bus.cb_rp_rx.tx_data_valid)
213
            tr_h.data[i] <= chnl_bus.cb_rp_rx.tx_data;
214
 
215
      rx_q.put(tr_h);
216
      set_default();
217
      ->rx_done;
218
    endtask: transmit
219
 
220
 
221
    //--------------------------------------------------------------------
222
    //
223
    function new(virtual riffa_chnl_if  #(.N(N)) chnl_bus);
224
      this.chnl_bus = chnl_bus;
225
      this.rx_q = new();
226
      fork
227
        set_default();
228
      join_none
229
    endfunction: new
230
 
231
 
232
    // --------------------------------------------------------------------
233
    //
234
  endclass: rp_rx_bfm_class
235
 
236
// --------------------------------------------------------------------
237
//
238
endpackage: riffa_bfm_class_pkg
239
 

powered by: WebSVN 2.1.0

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