安装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
命令参数解析:
完成!