I'm confused about the exact meaning of the wait statement.
What happens in this case:
forever begin wait (vif.xn_valid == 1'b1); @(posedge vif.clk);
endIs the wait statement blocking? Is the
@(posedge vif.clk)executed every time inside the loop, regardless of the evaluation of the wait expression?
And in this case:
forever begin wait(vif.cyc_tic == 1'b1) @(posedge vif.clk) #0 fact_log2_samp_t = vif.fact_log2_samp;
endIs the code after the wait (#0 fact_log2_samp_t = vif.fact_log2_samp;) executed only if the evaluation of the wait expression is true?
1 Answer
In this case
forever begin wait (vif.xn_valid == 1'b1); @(posedge vif.clk);
endthe loop blocks until the expression (vif.xn_valid == 1'b1) is true, then it blocks until there is a posedge on vif.clk.
A wait statement blocks until the condition is true. If the condition is already true then execution carries on immediately.
In this case:
forever begin wait(vif.cyc_tic == 1'b1) @(posedge vif.clk) #0 fact_log2_samp_t = vif.fact_log2_samp;
endthe loop blocks until the expression (vif.cyc_tic == 1'b1) is true, then it blocks until there is a posedge on vif.clk. It is the same as:
forever begin wait(vif.cyc_tic == 1'b1); @(posedge vif.clk); #0 fact_log2_samp_t = vif.fact_log2_samp;
end