Professional Documents
Culture Documents
Interface Ports PDF
Interface Ports PDF
An interface can also have input, output or inout ports. Only the variables or nets declared in
the port list of an interface can be connected externally by name or position when the
interface is instantiated, and therefore can be shared with other interfaces. The ports are
declared using the ANSI-style.
Here is an example showing an interface with a clock port:
interface ClockedBus (input Clk);
logic[7:0] Addr, Data;
logic RWn;
endinterface
Parameterised Interface
A new construct related to Interface is also added: Modport. This provides direction
information for module interface ports and controls the use of tasks and functions within
certain modules. The directions of ports are those seen from the module.
This example includes modports, which are used to specify the direction of the signals in the
interface. The directions are the ones seen from the module to which the modport is
connected, in our case the RAM:
interface MSBus (input Clk);
logic [7:0] Addr, Data;
logic RWn;
modport Slave (input Addr, inout Data);
endinterface
module TestRAM;
logic Clk;
MSBus TheBus(.Clk(Clk));
RAM TheRAM (.MemBus(TheBus.Slave));
...
endmodule
Tasks in Interfaces
Tasks and functions can be defined in interfaces, to allow a more abstract level of modelling.
The next example shows two tasks in an interface being used to model bus functionality. The
tasks are called inside the testRAM module:
interface MSBus (input Clk);
logic [7:0] Addr, Data;
logic RWn;
module TestRAM;
logic Clk;
logic [7:0] data;
MSBus TheBus(.Clk(Clk));
RAM TheRAM (.MemBus(TheBus));
initial
begin
// Write to the RAM
for (int i = 0; i<256; i++)
TheBus.MasterWrite(i[7:0],i[7:0]);