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