Tutorials

Protocols

Learn More

A sequence can call a function, task, or system task when a sequence item matches. A property can also instantiate another property so the same check can be reused.

On a successful match of a sequence, task or function (including system task/function) can be called.

Calling functions or tasks in a sequence example

A subroutine call can be attached to a sequence expression after a comma. It runs only when that expression matches.

This is useful for calculating a value, saving information in a local variable, or printing a debug message at the exact matching point.

On matching a sequence, function func is called and its return value is stored locally in variable value and system task $display is used to print the local variable.

sequence seq;
  logic value;
  req1 ##1 (req2, value = func, $display("Output of function value = %0h", value)) ;
endsequence

Suppose req1 matches at cycle 0. The ##1 delay checks req2 at cycle 1. If req2 is true, func() is called, its return value is stored in the local variable value, and $display prints that saved value.

If req2 is false at cycle 1, this sequence attempt does not match, so the attached assignment and display call are not executed for that attempt.

Each active sequence attempt has its own copy of value. A result saved by one attempt does not overwrite the value stored by another attempt.

Instantiation of property in another property

The property expression can be instantiated in another property as shown in the below example.

Instantiation of property in another property example

property p1(req1, req2);
  req1 |-> req2;
endproperty

property p2;
  @(posedge clk);
  Req3 ##2 |=> 
    if(en)
      p1(req1, req2)
    else out = 0;
endproperty

If req3 is true at cycle 0, non-overlapped implication moves the consequent to cycle 1. At cycle 1, the value of en selects the required branch.

When en = 1, p1(req1, req2) is evaluated. If req1 is true, req2 must also be true on that clock because p1 uses |->.

When en = 0, the property requires out = 0 on that clock.

When req3 = 0, no consequent branch is required for that attempt.

Points to Remember

  1. Attach a function, task, assignment, or system task to a matching sequence item after a comma.
  2. The attached call runs only when that sequence item matches.
  3. Use local variables to store results separately for each active sequence attempt.
  4. Instantiate named properties to reuse a check instead of copying its expression.