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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [axi4_stream_lib/] [sim/] [tests/] [tb_axis_gear_box/] [axis_pkg.sv] - Blame information for rev 40

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

Line No. Rev Author Line
1 40 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
//
30
package axis_pkg;
31
 
32
  // --------------------------------------------------------------------
33
  //
34
  import uvm_pkg::*;
35
  `include "uvm_macros.svh"
36
  import axis_pkg::*;
37
 
38
  // --------------------------------------------------------------------
39
  //
40
  typedef struct packed
41
  {
42
    int unsigned N; // data bus width in bytes
43
    int unsigned I; // TID width
44
    int unsigned D; // TDEST width
45
    int unsigned U; // TUSER width
46
    bit USE_TSTRB; // set to 1 to enable, 0 to disable
47
    bit USE_TKEEP; // set to 1 to enable, 0 to disable
48
    bit USE_ROUTING; // set to 1 to enable, 0 to disable
49
  } axis_config_t;
50
 
51
  // --------------------------------------------------------------------
52
  //
53
  class axis_sequence_item #(axis_config_t cfg)
54
    extends uvm_sequence_item;
55
    `uvm_object_param_utils(axis_sequence_item #(cfg))
56
 
57
    // --------------------------------------------------------------------
58
    //
59
    localparam N = cfg.N;
60
    localparam I = cfg.I;
61
    localparam D = cfg.D;
62
    localparam U = cfg.U;
63
    localparam USE_TSTRB = cfg.USE_TSTRB;
64
    localparam USE_TKEEP = cfg.USE_TKEEP;
65
    localparam USE_ROUTING = cfg.USE_ROUTING;
66
 
67
    // --------------------------------------------------------------------
68
    //
69
    rand logic [(8*N)-1:0]  tdata;
70
    rand logic [N-1:0]      tstrb;
71
    rand logic [N-1:0]      tkeep;
72
    rand logic              tlast;
73
    rand logic [I-1:0]      tid;
74
    rand logic [D-1:0]      tdest;
75
    rand logic [U-1:0]      tuser;
76
 
77
    // --------------------------------------------------------------------
78
    //
79
    function new(string name = "");
80
      super.new(name);
81
    endfunction : new
82
 
83
    // --------------------------------------------------------------------
84
    //
85
    function bit do_compare(uvm_object rhs, uvm_comparer comparer);
86
      axis_sequence_item #(cfg) tested;
87
      bit same;
88
 
89
      if (rhs==null)
90
        `uvm_fatal(get_type_name(), "| %m | comparison to a null pointer");
91
 
92
      if (!$cast(tested,rhs))
93
        same = 0;
94
      else
95
        same  = super.do_compare(rhs, comparer)
96
              & (tested.tdata == tdata)
97
              & (USE_TSTRB ? (tested.tstrb == tstrb) : 1)
98
              & (USE_TKEEP ? (tested.tkeep == tkeep) : 1)
99
              & (tested.tlast == tlast)
100
              & (USE_ROUTING ? (tested.tid == tid) : 1)
101
              & (USE_ROUTING ? (tested.tdest == tdest) : 1)
102
              & (tested.tuser == tuser);
103
      return same;
104
    endfunction : do_compare
105
 
106
    // --------------------------------------------------------------------
107
    //
108
    function void do_copy(uvm_object rhs);
109
      axis_sequence_item #(cfg) item;
110
      assert(rhs != null) else
111
        `uvm_fatal(get_type_name(), "| %m | copy null transaction");
112
      super.do_copy(rhs);
113
      assert($cast(item,rhs)) else
114
        `uvm_fatal(get_type_name(), "| %m | failed cast");
115
      tdata = item.tdata;
116
      tstrb = item.tstrb;
117
      tkeep = item.tkeep;
118
      tlast = item.tlast;
119
      tid   = item.tid;
120
      tdest = item.tdest;
121
      tuser = item.tuser;
122
    endfunction : do_copy
123
 
124
    // --------------------------------------------------------------------
125
    //
126
    function string convert2string();
127
      string s0, s1;
128
      s0 = $sformatf("| tdata: %h\n" ,tdata);
129
      s1 = $sformatf("| tlast: %1h | tuser: %h" , tlast, tuser);
130
      return {s1, s0};
131
    endfunction : convert2string
132
 
133
  // --------------------------------------------------------------------
134
  //
135
  endclass : axis_sequence_item
136
 
137
  // --------------------------------------------------------------------
138
  //
139
  class axis_driver #(parameter axis_config_t cfg)
140
    extends uvm_driver #(axis_sequence_item #(cfg));
141
     `uvm_component_param_utils(axis_driver#(cfg))
142
 
143
    // --------------------------------------------------------------------
144
    //
145
    localparam N = cfg.N;
146
    localparam I = cfg.I;
147
    localparam D = cfg.D;
148
    localparam U = cfg.U;
149
    localparam USE_TSTRB = cfg.USE_TSTRB;
150
    localparam USE_TKEEP = cfg.USE_TKEEP;
151
    localparam USE_ROUTING = cfg.USE_ROUTING;
152
 
153
    // --------------------------------------------------------------------
154
    //
155
    virtual axis_if #(.N(N), .I(I), .D(D), .U(U)) axis_bus;
156
 
157
    //--------------------------------------------------------------------
158
    //
159
    function void set_default;
160
      axis_bus.cb_m.tvalid  <= 0;
161
      axis_bus.cb_m.tdata   <= 'bx;
162
      axis_bus.cb_m.tstrb   <= 'bx;
163
      axis_bus.cb_m.tkeep   <= 'bx;
164
      axis_bus.cb_m.tlast   <= 'bx;
165
      axis_bus.cb_m.tid     <= 'bx;
166
      axis_bus.cb_m.tdest   <= 'bx;
167
      axis_bus.cb_m.tuser   <= 'bx;
168
    endfunction: set_default
169
 
170
 
171
    //--------------------------------------------------------------------
172
    //
173
    virtual task run_phase(uvm_phase phase);
174
      axis_sequence_item #(cfg) item;
175
      super.run_phase(phase);
176
 
177
      $display("^^^ %16.t | %m | ", $time);
178
 
179
      set_default();
180
 
181
      @(axis_bus.cb_m) forever
182
      begin
183
        // seq_item_port.try_next_item(item);
184
        seq_item_port.get_next_item(item);
185
 
186
        axis_bus.cb_m.tvalid  <= 1;
187
        axis_bus.cb_m.tdata   <= item.tdata;
188
        axis_bus.cb_m.tstrb   <= 0;
189
        axis_bus.cb_m.tkeep   <= 0;
190
        axis_bus.cb_m.tlast   <= item.tlast;
191
        axis_bus.cb_m.tid     <= 0;
192
        axis_bus.cb_m.tdest   <= 0;
193
        axis_bus.cb_m.tuser   <= item.tuser;
194
 
195
        @(axis_bus.cb_m);
196
        wait(axis_bus.cb_m.tready);
197
        // @(axis_bus.cb_m iff axis_bus.cb_m.tready);
198
 
199
        set_default();
200
 
201
        seq_item_port.item_done();
202
      end
203
    endtask : run_phase
204
 
205
 
206
    //--------------------------------------------------------------------
207
    //
208
    function new(string name, uvm_component parent);
209
      super.new(name, parent);
210
    endfunction
211
 
212
  // --------------------------------------------------------------------
213
  //
214
  endclass : axis_driver
215
 
216
 
217
  // --------------------------------------------------------------------
218
  //
219
  class axis_sequencer #(axis_config_t cfg)
220
    extends uvm_sequencer #(axis_sequence_item #(cfg));
221
    `uvm_component_param_utils(axis_sequencer #(cfg))
222
 
223
    // --------------------------------------------------------------------
224
    //
225
    function new(string name, uvm_component parent);
226
      super.new(name, parent);
227
      $display("^^^ %16.t | %m | ", $time);
228
    endfunction
229
 
230
  // --------------------------------------------------------------------
231
  //
232
  endclass : axis_sequencer
233
 
234
  // --------------------------------------------------------------------
235
  //
236
  class axis_counting_sequence #(axis_config_t cfg)
237
    extends uvm_sequence #(axis_sequence_item #(cfg));
238
     `uvm_object_param_utils(axis_counting_sequence #(cfg))
239
 
240
    // --------------------------------------------------------------------
241
    //
242
    localparam LENGTH = 16;
243
 
244
    // --------------------------------------------------------------------
245
    //
246
    virtual task body();
247
      axis_sequence_item #(cfg) item;
248
 
249
      $display("^^^ %16.t | %m | ", $time);
250
 
251
      for(int i = 0; i < LENGTH; i++)
252
      begin
253
        item = axis_sequence_item #(cfg)::type_id::create("axis_sequence_item");
254
 
255
        item.tdata = i;
256
        item.tlast = (i == LENGTH - 1);
257
 
258
        start_item (item);
259
        finish_item(item);
260
      end
261
    endtask
262
 
263
    // --------------------------------------------------------------------
264
    //
265
    function new(string name = "axis_counting_sequence");
266
      super.new(name);
267
    endfunction
268
 
269
  // --------------------------------------------------------------------
270
  //
271
  endclass : axis_counting_sequence
272
 
273
  // --------------------------------------------------------------------
274
  //
275
  class axis_agent #(axis_config_t cfg)
276
    extends uvm_agent;
277
     `uvm_component_param_utils(axis_agent #(cfg))
278
 
279
    // --------------------------------------------------------------------
280
    //
281
    localparam N = cfg.N;
282
    localparam I = cfg.I;
283
    localparam D = cfg.D;
284
    localparam U = cfg.U;
285
    localparam USE_TSTRB = cfg.USE_TSTRB;
286
    localparam USE_TKEEP = cfg.USE_TKEEP;
287
    localparam USE_ROUTING = cfg.USE_ROUTING;
288
 
289
    // --------------------------------------------------------------------
290
    //
291
    // virtual axis_if #(.N(N), .I(I), .D(D), .U(U)) axis_bus;
292
    virtual tb_dut_if #(.IN_N(N), .OUT_N(N), .I(I), .D(D), .U(U)) dut_bus;
293
 
294
     axis_driver #(cfg) driver;
295
     // my_monitor    #(cfg) monitor;
296
     axis_sequencer #(cfg) sequencer;
297
 
298
    // --------------------------------------------------------------------
299
    //
300
    virtual function void build_phase(uvm_phase phase);
301
      super.build_phase(phase);
302
 
303
      $display("^^^ %16.t | %m | ", $time);
304
 
305
      if (!uvm_config_db #(virtual tb_dut_if #(.IN_N(N), .OUT_N(N), .I(I), .D(D), .U(U)))::get(this, "", "dut_bus", dut_bus))
306
         `uvm_fatal(get_name(), "Could not get the virtual interface handle from the config database.")
307
 
308
      driver = axis_driver #(cfg)::type_id::create("driver", this);
309
      // monitor   = my_monitor  #(cfg)::type_id::create("monitor"  , this);
310
      sequencer = axis_sequencer #(cfg)::type_id::create("sequencer", this);
311
    endfunction
312
 
313
    // --------------------------------------------------------------------
314
    //
315
    virtual function void connect_phase(uvm_phase phase);
316
      super.connect_phase(phase);
317
 
318
      $display("^^^ %16.t | %m | ", $time);
319
 
320
      driver.axis_bus = dut_bus.axis_in;
321
      // monitor.vif = vif;
322
 
323
      driver.seq_item_port.connect(sequencer.seq_item_export);
324
    endfunction
325
 
326
    // --------------------------------------------------------------------
327
    //
328
     function new(string name, uvm_component parent);
329
        super.new(name, parent);
330
     endfunction
331
 
332
  // --------------------------------------------------------------------
333
  //
334
  endclass : axis_agent
335
 
336
  // --------------------------------------------------------------------
337
  //
338
 
339
  class my_test extends uvm_test;
340
     `uvm_component_utils(my_test)
341
 
342
    localparam axis_config_t cfg_a =  '{ 1, 1, 1, 1, 0, 0, 0};
343
 
344
     axis_agent #(cfg_a) agent_h;
345
     // my_agent#(cfg_b) agent_b;
346
 
347
     function new(string name = "my_test", uvm_component parent);
348
        super.new(name, parent);
349
     endfunction
350
 
351
     virtual function void build_phase(uvm_phase phase);
352
        super.build_phase(phase);
353
 
354
      $display("^^^ %16.t | %m | ", $time);
355
 
356
        agent_h = axis_agent #(cfg_a)::type_id::create("agent_h", this);
357
        // agent_b = my_agent#(cfg_b)::type_id::create("agent_b", this);
358
     endfunction
359
 
360
     virtual function void end_of_elaboration_phase(uvm_phase phase);
361
        uvm_phase run_phase = uvm_run_phase::get();
362
        run_phase.phase_done.set_drain_time(this, 300ns);
363
     endfunction
364
 
365
     virtual task run_phase(uvm_phase phase);
366
        axis_counting_sequence #(cfg_a) seq_a;
367
        super.run_phase(phase);
368
 
369
      $display("^^^ %16.t | %m | ", $time);
370
 
371
        phase.raise_objection(this);
372
 
373
        // fork
374
           // repeat (3) begin
375
              seq_a = axis_counting_sequence #(cfg_a)::type_id::create("seq_a");
376
              seq_a.start(agent_h.sequencer);
377
           // end
378
 
379
           // repeat (3) begin
380
              // my_sequence#(cfg_b) seq_b = my_sequence#(cfg_b)::type_id::create("seq_b");
381
              // seq_b.start(agent_b.sequencer);
382
           // end
383
        // join
384
 
385
        phase.drop_objection(this);
386
     endtask
387
  endclass
388
 
389
 
390
// --------------------------------------------------------------------
391
//
392
endpackage: axis_pkg

powered by: WebSVN 2.1.0

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