Professional Documents
Culture Documents
4-8 March
4-8 March
Polymorphism means having many forms. A base class handle can invoke methods of its child class
which has the same name. Hence, an object can take many forms.
1. As we know, the derived class object can override methods of its base class. Similarly, the
base class object can also override the method of one of the child classes. It means a base
class method has different forms based on derived class implementation.
2. To use many forms of the method, the virtual keyword must be used in the method
definition.
Steps for Polymorphism:
Data hiding is a mechanism to hide class members within the class. They are not accessible outside
of class scope. This avoids class member modification outside the class scope and its misuse.
By default, all class members are accessible with class handles in SystemVerilog. To restrict access,
access qualifiers are used.
A protected class member can not be accessed outside class scope except access by their child
classes.
Interface:
Unlike Verilog that has module ports for communication, SystemVerilog provides an interface
construct that simply contains a bundle of sets of signals. This encapsulates signals and
communicates with design, testbench components.
interface bus (input clk); interface bus #(parameter WIDTH = 32)(input clk);
logic [31:0] addr; logic [WIDTH-1:0] addr;
logic [31:0] data; logic [WIDTH-1:0] data;
logic en; logic en;
endinterface endinterface
interface fa_if; module half_addr(input a, b, output so, co);
logic a, b, c; assign so = a^b;
logic s_out, c_out; assign co = a & b;
endinterface endmodule
Syntax:
modport <name> ( input <port_list>, output <port_list>);
To specify synchronization scheme and timing requirements for an interface, a clocking block is
used. The testbench can have multiple clocking blocks but only one clocking block per clock.
The clocking block can be declared in the program, module, or interface.
Syntax:
clocking <clocking_name> (<clocking event>);
Default input <delay> output <delay>;
<signals>
endclocking
Clocking Skew:
The input or output clocking block signals can be sampled before or after some time unit delay known as clocking
skew. It is declared as:
default input #2 output #3;
Input clocking skew: #2
Output clocking skew: #3
1. This means input signals is sampled #2 time unit before the clocking event and output signals are driven, #3 time
units after the clocking event.
2. The input and output skews must be either parameter or constant. By default, input and output skews are 0 time
units if not specified. It is possible to specify particular time units otherwise by default skews are considered based
on the timescale in the current scope.
Note: In the clocking block, the direction of signals is mentioned w.r.t. testbench (not w.r.t. DUT).
Clocking Block Declarations
//1 //4
clocking cb @(negedge clk); clocking cb @(posedge clk);
default input #2 output #3; default input #1ps output #4; // explicit declaration of time
input ... unit
output ... input ...
endclocking output ...
endclocking
//2
clocking cb @(clk); // clocking event without edge //5
//outputs are driven on negedge clk clocking cb @(posedge clk);
default input #2 output negedge; default input #1ps output #4; // explicit declaration of time
input ... unit
output ... input #2ps <signal_name>;
endclocking input #3 output #4 <signal_name>;
endclocking
//3
clocking cb @(posedge clk);
default input #1 output negedge;
//outputs are driven on negedge clk
input ...
output ...
endclocking
Virtual Interface
An interface represents signals that are used to connect design modules or testbench to the DUT and commonly
known as a physical interface. The design and physical interface are static in nature. Hence, they can not be used
dynamically. In modern testbench, randomized class objects are used and connect to the design dynamically. Hence, to
bridge the gap between the static world of modules and the dynamic world of objects, a virtual interface is used as a
pointer or handle for an actual interface.
SV File: C File:
module tb;
#include <stdio.h>
import "DPI-C" function void addition(int a, int b);
C File: SV File:
#include <stdio.h> module tb;
//#include <svdpi.h>
export "DPI-C" function addition; // This is not a function prototype
extern void addition(int, int); import "DPI-C" context function void c_caller();
} initial
begin
c_caller();
end
endmodule
Output:
Extern Methods:
1. Method definition and declaration should have the same number of argument lists, data types, and argument
names.
2. For the extern function return type should be the same if used.
3. If the definition of method (task or function) is written outside the body of class then the method is called
external method.
4. To do this, need to declare the method with an “extern” keyword in the class body.
5. The extern qualifier indicates that the body of the method(its implementation) is to be found outside the class
declaration.
6. Before the method name the class name should be specified with a class scope resolution to specify to which
class the method corresponds to.
7. Number of arguments, argument name and argument type should match between method declaration and
method definition.
Output:
data = 100 and id = 1
Time = 50, delayed data = 100