5 Interafces
5 Interafces
1. It is easier to add new signals along with the existing connections in the interface(reusability).
2. signals within an Interface can be easily shared across the components by passing its handle.
3. It provides directional information (modports) and timing information (clocking blocks).
4. Interfaces can contain parameters, variables, functional coverage, assertions, tasks and functions.
5. Interfaces can contain procedural initial and always blocks and continuous assign statements.
Note: A module cannot be instantiated in an interface, But vice-versa is possible. Interfaces supports parameterization like modules.
Example-1:
endmodule i2.RWn=1;
i2.Data=mem[0];
end
endmodule
Example-2: (connecting multiplier with its testbench through interface driven by clock)
initial begin
$dumpfile("dump.vcd"); $dumpvars;
end
endmodule
Design Example: Two modules master and slave connected through bus structure through which address and data is communicated between master and slave using
interface.
5.Interafces Page 1
modport RTL (input clk, reset, a,b, en, output out,
endmodule ack);
endinterface
//connecting master and slave together
via Interface with modport
module top(ms_if tif);
Example: Multiplier
// Design code // Defining Interface // Defining Testbench
module multiplier(mult_if inf); interface mult_if (input logic clk, reset); module tb_top;
logic [7:0] a, b; bit clk;
always@(posedge inf.clk or posedge logic [15:0] out; bit reset;
inf.reset) begin logic en,ack;
if(inf.reset) begin modport TB (output a,b, en, input out, ack); always #2 clk = ~clk;
inf.out <= 0; modport RTL (input clk, reset, a,b, en, output out, ack);
inf.ack <= 0; endinterface initial begin
end clk = 0;
else if(inf.en) begin reset = 1;
inf.out <= inf.a * inf.b; #2;
inf.ack <= 1; reset = 0;
end end
else inf.ack <= 0;
end mult_if inf(clk, reset);
endmodule multiplier DUT(inf);
initial begin
// accessible signals: inf.TB.en , inf.TB.a ….
end
initial begin
$dumpfile("dump.vcd"); $dumpvars;
end
endmodule
Example-4(Parameterized Interface)
module Top; interface Channel #(parameter N=0)(input bit Clock, bit Ack, bit Sig); module TX(Channel Ch);
bit Clock, Ack, Sig; bit Buff[N-1:0];
initial for(int i=0; i<N; i++) Buff[i]=0;
//Instantiate the interface //accessible signals Ch.Clock, Ch.Ack, Ch.Sig….
Channel #(.N(7)) TheCh(.*); always @(posedge Clock)
if(Ack) Sig=Buff[N-1];
TX DUT(.Ch(TheCh)); else Sig=0; endmodule
…..
endmodule endinterface
In the below example we have specified that by default, input must be sampled 1 time unit before(Input Skew) and output should be driven 2 time unit(output skew) after
posedge clk.
module multiplier(mult_if.RTL inf); interface mult_if (input logic clk, reset);
logic [7:0] a, b; module tb_top;
always@(posedge inf.clk or posedge inf.reset) begin logic [15:0] out; bit clk,reset;
//accessible signals inf.out, inf.ack, inf.en, inf.a, inf.b logic en,ack; always #2 clk = ~clk;
end
Note: endmodule
• If we specify (default input #1ps output
@negedge )within clocking block means that
input is sampled at exactly 1ps, and outputs are
driven at negetive edge of clock instead of default
posedge.
• If default values not specified then input sampling
5.Interafces Page 2
• If default values not specified then input sampling
and output driving takesplace exactly at clocking
event.
Example: Consider a design with inputs clk, req drives an output signal gnt. grant is provided as soon as request is received. Interface is created to for port signals. Next
we drive inputs to the design so that it gives back the grant signal. It can be simulated in output window that req is driven #5ns after the clock edge.
endmodule
Interface Bundles:
Interface bundles is a collection of related signals, variables or other interfaces grouped together under a single interface name. It allows for modular design by
encapsulating related functionality or communication protocols.
Interface bundles are commonly used to represent the communication between different modules or blocks within the design, providing the standardized interface for
interactions.
Example: In the below example, the design refrences the actual interface name for access to its signals. The example below shows myDesign and yourDesign declares a
port in the portlist called if0 of type myInterface to access signals.
5.Interafces Page 3
Extra Concepts(Not Important)
➢ What are input and output skews in a clocking blocks?
For input skew in a clocking block all input signals within that block will be sampled at skew time units before the clock event, and all output signals in that block will be
driven skew times after the corresponding clock event.
Skew is specified as a constant expression or as a parameter. In the example shown below, we declared the clocking block to describe the signals belonging to this block has
be be sampled. signal req is specified to have a skew of 1ps and will be sampled 1ps before the clock edge clk, The output signal gnt has an output skew of 2 time units,
hence will be driven 2ns after the clock edge, the last signal sig is of inout type and will be sampled 1ns before the clockedge and driven 3ns after clockedge.
An input skew of 1step indicates that the signal should be sampled at immediately before the positive clockedge.
Output skew: In SV output skew refers to maximum allowable difference in arrival times of signals on different output ports of a module. It represents the time delay
variation between when different output signals transition from one state to another. Minimizing output skew ensures the proper operation of synchronous high speed
design.
• In the testbench we use for loop to iterate through each stimulus and use different clocking block for each iteration.
Input skew: In system verilog input skew refers to the maximum allowable difference in arrival times of signal on different input ports of a module. It represents the
time delay variation between when different input signals are sampled or recognized by the module.
• The interface declaration shown below has different clocking blocks before each with a different input skew.
• In the testbench, we'll fork 4 different threads at a time 0ns where each thread waits for the positive edge of clock and samples the output from DUT.
5.Interafces Page 4
5.Interafces Page 5