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
相关推荐
我爱C编程20 小时前
【仿真测试】基于FPGA的完整16QAM软解调链路实现,含频偏锁定,帧同步,定时点,Viterbi译码,信道,误码统计
fpga开发·16qam·软解调·帧同步·维特比译码·频偏估计·定时点提取
高速上的乌龟21 小时前
Lattice LFCPNX-100 Fpga开发+源码:基于spi协议的flash驱动控制
fpga开发
ehiway1 天前
中科亿海微SoM模组——FPGA高速信号采集解决方案
fpga开发
tiantianuser1 天前
RDMA设计13:融合以太网协议栈设计2
fpga开发·rdma·高速传输·cmac·roce v2
XINVRY-FPGA1 天前
XC3S1000-4FGG320I Xilinx AMD Spartan-3 SRAM-based FPGA
嵌入式硬件·机器学习·计算机视觉·fpga开发·硬件工程·dsp开发·fpga
国科安芯2 天前
航天医疗领域AS32S601芯片的性能分析与适配性探讨
大数据·网络·人工智能·单片机·嵌入式硬件·fpga开发·性能优化
贝塔实验室2 天前
新手如何使用Altium Designer创建第一张原理图(三)
arm开发·单片机·嵌入式硬件·fpga开发·射频工程·基带工程·嵌入式实时数据库
FPGA_无线通信2 天前
OFDM 同步设计(3)
算法·fpga开发
贝塔实验室2 天前
Altium Designer全局编辑
arm开发·经验分享·笔记·fpga开发·dsp开发·射频工程·基带工程
北京青翼科技2 天前
【TES818 】基于 VU13P FPGA+ZYNQ SOC 的 8 路 100G 光纤通道处理平台
图像处理·人工智能·fpga开发·信号处理·智能硬件