UVM学习整理——UVM结构(component派生类)
目錄
二、UVM結(jié)構(gòu)
2.1UVM組件
2.1.1uvm_driver
2.1.2uvm_monitor
2.1.3uvm_sequencer
2.1.4uvm_agent
2.1.5uvm_scoreboard
2.1.6reference model
2.1.7uvm_env
2.1.8uvm_test
2.1.9uvm_component相關(guān)宏
2.2UVM驗(yàn)證平臺(tái)的樹(shù)形結(jié)構(gòu)
二、UVM結(jié)構(gòu)
2.1UVM組件
UVM的組件(uvm_component類(lèi))繼承于UVM的核心基類(lèi)中一個(gè)核心分支,均可構(gòu)成驗(yàn)證環(huán)境,這是因?yàn)樗鼈兌紡膗vm_component類(lèi)繼承了phase機(jī)制(必須在build_phase中實(shí)例化),都會(huì)經(jīng)歷各個(gè)phase階段。主要介紹構(gòu)成環(huán)境的常見(jiàn)組件類(lèi):uvm_driver、uvm_monitor、uvm_sequencer、uvm_agent、uvm_scoreboard、uvm_env和uvm_test等。
圖 5uvm_component類(lèi)和子類(lèi)
2.1.1uvm_driver
所有driver派生自u(píng)vm_driver。Driver的功能主要就是向sequencer索要sequence_item(transaction),并通過(guò)虛擬接口把sequence_item里的信息驅(qū)動(dòng)到DUT的接口上。相當(dāng)于完成了transaction級(jí)別到DUT能夠接受的端口級(jí)別信息的轉(zhuǎn)變。
drive使用工廠機(jī)制注冊(cè)類(lèi)通常需要三步:聲明,注冊(cè),調(diào)用new()函數(shù)。
class my_driver extends uvm_driver#(my_transaction);? ? //my_transaction是sequence item類(lèi)型virtual my_if vif; //virtual interface`uvm_component_utils(my_driver) //在factory中注冊(cè)my_driverfunction new(string name = "my_driver", uvm_component parent = null);super.new(name, parent);endfunctionvirtual function void build_phase(uvm_phase phase);super.build_phase(phase);if(!uvm_config_db#(virtual my_if)::get(this, "", "vif", vif))`uvm_fatal("my_driver", "virtual interface must be set for vif!!!")endfunctionextern task main_phase(uvm_phase phase);extern task drive_one_pkt(my_transaction tr); endclassuvm_driver在uvm_component基礎(chǔ)上沒(méi)有擴(kuò)展新的函數(shù)/任務(wù),而只是擴(kuò)展了一些用來(lái)通信的端口seq_item_port和rsp_port。在構(gòu)建環(huán)境組件時(shí),派生uvm_driver和uvm_sequencer的類(lèi),可以直接使用這些成員變量。
如果不想使用自帶的成員變量,想加入改動(dòng),也可以由uvm_component來(lái)派生Driver等組件,然后自行定義uvm_seq_item_pull_port #(REQ, RSP)等類(lèi)型的變量,名字可以不再是seq_item_port等(源碼見(jiàn)附錄一)。
注:uvm_driver和子類(lèi)都是參數(shù)化類(lèi),定義新driver類(lèi)時(shí),應(yīng)聲明獲取的事務(wù)參數(shù)REQ類(lèi)型(事務(wù)參數(shù))。
2.1.2uvm_monitor
monitor通過(guò)虛擬接口收集總線信息,并將數(shù)據(jù)轉(zhuǎn)換成transation級(jí)別的sequence_item,再通過(guò)端口將數(shù)據(jù)發(fā)送至其他驗(yàn)證組件。收集的數(shù)據(jù)可用于簡(jiǎn)單的功能和時(shí)序檢查。
所有用戶(hù)自定義數(shù)據(jù)監(jiān)測(cè)行為的monitor都繼承自u(píng)vm_monitor,uvm_monitor繼承自u(píng)vm_component,從源代碼來(lái)看并沒(méi)有增添新的成員和方法,但將monitor類(lèi)都繼承于uvm_monitor有助于實(shí)現(xiàn)父類(lèi)monitor的方法和特性。(源碼見(jiàn)附錄一)
monitor使用工廠機(jī)制注冊(cè)類(lèi)通常也需要三步:聲明uvm_monitor,向工廠注冊(cè)并調(diào)用new()函數(shù)。
class my_monitor extends uvm_monitor;virtual my_if vif;uvm_analysis_port #(my_transaction) ap;`uvm_component_utils(my_monitor) 在factory中注冊(cè)my_monitorfunction new(string name = "my_monitor", uvm_component parent = null);super.new(name, parent);endfunctionvirtual function void build_phase(uvm_phase phase);super.build_phase(phase);if(!uvm_config_db#(virtual my_if)::get(this, "", "vif", vif))`uvm_fatal("my_monitor", "virtual interface must be set for vif!!!")ap = new("ap", this);endfunctionextern task main_phase(uvm_phase phase);extern task collect_one_pkt(my_transaction tr); endclass2.1.3uvm_sequencer
所有的sequencer都要派生自u(píng)vm_sequencer。功能是組織管理sequence,當(dāng)driver要求數(shù)據(jù)時(shí),他就把sequence生成sequence_item轉(zhuǎn)發(fā)給driver。同時(shí)若需要的話(huà),uvm_sequencer也可以從uvm_driver那里獲取隨后的RSP對(duì)象來(lái)得知數(shù)據(jù)通信是否正常(源碼見(jiàn)附錄一)。
sequencer使用工廠機(jī)制注冊(cè):
class my_sequencer extends uvm_sequencer #(my_transaction); //my_transaction為sequence_item類(lèi)型function new(string name, uvm_component parent);super.new(name, parent);endfunction `uvm_component_utils(my_sequencer) //在factory中注冊(cè)my_sequencer endclass一個(gè)Sequencer可以?huà)燧d多個(gè)不同的sequence,sequencer可以通過(guò)內(nèi)置的方法來(lái)選擇需要發(fā)送的sequence,針對(duì)不同的測(cè)試條件發(fā)送不同的transaction。
2.1.4uvm_agent
將driver,monitor,sequencer封裝成一個(gè)agent模塊,方便復(fù)用。uvm_agent與uvm_component相比最大的改動(dòng)在于引入了一個(gè)變量is_active,缺省值是UVM_ACTIVE。處在active模式的agent需要例化driver、monitor和sequencer;而如果is_active的值是UVM_PASSIVE,這表示agent是passive模式,只可以例化monitor。
通過(guò)is_active變量,agent需要在build_phase()和connect_phase()等函數(shù)中通過(guò)選擇語(yǔ)句來(lái)對(duì)driver和sequencer進(jìn)行有條件的例化和連接(源碼見(jiàn)附錄一)。
class my_agent extends uvm_agent ;my_sequencer sqr;my_driver drv;my_monitor mon;uvm_analysis_port #(my_transaction) ap;function new(string name, uvm_component parent);super.new(name, parent);endfunction extern virtual function void build_phase(uvm_phase phase);extern virtual function void connect_phase(uvm_phase phase);`uvm_component_utils(my_agent) //在factory中注冊(cè)my_agent endclass function void my_agent::build_phase(uvm_phase phase);super.build_phase(phase);if (is_active == UVM_ACTIVE) begin //通過(guò)選擇語(yǔ)句來(lái)對(duì)driver和sequencer進(jìn)行有條件的例化。sqr = my_sequencer::type_id::create("sqr", this);drv = my_driver::type_id::create("drv", this);endmon = my_monitor::type_id::create("mon", this); endfunction function void my_agent::connect_phase(uvm_phase phase);super.connect_phase(phase);if (is_active == UVM_ACTIVE) begin //通過(guò)選擇語(yǔ)句來(lái)對(duì)driver和sequencer進(jìn)行有條件的連接。drv.seq_item_port.connect(sqr.seq_item_export);endap = mon.ap; endfunction2.1.5uvm_scoreboard
一般的scoreboard都要派生自u(píng)vm_scoreboard。其功能就是比較reference model和monitor分別發(fā)送來(lái)的數(shù)據(jù),根據(jù)比較結(jié)果判斷DUT是否正確。與uvm_component相比uvm_scoreboard也沒(méi)有額外的成員變量和方法,但UVM建議用戶(hù)將檢查比較類(lèi)都繼承于uvm_scoreboard,這也便于日后的子類(lèi)可以自動(dòng)繼承于可能被擴(kuò)充到uvm_scoreboard中的成員(源碼見(jiàn)附錄一)。
在scoreboard中通常會(huì)聲明TLM端口供monitor傳輸數(shù)據(jù)。
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) //在factory中注冊(cè)my_scoreboardextern 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); endclass2.1.6reference model
reference model是直接派生自u(píng)vm_component。其作用就是模仿DUT,完成與DUT相同的功能,可以直接使用systemverilog的特性,或者可以通過(guò)DPI等接口調(diào)用其它語(yǔ)言來(lái)完成與DUT相同功能,將產(chǎn)生的結(jié)果輸出到scoreboard進(jìn)行比較。
2.1.7uvm_env
所有env都要派生自u(píng)vm_env,屬于uvm_component類(lèi),相對(duì)于uvm_component類(lèi)沒(méi)有做過(guò)多擴(kuò)展。env把驗(yàn)證平臺(tái)固定不變的component(如agent、reference model、scoreboard和底層env等)封裝在一起,并配置各個(gè)組件間的通信端口。這樣在要運(yùn)行不同case時(shí),只要在case中實(shí)例化此env即可(源碼見(jiàn)附錄一)。
class my_env extends uvm_env;my_agent i_agt;my_agent o_agt;my_model mdl;my_scoreboard scb;uvm_tlm_analysis_fifo #(my_transaction) agt_scb_fifo;uvm_tlm_analysis_fifo #(my_transaction) agt_mdl_fifo;uvm_tlm_analysis_fifo #(my_transaction) mdl_scb_fifo;function new(string name = "my_env", uvm_component parent);super.new(name, parent);endfunctionvirtual function void build_phase(uvm_phase phase); //在build_phase中實(shí)例化組件以及通信管道FIFOsuper.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;o_agt.is_active = UVM_PASSIVE;mdl = my_model::type_id::create("mdl", this);scb = my_scoreboard::type_id::create("scb", this);agt_scb_fifo = new("agt_scb_fifo", this);agt_mdl_fifo = new("agt_mdl_fifo", this);mdl_scb_fifo = new("mdl_scb_fifo", this);endfunctionextern virtual function void connect_phase(uvm_phase phase);`uvm_component_utils(my_env) //在factory注冊(cè)my_env endclass2.1.8uvm_test
所有的測(cè)試用例都要派生自u(píng)vm_test或派生類(lèi),屬于uvm_component類(lèi),相對(duì)于uvm_component類(lèi)也沒(méi)有做過(guò)多擴(kuò)展。不同的case之間差異很大,所以從uvm_test派生出來(lái)的類(lèi)各不同。任何一個(gè)派生的case都要實(shí)例化env,只有這樣才能正常傳數(shù)(源碼見(jiàn)附錄一)。
class base_test extends uvm_test;my_env env;function new(string name = "base_test", uvm_component parent = null);super.new(name,parent);endfunctionextern virtual function void build_phase(uvm_phase phase);extern virtual function void report_phase(uvm_phase phase);`uvm_component_utils(base_test) //在factory中注冊(cè)base_test endclass2.1.9uvm_component相關(guān)宏
1.`uvm_component_utils:把一個(gè)直接或間接派生自u(píng)vm_component的類(lèi)注冊(cè)到factory中。
2.`uvm_component_param_utils:把一個(gè)直接或間接派生自u(píng)vm_component的參數(shù)化的類(lèi)注冊(cè)到factory中。
3.`uvm_component_utils_begin:用于同時(shí)需要factory和field_automation機(jī)制注冊(cè)的類(lèi),與uvm_object_utils_begin相似。最大的意義在于可以自動(dòng)使用config_db得到某些變量的值。
4.`uvm_component_param_utils_begin:用于參數(shù)化class實(shí)現(xiàn)某些變量field_automation機(jī)制。
5.`uvm_component_utils_end:總是與uvm_component_*_begin成對(duì)出現(xiàn),作為factory注冊(cè)結(jié)束的標(biāo)志。
2.2UVM驗(yàn)證平臺(tái)的樹(shù)形結(jié)構(gòu)
UVM通過(guò)uvm_component實(shí)現(xiàn)驗(yàn)證平臺(tái)的樹(shù)形結(jié)構(gòu),uvm_component在new()時(shí),需要指定一個(gè)類(lèi)型為uvm_component、名字是parent的變量。
仿真過(guò)程中,會(huì)先執(zhí)行build_phase()。該phase用于構(gòu)建uvm-tree的結(jié)構(gòu),注:uvm_component組件類(lèi)必須在build_phase中實(shí)例化,build_phase()的主要用途就是實(shí)例化組件類(lèi),創(chuàng)建和配置測(cè)試平臺(tái)的結(jié)構(gòu),構(gòu)建tree,典型的UVM樹(shù)如下圖:
一般來(lái)說(shuō),對(duì)組件實(shí)例化時(shí),會(huì)向parent參數(shù)傳遞指定的父類(lèi)(如this指針),若傳遞null,此component的父類(lèi)將被設(shè)置成uvm_top;
env = my_env::type_id::create("env", this);
env = my_env::type_id::create("env", null);
uvm_top是一個(gè)全局變量,它是uvm_root的一個(gè)實(shí)例(也是唯一的一個(gè)實(shí)例),而uvm_root本質(zhì)上是一個(gè)uvm_component派生自u(píng)vm_component,它是UVM樹(shù)的根。uvm_test_top的parent是uvm_top,而uvm_top的parent是null。
uvm_root的存在可以保證整個(gè)驗(yàn)證平臺(tái)中只有一棵樹(shù),所有結(jié)點(diǎn)都是uvm_top的子結(jié)點(diǎn)。在導(dǎo)入uvm_pkg文件包(import uvm_pkg::*;)時(shí),會(huì)自動(dòng)創(chuàng)建一個(gè)頂層類(lèi)uvm_root所例化的對(duì)象uvm_top。
UVM提供了一系列的接口函數(shù)用于訪問(wèn)UVM樹(shù)中的結(jié)點(diǎn),主要的包括:
源碼:extern function uvm_component get_child (string name);
源碼:extern function void get_children(ref uvm_component children[$]);
源碼:?????extern function int get_first_child (ref string name);
????????????????extern function int get_next_child (ref string name);
總結(jié)
以上是生活随笔為你收集整理的UVM学习整理——UVM结构(component派生类)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【LLC原理】适用于高压大功率场合的三相
- 下一篇: 用Excel制作一个漂亮的分类散点图