如何更改转储的 VCD 文件的时间刻度?

How to change timescale of VCD file dumped?

我正在尝试在 "real-world" 项目中使用 Chisel,并且正在用 C++ 编写测试台代码部分。 效果很好,我可以使用 gtkwave 在 dump.vcd 文件中看到我所有的转储信号。

但是我的时间刻度有问题,默认情况下,功能模块->dump()记录时间刻度为1ps的信号:

$timescale 1ps $end

你知道怎么改吗?

我发现在测试平台 C++ 代码中更改它的唯一方法是在关闭 vcd 后重新打开它并修改第一行:

#define CYCLE_PERIOD_NS   10
FILE *f = fopen("./dump.vcd", "w");
module->set_dumpfile(f);
[...]
/*several module->dump() call */
[...]
if (f) {
    fclose(f);

    std::string line;
    std::ifstream input("./dump.vcd");
    std::ofstream output("./tmp.vcd");
    std::getline(input, line);
    output << "$timescale " << CYCLE_PERIOD_NS << "ns $end" << endl;
    while(std::getline(input, line)) {
        output << line << endl;
    }
    rename("./tmp.vcd", "./dump.vcd");
}

我给出的方法只适用于C++后端,如果我们使用chisel class测试,问题仍然存在。 我修改了 Chisel 代码以在 implicitClock 对象中添加 period。然后我修改了 Vcd class 以使用正确的周期值转储 VCD。可以看到补丁here.

然后要更改时间刻度,您只需在顶部 Chisel 模块中添加以下行:

class myModule extends Module {
[...]
Driver.implicitClock.period = "10ns"
[...]
}

已为 Chisel 2.2.28 版提交此补丁。