1.dut的端口声明如下,文件名为top.v:
- module top
- (
- input clk ,
- input rst_n ,
-
- input wr_n ,
- input rd_n ,
- input cs0_n ,
- input cs7_n ,
- input [15 : 0] bus_addr_in ,
- //UART淇″彿
- input rx0_d ,
- output tx0_d ,
- );
2.定义interface接口,文件名为top_if.sv;
- interface top_if( input bit clk );
-
-
- logic rst_n ;
-
- logic wr_n ;
- logic rd_n ;
- logic cs0_n ;
- logic cs7_n ;
- logic [15 : 0] bus_addr_in ;
- //UART信号
- logic rx0_d ;
- logic tx0_d ;
- );
3.在testbench模块中连接interface接口与dut的端口,interface与dut的端口连接时,只能按照信号名称一个一个的绑定。接下来就可以在testbench中通过interface的实例引用信号名,来对其进行赋值。这里通过`include "top_if.sv"将接口引进来。
- `include "top_if.sv"
- module tb;
- bit clk ;
-
- top_if topif(clk); //实例化top_if对象,将clk传递给interface
-
- top top_inst( .clk(topif.clk), //将topif接口对象与DUT端口绑定,这里直接按照位置绑定
- .rst_n( topif.rst_n ),
- .wr_n(topif.wr_n),
- .rst_n(topif.rst_n) ,
- .wr_n (topif.wr_n ) ,
- .rd_n(topif.rd_n) ,
- .cs0_n(topif.cs0_n) ,
- .cs7_n (topif.cs7_n) ,
- . bus_addr_in(topif.bus_addr_in) ,
-
- .rx0_d (topif.rx0_d) ,
- .tx0_d(topif.tx0_d)
- );
- initial
- begin
- clk=0;
- topif.rst_n=0;
- #100 topif.rst_n=1;
-
- end
-
- always #12.5 clk=~clk;
-
- endmodule