如何在 Cocotb 中指定时间分辨率?

How do I specify the time resolution in Cocotb?

当我模拟 Endian Swapper example of Cocotb in VHDL and Verilog mode using QuestaSim. The clock is generated in the same way for both modes in the provided example code:

时,我得到了不同的时钟周期
@cocotb.coroutine
def clock_gen(signal):
    while True:
        signal <= 0
        yield Timer(5000)
        signal <= 1
        yield Timer(5000)


@cocotb.coroutine
def run_test(dut): # stripped un

    cocotb.fork(clock_gen(dut.clk))

当 运行在 Verilog 模式下使用:

make SIM=questa GUI=1

时钟周期为1000ns(千纳秒),因此时间分辨率为100ps.

当 运行在 VHDL 模式下使用:

make SIM=questa GUI=1 TOPLEVEL_LANG=vhdl

时钟周期为 10000 ns( 千纳秒),因此,时间分辨率为 1 ns。

我在另外两个 VHDL 项目中使用相同的时钟生成。在一个中,我也得到了 10000 ns 的时钟周期(1 ns 分辨率)。但在另一个中,时钟周期仅为 10 ns,分​​辨率为 1 ps.

为什么所有这些 运行 模式和项目的时间分辨率都不同?

如何一致地指定时间分辨率?

Makefile 生成的 runsim.do 文件中的 vsim 命令没有指定时间分辨率。因此,模拟器的默认时间分辨率按照 modelsim.ini 中的规定使用。其他 VHDL 项目之一有一个私有 modelsim.ini,时间分辨率设置为 1 ps (Resolution = ps) 而不是默认的 1 ns (Resolution = ns)。

额外的 vsim 参数可以由 Cocotb 构建系统的 Makefile 变量 VSIM_ARGS 指定。但是在命令行上设置这个变量:

make SIM=questa GUI=1 "VSIM_ARGS=-t 1ps"

没有按预期工作,因为其他必需的 vsim 参数现在已被删除。

必须在项目特定的 Makefile 中设置此变量,例如,在包含系统范围的 Makefile 之前:

VSIM_ARGS=-t 1ps

include $(COCOTB)/makefiles/Makefile.inc
include $(COCOTB)/makefiles/Makefile.sim

这样,就可以在 VHDL 和 Verilog 中获得一致的时间分辨率。必须为每个项目相应地设置参数。

因为cocotb 1.3.0, you can use COCOTB_HDL_TIMEUNIT and COCOTB_HDL_TIMEPRECISION makefile 变量以模拟器不可知的方式定义时间尺度。