这是代码
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 endmoduleNow 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.
更多推荐
发布评论