verilator——牛刀小試
安裝verilator可見(jiàn):https://blog.csdn.net/qq_40676869/article/details/132648522?spm=1001.2014.3001.5501
正文開(kāi)始
編寫(xiě)一個(gè)異或的電路模塊如下:
top.v
module top(
input a,
input b,
output f
);
assign f = a ^ b;
endmodule
編寫(xiě)C++測(cè)試文件
tb_top.cpp
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "verilated.h"
#include "verilated_vcd_c.h"
#include "Vtop.h"
#define MAX_SIM_TIME 200
vluint64_t sim_time = 0;
int main(int argc, char** argv) {
Vtop *dut = new Vtop;
Verilated::traceEverOn(true);
VerilatedVcdC* m_trace = new VerilatedVcdC;
dut->trace(m_trace, 5);
m_trace->open("waveform.vcd");
while (sim_time < MAX_SIM_TIME) {
int a = rand() & 1;
int b = rand() & 1;
dut->a = a;
dut->b = b;
dut->eval();
printf("a = %d, b = %d, f = %d\n", a, b, dut->f);
m_trace->dump(sim_time);
sim_time++;
assert(dut->f == (a ^ b));
}
m_trace->close();
delete dut;
return 0;
}
編譯并運(yùn)行
verilator --cc --trace --exe --build -Wall tb_top.cpp top.v
–cc 將.v文件翻譯成c++
–exe 創(chuàng)建可執(zhí)行文件
–build verilator自動(dòng)進(jìn)行make
–trace 記錄波形
查看波形
sudo apt install gtkwave
gtkwave waveform.vcd
波形如下:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-693082.html
github鏈接:https://github.com/mulinhu/CPPer/tree/main/verilog/demo1文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-693082.html
到了這里,關(guān)于verilator——牛刀小試的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!