gpt4 book ai didi

verilog - Verilog 中的事件调度

转载 作者:行者123 更新时间:2023-12-01 12:44:45 28 4
gpt4 key购买 nike

我正在学习 verilog 分层事件队列。我对非事件事件有一点疑问。我知道它们是在当前模拟时间完成所有事件事件后执行的。但是我写了一个简单的代码来更好地理解这个概念,但我得到的结果让我感到困惑。这是我写的代码:

module main;

int x;

initial begin

$monitor("x is %0d",x);

#0 x = 5; // inactive event
x = 3; // active event
end

endmodule

结果:x 为 3。

根据我的知识,#0 延迟会创建一个非事件事件,因此结果应该是 x 是 5。但我对这个概念的理解可能在某处是错误的。任何帮助将不胜感激。谢谢。

最佳答案

来自 IEEE Std 1800-2012 的区域定义:

4.4.2.2 Active events region
The Active region holds the current active region set events being evaluated and can be processed in any order.

4.4.2.3 Inactive events region
The Inactive region holds the events to be evaluated after all the Active events are processed.

If events are being executed in the active region set, an explicit #0 delay control requires the process to be suspended and an event to be scheduled into the Inactive region of the current time slot so that the process can be resumed in the next Inactive to Active iteration.

...

4.4.2.9 Postponed events region
$monitor, $strobe, and other similar events are scheduled in the Postponed region. No new value changes are allowed to happen in the current time slot once the Postponed region is reached.

Within this region, it is illegal to write values to any net or variable or to schedule an event in any previous region within the current time slot.



图表参见图 4-1—事件区域上的调度器图表

您对 #0 的理解是正确的。把 x = 5;进入非事件区域。然而,这个 #0也阻止了 x = 3;从第一次进入事件区域执行。它在第二遍执行到由非事件区域操纵的事件区域。这是因为阻塞语句总是顺序的。 $monitor()始终显示在时间步长的末尾,在所有其他区域完成后,因此您只会在 x 时获得最终值。 .

通过将语句放在 fork-join 中,这两个语句将并行执行。这将允许 x = 3;第一次进入事件区域时执行。
module main;
int x;
initial begin
$monitor("From $monitor: x is %0d",x);
#0 x = 5; // inactive event
x = 3; // active event (after inactive event)
#1; // go to next time stamp
fork
#0 x = 7; // inactive event
x = 11; // active event
join
end
// reactive event, x value from the observed region
always @* $display("From @* $display: x is %0d",x);
endmodule

输出:
From @* $display: x is 3
From $monitor: x is 3
From @* $display: x is 11
From @* $display: x is 7
From $monitor: x is 7

关于verilog - Verilog 中的事件调度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21315650/

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