本文介紹了cocotb的安裝、python tb文件的寫法、用xrun仿真cocotb的腳本等,我們來看看體驗如何。
一、準(zhǔn)備
二、寫RTL
top.svmodule top(input wire clk,input wire rst_n,input wire [7:0] din,output reg [7:0] dout);initial begin$fsdbDumpfile("top.fsdb");top);endclk, negedge rst_n)if(!rst_n)dout <= 'd0;elsedout <= din;endmodule // top
三、寫tb
# tb.pyimport cocotbfromcocotb.triggersimportTimer, FallingEdgeasync def gen_clk(dut):for cycle in range(100):dut.clk.value = 0await Timer(10, units="ns")dut.clk.value = 1awaitTimer(10,units="ns")async def gen_rst(dut):dut.rst_n.value = 0await Timer(22, units="ns")dut.rst_n.value = 1print("ResetDone")async def tb(dut):await cocotb.start(gen_clk(dut))await cocotb.start(gen_rst(dut))test_data_list = range(0,50, 5)for test_data in test_data_list:await FallingEdge(dut.clk)dut.din.value=test_dataawait Timer(100, units="ns")
6~11行:定義了一個時鐘,50MHz,100個周期。
13~17行:定義了一個復(fù)位信號,低電平有效。復(fù)位拉高打印“Reset Done”,方便看log。
19行:用@cocotb.test()裝飾器指定了tb的頂層主函數(shù)。
22行:異步啟動gen_clk
23行:異步啟動gen_rst
25~28行:產(chǎn)生了一些測試數(shù)據(jù),在時鐘下降沿后驅(qū)動dut的din。
30行:等待100ns結(jié)束仿真
四、寫仿真腳本Makefile
SIM ?= xceliumTOPLEVEL_LANG ?= verilogVERILOG_SOURCES += ./top.svTOPLEVEL = topMODULE = tbinclude $(shell cocotb-config --makefiles)/Makefile.sim
設(shè)置默認(rèn)仿真器為cadence xcellium,RTL語言選verilog,指定RTL頂層模塊名字(就是dut的名字),testbench的名字為tb,最后include一個cocotb共用的makefile。
五、仿真和看波形
把top.sv、tb.py、Makefile放同一個目錄下,敲linux命令:make。不出意外的話,仿真可以正確編譯和仿真,如下圖:

由于我們在RTL頂層加入了dump fsdb波形的代碼,所以在log里可以看到有波形產(chǎn)生。280ns仿真結(jié)束,并顯示“tb passed”,并打印出匯總信息。可見log還是很友好的。
用verdi打開fsdb,與預(yù)期一致:

審核編輯 :李倩
-
仿真器
+關(guān)注
關(guān)注
14文章
1053瀏覽量
88216 -
代碼
+關(guān)注
關(guān)注
30文章
4977瀏覽量
74419 -
python
+關(guān)注
關(guān)注
58文章
4889瀏覽量
90330
原文標(biāo)題:厭倦了sv/uvm?來看看用python寫驗證環(huán)境
文章出處:【微信號:處芯積律,微信公眾號:處芯積律】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
cocotb的安裝、python tb文件的寫法
評論