# How Can I Hold Off an Assertion Until Sync is Established Using a Local Variable?

**URL:** <https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, local-variables, assertion\
**Created:** [May 21, 2014, 4:53pm UTC](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489 "2014-05-21T16:53:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![hal9e3](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/c6cbf5/32.png) [@hal9e3](https://verificationacademy.com/forums/u/hal9e3)\
**Post date:** [May 21, 2014, 4:53pm UTC](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489/1 "2014-05-21T16:53:19Z")

</div>

I want to hold off an assertion until the first occurrence of a sync byte, then execute the assertion every byte thereafter. I thought that a local variable would be the ideal way to do this - but no! Every permutation I tried either fired intermittently (only when byte matched sync byte) or failed to compile. Some examples:

property data\_parity\_prop (clk, rst, d, available, parity);  
bit flag = 0;  
@(posedge clk) disable iff (rst !== 1)  
((d == SYNC\_DATA), flag = 1) || flag |-\> ^d ^ available ^ parity;  
endproperty

FAILED TO COMPILE - Syntax error

property data\_parity\_prop (clk, rst, d, available, parity);  
@(posedge clk) disable iff (rst !== 1)  
((d == SYNC\_DATA), flag = 1) || flag |-\> ^d ^ available ^ parity;  
endproperty

FAILED TO COMPILE - flag not declared

bit flag;

property data\_parity\_prop (clk, rst, d, available, parity);  
@(posedge clk) disable iff (rst !== 1)  
((d == SYNC\_DATA), flag = 1) || flag |-\> ^d ^ available ^ parity;  
endproperty

FAILED TO COMPILE - Can’t assign to variables other than local ones

I also tried putting flag in the sequence and passing it to the property and a bunch of other variants without success. Please help save what little hair I have left and tell me what I’m doing wrong. Thanks!

---

<div class="post-metadata">

**Author:** ![hal9e3](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/c6cbf5/32.png) [@hal9e3](https://verificationacademy.com/forums/u/hal9e3)\
**Post date:** [May 21, 2014, 5:56pm UTC](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489/2 "2014-05-21T17:56:20Z")

</div>

_In reply to [hal9e3](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489):_

Here’s the version that compiles OK but only fires when the data byte matches the sync value:

```
property data_parity_prop (clk, rst, d, available, parity);
	bit flag = 0;
	@(posedge clk) disable iff (rst !== 1)
		(flag || (d == SYNC_DATA), flag = 1) |-> ^d ^ available ^ parity;
	endproperty

```

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [May 21, 2014, 11:45pm UTC](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489/3 "2014-05-21T23:45:17Z")

</div>

You needed the property “or” operator.

```auto
property data_parity_prop (clk, rst, d, available, parity);
  bit flag = 0;
  @(posedge clk) disable iff (rst !== 1)
((d == SYNC_DATA), flag = 1) or flag |-> ^d ^ available ^ parity;
endproperty
// Could also use
property data_parity_prop (clk, rst, d, available, parity);
  bit flag = 0;
  @(posedge clk) disable iff (rst !== 1)
  ($rose(d == SYNC_DATA), flag = 1) or flag |-> ^d ^ available ^ parity;
endproperty
// Suggest you also use the default disable iff

```

> property\_expr ::=  
> sequence\_expr  
> | strong ( sequence\_expr )  
> | weak ( sequence\_expr )  
> | ( property\_expr )  
> | not property\_expr  
> | property\_expr or property\_expr // \<-----------  
> | property\_expr and property\_expr  
> | sequence\_expr |-\> property\_expr  
> | sequence\_expr |=\> property\_expr  
> …

* * *

Ben Cohen  
[http://www.systemverilog.us/](http://www.systemverilog.us/) [ben@systemverilog.us](mailto:ben@systemverilog.us)

- A Pragmatic Approach to VMM Adoption 2006 ISBN 0-9705394-9-5
- SystemVerilog Assertions Handbook, 2005 ISBN 0-9705394-7-9
- Using PSL/SUGAR for Formal and Dynamic Verification 2nd Edition, 2004, ISBN 0-9705394-6-0
- Real Chip Design and Verification Using Verilog and VHDL, 2002 isbn 0-9705394-2-8
- Component Design by Example ", 2001 ISBN 0-9705394-0-1
- VHDL Coding Styles and Methodologies, 2nd Edition, 1999 ISBN 0-7923-8474-1
- VHDL Answers to Frequently Asked Questions, 2nd Edition ISBN 0-7923-8115

* * *

---

<div class="post-metadata">

**Author:** ![hal9e3](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/c6cbf5/32.png) [@hal9e3](https://verificationacademy.com/forums/u/hal9e3)\
**Post date:** [May 22, 2014, 2:10pm UTC](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489/4 "2014-05-22T14:10:47Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489/3):_

Thanks, that cleared it up!

---

<div class="post-metadata">

**Author:** ![hal9e3](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/c6cbf5/32.png) [@hal9e3](https://verificationacademy.com/forums/u/hal9e3)\
**Post date:** [May 22, 2014, 3:52pm UTC](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489/5 "2014-05-22T15:52:47Z")

</div>

_In reply to [hal9e3](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489/4):_

My, mistake, this did NOT fix the problem, either variant. The assertion only fires when d == SYNC\_DATA.

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [May 22, 2014, 5:20pm UTC](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489/6 "2014-05-22T17:20:44Z")

</div>

_In reply to [hal9e3](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489/5):_

Did you use this?  
($rose(d == SYNC\_DATA), flag = 1) or flag |-\> ^d ^ available ^ parity;  
This states that a new d==SYNC\_DATA will set the flag.  
To get A part of the property fired one and ONLY ONCE, you could do this

```auto
property data_parity_prop (clk, rst, d, available, parity);
  bit flag = 0;
  bit done= 0;
  @(posedge clk) disable iff (rst !== 1)
((d == SYNC_DATA && !done), flag = 1, done=1) or flag |-> ^d ^ available ^ parity;
endproperty
// or more simply with one variable 
property data_parity_prop (clk, rst, d, available, parity);
  bit flag = 0;
  @(posedge clk) disable iff (rst !== 1)
((d == SYNC_DATA && !flag), flag = 1) or flag |-> ^d ^ available ^ parity;

```

---

<div class="post-metadata">

**Author:** ![hal9e3](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/c6cbf5/32.png) [@hal9e3](https://verificationacademy.com/forums/u/hal9e3)\
**Post date:** [May 27, 2014, 2:53pm UTC](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489/7 "2014-05-27T14:53:28Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489/6):_

I tried both of your solutions. Also, both of them are trying to achieve my desired behaviour - hold off until first match, then fire every cycle after that.

---

<div class="post-metadata">

**Author:** ![hal9e3](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/c6cbf5/32.png) [@hal9e3](https://verificationacademy.com/forums/u/hal9e3)\
**Post date:** [May 27, 2014, 7:32pm UTC](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489/8 "2014-05-27T19:32:14Z")

</div>

_In reply to [hal9e3](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489/7):_

Another non-solution:

((d == SYNC\_DATA) or flag, flag = 1) |-\> ^d ^ available ^ parity;

Only fires when d == sync\_data

---

<div class="post-metadata">

**Author:** ![hal9e3](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/c6cbf5/32.png) [@hal9e3](https://verificationacademy.com/forums/u/hal9e3)\
**Post date:** [May 28, 2014, 2:54pm UTC](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489/9 "2014-05-28T14:54:47Z")

</div>

_In reply to [hal9e3](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489/8):_

OK, solved this but had to go outside SVA to do it:

```
bit start_asserts;

always @(posedge clk) begin
	if (rst !== 1) begin
		#1 start_asserts <= 0;
		end
	else if ((d == SYNC_DATA) & !available) begin
		#1 start_asserts <= 1;
		end
	else begin
		#1 start_asserts <= start_asserts;;
		end
	end

property data_parity_prop (clk, rst, d, available, parity, start_asserts);
	@(posedge clk) disable iff (rst !== 1)
		start_asserts |-> (^d ^ available ^ parity);
	endproperty

```

Not pretty or elegant but it works.

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [May 28, 2014, 6:21pm UTC](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489/10 "2014-05-28T18:21:11Z")

</div>

_In reply to [hal9e3](https://verificationacademy.com/forums/t/how-can-i-hold-off-an-assertion-until-sync-is-established-using-a-local-variable/29489/9):_

What you have done that is new is added the " !available"  
The following options would work:

```auto
module test8;
bit start_asserts, available, parity, clk, rst;
logic[7:0] SYNC_DATA, d;
// property would show ONE pass (and only one) when ((d == SYNC_DATA)&& !available )
// That may skew the statistic a tiny bit. 
// The other passes are when the consequent is true
property data_parity_prop (clk, rst, d, available, parity);
  bit flag = 0;
  @(posedge clk) disable iff (rst !== 1)
  ((d == SYNC_DATA) && !available, flag = 1) or flag |-> ^d ^ available ^ parity;
endproperty
ap_data_parity_prop: assert property(data_parity_prop
		(clk, rst, d, available, parity));
	
	
// If this is not acceptable, then you can write 2 separate properties and use the action block
ap_start: assert property(@(posedge clk) // disable iff (rst !== 1)
   (d == SYNC_DATA) && !available) start_asserts <= 1; 
   
property data_parity_prop_v2 (clk, rst, d, available, parity, start_asserts);
  @(posedge clk) disable iff (rst !== 1)
  start_asserts |-> (^d ^ available ^ parity);
endproperty
ap_data_parity_prop_v2: assert property(data_parity_prop_v2
			(clk, rst, d, available, parity, start_asserts));
	
endmodule

```

A side comment, from LRM

> & | ^ ^~ ~^ Binary bitwise operators  
> && || –\> \<–\> Binary logical operators

You should use the logical operators when you are doing logical operations.

```auto
//Thus, instead of 
else if ((d == SYNC_DATA) & !available) 
// WRITE
else if ((d == SYNC_DATA) && !available)

```

Also, in your code, you should skip the last "else. Thus

```auto
always @(posedge clk) begin
  if (rst !== 1) begin
     #1 start_asserts <= 0;
  end
  else if ((d == SYNC_DATA) & !available) begin
     #1 start_asserts <= 1;
   end
   // else begin
   // #1 start_asserts <= start_asserts;;
   // end
end

```

Ben [SystemVerilog.us](http://SystemVerilog.us)
