SV中的Interface和Program

來源:互聯網
上載者:User

標籤:

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中的訊號,而且Interface中的訊號,只能使用<=非阻塞賦值。

                                        @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完成模擬。

SV中的Interface和Program

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.