Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add doc about SVIF (system verilog interface) #247

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 171 additions & 0 deletions source/SpinalHDL/Data types/SVIF.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
.. _SVIF:

Check warning on line 1 in source/SpinalHDL/Data types/SVIF.rst

View workflow job for this annotation

GitHub Actions / build

document isn't included in any toctree

Check warning on line 1 in source/SpinalHDL/Data types/SVIF.rst

View workflow job for this annotation

GitHub Actions / test

document isn't included in any toctree

SVIF
======

Description
^^^^^^^^^^^

The ``SVIF`` type specifically targets system Verilog designs.This type extends from ``Bundle``.When generating Verilog or VHDL, the behavior of this type is exactly the same as that of ``Bundle``.However, when generating System Verilog and enabling the ``svInterface`` option in SpinalConfig, this type will be generated as an Interface.

This type is still an experimental feature

Declaration
^^^^^^^^^^^

The syntax to declare a SVIF is as follows:

.. code-block:: scala

case class myBundle extends SVIF {
val bundleItem0 = AnyType
val bundleItem1 = AnyType
val bundleItemN = AnyType
}

For example, a SVIF holding a color could be defined as:

.. code-block:: scala

case class Color(channelWidth: Int) extends SVIF {
val r, g, b = UInt(channelWidth bits)
}

modport
~~~~~~~

``modport`` can be implemented through add annotations above functions, with the function name serving as the modport name.

.. code-block:: scala

case class Color(channelWidth: Int) extends SVIF {
val r, g, b = UInt(channelWidth bits)

@modport
def mst = {
out(r, g, b)
}

@modport
def slv = {
in(r, g, b)
}
}

with ``IMasterSlave``:

.. code-block:: scala

case class Color(channelWidth: Int) extends SVIF with IMasterSlave {
val r, g, b = UInt(channelWidth bits)

override def asMaster = {
out(r, g, b)
}

@modport
def mst = asMaster

@modport
def slv = asSlave
}

Parameter
~~~~~~~~~

.. code-block:: scala

case class Color(channelWidth: Int) extends SVIF {
val width = addGeneric("WIDTH", channelWidth)// or addParameter
val r, g, b = UInt(channelWidth bits)
tieGeneric(r, width)// or tieParameter
tieGeneric(g, width)
tieGeneric(b, width)

@modport
def mst = out(r, g, b)

@modport
def slv = in(r, g, b)
}

.. code-block:: scala

case class ColorHandShake(Width: Int) extends SVIF with IMasterSlave {
val w = addGeneric("W", Width, default = "8")
val valid = Bool()
val payload = Color(Width)
val ready = Bool()
tieIFParameter(payload, "WIDTH", "W") // for generate " .WIDTH (W)"

override def asMaster = {
out(valid, payload)
in(ready)
}

@modport
def mst = asMaster

@modport
def slv = asSlave
}

this will generate system verilog code as below:

.. code-block:: scala

interface ColorHandShake #(
parameter W = 8
) () ;

logic valid ;
Color #(
.WIDTH (W)
) payload();
logic ready ;

modport mst (
output valid,
Color.slv payload,
input ready
);

modport slv (
input valid,
Color.mst payload,
output ready
);

endinterface

interface Color #(
parameter WIDTH
) () ;

logic [WIDTH-1:0] r ;
logic [WIDTH-1:0] g ;
logic [WIDTH-1:0] b ;

modport mst (
input r,
input g,
input b
);

modport slv (
output r,
output g,
output b
);

endinterface

Definition Name
~~~~~~~~~~~~~~~

you can use ``setDefinitionName`` to set the definition name. But remember to use it before any clone of this interface

Not Interface
~~~~~~~~~~~~~

If you have used a certain interface in multiple places, and at one of those locations ``sigA``, you wish to flatten it instead of generating an interface, you can achieve this by calling ``sigA.notSVIF()`` to fully flatten the signal. If the signal has nested interfaces and you only want to expand the outermost layer, you can use ``sigA.notSVIFthisLevel()``.
Loading