Verilog 中的事件调度 [英] Event scheduling in Verilog

查看:40
本文介绍了Verilog 中的事件调度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was learning about the verilog stratified event queue. I had a minor doubt about the inactive events. I understood that they are carried out after all the active events are done with at the current simulation time. But I wrote a simple code to understand the concept better but the result I got is what confuses me. Here is the code I wrote:

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.但我对这个概念的理解可能在某处是错误的.任何帮助将不胜感激.谢谢.

According to my knowledge the #0 delay creates an inactive event and therefore the result should have been x is 5. But my understanding of the concept might be wrong somewhere. Any help will be appreciated. Thanks.

推荐答案

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

4.4.2.2 活动事件区域
活动区域保存正在评估的当前活动区域设置事件,并且可以按任何顺序进行处理.

4.4.2.3 非活动事件区域
Inactive 区域保存了在处理完所有 Active 事件后要评估的事件.

如果事件正在活动区域​​集中执行,则显式 #0 延迟控制要求暂停进程并将事件调度到当前时隙的非活动区域,以便进程可以在下一个非活动到活动迭代中恢复.

...

4.4.2.9 延期事件区域
$monitor$strobe 和其他类似事件都安排在推迟区域.一旦到达延迟区域,就不允许在当前时间段内发生新的值更改.

在该区域内,将值写入任何网络或变量或在当前时间段内的任何先前区域中安排事件都是非法的.

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—事件区域的调度器图表

Diagram see a diagram of scheduler on Figure 4-1—Event regions

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

You are correct in your understanding that the #0 puts the x = 5; into the inactive region. However, this #0 also blocks the x = 3; from executing in the first time entering in the active region. It is executed in the second pass to the active region rigged by the Inactive region. This is because blocking statements are always always sequential. $monitor() is always displayed at the end to the time step, after all other regions have completed, hence you will only get the final value if x.

通过将语句放在 fork-join 中,两个语句将并行执行.这将允许 x = 3; 在第一次进入活动区域时执行.

By placing the statements inside of a fork-join, then the two statements will execute in parallel. This will allow the x = 3; to execute the first time the active region is entered.

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 中的事件调度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆