SPI_Test/tb/testbench/mcureg_tb/mcureg_monitor.sv

110 lines
2.6 KiB
Systemverilog
Raw Permalink Normal View History

2024-06-25 16:41:01 +08:00
class mcureg_monitor;
virtual mcureg_if mif;
virtual spi_if wif;
virtual sram_if xif;
static int pktnum;
//Mask Cache
bit[3 :0] mask_temp[$];
//Collected Vars
mcureg_trans mcu_tr[$];
function new();
endfunction
extern task do_mon();
extern task collect();
endclass : mcureg_monitor
task mcureg_monitor::do_mon();
int pkt_i=0;
fork
while(1) begin: mcureg_monitor
if(pkt_i==pktnum) break;
if(wif.csn) @(negedge wif.csn);
collect();
end: mcureg_monitor
repeat(pktnum) begin: kill_progress
@(negedge wif.csn);
pkt_i++;
end
join
endtask: do_mon
task mcureg_monitor::collect();
mcureg_trans mcu_tr_temp;
bit[31:0] cmd_temp;
int size=0;
int i=0,j=0;
for(j=0;j<31;j++) begin
@(posedge wif.sclk or posedge wif.csn)
if(wif.error_check | wif.csn)
break;
cmd_temp[j] = wif.mosi;
end
size = cmd_temp[1] ? 16 : 1;
mcu_tr.delete;
j=0;
repeat(size) begin
mcu_tr_temp = new();
//if read, collect regfile's input port as exp_data
//act_data is monitored by spi_monitor(MISO)
if(cmd_temp[0]) begin: mcureg_in_monitor
//get the "mask" @ the last write_enable
//because registers update "mask" only @ "wren"
mcu_tr_temp.wrmask = mask_temp[j];
@(posedge xif.rden);
repeat(1) @(posedge wif.clk);
mcu_tr_temp.mcu_param = mif.mcu_param;
mcu_tr_temp.run_time = mif.run_time;
mcu_tr_temp.instr_num = mif.instr_num;
mcu_tr_temp.fb_st_info = mif.fb_st_info;
end: mcureg_in_monitor
//if write, collect regfile's output port as act_data
//exp_data is monitored by spi_monitor(MOSI)
else begin: mcureg_out_monitor
@(posedge xif.wren);
repeat(2) @(posedge wif.clk);
mcu_tr_temp.wrmask = mif.wrmask;
mask_temp[j] = mif.wrmask;
//wait half_clk to sample output port,for stability
@(negedge wif.clk);
mcu_tr_temp.mcu_result = mif.mcu_result;
mcu_tr_temp.mcu_cwfr = mif.mcu_cwfr;
mcu_tr_temp.mcu_gapr = mif.mcu_gapr;
mcu_tr_temp.mcu_ampr = mif.mcu_ampr;
mcu_tr_temp.mcu_baisr = mif.mcu_baisr;
mcu_tr_temp.mcu_intp_sel = mif.mcu_intp_sel;
mcu_tr_temp.mcu_nco_pha_clr = mif.mcu_nco_pha_clr;
mcu_tr_temp.mcu_rz_pha = mif.mcu_rz_pha;
end: mcureg_out_monitor
mcu_tr.push_back(mcu_tr_temp);
j++;
//$display("cmd:%0d",cmd_temp[0]);
//$display("size:%0d",size);
//$display("mcu_param[0]:%d",mcu_tr_temp.mcu_param[0]);
//$display("wrmask:%0d",mcu_tr_temp.wrmask);
end
if(cmd_temp[0] & !wif.csn) @(posedge wif.csn);
endtask