Systemverilog (Green Book) Chapter 4-Connection Design (1) Interface

module top;
bit clk;
always #5 clk = ~clk;
arb_if arbif(clk);              //例化一个接口,将时钟传入
arb a1 (arbif);                 //例化一个设计模块,接口作为参数传入
test t1 (arbif);                //例化一个测试模块,接口作为参数传入
endmodule : top


//接口的定义
interface arb_if(input bit clk);
    logic [1:0] grant,request;
    logic rst;
endinterface

//设计模块
module arb(arb_if arbif);    //module中的interface不需要声明方向
    ...

    always @(posedge arbif.clk or pasedge arbif.rst) begin
        if (arbif.rst)       //索引interface信号
            arbif.grant <= 2'b00;
        else
            arbif.grant <= next_grant;
        ....
    end
endmodule

//测试模块
module test(arb_if arbif);
    ...
    initial begin
    //复位
    @(posedge arbif.clk) arbif.request <= 2'b01;
    $display("@%0t: Drove req=01",$time);
    repeat (2) @(posedge arbif.clk)
    if (arbif.grant != 2'b01) $display("@%0t: a1: grant !=2'b01",$time);
    $finish;
    end
endmodule : test

 

Published 14 original articles · won 10 · views 20,000 +

Guess you like

Origin blog.csdn.net/Jay_who/article/details/105611140