1、ntb_template -t router router.v 執行該命令會生成3個文件(命令中router.v是dut)
a、router.if.vrh,包含信號端口的方向(相對於dut)、位寬,可將此信號加上類型(logic或者bit),去掉方向,作為interface中的信號聲明。將此信號去掉位寬來作為interface中clocking模塊中同步信號的聲明;
b、router.test_top 此文件中會產生仿真時鍾信號,接口例化等信號,仿真時鍾可直接拷貝到Test Harness File使用,例化拷貝后稍加修改即可使用;
2、interface
a、在interface中,信號方向的指定:
同步信號:in a clocking block
異步信號:in a modport
b、一個interface應包括:(below example)
1 interface router_io(input bit clock);//interface中有同步信號,引入時鍾 2 信號聲明<類型(logic或bit) + 位寬 + 信號名> 3 logic reset_n; 4 logic [15:0] din; 5 ... 6 7 //同步時鍾模塊,執行同步信號的驅動和采樣 8 clocking cb @(posedge clock) 9 default input #1ns output #1ns //去除輸入輸出的抖動 10 //信號方向(相對於dut) + 信號名 11 output reset_n; 12 output din; 13 ... 14 endclocking:cb 15 16 //使用modport將interface和test program 連接起來,在modport參數列表中,應包含前面鎖創建的同步信號和潛在的異步信號。 17 //異步信號方向指定 18 modport TB(clocking cb,output reset_n);//需要注意,reset_n既是同步信號,也是異步信號 19 endinterface:router_io
3、Test Program File 測試程序:
1 program automatic test(router.TB rtr_io);//將test program 和interface相連 2 3 initial begin 4 $display("This My first SV testbench"); 5 reset(); 6 end 7 8 task reset(); 9 rtr_io.reset_n = 1'b0;//異步信號,阻塞賦值 10 rtr_io.cb.frame_n <= 1'b1;//同步信號,非阻塞賦值 11 rtr_io.cb.valid_n <= 1'b1;//同上 12 //阻塞賦值和非阻塞賦值是同時執行的,最后來到##2延時2個時鍾周期后拉高reset_n 13 14 ##2 rtr_io.cb.reset_n <= 1'b1;//reset_n拉低2個時鍾周期然后拉高 15 repeat(15) @(router.cb); 16 endtask:reset 17 18 endprogram:test
4、Test Harness File
1 `timescale 1ns/100ps 2 module router_test_top; 3 //時鍾生成可使用ntb_template產生文件中的時鍾 4 parameter simulation_cycle = 100; 5 bit SystemClock; 6 7 router_io top_io(SystemClock);//例化一個接口 8 test t(top_io);//將接口和tb連接起來 9 router dut(//將接口和dut連接起來 10 .reset_n (top_io.reset_n), 11 .clock (top_io.clock), 12 .din (top_io.din), 13 ... 14 .frameo_n (top_io.frameo_n) 15 ); 16 17 initial begin 18 $timeformat(-9,1,"ns",10); //set time 19 SystemClock = 0; 20 forever begin 21 #(simulation_cycle/2) 22 SystemClock = ~SystemClock; 23 end 24 end 25 26 endmodule
5、compile and simulation
vcs -sverilog -fsdb router_test_top.sv test.sv router_io.sv router.v //執行詞句會生成可執行文件simv ./simv //執行詞句可產生仿真結果,並且產生需要保存的波形文件(下面介紹);
6、waveform dump
第一種波形文件:
$vcdpluson;//加入此句vcdplus.vpd文件
第二種波形文件:
$fsdbDumpfile("test.fsdb");//被保存的波形文件名命名 $fsdbDumpvars(0,router_test_top);//router_test_top即代表你要保存的波形是哪個文件中的信號;