• 正文
  • 推薦器件
  • 相關(guān)推薦
申請入駐 產(chǎn)業(yè)圖譜

設(shè)計(jì)模式在芯片驗(yàn)證中的應(yīng)用——單例

2024/06/12
945
加入交流群
掃碼加入
獲取工程師必備禮包
參與熱點(diǎn)資訊討論

單例模式

單例模式(Singleton)是一種創(chuàng)建型設(shè)計(jì)模式,能夠保證一個(gè)類只有一個(gè)實(shí)例, 并提供一個(gè)訪問該實(shí)例的全局節(jié)點(diǎn)。驗(yàn)證環(huán)境配置(configuration)類、超時(shí)(timeout)處理類等可以使用單例實(shí)現(xiàn)。比如說驗(yàn)證環(huán)境需要在特定場景中監(jiān)測特定接口上的超時(shí)事件,環(huán)境的每個(gè)組件都可以依賴超時(shí)處理類來設(shè)定超時(shí)的時(shí)刻。讓所有組件都使用超時(shí)處理類的相同對象有助于調(diào)試。

單例模式主要包括以下兩個(gè)組件:

單例類(Singleton class):該類只能創(chuàng)建有限數(shù)量的對象,通常是一個(gè)對象。為了實(shí)現(xiàn)這一點(diǎn),類的構(gòu)造函數(shù)被定義為protected。使用靜態(tài)instance()方法訪問對象,該方法在第一次調(diào)用時(shí)執(zhí)行初始化,后面直接返回這個(gè)類的句柄。

客戶端(Client):任何UVM組件都可以使用單例類的instance()方法來訪問類對象。

下圖為單例設(shè)計(jì)模式在timeout處理中應(yīng)用的UML類圖。

參考代碼

單例設(shè)計(jì)模式用于timeout處理的參考代碼如下:

class timeout;
    local static timeout m_inst = null;
    protected function new();    endfunction : new
    static function timeout get_inst();        if ( m_inst == null )            m_inst = new();        return m_inst;    endfunction : get_inst
    task wait_timeout(int unsigned timeout_value);        #(timeout_value*1ns);    endtask : wait_timeout
endclass : timeout

測試代碼如下:

timeout inst = timeout::get_inst();
fork    begin        `uvm_info("START TIMEOUT COUNT 1", "", UVM_NONE)        inst.wait_timeout(500);        `uvm_info("END TIMEOUT COUNT 1", "", UVM_NONE)    end    begin        `uvm_info("START TIMEOUT COUNT 2", "", UVM_NONE)        inst.wait_timeout(1000);        `uvm_info("END TIMEOUT COUNT 2", "", UVM_NONE)    endjoin_none

仿真日志如下:

@ 0.000ns: [START TIMEOUT COUNT 1]@ 0.000ns: [START TIMEOUT COUNT 2]@ 500.000ns: [END TIMEOUT COUNT 1]@?1000.000ns:?[END?TIMEOUT?COUNT?2]

根據(jù)仿真結(jié)果,timeout處理類能夠同時(shí)跟蹤多個(gè)超時(shí)事件,在第一個(gè)超時(shí)(time = 500ns)和第二個(gè)超時(shí)(time = 1000ns)時(shí)發(fā)出超時(shí)信號。

微信號|c(diǎn)hip_yes,微信公眾號|專芯致志er

推薦器件

更多器件
器件型號 數(shù)量 器件廠商 器件描述 數(shù)據(jù)手冊 ECAD模型 風(fēng)險(xiǎn)等級 參考價(jià)格 更多信息
ABC2-4.9152MHZ-4-T 1 Abracon Corporation CRYSTAL 4.9152MHZ 18PF SMD
$2.21 查看
NC7WZ07P6X 1 Fairchild Semiconductor Corporation Buffer, LVC/LCX/Z Series, 2-Func, 1-Input, CMOS, PDSO6, 1.25 MM, EIAJ, SC-88, SC-70, 6 PIN
$0.28 查看
DP83867IRRGZR 1 Texas Instruments Industrial temperature, robust gigabit Ethernet PHY transceiver 48-VQFN -40 to 85

ECAD模型

下載ECAD模型
$59.73 查看

相關(guān)推薦

登錄即可解鎖
  • 海量技術(shù)文章
  • 設(shè)計(jì)資源下載
  • 產(chǎn)業(yè)鏈客戶資源
  • 寫文章/發(fā)需求
立即登錄