UVM前置基礎(chǔ):
1.UVM基礎(chǔ)-factory機(jī)制、phase機(jī)制
2.UVM基礎(chǔ)-組件(driver、monitor、agent...)
3.UVM基礎(chǔ)-TLM通信機(jī)制(一)
4.UVM基礎(chǔ)-TLM通信機(jī)制(二)
...還在更新
從零搭建一個(gè)UVM驗(yàn)證平臺(tái):
從零開始,搭建一個(gè)簡(jiǎn)單的UVM驗(yàn)證平臺(tái)(一)
從零開始,搭建一個(gè)簡(jiǎn)單的UVM驗(yàn)證平臺(tái)(二)
從零開始,搭建一個(gè)簡(jiǎn)單的UVM驗(yàn)證平臺(tái)(三)
從零開始,搭建一個(gè)簡(jiǎn)單的UVM驗(yàn)證平臺(tái)(四)
...還在更新
目錄
reference model
reference model代碼
思路詳解
scoreboard
field_automation 機(jī)制
????????在上篇博客里,我們封裝了monitor來監(jiān)測(cè)輸入及輸出的信號(hào),還將monitor和driver封裝成了一個(gè)可配置是否實(shí)例化driver的功能性agent,再將輸入輸出的兩個(gè)agent封裝到一個(gè)更大的env環(huán)境中。整個(gè)架構(gòu)可以如下描述:
????????這篇文章我們將著重講解如何給我們的驗(yàn)證模塊添加reference model以及scoreboard。
reference model
? ? ? ? 在驗(yàn)證平臺(tái)當(dāng)中,reference model的作用是完成和DUT相同的功能,在我們不確定RTL代碼結(jié)果是否正確的時(shí)候,我們要保證reference model的結(jié)果必須正確,然后再將RTL代碼的結(jié)果和reference model的結(jié)果作對(duì)比,兩者實(shí)現(xiàn)的功能是完全一致的。
reference model代碼
`ifndef MY_REFERENCE_DEFINES
`define MY_REFERENCE_DEFINES
`include "uvm_macros.svh"
`include "my_transaction.sv"
import uvm_pkg::*;
class my_reference_model extends uvm_component;
//TLM 機(jī)制
uvm_blocking_get_port #(my_transaction) port;
uvm_analysis_port #(my_transaction) ap;
extern function new(string name, uvm_component parent);
extern function void build_phase(uvm_phase phase);
extern virtual task main_phase(uvm_phase phase);
`uvm_component_utils(my_reference_model)
endclass
function my_reference_model::new(string name, uvm_component parent);
super.new(name, parent);
endfunction
function void my_reference_model::build_phase(uvm_phase phase);
super.build_phase(phase);
port = new("port", this);
ap = new("ap", this);
endfunction
task my_reference_model::main_phase(uvm_phase phase);
my_transaction tr;
my_transaction new_tr;
super.main_phase(phase);
while(1)begin
port.get(tr);
new_tr = new("new_tr");
new_tr.my_copy(tr);
`uvm_info("my_reference_model", "get one transaction, copy and print it:", UVM_LOW)
new_tr.my_print();
ap.write(new_tr);
end
endtask
`endif
? ? ? ? reference model的代碼,在一開始使用了TLM機(jī)制:
? uvm_blocking_get_port #(my_transaction) port;
? uvm_analysis_port #(my_transaction) ap;?
????????TLM通信需要兩個(gè)通信的對(duì)象,這兩個(gè)對(duì)象分別稱為 initiator 和 target 。區(qū)分它們的方法在于,誰先發(fā)起通信請(qǐng)求,誰就屬于initiator;誰作為發(fā)起通信的響應(yīng)方,誰就屬于target ,但這個(gè)分類并不代表transaction一定是initiator發(fā)起的,transaction也可能是從target流向initiator。
端口按照類型可以劃分為三種:
? ? ? ? ※ port:經(jīng)常作為initiator的發(fā)起端,initiator憑借port才可以訪問target的TLM通信方法。
? ? ? ? ※ export:作為initiator和target中間層次的端口。
? ? ? ? ※ imp:只能作為target接收request的末端,它無法作為中間層次的端口,所以imp的連接無法再次延伸。
????????使用TLM機(jī)制來進(jìn)行transaction的傳輸,? 如果數(shù)據(jù)是從同一個(gè)源的TLM端口發(fā)出到達(dá)不同組件,這就要求該種端口可以滿足從一端到多端的需求,analysis_port 就可以實(shí)現(xiàn)這個(gè)需求。按照傳輸方法和端口方向組合,可以將 analysis port 分為:uvm_analysis_port 、uvm_analysis_export 以及uvm_analysis_imp。
reference model 編寫流程:
????????在reference model中,我們先定義了兩個(gè)port;然后在build_phase里將兩個(gè)port進(jìn)行實(shí)例化;接著運(yùn)行完build_phase進(jìn)入main_phase后,實(shí)例化new_tr,把in_agent中得到的tr復(fù)制一份給scoreboard。my_copy是定義在transaction中的函數(shù):
Transaction
`ifndef MY_TRANS_DEFINES
`define MY_TRANS_DEFINES
`include "uvm_macros.svh"
import uvm_pkg::*;
class my_transaction extends uvm_sequence_item;
rand bit [63:0] password; //assume there is a 64bits password
`uvm_object_utils(my_transaction);
function new(string name = "my_transaction");
super.new(name);
endfunction
function void my_print();
$display("password = %0h", password);
endfunction
extern function void my_copy(my_transaction tr);
endclass
function void my_transaction::my_copy(my_transaction tr);
if(tr == null)
`uvm_fatal("my_transaction", "tr is null!!!")
password = tr.password;
endfunction
`endif
????????這里實(shí)現(xiàn)了兩個(gè)transaction的復(fù)制。不僅如此,因?yàn)樘砑恿藃eference model,這個(gè)組件是搭載在env環(huán)境下的, 所以我們還需要在my_env中對(duì)其進(jìn)行實(shí)例化(在env的build_phase中使用type_id::create創(chuàng)建實(shí)例)。
? ? ? ? 在上面,component之間transaction級(jí)別的數(shù)據(jù)通信是使用TLM機(jī)制進(jìn)行的。我們現(xiàn)在要實(shí)現(xiàn)的目的其實(shí)就是在reference model中,將in_agent中的monitor發(fā)出的transaction復(fù)制到reference model中,在reference model里面我們聲明了TLM機(jī)制中的uvm_blocking_get_port(),并在reference model的main_phase中對(duì)其進(jìn)行了實(shí)例化,然后利用port.get()任務(wù)來得到從in_agent中的monitor發(fā)出的transaction。
? ? ? ? 但截止目前,我們只在reference model中創(chuàng)建了uvm_blocking_get_port,它的目的是接收monitor發(fā)出的transaction,所以我們還需要在monitor中添加發(fā)送transaction的port:
? ? ? ? 在工廠注冊(cè)之前,聲明:uvm_analysis_port #(my_transacion) ap;
? ? ? ? 在monitor的build_phase中將port實(shí)例化:ap = new("new", this);
? ? ? ? 在main_phase中,添加ap.write(tr);//將收集的transaction數(shù)據(jù)寫入tr
? ? ? ? 這里用到的write是uvm_analysis_port的一個(gè)內(nèi)建函數(shù)。
? ? ? ? 以上,在my_monitor和reference model中定義并實(shí)例化了各自的端口后,端口和端口之間并沒有連接在一起,因此我們需要在env環(huán)境中,使用fifo將兩個(gè)端口聯(lián)系在一起,即①在my_env中定義一個(gè)fifo,②并在build_phase中將其實(shí)例化,③并在connect_phase中將fifo分別與my_monitor中的analysis_port和reference model中的blocking_get_port相連:
`include "uvm_macros.svh"
import uvm_pkg::*;
`include "my_agent.sv"
`include "my_transaction.sv"
class my_env extends uvm_env;
my_agent i_agt;
my_agent o_agt;
my_reference_model mrm;
uvm_tlm_analysis_fifo #(my_transaction) agt_mrm_fifo;
function new(string name = "my_env", uvm_component parent);
super.new(name, parent);
endfunction
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
i_agt = my_agent::type_id::create("i_agt", this);
o_agt = my_agent::type_id::create("o_agt", this);
i_agt.is_active = UVM_ACTIVE;
i_agt.is_active = UVM_PASSIVE;
mrm = my_reference_model::type_id::create("mrm", this);
agt_mrm_fifo = new("agt_mon_fifo", this);
endfunction
extern virtual function void connect_phase(uvm_phase phase);
`uvm_component_utils(my_env);
endclass
function void my_env::connect_phase(uvm_phase phase);
super.connect_phase(phase);
in_agt.ap.connect(agt_mrm_fifo.analysis_export);
mrm.port.connect(agt_mrm_fifo.blocking_get_export);
endfunction
????????connect_phase和build_phase以及main_phase類似,都是UVM內(nèi)建的phase,它在build_phase執(zhí)行完成之后馬上執(zhí)行。但是與build_phase不同的是,它執(zhí)行的順序不是從樹根到樹葉,而是從樹葉到樹根---先執(zhí)行driver和monitor的connect_phase,再執(zhí)行agent的connect_phase,最后執(zhí)行env的connect_phase。
思路詳解
? ? ? ? 為了讓思路更加清晰,我們來整理一下上邊my_env的代碼思路:目前在我們的env環(huán)境中,有一個(gè)reference model,in_agent和out_agent,所以要將三個(gè)組件例化;然后我們?cè)趓eference model中設(shè)置了一個(gè)port,在monitor中也設(shè)置了一個(gè)port,利用TLM機(jī)制來傳輸monitor監(jiān)測(cè)到的transaction給reference model。
????????考慮到analysis_port是非阻塞性質(zhì)的,我們實(shí)例化了一個(gè)一transaction為變量類型的fifo來存儲(chǔ)可能會(huì)被blocking_get_port堵塞的transaction;在build_phase中創(chuàng)建agent實(shí)例,并設(shè)置in_agent有driver,out_agent沒有driver(is_active = UVM_PASSIVE);
????????reference model的port連接到monitor的port時(shí)要進(jìn)入到agent組件,這就需要agent組件也得有一個(gè)port供transaction傳輸,所以我們另外還需要在my_agent.sv中聲明一個(gè)port,讓reference model的port連接到in_agent上,再讓in_agent的port連接到monitor上,在connect_phase中連接完所有port后,connect_phase的順序是從樹葉到樹根,所以會(huì)先執(zhí)行my_agent的connect_phase,接著才是執(zhí)行my_env的connect_phase。
scoreboard
? ? ? ? 驗(yàn)證平臺(tái)中已經(jīng)有了reference model和agent,最后一步就是給我們的平臺(tái)添加scoreboard。scoreboard要比較的數(shù)據(jù),一個(gè)是來自reference model,一個(gè)是來自out_agent的monitor。
`include "uvm_macros.svh"
import uvm_pkg::*;
`include "my_transaction.sv"
class my_scoreboard extends uvm_scoreboard;
my_transaction expect_queue [$];
uvm_blocking_get_port #(my_transaction) exp_port;
uvm_blocking_get_port #(my_transaction) act_port;
`uvm_component_utils(my_scoreboard)
extern function new(string name, uvm_component parent = null);
extern virtual function void build_phase(uvm_phase phase);
extern virtual task main_phase(uvm_phase phase);
endclass
function my_scoreboard::new(string name, uvm_component parent = null);
super.new(name, parent);
endfunction
function void my_scoreboard::build_phase(uvm_phase phase);
super.build_phase(phase);
exp_port = new("exp_port", this);
act_port = new("act_port", this);
endfunction
task my_scoreboard::main_phase(uvm_phase phase);
my_transaction get_expect, get_actual, temp_tran;
bit result;
super.main_phase(phase);
fork
while(1)begin
exp_port.get(get_expect);
expect_queue.push_back(get_expect);
end
while(1)begin
act_port.get(get_actual);
if(expect_queue.size()>0)begin
temp_tran = expect_queue.pop_front();
result = get_actual.my_compare(temp_tran);//比較
if(result)begin
`uvm_info("my_scoreboard", "Compare SUCCESSFULLY", UVM_LOW)
end
else begin
`uvm_error("my_scoreboard", "Compare FALLED")
$display("the expect password is");
temp_tran.my_print();
$display("the actual password is");
get_actual.my_print();
end
end
else begin
`uvm_error("my_scoreboard", "Received from DUT, while Expect queue is empty")
$display("the unexpected password is");
get_actual.my_print();
end
end
join
endtask
? ? ? ? 在上面這段代碼中通過fork建立了兩個(gè)進(jìn)程,一個(gè)進(jìn)程處理exp_port的數(shù)據(jù),當(dāng)收到數(shù)據(jù)后,把數(shù)據(jù)放到expect_queue中;另外一個(gè)進(jìn)程處理act_port數(shù)據(jù),這是DUT的輸出數(shù)據(jù),當(dāng)收集到這些數(shù)據(jù)后,從expect_queue中彈出之前從exp_port收到的數(shù)據(jù),并調(diào)用my_transaction中的my_compare函數(shù)。這樣處理的前提是exp_port要比act_port先收到數(shù)據(jù),由于DUT處理數(shù)據(jù)需要延時(shí),而reference model是基于高級(jí)語言的處理,一般不需要延時(shí),因此可以保證exp_port的數(shù)據(jù)在act_port的數(shù)據(jù)之前到來。?
? ? ? ? 另外別忘了,寫了scoreboard之后,我們還需要在env環(huán)境中創(chuàng)建并實(shí)例化該組件,然后在connect_phase中,將組件與組件之間的port連接好。
`ifndef MY_ENV_SV
`define MY_ENV_SV
`include "uvm_macros.svh"
import uvm_pkg::*;
`include "my_agent.sv"
`include "my_transaction.sv"
`include "my_reference_model.sv"
`include "my_scoreboard.sv"
class my_env extends uvm_env;
my_agent in_agt;
my_agent out_agt;
my_reference_model mrm;
my_scoreboard scb;
uvm_tlm_analysis_fifo #(my_transaction) agt_mrm_fifo;
uvm_tlm_analysis_fifo #(my_transaction) agt_scb_fifo;
uvm_tlm_analysis_fifo #(my_transaction) mrm_scb_fifo;
function new(string name = "my_env", uvm_component parent);
super.new(name, parent);
endfunction
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
in_agt = my_agent::type_id::create("in_agt", this);
out_agt = my_agent::type_id::create("out_agt", this);
in_agt.is_active = UVM_ACTIVE;
out_agt.is_active = UVM_PASSIVE;
mrm = my_reference_model::type_id::create("mrm", this);
scb = my_scoreboard::type_id::create("scb", this);
agt_mrm_fifo = new("agt_mon_fifo", this);
agt_scb_fifo = new("agt_scb_fifo", this);
mrm_scb_fifo = new("mrm_scb_fifo", this);
endfunction
extern virtual function void connect_phase(uvm_phase phase);
`uvm_component_utils(my_env);
endclass
function void my_env::connect_phase(uvm_phase phase);
super.connect_phase(phase);
//connect input agent with reference model
in_agt.ap.connect(agt_mrm_fifo.analysis_export);
mrm.port.connect(agt_mrm_fifo.blocking_get_export);
//connect reference model with scoreboard
mrm.ap.connect(mrm_scb_fifo.analysis_export);
scb.exp_port.connect(mrm_scb_fifo.blocking_get_export);
//connect output agent with scoreboard
out_agt.ap.connect(agt_scb_fifo.analysis_export);
scb.act_port.connect(agt_scb_fifo.blocking_get_export);
endfunction
`endif
????????在transaction中定義一個(gè)compare函數(shù),很簡(jiǎn)單,比較發(fā)送的transaction中的password是否一致即可,但這一步compare函數(shù)可以通過field_automation機(jī)制省略自定義的過程,但為了體現(xiàn)field_automation機(jī)制的優(yōu)越性,我們還是先使用自定義的compare方法:
`ifndef MY_TRANS_DEFINES
`define MY_TRANS_DEFINES
`include "uvm_macros.svh"
import uvm_pkg::*;
class my_transaction extends uvm_sequence_item;
rand bit [63:0] password; //assume there is a 64bits password
`uvm_object_utils(my_transaction);
function new(string name = "my_transaction");
super.new(name);
endfunction
function void my_print();
$display("password = %0h", password);
endfunction
extern function void my_copy(my_transaction tr);
extern function bit my_compare(my_transaction);
endclass
function void my_transaction::my_copy(my_transaction tr);
if(tr == null)
`uvm_fatal("my_transaction", "tr is null!!!")
password = tr.password;
endfunction
function bit my_transaction::my_compare(my_transaction tr);
bit result;
if(tr == null)
`uvm_fatal("my_transaction", "tr is null!");
result = (password == tr.password);
return result;
endfunction
`endif
field_automation 機(jī)制
? ? ? ? 在transaction.sv中我們?cè)趖ransaction里定義了很多的function,譬如my_print、my_compare 函數(shù),它們都有一個(gè)特點(diǎn)就是需要逐字段地對(duì)transaction進(jìn)行某些操作。但其實(shí)這些函數(shù)我們可以不用自己定義,而是使用UVM中的field_automation機(jī)制,使用uvm_field來自動(dòng)預(yù)定義好這些常用的函數(shù),而不需要自己額外定義了。
????????由宏定義`uvm_object_utils_begin和`uvm_object_utils_end包起來的部分,為域自動(dòng)化部分。UVM_ALL_ON是一個(gè)用于數(shù)據(jù)操作的內(nèi)容
`ifndef MY_TRANS_DEFINES
`define MY_TRANS_DEFINES
`include "uvm_macros.svh"
import uvm_pkg::*;
class my_transaction extends uvm_sequence_item;
rand bit [63:0] password; //assume there is a 64bits password
`uvm_object_utils_begin(my_transaction);
`uvm_field_int(password, UVM_ALL_ON)
`uvm_object_utils_end
function new(string name = "my_transaction");
super.new(name);
endfunction
endclass
`endif
? ? ? ? 使用了域的自動(dòng)化后,我們的transaction的代碼量就大大減小了。當(dāng)上述宏注冊(cè)之后,可以直接調(diào)用copy、compare、print等函數(shù),極大的簡(jiǎn)化了驗(yàn)證平臺(tái)的搭建,提高了效率。
? ? ? ? 加入scoreboard 以及 reference model之后,我們現(xiàn)在的整個(gè)驗(yàn)證框架如圖所示:
文章來源:http://www.zghlxwxcb.cn/news/detail-412827.html
? ? ? ? 在這篇文章里,我們?cè)趀nv環(huán)境中添加了reference model 以及 scoreboard并在各個(gè)組件的connect_phase中,將組件與組件之間的port連接在了一起,并且利用UVM的field_automation機(jī)制,可以調(diào)用自定義的函數(shù)print、copy、compare等,極大的簡(jiǎn)化了我們transaction的代碼。下篇博客我們將著重講解如何給我們的驗(yàn)證環(huán)境添加sequencer。文章來源地址http://www.zghlxwxcb.cn/news/detail-412827.html
到了這里,關(guān)于從零開始,搭建一個(gè)簡(jiǎn)單的UVM驗(yàn)證平臺(tái)(四)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!