| 1 |
50 |
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 bfm_pkg::*;
|
| 37 |
|
|
|
| 38 |
|
|
// --------------------------------------------------------------------
|
| 39 |
|
|
//
|
| 40 |
|
|
typedef struct
|
| 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 |
|
|
delay_class delay_h;
|
| 70 |
|
|
rand logic [(8*N)-1:0] tdata;
|
| 71 |
|
|
rand logic [N-1:0] tstrb;
|
| 72 |
|
|
rand logic [N-1:0] tkeep;
|
| 73 |
|
|
rand logic tlast;
|
| 74 |
|
|
rand logic [I-1:0] tid;
|
| 75 |
|
|
rand logic [D-1:0] tdest;
|
| 76 |
|
|
rand logic [U-1:0] tuser;
|
| 77 |
|
|
|
| 78 |
|
|
// --------------------------------------------------------------------
|
| 79 |
|
|
//
|
| 80 |
|
|
function new(string name = "");
|
| 81 |
|
|
super.new(name);
|
| 82 |
|
|
delay_h = new;
|
| 83 |
|
|
endfunction : new
|
| 84 |
|
|
|
| 85 |
|
|
// --------------------------------------------------------------------
|
| 86 |
|
|
//
|
| 87 |
|
|
function bit do_compare(uvm_object rhs, uvm_comparer comparer);
|
| 88 |
|
|
axis_sequence_item #(cfg) tested;
|
| 89 |
|
|
bit same;
|
| 90 |
|
|
|
| 91 |
|
|
if (rhs==null)
|
| 92 |
|
|
`uvm_fatal(get_type_name(), "| %m | comparison to a null pointer");
|
| 93 |
|
|
|
| 94 |
|
|
if (!$cast(tested,rhs))
|
| 95 |
|
|
same = 0;
|
| 96 |
|
|
else
|
| 97 |
|
|
same = super.do_compare(rhs, comparer)
|
| 98 |
|
|
& (tested.tdata == tdata)
|
| 99 |
|
|
& (USE_TSTRB ? (tested.tstrb == tstrb) : 1)
|
| 100 |
|
|
& (USE_TKEEP ? (tested.tkeep == tkeep) : 1)
|
| 101 |
|
|
& (tested.tlast == tlast)
|
| 102 |
|
|
& (USE_ROUTING ? (tested.tid == tid) : 1)
|
| 103 |
|
|
& (USE_ROUTING ? (tested.tdest == tdest) : 1)
|
| 104 |
|
|
& (tested.tuser == tuser);
|
| 105 |
|
|
return same;
|
| 106 |
|
|
endfunction : do_compare
|
| 107 |
|
|
|
| 108 |
|
|
// --------------------------------------------------------------------
|
| 109 |
|
|
//
|
| 110 |
|
|
function void do_copy(uvm_object rhs);
|
| 111 |
|
|
axis_sequence_item #(cfg) item;
|
| 112 |
|
|
assert(rhs != null) else
|
| 113 |
|
|
`uvm_fatal(get_type_name(), "| %m | copy null transaction");
|
| 114 |
|
|
super.do_copy(rhs);
|
| 115 |
|
|
assert($cast(item,rhs)) else
|
| 116 |
|
|
`uvm_fatal(get_type_name(), "| %m | failed cast");
|
| 117 |
|
|
tdata = item.tdata;
|
| 118 |
|
|
tstrb = item.tstrb;
|
| 119 |
|
|
tkeep = item.tkeep;
|
| 120 |
|
|
tlast = item.tlast;
|
| 121 |
|
|
tid = item.tid;
|
| 122 |
|
|
tdest = item.tdest;
|
| 123 |
|
|
tuser = item.tuser;
|
| 124 |
|
|
endfunction : do_copy
|
| 125 |
|
|
|
| 126 |
|
|
// --------------------------------------------------------------------
|
| 127 |
|
|
//
|
| 128 |
|
|
function string convert2string();
|
| 129 |
|
|
string s0, s1;
|
| 130 |
|
|
s0 = $sformatf("| tdata: %h\n" ,tdata);
|
| 131 |
|
|
s1 = $sformatf("| tlast: %1h | tuser: %h" , tlast, tuser);
|
| 132 |
|
|
return {s1, s0};
|
| 133 |
|
|
endfunction : convert2string
|
| 134 |
|
|
|
| 135 |
|
|
// --------------------------------------------------------------------
|
| 136 |
|
|
//
|
| 137 |
|
|
endclass : axis_sequence_item
|
| 138 |
|
|
|
| 139 |
|
|
// --------------------------------------------------------------------
|
| 140 |
|
|
//
|
| 141 |
|
|
class axis_driver #(parameter axis_config_t cfg)
|
| 142 |
|
|
extends uvm_driver #(axis_sequence_item #(cfg));
|
| 143 |
|
|
`uvm_component_param_utils(axis_driver#(cfg))
|
| 144 |
|
|
|
| 145 |
|
|
// --------------------------------------------------------------------
|
| 146 |
|
|
//
|
| 147 |
|
|
localparam N = cfg.N;
|
| 148 |
|
|
localparam I = cfg.I;
|
| 149 |
|
|
localparam D = cfg.D;
|
| 150 |
|
|
localparam U = cfg.U;
|
| 151 |
|
|
localparam USE_TSTRB = cfg.USE_TSTRB;
|
| 152 |
|
|
localparam USE_TKEEP = cfg.USE_TKEEP;
|
| 153 |
|
|
localparam USE_ROUTING = cfg.USE_ROUTING;
|
| 154 |
|
|
|
| 155 |
|
|
// --------------------------------------------------------------------
|
| 156 |
|
|
//
|
| 157 |
|
|
virtual axis_if #(.N(N), .I(I), .D(D), .U(U)) axis_bus;
|
| 158 |
|
|
|
| 159 |
|
|
//--------------------------------------------------------------------
|
| 160 |
|
|
//
|
| 161 |
|
|
function void set_default;
|
| 162 |
|
|
axis_bus.cb_m.tvalid <= 0;
|
| 163 |
|
|
axis_bus.cb_m.tdata <= 'bx;
|
| 164 |
|
|
axis_bus.cb_m.tstrb <= 'bx;
|
| 165 |
|
|
axis_bus.cb_m.tkeep <= 'bx;
|
| 166 |
|
|
axis_bus.cb_m.tlast <= 'bx;
|
| 167 |
|
|
axis_bus.cb_m.tid <= 'bx;
|
| 168 |
|
|
axis_bus.cb_m.tdest <= 'bx;
|
| 169 |
|
|
axis_bus.cb_m.tuser <= 'bx;
|
| 170 |
|
|
endfunction: set_default
|
| 171 |
|
|
|
| 172 |
|
|
//--------------------------------------------------------------------
|
| 173 |
|
|
//
|
| 174 |
|
|
virtual task run_phase(uvm_phase phase);
|
| 175 |
|
|
axis_sequence_item #(cfg) item;
|
| 176 |
|
|
super.run_phase(phase);
|
| 177 |
|
|
|
| 178 |
|
|
set_default();
|
| 179 |
|
|
wait(~axis_bus.aresetn);
|
| 180 |
|
|
@(axis_bus.cb_m);
|
| 181 |
|
|
|
| 182 |
|
|
forever
|
| 183 |
|
|
begin
|
| 184 |
|
|
// seq_item_port.try_next_item(item);
|
| 185 |
|
|
seq_item_port.get_next_item(item);
|
| 186 |
|
|
|
| 187 |
|
|
axis_bus.cb_m.tvalid <= 1;
|
| 188 |
|
|
axis_bus.cb_m.tdata <= item.tdata;
|
| 189 |
|
|
axis_bus.cb_m.tstrb <= 0;
|
| 190 |
|
|
axis_bus.cb_m.tkeep <= 0;
|
| 191 |
|
|
axis_bus.cb_m.tlast <= item.tlast;
|
| 192 |
|
|
axis_bus.cb_m.tid <= 0;
|
| 193 |
|
|
axis_bus.cb_m.tdest <= 0;
|
| 194 |
|
|
axis_bus.cb_m.tuser <= item.tuser;
|
| 195 |
|
|
|
| 196 |
|
|
@(axis_bus.cb_m);
|
| 197 |
|
|
wait(axis_bus.cb_m.tready);
|
| 198 |
|
|
// @(axis_bus.cb_m iff axis_bus.cb_m.tready);
|
| 199 |
|
|
|
| 200 |
|
|
set_default();
|
| 201 |
|
|
repeat(item.delay_h.next()) @(axis_bus.cb_m);
|
| 202 |
|
|
|
| 203 |
|
|
seq_item_port.item_done();
|
| 204 |
|
|
end
|
| 205 |
|
|
endtask : run_phase
|
| 206 |
|
|
|
| 207 |
|
|
//--------------------------------------------------------------------
|
| 208 |
|
|
//
|
| 209 |
|
|
function new(string name, uvm_component parent);
|
| 210 |
|
|
super.new(name, parent);
|
| 211 |
|
|
endfunction
|
| 212 |
|
|
|
| 213 |
|
|
// --------------------------------------------------------------------
|
| 214 |
|
|
//
|
| 215 |
|
|
endclass : axis_driver
|
| 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 |
|
|
endfunction
|
| 228 |
|
|
|
| 229 |
|
|
// --------------------------------------------------------------------
|
| 230 |
|
|
//
|
| 231 |
|
|
endclass : axis_sequencer
|
| 232 |
|
|
|
| 233 |
|
|
// --------------------------------------------------------------------
|
| 234 |
|
|
//
|
| 235 |
|
|
class axis_counting_sequence #(axis_config_t cfg)
|
| 236 |
|
|
extends uvm_sequence #(axis_sequence_item #(cfg));
|
| 237 |
|
|
`uvm_object_param_utils(axis_counting_sequence #(cfg))
|
| 238 |
|
|
|
| 239 |
|
|
rand int length = 16;
|
| 240 |
|
|
|
| 241 |
|
|
// --------------------------------------------------------------------
|
| 242 |
|
|
//
|
| 243 |
|
|
virtual task body();
|
| 244 |
|
|
axis_sequence_item #(cfg) item;
|
| 245 |
|
|
|
| 246 |
|
|
for(int i = 0; i < length; i++)
|
| 247 |
|
|
begin
|
| 248 |
|
|
item = axis_sequence_item #(cfg)::type_id::create("axis_sequence_item");
|
| 249 |
|
|
|
| 250 |
|
|
item.tdata = i;
|
| 251 |
|
|
item.tlast = (i == length - 1);
|
| 252 |
|
|
|
| 253 |
|
|
start_item (item);
|
| 254 |
|
|
finish_item(item);
|
| 255 |
|
|
end
|
| 256 |
|
|
endtask
|
| 257 |
|
|
|
| 258 |
|
|
// --------------------------------------------------------------------
|
| 259 |
|
|
//
|
| 260 |
|
|
function new(string name = "axis_counting_sequence");
|
| 261 |
|
|
super.new(name);
|
| 262 |
|
|
endfunction
|
| 263 |
|
|
|
| 264 |
|
|
// --------------------------------------------------------------------
|
| 265 |
|
|
//
|
| 266 |
|
|
endclass : axis_counting_sequence
|
| 267 |
|
|
|
| 268 |
|
|
// --------------------------------------------------------------------
|
| 269 |
|
|
//
|
| 270 |
|
|
class axis_agent #(axis_config_t cfg)
|
| 271 |
|
|
extends uvm_agent;
|
| 272 |
|
|
`uvm_component_param_utils(axis_agent #(cfg))
|
| 273 |
|
|
|
| 274 |
|
|
// --------------------------------------------------------------------
|
| 275 |
|
|
//
|
| 276 |
|
|
localparam N = cfg.N;
|
| 277 |
|
|
localparam I = cfg.I;
|
| 278 |
|
|
localparam D = cfg.D;
|
| 279 |
|
|
localparam U = cfg.U;
|
| 280 |
|
|
localparam USE_TSTRB = cfg.USE_TSTRB;
|
| 281 |
|
|
localparam USE_TKEEP = cfg.USE_TKEEP;
|
| 282 |
|
|
localparam USE_ROUTING = cfg.USE_ROUTING;
|
| 283 |
|
|
|
| 284 |
|
|
// --------------------------------------------------------------------
|
| 285 |
|
|
//
|
| 286 |
|
|
virtual axis_if #(.N(N), .I(I), .D(D), .U(U)) axis_bus;
|
| 287 |
|
|
|
| 288 |
|
|
axis_driver #(cfg) driver;
|
| 289 |
|
|
// my_monitor #(cfg) monitor;
|
| 290 |
|
|
axis_sequencer #(cfg) sequencer;
|
| 291 |
|
|
|
| 292 |
|
|
// --------------------------------------------------------------------
|
| 293 |
|
|
//
|
| 294 |
|
|
virtual function void build_phase(uvm_phase phase);
|
| 295 |
|
|
super.build_phase(phase);
|
| 296 |
|
|
|
| 297 |
|
|
if(!uvm_config_db #(virtual axis_if #(.N(N), .I(I), .D(D), .U(U)))::get(this, "", "axis_bus", axis_bus))
|
| 298 |
|
|
`uvm_fatal(get_name(), "Couldn't get virtual interface!")
|
| 299 |
|
|
|
| 300 |
|
|
driver = axis_driver #(cfg)::type_id::create("driver", this);
|
| 301 |
|
|
// monitor = my_monitor #(cfg)::type_id::create("monitor" , this);
|
| 302 |
|
|
sequencer = axis_sequencer #(cfg)::type_id::create("sequencer", this);
|
| 303 |
|
|
endfunction
|
| 304 |
|
|
|
| 305 |
|
|
// --------------------------------------------------------------------
|
| 306 |
|
|
//
|
| 307 |
|
|
virtual function void connect_phase(uvm_phase phase);
|
| 308 |
|
|
super.connect_phase(phase);
|
| 309 |
|
|
|
| 310 |
|
|
driver.axis_bus = axis_bus;
|
| 311 |
|
|
// monitor.vif = vif;
|
| 312 |
|
|
|
| 313 |
|
|
driver.seq_item_port.connect(sequencer.seq_item_export);
|
| 314 |
|
|
endfunction
|
| 315 |
|
|
|
| 316 |
|
|
// --------------------------------------------------------------------
|
| 317 |
|
|
//
|
| 318 |
|
|
function new(string name, uvm_component parent);
|
| 319 |
|
|
super.new(name, parent);
|
| 320 |
|
|
endfunction
|
| 321 |
|
|
|
| 322 |
|
|
// --------------------------------------------------------------------
|
| 323 |
|
|
//
|
| 324 |
|
|
endclass : axis_agent
|
| 325 |
|
|
|
| 326 |
|
|
// --------------------------------------------------------------------
|
| 327 |
|
|
//
|
| 328 |
|
|
endpackage: axis_pkg
|