1 .monitor设置uvm_analysis_port,scoreboard设置uvm_analysis_imp.在monitor调用port的地方一般是在monitor获取有效监测数据的地方。此时需注意 port.write(tr), 这里的tr必须要每次调用都要new一下,这样子传到scoreboard的wrtite函数口上时,每次的数据是不一样的。否则write函数中将传送的tr push到queue或者fifo里面的时候都是同样的值,不能够获取到全部的有效数据。
具体写法。
monitor中:
class monitor extends uvm_monitor;
`uvm_component_utils(monitor)
uvm_analysis_port #(transaction) monitor_port;
。。。。。。。
virtual function build_phase(uvm_phase phase)
super.build_phase(phase);
monitor_port = new("monitor_port",this);
endfunction
virtual task run_phase(uvm_phase phase);
super.run_phase(phase);
while(1)begin
@(posedge clk);
if(valid=1)begin
transaction tr=new("tr");
tr.a=vif.data;
port.write(tr);
end
end
endtask
endclass
scorboard中关键部分。
class scoreboard extends uvm_scoreboard;
`uvm_component_utils(scoreboard)
uvm_analysis_imp #(transaction,scoreboard) scoreboard_imp;
//if has another name imp
//`uvm_analysis_imp_decl(_ll)
//uvm_analysis_imp_ll #(transaction,scoreboard) scoreboard_imp;
//what's more,write() function must be replaced by name write_ll();
transaction expect_queue[$];//这里的queue没有new的过程,不知道为什么
virtual function build_phase(uvm_phase phase);
super.build_phase(phase);
scoreborad_imp=new("scoreboard_imp");
endfunction
virtual task run_phase(uvm_phase phase);
super.run_phase(phase);
//do nothing.
endfunction
virtual function write(transaction tr);
transaction tr_copy=new("tr_copy");
tr_copy=tr;
expect_queue.push_back(tr_copy);
//this place can add some comparasion when received one transaction ,it called compared sychornously.
endfunction
virtual function report_phase(uvm_phase phase);
super.report_phase(phase);
//do compare after run_phase finished. due to phase execution rule. this means expect_queue collected all the information you wanted and just use it to compare.
endfunction
endclass
scoreboard 中,将tr传送给内部的queue的实现。取别名的声明方式。同步比较和run_phase完成后的异步比较。
2. monitor 中的所需要的信号尽量是一个时钟域的,也就是说interface里面尽量只有一个clk,方便后面的scoreboard进行对比处理。否则的话,可以包成多个小monitor。
3. monitor采样的技巧。
如果所需数据出现在clk上升沿的后面不是很对齐且小于半个周期的时候,把clk反一下使其延迟半个周期去采数据,就可以采到了。(clk处理的极限是半个周期)
4. 怎么排除指定3个时钟周期采同一值的情况里出现了1个周期出现了同样值的极端。
采样周期内再嵌套一层只有3个周期都是同一个值的这种情况才记录,加个counter。 counter为3时才去采。counter不为3就不采。