03 安装VERILATOR并仿真实现双控开关 ysyx

安装VERILATOR并仿真实现双控开关 ysyx

VERILATOR官网如下:
参考:https://verilator.org/guide/latest/install.html

安装

利用github git得到v4.210版本的

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

# 环境变量
unsetenv VERILATOR_ROOT #有问题没关系
unset VERILATOR_ROOT
cd verilator
# 安装依赖
sudo apt-get install git help2man perl python3 make
sudo apt-get install g++  # Alternatively, clang
sudo apt-get install libgz  # Non-Ubuntu (ignore if gives error)
sudo apt-get install libfl2  # Ubuntu only (ignore if gives error)
sudo apt-get install libfl-dev  # Ubuntu only (ignore if gives error)
sudo apt-get install zlibc zlib1g zlib1g-dev  # Ubuntu only (ignore if gives error)
sudo apt-get install ccache  # If present at build, needed for run
sudo apt-get install libgoogle-perftools-dev numactl
#执行
autoconf         # Create ./configure script
./configure      # Configure and create Makefile
make -j `nproc`  # Build Verilator itself (if error, try just 'make')
sudo make install

根据指导运行例程

历程:https://verilator.org/guide/latest/examples.html

双控开关

top.v 文件命名具有作用 可以理解为一个头文件Vtop
  1 module top(
  2   input a,
  3   input b,
  4   output f
  5 );
  6   assign f = a ^ b;
  7 endmodule

test_our.cpp

  1   #include "Vtop.h"
  2   #include "verilated.h"
  3  int main(int argc, char** argv) {
  4       VerilatedContext* contextp = new VerilatedContext;
  5       contextp->commandArgs(argc, argv);
  6       Vtop* top = new Vtop{contextp};
  7       while (!contextp->gotFinish()) {
  8         int a = rand() & 1;
  9         int b = rand() & 1;
 10         top->a = a;
 11         top->b = b;
 12         top->eval();
 13         printf("a = %d, b = %d, c = %d\n", a, b, top->f);
 14         assert(top->f == (a ^ b));
 15        }
 16       delete top;
 17       delete contextp;
 18       return 0;
 19   }

利用如下命令执行:

verilator --cc --exe --build -j 0 -Wall sim_main.cpp our.v

命令参数解析:
在这里插入图片描述
在这里插入图片描述
完成!

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值