sarad
sarad

Reputation: 117

System Verilog- Wait statements

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);
end

Is 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;
end

Is 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?

Upvotes: 3

Views: 54755

Answers (1)

Matthew
Matthew

Reputation: 13977

In this case

forever begin
    wait (vif.xn_valid == 1'b1);
    @(posedge vif.clk);
end

the 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;
end

the 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

Upvotes: 6

Related Questions