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] - Rev 36
Go to most recent revision | Compare with Previous | Blame | View Log
////////////////////////////////////////////////////////////////////////// //////// Copyright (C) 2017 Authors and OPENCORES.ORG //////// //////// This source file may be used and distributed without //////// restriction provided that this copyright statement is not //////// removed from the file and that any derivative work contains //////// the original copyright notice and the associated disclaimer. //////// //////// This source file is free software; you can redistribute it //////// and/or modify it under the terms of the GNU Lesser General //////// Public License as published by the Free Software Foundation; //////// either version 2.1 of the License, or (at your option) any //////// later version. //////// //////// This source is distributed in the hope that it will be //////// useful, but WITHOUT ANY WARRANTY; without even the implied //////// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //////// PURPOSE. See the GNU Lesser General Public License for more //////// details. //////// //////// You should have received a copy of the GNU Lesser General //////// Public License along with this source; if not, download it //////// from http://www.opencores.org/lgpl.shtml //////// //////////////////////////////////////////////////////////////////////////package riffa_bfm_class_pkg;// --------------------------------------------------------------------//import q_pkg::*;// --------------------------------------------------------------------//class riffa_transaction_class #(N);rand logic [31:0] len;rand logic [30:0] off;rand logic last;rand logic [(8*N)-1:0] data[];//--------------------------------------------------------------------//function int get_data_size(int len);// int words = $ceil(len/(N/4)); // need to fixint words = len/(N/4);// $display("^^^ %16.t | words = %d", $time, words);return(words);endfunction: get_data_size//--------------------------------------------------------------------//function void constant(int len, int off, bit last, logic [(8*N)-1:0] value);this.data = new[get_data_size(len)];this.len = len;this.off = off;this.last = last;foreach(this.data[i])this.data[i] = value;endfunction: constant//--------------------------------------------------------------------//function void counting(int len, int off, bit last);this.data = new[get_data_size(len)];this.len = len;this.off = off;this.last = last;foreach(this.data[i])this.data[i] = i;endfunction: counting//--------------------------------------------------------------------//function void random(int len, int off, bit last);this.data = new[get_data_size(len)];assert(this.randomize() with{this.len == len; // why not working?this.off == off;this.last == last;});this.len = len;this.off = off;this.last = last;endfunction: random//--------------------------------------------------------------------//function void compare(riffa_transaction_class #(N) to, int max_mismatches = 8);int error_count = 0;$display("!!! %16.t | %m", $time);if(this.len != to.len)$display("!!! %16.t | ERROR! len mismatch", $time);if(this.off != to.off)$display("!!! %16.t | ERROR! off mismatch", $time);if(this.last != to.last)$display("!!! %16.t | ERROR! last mismatch", $time);foreach(this.data[i])beginif(error_count > max_mismatches)break;if(this.data[i] != to.data[i])begin$display("!!! %16.t | ERROR! | 0x%x | this != to | 0x%x != 0x%x", $time, i, this.data[i], to.data[i]);error_count++;endendendfunction: compare// // --------------------------------------------------------------------// //// function void copy(ref riffa_transaction_class #(N) from);// this.len = from.len;// this.off = from.off;// this.last = from.last;// endfunction: copy// // --------------------------------------------------------------------// //// function riffa_transaction_class #(N) clone();// clone = new(0, 0, 0);// clone.copy(this);// endfunction: clone//--------------------------------------------------------------------function new(int len, int off, bit last);this.data = new[get_data_size(len)];this.len = len;this.off = off;this.last = last;endfunction: new// --------------------------------------------------------------------//endclass: riffa_transaction_class// --------------------------------------------------------------------// root port txclass rp_tx_bfm_class #(N)extends blocking_transmission_q_class #(riffa_transaction_class #(N));virtual riffa_chnl_if #(.N(N)) chnl_bus;// --------------------------------------------------------------------//task set_default;chnl_bus.cb_rp_tx.rx <= 0;chnl_bus.cb_rp_tx.rx_last <= 'bx;chnl_bus.cb_rp_tx.rx_len <= 'bx;chnl_bus.cb_rp_tx.rx_off <= 'bx;chnl_bus.cb_rp_tx.rx_data <= 'bx;chnl_bus.cb_rp_tx.rx_data_valid <= 0;endtask: set_default// --------------------------------------------------------------------//event tx_done;task transmit(ref Q_T tr_h);@(chnl_bus.cb_rp_tx);chnl_bus.cb_rp_tx.rx_len <= tr_h.len; // must be => 4chnl_bus.cb_rp_tx.rx_off <= tr_h.off;chnl_bus.cb_rp_tx.rx_last <= tr_h.last;chnl_bus.cb_rp_tx.rx <= 1;@(chnl_bus.cb_rp_tx iff chnl_bus.cb_rp_tx.rx_ack);chnl_bus.cb_rp_tx.rx_data_valid <= 1;foreach(tr_h.data[i])beginchnl_bus.cb_rp_tx.rx_data <= tr_h.data[i];@(chnl_bus.cb_rp_tx iff chnl_bus.cb_rp_tx.rx_data_ren);endset_default();->tx_done;endtask: transmit//--------------------------------------------------------------------//function new(virtual riffa_chnl_if #(.N(N)) chnl_bus);this.chnl_bus = chnl_bus;forkset_default();join_noneendfunction: new// --------------------------------------------------------------------//endclass: rp_tx_bfm_class// --------------------------------------------------------------------// root port rxclass rp_rx_bfm_class #(N)extends blocking_transmission_q_class #(riffa_transaction_class #(N));virtual riffa_chnl_if #(.N(N)) chnl_bus;mailbox #(riffa_transaction_class #(N)) rx_q;// --------------------------------------------------------------------//task set_default;chnl_bus.cb_rp_rx.tx_ack <= 0;chnl_bus.cb_rp_rx.tx_data_ren <= 0;endtask: set_default// --------------------------------------------------------------------//event rx_done;task automatic transmit(ref Q_T tr_h);int last;int len;int off;@(chnl_bus.cb_rp_rx iff chnl_bus.cb_rp_rx.tx);last = chnl_bus.cb_rp_rx.tx_last;len = chnl_bus.cb_rp_rx.tx_len; // must be => 4off = chnl_bus.cb_rp_rx.tx_off;tr_h = new(len, off, last);chnl_bus.cb_rp_rx.tx_ack <= 1;chnl_bus.cb_rp_rx.tx_data_ren <= 1;fork@(chnl_bus.cb_rp_tx)chnl_bus.cb_rp_rx.tx_ack <= 0;join_none// foreach(tr_h.data[i])// @(chnl_bus.cb_rp_tx)// if(~chnl_bus.cb_rp_rx.tx)// break;// else if(chnl_bus.cb_rp_rx.tx_data_valid)// tr_h.data[i] <= chnl_bus.cb_rp_rx.tx_data;foreach(tr_h.data[i])@(chnl_bus.cb_rp_tx iff chnl_bus.cb_rp_rx.tx_data_valid)tr_h.data[i] <= chnl_bus.cb_rp_rx.tx_data;rx_q.put(tr_h);set_default();->rx_done;endtask: transmit//--------------------------------------------------------------------//function new(virtual riffa_chnl_if #(.N(N)) chnl_bus);this.chnl_bus = chnl_bus;this.rx_q = new();forkset_default();join_noneendfunction: new// --------------------------------------------------------------------//endclass: rp_rx_bfm_class// --------------------------------------------------------------------//endpackage: riffa_bfm_class_pkg
Go to most recent revision | Compare with Previous | Blame | View Log
