等待SV中同一时间步的位变化(Wait for A Bit Change in Same Timestep in SV)

编程入门 行业动态 更新时间:2024-10-28 12:25:00
等待SV中同一时间步的位变化(Wait for A Bit Change in Same Timestep in SV)

这是代码

module m; bit x; initial begin fork begin wait(x == 1); wait(x == 0); end begin @(x == 1); @(x == 0); end #10 $display("Timeout"); join_any disable fork; end initial begin #5; x = 1; // Some other Logical Stuff x = 0;; end endmodule

现在在此代码中,将发生超时,因为x = 1&x = 0在单个时间步骤中完成。

一种解决方案是在x = 1和x = 0之间提供延迟,然后两个等待都将正常工作。

有没有其他方法可以在不提供硬编码延迟的情况下工作?

注意: - 对于事件或信号量之类的东西,这个问题可以解决。 但我正在寻找编码风格或方法的答案,它可以在不使用事件的情况下工作。

Here is the code

module m; bit x; initial begin fork begin wait(x == 1); wait(x == 0); end begin @(x == 1); @(x == 0); end #10 $display("Timeout"); join_any disable fork; end initial begin #5; x = 1; // Some other Logical Stuff x = 0;; end endmodule

Now in this code, Timeout will happen, because x = 1 & x = 0 is done in the single time step.

One solution is to provide delay between x = 1 & x = 0, then both waits will work fine.

Is there any other method, which can work without providing hard-coded delays?

Note :- With events or semaphores like stuff, this problem can be solved. But I am looking for the answer in terms of coding style or methods, which can work without usage of events.

最满意答案

有几种方法可以在这里使用,比如事件,信号量,标志等。我在你的代码中添加了一个事件。 请在下面的链接中找到修改后的代码。 http://www.edaplayground.com/x/Ws3

还有其他方式,比如 1.在声明期间为x赋值“1” 例如,位x = 1; 2.在第二个初始块中一起使用阻塞和非阻塞分配。 例如,

initial begin #5; x = 1; // Some other Logical Stuff x <= 0; // Add non-blocking assignment end end

=>第二个选项不是一个好的编码实践,但它会解决您的问题,因为两个分配语句都适用于不同的区域。

There are several ways, which you can use here like event, semaphore, flag, etc. I have added an event in your code. Please find a modified code in below link. http://www.edaplayground.com/x/Ws3

There are other ways also like, 1. Assign value "1" to x, during its declaration E.g., bit x=1; 2. Use blocking and nonblocking assignment together in your 2nd initial block. E.g.,

initial begin #5; x = 1; // Some other Logical Stuff x <= 0; // Add non-blocking assignment end end

=> The second option is not a good coding practice, but it'll solve your issue as both the assignment statments will work on different regions.

更多推荐

本文发布于:2023-08-05 07:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1429729.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Wait   SV   Bit   Timestep   Change

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!