• verilator的第一个程序,注意流程和命令


    1. 已有文件

    已知our_OnOff.v和main.cpp文件,编写Makefile文件,在verilator软件仿真

    our_OnOff.v

    1. module our_OnOff(a,b,f);
    2. input a;
    3. input b;
    4. output f;
    5. assign f = a ^ b;
    6. endmodule

    main.cpp

    1. #include "verilated_vcd_c.h" //可选,如果要导出vcd则需要加上
    2. #include "Vour_OnOff.h"
    3. #include "stdio.h"
    4. #include
    5. vluint64_t main_time = 0; //initial 仿真时间
    6. double sc_time_stamp()
    7. {
    8. return main_time;
    9. }
    10. int main(int argc, char **argv)
    11. {
    12. Verilated::commandArgs(argc, argv);
    13. Verilated::traceEverOn(true); //导出vcd波形需要加此语句
    14. VerilatedVcdC* tfp = new VerilatedVcdC; //导出vcd波形需要加此语句
    15. Vour_OnOff *top = new Vour_OnOff("top"); //调用VAccumulator.h里面的IO struct
    16. top->trace(tfp, 0);
    17. tfp->open("wave.vcd"); //打开vcd
    18. while (sc_time_stamp() < 20 && !Verilated::gotFinish()) { //控制仿真时间
    19. int a = rand() & 1;
    20. int b = rand() & 1;
    21. top->a = a;
    22. top->b = b;
    23. top->eval();
    24. printf("a = %d, b = %d, f = %d\n", a, b, top->f);
    25. tfp->dump(main_time); //dump wave
    26. main_time++; //推动仿真时间
    27. }
    28. top->final();
    29. tfp->close();
    30. delete top;
    31. return 0;
    32. }

    2. 执行流程

    运行仿真分成三步:;

    (1)生成目标文件夹;(2)编译;(3)运行和查看波形

    2.1 生成目标文件夹

    命令:verilator -Wno-fatal our_OnOff.v main.cpp --top-module our_OnOff --cc --trace --exe

    -Wno: 忽略非 fatal 的 warning
    our_OnOff.v: 是设计文件
    main.c"是主程序
    --top-module:顶层模块名,注意是模块名,不是文件名
    --cc:表明是C++,不过 c 程序也是支持的
    --trace 表明会追踪波形,如果需要导出vcd 或者 fst 等其他波形文件,需要加上这个选项
    --exe:生成可执行文件

    运行完后会在当前目录生成obj_dir文件夹,这么多文件不需要深究。

    2.2 编译

    命令:make -C obj_dir -f Vour_OnOff.mk Vour_OnOff

    • 使用 -C 选项改变目录,你能看到 make 命令首先切到特定的目录下,在那执行
    • Vour_OnOff.mk 也是生成出来的一个文件,在 obj_dir 文件夹里面,用于自动化的编译控制
    • 最后一个参数是输出可执行文件的文件名,最好不要乱改,就"V" + "design_name"

    2.3 运行和查看波形

    ./obj_dir/Vour_OnOff
    gtkwave wave.vcd

  • 相关阅读:
    2271. 毯子覆盖的最多白色砖块数-快速排序+滑动窗口,力扣双百代码
    Polygon zkEVM 基本概念
    揭秘.NET Core剪裁器背后的技术
    【达梦数据库】学习笔记
    【暑期每日一题】洛谷 P7798 [COCI2015-2016#6] PUTOVANJE
    Vue基础3
    合宙Air101 的LCD怎么用Arudino IDE驱动
    【数据结构】欧拉回路(优化最短路-图论)
    【C++】一文带你走入vector
    软件测试 | 当面试时被问到“搭建过测试环境吗”, 身为小白要怎么回答?
  • 原文地址:https://blog.csdn.net/qianniuwei321/article/details/126835422