cocotb value cocotb—基础语法对照篇

cocotb---基础语法对照篇

python 复制代码
import cocotb
from cocotb.triggers import Timer
from adder_model import adder_model
from cocotb.clock import Clock
from cocotb.triggers import RisingEdge
import random

@cocotb.test()
async def adder_basic_test(dut):

    """Test for 5 + 10"""
    cocotb.fork(Clock(dut.clk, 10, units='ns').start())
    A = 5
    B = 10

    #dut.A <= A
    #dut.B <= B  # 和下边两行等价
    dut.A.value =A
    dut.B.value =B
    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
    assert dut.X.value == adder_model(A, B), "Adder result is incorrect: {} != 15".format(dut.X.value)


@cocotb.test()
async def adder_randomised_test(dut):
    """Test for adding 2 random numbers multiple times"""
    cocotb.fork(Clock(dut.clk, 5, units='ns').start())
    for i in range(10):

        A = random.randint(0, 15)
        B = random.randint(0, 15)

        #dut.A <= A
        #dut.B <= B
        dut.A.value = A
        dut.B.value = B

        await RisingEdge(dut.clk)
        await RisingEdge(dut.clk)

        assert dut.X.value == adder_model(A, B), "Randomised test failed with: {A} + {B} = {X}".format(
            A=dut.A.value, B=dut.B.value, X=dut.X.value)
复制代码
#adder_model.py
def adder_model(a: int, b: int) -> int:
    """ model of adder """
    return a + b
Makefile 复制代码
# Makefile
TOPLEVEL_LANG= verilog
PWD=$(shell pwd)

VERILOG_SOURCES=./adder.v

TOPLEVEL=adder
MODULE= test_adder

SIM=icarus

include $(shell cocotb-config --makefiles)/Makefile.sim

多文件tb, 多文件dut

复制代码
# makefile template

VERILOG_SOURCES = $(PWD)/submodule.sv $(PWD)/my_design.sv
# TOPLEVEL is the name of the toplevel module in your Verilog or VHDL file:
TOPLEVEL=my_design
# MODULE is the name of the Python test file:
MODULE=test_my_design

include $(shell cocotb-config --makefiles)/Makefile.sim
相关推荐
LabVIEW开发5 小时前
LabVIEW与FPGA超声探伤
fpga开发·labview·labview功能
cycf6 小时前
FPGA设计中的数据存储
fpga开发
FPGA之旅1 天前
FPGA从零到一实现FOC(一)之PWM模块设计
fpga开发·dubbo
XMAIPC_Robot1 天前
基于ARM+FPGA的光栅尺精密位移加速度测试解决方案
arm开发·人工智能·fpga开发·自动化·边缘计算
cycf1 天前
状态机的设计
fpga开发
szxinmai主板定制专家1 天前
【精密测量】基于ARM+FPGA的多路光栅信号采集方案
服务器·arm开发·人工智能·嵌入式硬件·fpga开发
千宇宙航2 天前
闲庭信步使用SV搭建图像测试平台:第三十二课——系列结篇语
fpga开发
千宇宙航2 天前
闲庭信步使用SV搭建图像测试平台:第三十一课——基于神经网络的手写数字识别
图像处理·人工智能·深度学习·神经网络·计算机视觉·fpga开发
小眼睛FPGA2 天前
【RK3568+PG2L50H开发板实验例程】FPGA部分/紫光同创 IP core 的使用及添加
科技·嵌入式硬件·ai·fpga开发·gpu算力
forgeda3 天前
如何将FPGA设计验证效率提升1000倍以上(2)
fpga开发·前沿技术·在线调试·硬件断点·时钟断点·事件断点