gpt4 book ai didi

interface - 为什么不通过接口(interface)时钟 block 驱动输出?

转载 作者:行者123 更新时间:2023-12-04 02:44:43 24 4
gpt4 key购买 nike

在下面的示例中,我试图在 my_interface 上脉冲输出 data。但是,data 始终保持为 0。

interface my_interface(
input clock,
output data);

clocking cb @(posedge clock);
output data;
endclocking
endinterface // my_interface

module test;

logic clock;
wire data;

my_interface my_interface(.*);

initial begin
clock = 0;
#1 $display("%0d data:%0d", $time, data);
#10;
my_interface.cb.data <= 1;
#1 $display("%0d data:%0d", $time, data);
@(my_interface.cb);
my_interface.cb.data <= 0;
#1 $display("%0d data:%0d", $time, data);
#20 $display("%0d data:%0d", $time, data);
$finish();
end

always #5 clock = ~clock;

endmodule

模拟输出是:

# 1 data:z
# 12 data:z
# 16 data:0
# 36 data:0

我想了解为什么在上面的示例中 data 永远不会是 1?我可以通过将 #10 替换为 @(my_interface.cb); 来解决这个问题,但我不知道为什么这个修复有效。

EDA Playground 上的代码和结果:http://www.edaplayground.com/s/4/198

最佳答案

在驱动或采样时钟 block 信号时使用除@(my_interface.cb) 之外的任何其他阻塞事件是非常危险的。您的代码以这种方式运行的原因是因为第 14.16 节同步驱动器中的声明:

It is possible for a drive statement to execute at a time that is not coincident with its clocking event. Such drive statements shall execute without blocking, but shall perform their drive action as if they had executed at the time of the next clocking event.

在您的示例中,您的两个驱动语句最终在同一个周期中驱动,最后写入获胜。

所以规则只是使用@(my_interface.cb) 来阻止正在驱动或采样时钟 block 信号的进程。这包括不使用 wait(cb.signal) 而是使用 @(cb iff (cb.signal))

关于interface - 为什么不通过接口(interface)时钟 block 驱动输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19061075/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com