cocotb-cocotb是一个基于协程的协同仿真库,用于用Python编写VHDL和Verilog测试台。-Chris Higgs, Stuart Hodgson Installation U...

cocotb-cocotb是一个基于协程的协同仿真库,用于用Python编写VHDL和Verilog测试台。-Chris Higgs, Stuart Hodgson

发布:2020-12-23 13:35:13.969124

做者:Chris Higgs, Stuart Hodgson

做者邮箱:

首页:https://docs.cocotb.org

文档:None

下载连接

cocotb is a coroutine based cosimulation library for writing VHDL and Verilog testbenches in Python.html

Documentation Status Build Status PyPI Gitpod Ready-to-Code codecov

Installation

Cocotb requires:python

  • Python 3.5+
  • A C++11 compiler
  • An HDL simulator (such as Icarus Verilog)

After installing these dependencies, the latest stable version of cocotb can be installed with pip.git

pip install cocotb

!!! Windows Users !!! See here for installation instructions.github

For more details on installation, including prerequisites, see the documentation.shell

For detail on how to install the development version of cocotb, see the lastest documentation.app

Usage

As a first trivial introduction to cocotb, the following example "tests" a flip-flop.dom

First, we need a hardware design which we can test. For this example, create a file dff.sv with SystemVerilog code for a simple D flip-flop. You could also use any other language a cocotb-supported simulator understands, e.g. VHDL.electron

// dff.sv

`timescale 1us/1ns

module dff (
    output logic q,
    input logic clk, d
);

always @(posedge clk) begin
    q <= d;
end

endmodule

An example of a simple randomized cocotb testbench:async

# test_dff.py

import random
import cocotb
from cocotb.clock import Clock
from cocotb.triggers import FallingEdge

@cocotb.test()
async def test_dff_simple(dut):
    """ Test that d propagates to q """

    clock = Clock(dut.clk, 10, units="us")  # Create a 10us period clock on port clk
    cocotb.fork(clock.start())  # Start the clock

    for i in range(10):
        val = random.randint(0, 1)
        dut.d <= val  # Assign the random value val to the input port d
        await FallingEdge(dut.clk)
        assert dut.q == val, "output q was incorrect on the {}th cycle".format(i)

A simple Makefile:测试

# Makefile

TOPLEVEL_LANG = verilog
VERILOG_SOURCES = $(shell pwd)/dff.sv
TOPLEVEL = dff
MODULE = test_dff

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

In order to run the test with Icarus Verilog, execute:

make SIM=icarus

asciicast

For more information please see the cocotb documentation and the wiki.

Tutorials, examples and related projects

For more related resources please check the wiki and the list of projects depending on cocotb.

Copy from pypi.org

查询时间:14.024ms
渲染时间:14.152ms

本文同步分享在 博客“zhenruyan”(other)。
若有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一块儿分享。

相关文章
相关标签/搜索