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
相关推荐
沐欣工作室_lvyiyi32 分钟前
基于FPGA的电梯控制系统设计(论文+源码)
单片机·fpga开发·毕业设计·计算机毕业设计·电子交易系统
阿sir1985 小时前
ZYNQ PS XADC读取芯片内部温度值,电压值。
fpga开发
@晓凡11 小时前
NIOS ii工程移植路径问题
fpga开发·nios ii
博览鸿蒙1 天前
FPGA会用到UVM吗?
fpga开发
ThreeYear_s2 天前
基于FPGA实现数字QAM调制系统
fpga开发
小飞侠学FPGA2 天前
VIVADO的IP核 DDS快速使用——生成正弦波,线性调频波
fpga开发·vivado·dds
博览鸿蒙2 天前
成为一个年薪30W+的FPGA工程师是一种什么体验?
fpga开发
喜欢丸子头2 天前
xilinx vivado fir ip(FIR Compiler)核 ADC高采样率,FPGA工作时钟为采样率的1/4,同一个时钟周期来四个数据。
fpga开发
璞致电子2 天前
【PZ-AU15P】璞致fpga开发板 Aritx UltraScalePlus PZ-AU15P 核心板与开发板用户手册
嵌入式硬件·fpga开发·fpga·fpga开发板·xilinx开发板
红糖果仁沙琪玛3 天前
fpga iic协议
fpga开发