The wait Statement

Definition

The wait statement is used as a level-sensitive control. The syntax is:

The processor waits when the expression is FALSE. When the expression is TRUE, the statement is executed.

The expression is treated as a Boolean value, therefore wait responds to TRUE and FALSE only. Values '0', 'x' and 'z' are FALSE. Logic '1' is TRUE.

Comparison Between Event and Level Sensitive Processes

An example of an event-driven control is given below as a comparison to the level-sensitive control which will be described later.

This process uses the @(expression) to trigger the process. The statement will be executed whenever there is an event on the start signal.

In comparison the following example illustrates a level-sensitive control:

The process waits until start is `1'. When the start expression is TRUE, the go signal toggles after 10 time units. If start continues to stay `1' then go will continue to toggle after every 10 time units due to the forever definition. The toggling statement will only stop when start returns to `0'.

An event sensitive process is triggered by the edge on a control signal, while a level sensitive process is triggered by the value on the control signal.

Applications Of The wait Statement

The wait statement can be used to:

The above example of a wait statement is also an example of synchronising. If more than one process is controlled by the start signal in a similar manner to that above, then when start goes high, several processes will start to run together. Thus they have been synchronised using the start signal.

The following is an example of hand shaking. The waveform below also refers to this example.

Both the processes run concurrently, so read and write are initialised to '1' and '0' respectively. Process 1 then waits for a '1' on the write signal. Process 2 is waiting for a '1' on the read signal. Because read is initialised to '1', process 2 continues (A). The data coming in is stored in a temporary register called datain. The write signal is then changed to a '1' to signify that the input data has been read (B). Process 2 is now waiting for the read signal to become '0'.

Process 1 is triggered by write being '1'. The data in the temporary register can now be safely manipulated and then written to another register called storeddata. When this process has completed, read is set to '0' to signify that the data has been successfully transferred (C). This triggers process 2 which has been waiting for read to go to '0'. Process 2 changes write to '0' to say it is ready to receive data whenever process 1 is ready (D). This triggers the last wait statement in process 1 to change read to '1'. The two processes are now back in their initial states and waiting to repeat the above procedure.

This hand shaking method avoids process 1 trying to manipulate the incoming data before it has been fully received. It also stops process 2 reading in more data before process 1 has finished with the previously read data.

The Difference Between wait And while

The wait statement should not be confused with the while statement. Two examples are given below:

The wait statement will halt the process when start = '0'. The whole process will not procede until the start expression is TRUE. When start = '1', go will be set to '1' and then stop will be set to '0'.

The while statement will not set go to '1' unless start is '1'. If start is '0', the while statement will not set go to '1' but stop will be set to '0'. The while statement does not stop the whole process. It only stops the statement within the while loop from being executed.

Summary

The wait statement can be used for synchronising or hand shaking between concurrent processes as shown in the examples above. The process waits until the expression is true. It then executes the statement.