Wait statement inside a driver

I am trying to understand the wait statement better. I use the wait statement inside my driver before driving my transaction data as shown below -


task drive_trans (seq_item trans);
  @(vif.driver_cb) // clocking block sampled at posedge of clk
  
  wait (vif.driver_cb.trigger == 1); // If trigger is not high, wait for it to go high

  vif.driver_cb.data <= trans.data; // push the data from the sequence onto the interface

endtask

My intention here is to push the transaction onto the interface only if ‘trigger’ is high. This code seems to work. I do see that whenever the ‘trigger’ is low the driver holds onto the previous transaction before pushing in the new transaction.

I would like to know if the wait statement introduces any simulation-time delay? My understanding is that the wait statement is a blocking statement that looks for the condition to be True during the current clock cycle. But I do see my simulation progress. Is this due to simulation time progressing in other parallel threads?

Update - Actually in my code the wait statement did not work. I had to use the while statement to drive as intended.


while (vif.driver_cb.trigger == 0) begin
  @(vif.driver_cb);
end

In reply to tpan:

You should use

@(vif.driver_cb iff vif.driver_cb.trigger == 0)

When using clocking blocks, you should not mix blocking statements with anything other than @(cb).

In reply to dave_59:

Shouldn’t my logic be the below instead since I need to wait for trigger to be set before driving my transaction


@(vif.driver_cb iff vif.driver_cb.trigger == 1)

vif.driver_cb.data <= trans.data;

For my understanding, what exactly does “@(vif.driver_cb iff vif.driver_cb.trigger == 1” translate to? Am I right when I say “Keep executing @(vif.driver_cb) until vif.driver_cb.trigger equals 1”?

Does this also mean that in the case of trigger being equal to 1 when the code is hit, the execution skips the blocking statement @(vif.driver_cb)?

In reply to tpan:
Sorry, that was a typo.

@(vif.driver_cb iff vif.driver_cb.trigger == 1)

translates to

do @(vif.driver_cb); while ( !(vif.driver_cb.trigger == 1))
1 Like