1. 程式人生 > 其它 >日常記錄(33)虛介面

日常記錄(33)虛介面

虛介面

沒有虛介面,那interface無法接入到class中。

interface SBus ();
    // nets
    logic req, grant;
    logic [7:0] addr, data;

endinterface : SBus

class SBusTrans;
    // data or class properties
    virtual SBus bus;

    function new(virtual SBus s);
        bus=s;
    endfunction : new

    task request();
        bus.req=1;
    endtask: request

    task wait_for_bus();
        @(posedge bus.grant);
    endtask: wait_for_bus
endclass : SBusTrans

module devA (SBus s);
    initial begin
        int handler=$fopen("devA.log");
        $fmonitor(handler, "A req, grant %d, %d", s.req, s.grant);
    end
endmodule

module devB (SBus s);
    initial begin
        int handler=$fopen("devB.log");
        $fmonitor(handler, "B req, grant %d, %d", s.req, s.grant);
    end
endmodule

module top ();
    SBus s[1:4]();
    devA a1(s[1]);
    devB a2(s[2]);
    initial begin
        SBusTrans t[2];
        t[0]=new(s[1]);
        t[1]=new(s[2]);

        #5 t[0].request;
        #5 t[1].request;
    end

endmodule

  

輸出

cat dev*
A req, grant x, x
A req, grant 1, x
B req, grant x, x
B req, grant 1, x

  

目標:

1.讀懂程式碼,

2.編寫程式

3.除錯程式碼

黑盒測試:激勵生成後,同時灌入DUT和參考模型,對比輸出。

灰盒測試:在黑盒的基礎上,不僅有參考模型,同時新增斷言和監控在DUT內,結果比較

白盒測試:在DUT內部或外部新增監控和斷言,結果比較。

驗證要考慮的要素:

1.完備性:制定方案最大限度的驗證被測設計。

2.可重用性:不同場合下驗證環境架構的的相容性。

3.可靠性:採用自動化工具完成系列操作。減少手動操作。

4.效率:給定時間內的驗證工作投入產出最大化

5.效能:驗證程式的效率

  

強制轉換

列舉,轉換前有一個'.

module taa ();
    typedef enum {R, G, B} colors;
    colors c;
    initial begin
        c=G;
        c=colors'(2);
        $display("color is %s", c);
    end
endmodule

  

型別判定、ref與input、預設引數、預設賦值

\$typename進行引數型別判定然後通過=進行資料傳遞,然後在function裡的第二個引數前,加了input防止變成ref型別報錯。

default可以新增預設的資料,但是被判斷不能混合賦值,這裡進行了分兩步的方式賦值。

完全不指定方向,function中預設第一個為input型別,完全不指定型別,預設為logic型別。

module taa ();
    function void calc(ref int a[], input int length=a.size-1);
         int sum=0;
         for (int i = 0; i <length+1; i++) begin
             sum+=a[i];
         end
         $display("the sum value of it is %d", sum);
    endfunction: calc

    initial begin
        int aa[10]={default:1};
        int bb[];
        aa[0:3]={1,2,3,4};
        bb = aa;
        $display("typename %s", $typename(aa));
        $display("typename %s", $typename(bb));
        calc(bb);
    end
endmodule

  

輸出

typename int$[0:9]
typename int$[]
the sum value of it is          16

  

Fork-Join的展開化

注意automatic的位置

module tbb ();
initial begin
    automatic int i;
    for (int i = 0; i < 10; i++) begin
        fork
            $display("i is %d", i);
        join_none
    end
    $display("start...");

    for (i = 0; i < 10; i++) begin
        fork
            $display("automatic i is %d", i);
        join_none
    end

    for (i = 0; i < 10; i++) begin
        fork
            automatic int j=i;
            $display("replace i is %d", j);
        join_none
    end
end
endmodule

  

輸出

start...
i is          10
i is          10
i is          10
i is          10
i is          10
i is          10
i is          10
i is          10
i is          10
i is          10
automatic i is          10
automatic i is          10
automatic i is          10
automatic i is          10
automatic i is          10
automatic i is          10
automatic i is          10
automatic i is          10
automatic i is          10
automatic i is          10
replace i is           0
replace i is           1
replace i is           2
replace i is           3
replace i is           4
replace i is           5
replace i is           6
replace i is           7
replace i is           8
replace i is           9

  

引數化信箱

引數化信箱內容為string

module tcc ();
    typedef mailbox #(string) box2;
    box2 ma2=new;
    string s;
    initial begin
        ma2.put("hello");
        ma2.put(123);

        ma2.get(s);
        $display("get : %s ",s);
        // error: mismatching
        /* ma2.get(s); */
        /* $display("get : %s ",s); */
    end
endmodule

  

輸出

get : hello 

  

本文來自部落格園,作者:大浪淘沙、,轉載請註明原文連結:https://www.cnblogs.com/bai2022/p/15775266.html