我通常使用@运算符来等待特定信号的任何逻辑值变化。 例如,等待信号a任何变化,我通常会这样做
wire a; //... @(a); // wait any value change 0->1 or 1->0, or x->1 etc但是现在我意识到上面的代码并不总是按预期工作,特别是当我们引入信号强度时,如下面的代码所示:
module test; wire a; logic sweak1 = 0; logic spull1 = 0; assign (weak0,weak1) a = sweak1 ? 1'b1 : 1'bz; assign (pull0,pull1) a = spull1 ? 1'b1 : 1'bz; task wait_a_change(); @(a); endtask initial forever begin $display("Value: a = %b %v @%0t", a, a, $time); wait_a_change(); end initial begin sweak1 = 1; #10; spull1 = 1; #10; spull1 = 0; #10; spull1 = 1; #10; end endmodule即使a的逻辑值没有改变,事件@(a)也会触发。 所以我的第一个解决方案就是:
task wait_a_change(); if (a) @(negedge a); else @(posedge a); endtask该解决方案需要额外检查(也行)。 有没有更好的解决方案?
I usually use the @ operator to wait for any logical value change of a particular signal. For example to wait on any change in signal a, I usually do
wire a; //... @(a); // wait any value change 0->1 or 1->0, or x->1 etcBut now I realized that the above codes will not always work as expected especially when we introduce signal strength, as illustrated in following code:
module test; wire a; logic sweak1 = 0; logic spull1 = 0; assign (weak0,weak1) a = sweak1 ? 1'b1 : 1'bz; assign (pull0,pull1) a = spull1 ? 1'b1 : 1'bz; task wait_a_change(); @(a); endtask initial forever begin $display("Value: a = %b %v @%0t", a, a, $time); wait_a_change(); end initial begin sweak1 = 1; #10; spull1 = 1; #10; spull1 = 0; #10; spull1 = 1; #10; end endmoduleThe event @(a) will trigger even if the logical value of a doesn't change. So my first solution to overcome this is by doing:
task wait_a_change(); if (a) @(negedge a); else @(posedge a); endtaskThat solution requires additional check (and line too). Is there any better solution?
最满意答案
试试@(!a) 。 通过布尔表达式,它失去了力量。 你唯一松动的是x-> z过渡。 (你的解决方案也不会抓到它)。 如果你需要,你最好更好地解释你想要完成的事情,这可能是一个完全不同的方法。
Try @(!a). By putting it through a Boolean expression, it loses its strength. The only thing you loose is x->z transitions. (your solution would not catch that either). If you need that, you had better explain better what you are trying to accomplish, where might be an entirely different approach to take.
更多推荐
发布评论