本文介绍了cocotb的安装、python tb文件的写法、用xrun仿真cocotb的脚本等,我们来看看体验如何。
一、准备
二、写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行:定义了一个复位信号,低电平有效。复位拉高打印“Reset Done”,方便看log。
19行:用@cocotb.test()装饰器指定了tb的顶层主函数。
22行:异步启动gen_clk
23行:异步启动gen_rst
25~28行:产生了一些测试数据,在时钟下降沿后驱动dut的din。
30行:等待100ns结束仿真
四、写仿真脚本Makefile
SIM ?= xceliumTOPLEVEL_LANG ?= verilogVERILOG_SOURCES += ./top.svTOPLEVEL = topMODULE = tbinclude $(shell cocotb-config --makefiles)/Makefile.sim
设置默认仿真器为cadence xcellium,RTL语言选verilog,指定RTL顶层模块名字(就是dut的名字),testbench的名字为tb,最后include一个cocotb共用的makefile。
五、仿真和看波形
把top.sv、tb.py、Makefile放同一个目录下,敲linux命令:make。不出意外的话,仿真可以正确编译和仿真,如下图:

由于我们在RTL顶层加入了dump fsdb波形的代码,所以在log里可以看到有波形产生。280ns仿真结束,并显示“tb passed”,并打印出汇总信息。可见log还是很友好的。
用verdi打开fsdb,与预期一致:

审核编辑 :李倩
-
仿真器
+关注
关注
14文章
1048浏览量
86757 -
代码
+关注
关注
30文章
4941浏览量
73137 -
python
+关注
关注
57文章
4857浏览量
89571
原文标题:厌倦了sv/uvm?来看看用python写验证环境
文章出处:【微信号:处芯积律,微信公众号:处芯积律】欢迎添加关注!文章转载请注明出处。
发布评论请先 登录
【EASY EAI Nano-TB(RV1126B)开发板试用】桌面系统功能测试-安装桌面系统chromium-browser
【EASY EAI Nano-TB(RV1126B)开发板试用】命令行功能测试-红绿灯按钮项目-Python实现简单的Web服务器
EASY EAI Nano-TB(RV1126B)开发板试用】1、初识
使用NucleiStudio生成tb仿真需要的.verilog文件
termux调试python猜数字游戏
termux如何搭建python游戏
linux虚拟环境中调用Linux 版matlab编译的python库时出错
【VisionFive 2单板计算机试用体验】安装openplc
如何在虚拟环境中使用 Python,提升你的开发体验~
创建OpenVINO™ Python脚本,运行可执行文件时遇到的报错怎么解决?
使用Python实现xgboost教程
Flexus 云服务器 X:Python 安装的极致便捷之旅

cocotb的安装、python tb文件的写法
评论