删除driver不必要的时序,使得时序更加紧凑
构建monitor:
在lvc_ahb_transaction中加入一个函数,使得添加数据时自动扩充:
function void increase_data(int n = 1);//如果新加入data,将data宽度+1,再把之前的data放入
data = new[data.size + 1] (data);
all_beat_response = new[all_beat_response.size + 1] (all_beat_response);
endfunction
lvc_ahb_monitor:
第一个周期从vif记录各种状态信号,第二周期记录读写数据 和write read同步
`ifndef LVC_AHB_MONITOR_SV
`define LVC_AHB_MONITOR_SV
class lvc_ahb_monitor extends uvm_monitor;
lvc_ahb_agent_configuration cfg;//添加配置、virtual接口
virtual lvc_ahb_if vif;
uvm_analysis_port #(lvc_ahb_transaction) item_observed_port;//广播到cov、scb
`uvm_component_utils(lvc_ahb_monitor)
function new(string name = "lvc_ahb_monitor", uvm_component parent = null);
super.new(name, parent);
item_observed_port = new("item_observed_port", this);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
endfunction
function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
endfunction
task run_phase(uvm_phase phase);
super.run_phase(phase);
fork
monitor_transactions();
join_none
endtask
task monitor_transactions();
lvc_ahb_transaction t;
forever begin
collect_transfer(t);
item_observed_port.write(t);//collect采样到transfer后通过analysis_port广播出去
end
endtask
task collect_transfer(output lvc_ahb_transaction t);
// collect transfer from interface收集interface来的trans
t = lvc_ahb_transaction::type_id::create("t");//创建一个trans
@(vif.cb_mon iff vif.cb_mon.htrans == NSEQ);//等到NSEQ开始(trans是向量和左边枚举类型有隐式转化)
t.trans_type = trans_type_enum'(vif.cb_mon.htrans);//把状态记录下来
t.xact_type = xact_type_enum'(vif.cb_mon.hwrite);//记录是write or read
t.burst_type = burst_type_enum'(vif.cb_mon.hburst);
t.burst_size = burst_size_enum'(vif.cb_mon.hsize);
t.addr = vif.cb_mon.haddr;
forever begin
monitor_valid_data(t);
if(t.trans_type == IDLE)
break;
end
t.response_type = t.all_beat_response[t.current_data_beat_num];//记录数据的最后一个rsp
endtask
task monitor_valid_data(lvc_ahb_transaction t);
@(vif.cb_mon iff vif.cb_mon.hready);
t.increase_data();//data新增加一位
t.current_data_beat_num = t.data.size() - 1;//当前传输的位数
t.data[t.current_data_beat_num] = t.xact_type == WRITE ? vif.cb_mon.hwdata : vif.cb_mon.hrdata;//判断读写传入数据
t.all_beat_response[t.current_data_beat_num] = response_type_enum'(vif.cb_mon.hresp);//传入当前rsp
t.trans_type = trans_type_enum'(vif.cb_mon.htrans);//当前传输状态
endtask
endclass
`endif // LVC_AHB_MONITOR_SV