ch6-Modport
2019-11-02
SystemVerilog Modport
Modport lists with directions are defined in an interface to impose certain restrictions on interface access within a module. The keyword modport
indicates that the directions are declared as if inside the module.
Syntax
1 |
|
Shown below is the definition of an interface myInterface which has a few signals and two modport
declarations. The modport dut0 essentially states that the signals ack and sel are inputs and gnt and irq0 are outputs to whatever module uses this particular modport.
Similarly, another modport called dut1 is declared which states that gnt and irq0 are inputs and the other two are outputs for any module that uses modport dut1.
1 |
|
Example of named port bundle
In this style, the design will take the required correct modport definition from the interface object as mentioned in its port list. The testbench only needs to provide the whole interface object to the design.
1 |
|
Example of connecting port bundle
In this style, the design simply accepts whatever directional information is given to it. Hence testbench is responsible to provide the correct modport values to the design.
1 |
|
What is the need for a modport ?
Nets declared within a simple interface is inout
by default and hence any module connected to the same net, can either drive values or take values from it. In simple words, there are no restrictions on direction of value propagation. You could end up with an X on the net because both the testbench and the design are driving two different values to the same interface net. Special care should be taken by the testbench writer to ensure that such a situation does not happen. This can be inherently avoided by the use of modports.
Example of connecting to generic interface
A module
can also have a generic interface as the portlist. The generic handle can accept any modport passed to it from the hierarchy above.
1 |
|
Design Example
Lets consider two modules master and slave connected by a very simple bus structure. Assume that the bus is capable of sending an address and data which the slave is expected to capture and update the information in its internal registers. So the master always has to initiate the transfer and the slave is capable of indicating to the master whether it is ready to accept the data by its sready signal.
Interface
Shown below is an interface
definition that is shared between the master and slavemodules.
1 |
|
Design
Assume that the master simply iterates the address from 0 to 3 and sends data equal to the address multiplied by 4. The master should only send when the slave is ready to accept and is indicated by the sready signal.
1 |
|
Assume that the slave accepts data for every addr and assigns them to internal registers. When the address wraps from 3 to 0, the slave requires 1 additional clock to become ready.
1 |
|
The two design modules are tied together at a top level.
1 |
|
Testbench
The testbench will pass the interface handle to the design, which will then assign master and slave modports to its sub-modules.
1 |
|
Simulation Output
Remember that the master initiates bus transactions and the slave captures data and stores it in its internal registers reg_* for the corresponding address.
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!