Mastering Assertion Control in Verilog and SystemVerilog
In this blog post, we will explore various assertion control functions in Verilog and SystemVerilog, diving deep into how you can use them effectively to manage and control assertions within your design. We will cover both the assertion control system tasks and the assertion actions, providing practical examples for each function. Let's get started!
Utilizing Assertion Control System Tasks
$assertcontrol: The Powerful Tool for Assertion Management
The $assertcontrol
system task allows you to manipulate the behavior of assertions, giving you precise control over their execution. The task has the following syntax:
$assertcontrol(control_type, assertion_type, directive_type);
The control_type
argument is an integer value that controls the assertion behavior. Here's a list of the available control_type
values and their meanings:
Value | Control Type | Description |
---|---|---|
1 | Lock | Lock assertion state |
2 | Unlock | Unlock assertion state |
3 | On | Enable assertion checking |
4 | Off | Disable assertion checking |
5 | Kill | Abort and stop assertion checking |
6 | PassOn | Enable pass action execution |
7 | PassOff | Disable pass action execution |
8 | FailOn | Enable fail action execution |
9 | FailOff | Disable fail action execution |
10 | NonvacuousOn | Enable pass action on nonvacuous success |
11 | VacuousOff | Disable pass action on vacuous success |
The assertion_type
argument specifies which types of assertions are affected by the control operation. Here's a list of the available assertion_type
values and their meanings:
Value | Assertion Type | Description |
---|---|---|
1 | Concurrent | Affects concurrent assertions |
2 | Simple Immediate | Affects simple immediate assertions |
4 | Observed Deferred Immediate | Affects observed deferred immediate assertions |
8 | Final Deferred Immediate | Affects final deferred immediate assertions |
16 | Expect | Affects expect statements |
32 | Unique | Affects unique constraints |
64 | Unique0 | Affects unique0 constraints |
128 | Priority | Affects priority constraints |
The directive_type
argument specifies which types of directives are affected by the control operation. Here's a list of the available directive_type
values and their meanings:
Value | Directive Type | Description |
---|---|---|
1 | Assert directives | Affects assert directives |
2 | Cover directives | Affects cover directives |
4 | Assume directives | Affects assume directives |
To use the $assertcontrol
system task, pass the appropriate values for control_type
, assertion_type
, and directive_type
as arguments. For example, to disable simple immediate assertions:
module TopModule;
// ...your code...
initial begin
$assertcontrol(4, 2, 1); // Disabling simple immediate assertions
end
endmodule
In this example, the control_type
value 4
corresponds to disabling assertions, the assertion_type
value 2
corresponds to simple immediate assertions, and the directive_type
value 1
corresponds to assert directives.
Here's another example that demonstrates enabling pass action execution for concurrent assertions:
module TopModule;
// ...your code...
initial begin
// Enabling pass action execution for concurrent assertions
$assertcontrol(6, 1, 1);
end
endmodule
In this case, the control_type
value 6
corresponds to enabling pass action execution, the assertion_type
value 1
corresponds to concurrent assertions, and the directive_type
value 1
corresponds to assert directives.
$asserton: Quickly Enable Assertion Checking
The $asserton
function allows you to enable assertion checking with ease. The example below demonstrates its usage:
module TopModule;
// ...your code...
initial begin
$asserton();
end
endmodule
$assertoff: Temporarily Disable Assertion Checking
With $assertoff
, you can temporarily disable assertion checking. Check out the following example:
module TopModule;
// ...your code...
initial begin
$assertoff();
end
endmodule
$assertkill: Abort and Stop Assertion Checking
When you need to abort and stop assertion checking, use the $assertkill
function. Here's how you can implement it:
module TopModule;
// ...your code...
initial begin
$assertkill();
end
endmodule
Managing Assertion Actions
$assertpasson: Enable Pass Action Execution
To enable the pass action execution for both vacuous and nonvacuous success, use the $assertpasson
function:
module TopModule;
// ...your code...
initial begin
$assertpasson();
end
endmodule
$assertpassoff: Disable Pass Action Execution
To disable pass action execution, you can use the $assertpassoff
function as shown below:
module TopModule;
// ...your code...
initial begin
$assertpassoff();
end
endmodule
$assertfailon: Enable Fail Action Execution
Use the $assertfailon
function to enable the fail action execution:
module TopModule;
// ...your code...
initial begin
$assertfailon();
end
endmodule
$assertfailoff: Disable Fail Action Execution
The $assertfailoff
function helps you disable fail action execution:
module TopModule;
// ...your code...
initial begin
$assertfailoff();
end
endmodule
$assertnonvacuouson: Enable Pass Action on Nonvacuous Success
To enable pass action execution only on nonvacuous success, use $assertnonvacuouson
:
module TopModule;
// ...your code...
initial begin
$assertnonvacuouson();
end
endmodule
$assertvacuousoff: Disable Pass Action on Vacuous Success
Lastly, to disable pass action execution on vacuous success, you can use the $assertvacuousoff
function:
module TopModule;
// ...your code...
initial begin
$assertvacuousoff();
end
endmodule
Here's a recap of the assertion control functions we've discussed in this blog post:
Function | Description |
---|---|
$assertcontrol | Fine-grained control over assertions and actions |
$asserton | Enable assertion checking |
$assertoff | Disable assertion checking |
$assertkill | Abort and stop assertion checking |
$assertpasson | Enable pass action execution |
$assertpassoff | Disable pass action execution |
$assertfailon | Enable fail action execution |
$assertfailoff | Disable fail action execution |
$assertnonvacuouson | Enable pass action on nonvacuous success |
$assertvacuousoff | Disable pass action on vacuous success |
By mastering the assertion control functions in Verilog and SystemVerilog, you can effectively manage and control the evaluation of assertions and the execution of action blocks in your designs. These functions provide a powerful way to ensure your designs meet your desired specifications, enabling you to create more reliable and efficient systems. Happy designing!