SV中的Interface和Program


Interface:SV中新定義的接口方式,用來簡化接口連接,使用時注意在module或program之外定義interface,然后通過'include來添加進工程。

        interface  arb_if(input bit clk);              //clk信號,一般單獨拿出來

                           logic [1:0]grant, request;       //只定義信號類型。類型在不同的modport中分別定義。

                           logic rst;

                           clocking cb @(posedge clk);    //定義時鍾塊,其中的信號都是clk上升沿有效

                                             output request;

                                             input  grant;

                           enclocking

                           modport TEST (clocking cb, output rst);   //直接引用clocking, 在定義rst的方向

                           modport DUT (input request, rst, output grant);  //定義各個信號的方向

        endinterface

        module  test(arb_if.TEST arbif);

                           initial  begin

                                        arbif.cb.request <= 0;    //直接引用clocking中的信號,而且clock blocking中的信號,最好使用<=非阻塞賦值。

                                        @arbif.cb;         //相當於@posedge clk

                                        $display("");

                                     end

        endmodule

interface可以直接與verilog-2001的端口進行連接:

        module   top;

                bit  clk;

                always #5  clk = ~clk;

                arb_if  arbif(clk);

                arb_port     a1(.grant(arbif,grant),

                                      .request(arbif.request),

                                      .rst(arbif.rst),

                                      .clk(arbif.clk) );

                test   t1(arbif);

         endmodule:top

Program:主要是為了在邏輯和仿真時間上,區分開RTL與驗證平台。在SV搭建的驗證環境中,testcase一般就定義一個program來開始執行。

               program中不能使用always,因為program相比較來說,與C語言更靠近一些。所以多用initial就可以。program中的仿真時間與RTL中的是有區別的,

               SV將同一仿真時刻分為四個區域,Active(design), Observed(assertion), Reactive(testbench), Postponed(sample)。相當於在原verilog的基礎

               上又為program增加了一個執行區間,一個采樣區間。所以clk的定義不能放在program中。當program中的initial結束時,SV會調用$finish完成仿真。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM