Move pmod resource to own file and convert it in one function.
authorStaf Verhaegen <staf@stafverhaegen.be>
Thu, 5 Dec 2019 16:22:20 +0000 (17:22 +0100)
committerStaf Verhaegen <staf@stafverhaegen.be>
Fri, 6 Dec 2019 19:15:44 +0000 (20:15 +0100)
c4m/nmigen/jtag/__init__.py
c4m/nmigen/jtag/jtag.py
c4m/nmigen/jtag/pmod.py [new file with mode: 0644]

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..bfa79573dcb7f30ed0eefde1a7761ed9a8a94e38 100644 (file)
@@ -0,0 +1 @@
+from .pmod import *
index 88d12922149c87d5763dc2f9670edd656831d66d..0e4de64a43e03e646114301e3614fa27a2da7506 100755 (executable)
@@ -8,53 +8,11 @@ from nmigen.lib.io import *
 from wishbone import Wishbone
 
 __all__ = [
-    "PmodJTAGMasterResource",
-    "PmodJTAGMasterAResource",
-    "PmodJTAGSlaveResource",
-    "PmodJTAGSlaveAResource",
     "JTAG",
 ]
 
 #TODO: Provide more documentation
 
-def PmodJTAGMasterResource(name, number, *, pmod, attrs=Attrs(IOSTANDARD="LVCMOS33")):
-    return Resource(name, number,
-        Subsignal("TCK", Pins("1", dir="o", conn=("pmod", pmod))),
-        Subsignal("TMS", Pins("2", dir="o", conn=("pmod", pmod))),
-        Subsignal("TDO", Pins("3", dir="o", conn=("pmod", pmod))),
-        Subsignal("TDI", Pins("4", dir="i", conn=("pmod", pmod))),
-        attrs,
-    )
-
-def PmodJTAGMasterAResource(name, number, *, pmod, attrs=Attrs(IOSTANDARD="LVCMOS33")):
-    return Resource(name, number,
-        Subsignal("TCK", Pins("1", dir="o", conn=("pmod", pmod))),
-        Subsignal("TMS", Pins("2", dir="o", conn=("pmod", pmod))),
-        Subsignal("TDO", Pins("3", dir="o", conn=("pmod", pmod))),
-        Subsignal("TDI", Pins("4", dir="i", conn=("pmod", pmod))),
-        Subsignal("TRST", PinsN("7", dir="o", conn=("pmod", pmod))),
-        attrs,
-    )
-
-def PmodJTAGSlaveResource(name, number, *, pmod, attrs=Attrs(IOSTANDARD="LVCMOS33")):
-    return Resource(name, number,
-        Subsignal("TCK", Pins("1", dir="i", conn=("pmod", pmod))),
-        Subsignal("TMS", Pins("2", dir="i", conn=("pmod", pmod))),
-        Subsignal("TDI", Pins("3", dir="i", conn=("pmod", pmod))),
-        Subsignal("TDO", Pins("4", dir="o", conn=("pmod", pmod))),
-        attrs,
-    )
-
-def PmodJTAGSlaveAResource(name, number, *, pmod, attrs=Attrs(IOSTANDARD="LVCMOS33")):
-    return Resource(name, number,
-        Subsignal("TCK", Pins("1", dir="i", conn=("pmod", pmod))),
-        Subsignal("TMS", Pins("2", dir="i", conn=("pmod", pmod))),
-        Subsignal("TDI", Pins("3", dir="i", conn=("pmod", pmod))),
-        Subsignal("TDO", Pins("4", dir="o", conn=("pmod", pmod))),
-        Subsignal("TRST", PinsN("7", dir="i", conn=("pmod", pmod))),
-        attrs,
-    )
-
 
 class ShiftReg(Elaboratable):
     def __init__(self, ircodes, length, domain):
diff --git a/c4m/nmigen/jtag/pmod.py b/c4m/nmigen/jtag/pmod.py
new file mode 100644 (file)
index 0000000..bda2f26
--- /dev/null
@@ -0,0 +1,46 @@
+from nmigen.build import *
+
+__all__ = [
+    "PmodJTAGResource",
+]
+
+
+def PmodJTAGResource(*args, pmod_name="pmod", pmod_number, attrs=None,
+                     master=False, reset=False):
+    """Get a resource for a JTAG pins on a pmod.
+
+    The pins are configured in such a way that the master pmod jtag can
+    be connected to the tap pmod with a straight cable.
+
+    Args:
+        *args: either number or name, number.
+        pmod_name (str): name of the pmod connector; default = "pmod"
+        pmod_number (int): number of pmod connector
+        attrs (Attrs): attributes for the ``Resource``
+        master (bool): wether if this a master interface
+        reset (bool): wether to include a reset signal
+    """
+    if master:
+        mosi = "o"
+        miso = "i"
+        tdo_pin = "3"
+        tdi_pin = "4"
+    else:
+        mosi = "i"
+        miso = "o"
+        tdo_pin = "4"
+        tdi_pin = "3"
+    conn = (pmod_name, pmod_number)
+
+    ios = [
+        Subsignal("tck", Pins("1", dir=mosi, conn=conn)),
+        Subsignal("tms", Pins("2", dir=mosi, conn=conn)),
+        Subsignal("tdo", Pins(tdo_pin, dir="o", conn=conn)),
+        Subsignal("tdi", Pins(tdi_pin, dir="i", conn=conn)),
+    ]
+    if reset:
+        ios.append(Subsignal("trst", PinsN("7", dir=mosi, conn=conn)))
+    if attrs is not None:
+        ios.append(attrs)
+
+    return Resource.family(*args, default_name="jtag", ios=ios)