EDA开源仿真工具verilator入门1:安装和测试

这篇具有很好参考价值的文章主要介绍了EDA开源仿真工具verilator入门1:安装和测试。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

Verilator介绍

Verilator是一种开源的Verilog/SystemVerilog仿真器,可用于编译代码以及代码在线检查,Verilator能够读取Verilog或者SystemVerilog文件,并进行lint checks(基于lint工具的语法检测),并最终将其转换成C++的源文件.cpp和.h。

Verilator不直接将Verilog HDL转换为C++或者SystemC,反之Verilator将代码编译成更快的优化过的并且支持多线程的模型,该模型被依次包装在(wrapped)在C++/SystemC模型中。这样就生成一个编译的Verilog模型,其功能和Verilog是一致的,但效率由于基于C++即使是单线程模型也可以10倍快于SystemC,100倍快于基于解释Verilog的仿真器,并且通过多线程可以进一步加速。

Verilator的优点:将Verilog/SystemVerilog转换成C++/SystemC,仿真速度快很多,如果有这方面的需求,那Verilator是不错的选择。

本节将先介绍下Verilator的安装以及基本的使用方法,所有操作均在Ubuntu16系统上实现。

Verilator安装

安装必要的软件包:

sudo apt-get install git perl python3 make autoconf g++ flex bison ccache
sudo apt-get install libgoogle-perftools-dev numactl perl-doc
sudo apt-get install libfl-dev
sudo apt-get install zlibc zlib1g zlib1g-dev

git上拷贝源代码:

git clone https://github.com/verilator/verilator

编译前的准备工作:

unset VERILATOR_ROOT  # For bash
cd verilator
git pull         # Make sure git repository is up-to-date
git tag          # See what versions exist

这里选择编译版本v4.210(最新版本会报错)

git checkout v4.210 

配置编译安装:

autoconf         # Create ./configure script
./configure      # Configure and create Makefile
make -j `nproc`  # Build Verilator itself (if error, try just 'make')
sudo make install

如果成功的话输入:

verilator --version

可以看到verilator的版本信息:

verilator安装,FPGA+EDA,fpga开发,verilator,verilog,verilog仿真,EDA

一个简单例子

下面我们看下官方示例,最简单的hello world代码,文件位置在verilator/examples/make_hello_c/下,主要两个文件:

top.v

// DESCRIPTION: Verilator: Verilog example module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2017 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0

// See also the EXAMPLE section in the verilator manpage/document.
module top;
   initial begin
      $display("Hello World!");
      $finish;
   end
endmodule

sim_main.cpp

// DESCRIPTION: Verilator: Verilog example module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2017 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
//======================================================================

// Include common routines
#include <verilated.h>

// Include model header, generated from Verilating "top.v"
#include "Vtop.h"

int main(int argc, char** argv, char** env) {
    // See a similar example walkthrough in the verilator manpage.

    // This is intended to be a minimal example.  Before copying this to start a
    // real project, it is better to start with a more complete example,
    // e.g. examples/c_tracing.

    // Prevent unused variable warnings
    if (false && argc && argv && env) {}

    // Construct the Verilated model, from Vtop.h generated from Verilating "top.v"
    Vtop* top = new Vtop;

    // Simulate until $finish
    while (!Verilated::gotFinish()) {

        // Evaluate model
        top->eval();
    }

    // Final model cleanup
    top->final();

    // Destroy model
    delete top;

    // Return good completion status
    return 0;
}

MakeFile文件:

######################################################################
#
# DESCRIPTION: Verilator Example: Small Makefile
#
# This calls the object directory makefile.  That allows the objects to
# be placed in the "current directory" which simplifies the Makefile.
#
# This file ONLY is placed under the Creative Commons Public Domain, for
# any use, without warranty, 2020 by Wilson Snyder.
# SPDX-License-Identifier: CC0-1.0
#
######################################################################
# Check for sanity to avoid later confusion

ifneq ($(words $(CURDIR)),1)
 $(error Unsupported: GNU Make cannot build in directories containing spaces, build elsewhere: '$(CURDIR)')
endif

######################################################################

# This is intended to be a minimal example.  Before copying this to start a
# real project, it is better to start with a more complete example,
# e.g. examples/make_tracing_c.

# If $VERILATOR_ROOT isn't in the environment, we assume it is part of a
# package install, and verilator is in your path. Otherwise find the
# binary relative to $VERILATOR_ROOT (such as when inside the git sources).
ifeq ($(VERILATOR_ROOT),)
VERILATOR = verilator
else
export VERILATOR_ROOT
VERILATOR = $(VERILATOR_ROOT)/bin/verilator
endif

default:
	@echo "-- Verilator hello-world simple example"
	@echo "-- VERILATE & BUILD --------"
	$(VERILATOR) -cc --exe --build -j top.v sim_main.cpp
	@echo "-- RUN ---------------------"
	obj_dir/Vtop
	@echo "-- DONE --------------------"
	@echo "Note: Once this example is understood, see examples/make_tracing_c."
	@echo "Note: Also see the EXAMPLE section in the verilator manpage/document."

######################################################################

maintainer-copy::
clean mostlyclean distclean maintainer-clean::
	-rm -rf obj_dir *.log *.dmp *.vpd core

MakeFile中核心的编译语句其实就是执行:

verilator -Wall --cc --exe --build top.v sim_main.cpp

直接执行编译:

make

执行生成的C++可执行文件,结果如下:

verilator安装,FPGA+EDA,fpga开发,verilator,verilog,verilog仿真,EDA

可以看到C++实现了和verilog相同的功能。

配合gtkwave实现波形仿真

安装gtkwave

gtkwave同样是开源的工具其git地址为:

https://github.com/gtkwave/gtkwave.git

这里我们直接安装:

sudo apt-get install gtkwave

简单示例

以一个简单的逻辑组合为例:

top.v

module top(
  input a,
  input b,
  input c,
  input d,
  output f
);
  assign f = ~((a&b) | (~(c&d)));
endmodule

top_main.cpp

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
 
#include "Vtop.h"  // create `top.v`,so use `Vtop.h`
#include "verilated.h"
 
#include "verilated_vcd_c.h" //可选,如果要导出vcd则需要加上
 
int main(int argc, char** argv, char** env) {
 
  VerilatedContext* contextp = new VerilatedContext;
  contextp->commandArgs(argc, argv);
  Vtop* top = new Vtop{contextp};
  
 
  VerilatedVcdC* tfp = new VerilatedVcdC; //初始化VCD对象指针
  contextp->traceEverOn(true); //打开追踪功能
  top->trace(tfp, 0); //
  tfp->open("wave.vcd"); //设置输出的文件wave.vcd
 
 
  while (!contextp->gotFinish()) {
    int a = rand() & 1;
    int b = rand() & 1;
    int c = rand() & 1;
    int d = rand() & 1;
    top->a = a;
    top->b = b;
    top->c = c;
    top->d = d;
    top->eval();
    printf("a = %d, b = %d, c = %d, d = %d, f = %d\n", a, b, c, d, top->f);
 
    tfp->dump(contextp->time()); //dump wave
    contextp->timeInc(1); //推动仿真时间
 
    assert(top->f == ~((a&b) | (~(c&d))));
  }
  delete top;
  tfp->close();
  delete contextp;
  return 0;
}

执行编译:

verilator -Wall top.v top_main.cpp --cc --trace --exe --build
#增加了--trace 是为了显示波形的
./obj_dir/Vtop   //必须执行这个,才会出现.vcd文件,需要强制退出
gtkwave wave.vcd //如果报错缺少canberra-gtk-module,apt安装即可

结果如下图:

verilator安装,FPGA+EDA,fpga开发,verilator,verilog,verilog仿真,EDA

 这一节先说到这里。文章来源地址https://www.toymoban.com/news/detail-803976.html

到了这里,关于EDA开源仿真工具verilator入门1:安装和测试的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 南京大学数字电路与计算机组成实验的Verilator仿真(二)

    top.v sim_main.cpp 仿真结果 top.v sim_main.cpp 仿真结果 top.v sim_main.cpp top.v bcd7seg.v sim_main.cpp nvboard约束文件 top.nxdc Makefile文件 结果展示

    2024年02月15日
    浏览(36)
  • FPGA——HLS入门-LED闪烁仿真

    HLS就是高综合(High level Synthesis)的缩写,通过HLS,我们可以将C或者c++语言编译为FPGA能够读懂和运行的RTL级别的语言。 这个术语是行为和电子系统的结合:是一门技术,也是一门科学,它把设计意图抽象化,抽象视图可以自动地将人类设计者的努力付诸现实。最终生成的设

    2024年02月11日
    浏览(35)
  • 【【萌新的FPGA学习之Vivado下的仿真入门-2】】

    我们上一章大概了解了 我们所需要进行各项操作的基本框架 对于内部实现其实一知半解 我们先从基本的出发 但从FPGA 了解一下 vivado下的仿真入门 正好帮我把自己的riscV 波形拉一下 行为级仿真 step1: 进入仿真界面:SIMULATION-单击 Run Simulation-单击 Run Behavioral Simulation。 Step2:设

    2024年02月08日
    浏览(29)
  • 不用编程超简单的自动化测试工具:Airtest安装使用入门篇

    很多刚入行或从其他行业转行做测试的同学,日复一日每天做点工已经点得疲惫和麻木,觉得做测试和在厂子里打螺丝没太大区别。也想着做一做自动化测试,奈何自己看着代码就头痛,当初就是因为不喜欢编程才选择的做测试。亦或者由于从其他行业转行过来的,隔行如隔

    2024年02月04日
    浏览(43)
  • 【数字IC精品文章收录】近500篇文章|学习路线|基础知识|接口|总线|脚本语言|芯片求职|安全|EDA|工具|低功耗设计|Verilog|低功耗|STA|设计|验证|FPGA|架构|AMBA|书籍|

    1.1 索引目的 本篇索引旨在 收藏CSDN全站中有关数字IC领域高价值文章 ,在数字芯片领域中,就算将架构,设计,验证,DFT,后端诸多岗位加在一起的数量,都不及软件类一个细分方向的岗位数量多,反映在社区氛围或是开源资料的丰富度而言,数字IC领域相较于软件/互联网领

    2024年02月03日
    浏览(107)
  • FPGA学习笔记(五)Testbench(测试平台)文件编写进行Modelsim仿真

    一、FPGA学习笔记(一)入门背景、软件及时钟约束 二、FPGA学习笔记(二)Verilog语法初步学习(语法篇1) 三、FPGA学习笔记(三) 流水灯入门FPGA设计流程 四、FPGA学习笔记(四)通过数码管学习顶层模块和例化的编写 五、FPGA学习笔记(五)Testbench(测试平台)文件编写进行

    2024年02月07日
    浏览(39)
  • EDA07--VCS仿真验证(一)

    VCS用于在Linux下仿真.v代码,vcs六大功能: ·System Verilog ·OVA ·NTB ·DVE调试环境 ·覆盖率统计 ·DirectC ·增量编译 ·64-bit模式 ·混合信号仿真 本文讲解VCS的知识内容,具体操作步骤单独写一篇… VCS-DVE仿真由三步构成: 编译、仿真、调试 。提前编写好设计文件和Testbench的.v文件。

    2024年02月08日
    浏览(40)
  • Synopsys EDA数字设计与仿真

    搭建EDA环境 参考如下博文安装Synopsys EDA开发工具 https://blog.csdn.net/tugouxp/article/details/132255002?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22132255002%22%2C%22source%22%3A%22tugouxp%22%7D Synopsys EDA工具的结构 下面使用Synopsys的EDA数字综合仿真工具直观感受以下数字设

    2024年02月12日
    浏览(28)
  • 立创EDA软件的学习记录——仿真(1)

     放置电源时,可以选择使用电压源和电流源,    同时又可以选择支流或者交流电,在放置完电源后,一端要接入VCC,另一端接地,如下图所示:  在接入交流电时,一端接VCC,一端接地,下图所示: 当我们在设置交流电的电压时,如果要输出有效值为220V的交流电时,将振

    2024年02月05日
    浏览(44)
  • 开源电路仿真软件CircuitJS1介绍与使用入门

    在做电路设计的过程中经常需要用到电路仿真软件对设计的电路进行仿真,以确定电路工作特性或者元件的参数取值。使用电路仿真软件可以缩短电路开发时间、降低成本、提高效率。 接触过的大多数电路仿真软件都是收费的,可以免费使用的电路仿真软件主要有下面两款:

    2024年02月02日
    浏览(30)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包