9.1.9 How do I generate waveforms (traces) in SystemC?
A. Verilator Trace Option
Pass the --trace
option to Verilator, and in your top-level sc_main()
, call:
Verilated::traceEverOn(true);
Then you may use $dumpfile
and $dumpvars
to enable traces, as with any Verilog simulator; see the non-SystemC example in examples/make_tracing_c
.
This will trace only the module containing the $dumpvar
.
B. SystemC Trace Generation
Alternatively, you may create a trace purely from SystemC, which can trace all Verilated designs in the SystemC model.
Create a VerilatedVcdSc
object as you would create a standard SystemC trace file. For an example, see the call to VerilatedVcdSc
in the examples/make_tracing_sc/sc_main.cpp
file of the distribution, as shown below:
#include "verilated_vcd_sc.h"
...
int main(int argc, char** argv) {
...
Verilated::traceEverOn(true);
VerilatedVcdSc* tfp = new VerilatedVcdSc;
topp->trace(tfp, 99); // Trace 99 levels of hierarchy
tfp->open("obj_dir/t_trace_ena_cc/simx.vcd");
...
sc_start(1);
...
tfp->close();
}
You also need to compile verilated_vcd_sc.cpp
and verilated_vcd_c.cpp
and add them to your link, preferably by adding the dependencies in your Makefile’s $(VK_GLOBAL_OBJS)
link rule. This is done for you if you are using the Verilator --binary
or --exe
option.
You can call ->trace()
on multiple Verilated objects with the same trace file if you want all data to land in the same output file.
9.1.9 如何在 SystemC 中生成波形(跟踪)?
A. Verilator 跟踪选项
将 --trace
选项传递给 Verilator,并在您的顶级 sc_main()
中调用:
Verilated::traceEverOn(true);
然后,您可以使用 $dumpfile
和 $dumpvars
来启用跟踪,就像在任何 Verilog 仿真器中一样;请参见 examples/make_tracing_c
中的非 SystemC 示例。
这将只跟踪包含 $dumpvar
的模块。
B. SystemC 跟踪生成
或者,您可以完全通过 SystemC 来创建跟踪,这样可以在 SystemC 模型中跟踪所有 Verilated 设计。
创建一个 VerilatedVcdSc
对象,就像创建标准的 SystemC 跟踪文件一样。示例如下,参见分发中的 examples/make_tracing_sc/sc_main.cpp
文件中的 VerilatedVcdSc
调用:
#include "verilated_vcd_sc.h"
...
int main(int argc, char** argv) {
...
Verilated::traceEverOn(true);
VerilatedVcdSc* tfp = new VerilatedVcdSc;
topp->trace(tfp, 99); // 跟踪 99 层层次
tfp->open("obj_dir/t_trace_ena_cc/simx.vcd");
...
sc_start(1);
...
tfp->close();
}
您还需要编译 verilated_vcd_sc.cpp
和 verilated_vcd_c.cpp
并将它们添加到您的链接中,最好通过在 Makefile 的 $(VK_GLOBAL_OBJS)
链接规则中添加依赖项来完成。如果您使用 Verilator 的 --binary
或 --exe
选项,系统会为您完成此操作。
如果希望所有数据都输出到同一个文件中,您可以在多个 Verilated 对象上调用 ->trace()
并使用相同的跟踪文件。
理解下面这些,结合手册9.1.8的内容可以很快上手。
SystemC 基于 C++ 的设计哲学,它利用 C++ 的面向对象特性,允许设计者以更高的抽象层次进行硬件建模。虽然 SystemC 本身不是一个硬件描述语言(如 Verilog 或 VHDL),但它允许开发者使用 C++ 语法来编写硬件行为模型,并通过 C++ 的机制来进行调试和优化。
SystemC 中的模块(例如,硬件组件)被表示为 C++ 类,设计中的信号和通信通常通过 C++ 的对象或方法来表示。这使得设计者能够以类似于软件编程的方式进行硬件建模,并在系统级上模拟和验证设计。