SPI_Test/tb/testbench/awgreg_tb/awgreg_driver.sv

84 lines
1.4 KiB
Systemverilog
Raw Normal View History

2024-06-25 16:41:01 +08:00
class awgreg_driver;
awgreg_trans tr;
//interface
virtual awgreg_if aif;
virtual spi_if wif;
int pktnum;
function new();
endfunction
extern task do_drive();
extern task make_pkt();
endclass : awgreg_driver
task awgreg_driver::do_drive();
int pkt_i = 0;
aif.fb_st_i =3'b0 ;
aif.run_time =32'b0 ;
aif.instr_num =32'b0 ;
aif.mcu_result0 =32'b0 ; // MCU result 0
aif.mcu_result1 =32'b0 ; // MCU result 1
aif.mcu_result2 =32'b0 ; // MCU result 2
aif.mcu_result3 =32'b0 ; // MCU result 3
fork
while(1) begin
if(pkt_i == pktnum) break;
make_pkt();
end
repeat(pktnum) begin: kill_progress
@(negedge wif.csn);
pkt_i++;
end
join
endtask
task awgreg_driver::make_pkt();
int cnt=0;
cnt = 0;
tr = new();
if(!tr.randomize())
$fatal(0,"Randomize Failed");
while(cnt<2000) begin
@(posedge wif.clk);
cnt = cnt + 1;
case(cnt)
tr.fb_st_i_time :
aif.fb_st_i <= tr.fb_st_i ;
tr.run_time_time :
aif.run_time <= tr.run_time ;
tr.instr_num_time :
aif.instr_num <= tr.instr_num ;
tr.mcu_result0_time:
aif.mcu_result0 <= tr.mcu_result0 ;
tr.mcu_result1_time:
aif.mcu_result1 <= tr.mcu_result1 ;
tr.mcu_result2_time:
aif.mcu_result2 <= tr.mcu_result2 ;
tr.mcu_result3_time:
aif.mcu_result3 <= tr.mcu_result3 ;
endcase
end
endtask : make_pkt