写了个tb
`ifdef FOLD // instantiation
dut_top u_dut_top(
.i_rx_clk (rx_intf.clk ),
.i_rx_rst (rx_intf.rst ),
.o_rx_rdy (rx_intf.rdy ),
.i_rx_vld (rx_intf.vld ),
.i_rx_sop (rx_intf.sop ),
.i_rx_eop (rx_intf.eop ),
.i_rx_err (rx_intf.err ),
.i_rx_empty (rx_intf.empty),
.i_rx_data (rx_intf.data ),
.i_tx_clk (tx_intf.clk ),
.i_tx_rst (tx_intf.rst ),
.i_tx_rdy (tx_intf.rdy ),
.o_tx_vld (tx_intf.vld ),
.o_tx_sop (tx_intf.sop ),
.o_tx_eop (tx_intf.eop ),
.o_tx_err (tx_intf.err ),
.o_tx_empty (tx_intf.empty),
.o_tx_data (tx_intf.data )
);
`endif
`ifdef FOLD //main logic
`include "../task_func/drv_intf.sv"
initial begin
Common common_obj;
common_obj = new();
common_obj.drive32("./**********srcfile", rx_intf);
end
`endif
Common类文件
class Common;
static int cnt=0; //已创建的对象的数目
int id;
virtual avalon32_interface drv_intf;
function new;
id = cnt++;
endfunction
task drive32(string linefpath, virtual avalon32_interface drv_intf);
automatic int f0=0;
automatic string line;
automatic logic vld ;
automatic logic sop ;
automatic logic eop ;
automatic logic err ;
automatic logic [01:00] empty;
automatic logic [03:00] keep ;
automatic logic [31:00] data ;
automatic logic [31:00] size ;
f0 = $fopen(linefpath, "r");
if(f0 == 0) $fatal("%s can not open", linefpath);
drv_intf.vld = 'd0;
drv_intf.sop = 'd0;
drv_intf.eop = 'd0;
drv_intf.err = 'd0;
drv_intf.empty = 'd0;
drv_intf.data = 'd0;
wait(!drv_intf.rst);
repeat(100) @(posedge drv_intf.clk);
while(1) begin
drv_intf.vld = 'd0;
drv_intf.sop = 'd0;
drv_intf.eop = 'd0;
drv_intf.err = 'd0;
drv_intf.empty = 'd0;
drv_intf.data = 'd0;
if(!drv_intf.rdy) begin
@(posedge drv_intf.clk);
end
else begin
$fgets(line, f0);
//1.这样是可以的
$sscanf(line, "%h %d %d %d %d %d %d",
data ,
empty,
sop ,
eop ,
vld ,
err ,
size );
drv_intf.data = data ;
drv_intf.empty = empty;
drv_intf.sop = sop ;
drv_intf.eop = eop ;
drv_intf.vld = vld ;
drv_intf.err = err ;
drv_intf.size = size ;
//2.这样是不可以的(sop,.eop,vld等会有Z态)
`ifdef USELESS
$sscanf(line, "%h %d %d %d %d %d %d",
drv_intf.data ,
drv_intf.empty,
drv_intf.sop ,
drv_intf.eop ,
drv_intf.vld ,
drv_intf.err ,
drv_intf.size );
`endif
$display("%h %d %d %d %d %d %d",
drv_intf.data ,
drv_intf.empty,
drv_intf.sop ,
drv_intf.eop ,
drv_intf.vld ,
drv_intf.err ,
drv_intf.size );
@(posedge drv_intf.clk);
end
end
$fclose(f0);
endtask
endclass:Common