shuffle interface-reading code around to create InterfacesBase class
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 10 Jul 2018 04:10:23 +0000 (05:10 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 10 Jul 2018 04:10:23 +0000 (05:10 +0100)
(use for myhdl as well)

src/bsv/actual_pinmux.py
src/bsv/interface_decl.py
src/ifacebase.py [new file with mode: 0644]
src/myhdl/__init__.py [new file with mode: 0644]
src/myhdl/pinmux_generator.py [new file with mode: 0644]
src/pinmux_generator.py

index 223d1f8ca4c29c130850920aceff8cd476ac96c6..d2ce8160341df4890df5f777ea0b1202906542a7 100644 (file)
@@ -174,7 +174,7 @@ def init(p, ifaces):
                 continue
             temp = transfn(cname)
             x = ifaces.getifacetype(temp)
-            #print (cname, temp, x)
+            print (cname, temp, x)
             assert x is not None, "ERROR: The signal : " + \
                 str(cname) + \
                 " of pinmap.txt isn't present \nin the current" + \
index b5e551bcf5ca7533f5419cd3b46cc442593ebff4..5493d16a23d26e7195ffed541071767834bc3725 100644 (file)
@@ -7,7 +7,7 @@ except ImportError:
 
 from bsv.wire_def import generic_io  # special case
 from bsv.wire_def import muxwire  # special case
-
+from ifacebase import InterfacesBase
 
 class Pin(object):
     """ pin interface declaration.
@@ -271,78 +271,12 @@ class IOInterface(Interface):
         return generic_io.format(*args)
 
 
-class Interfaces(UserDict):
+class Interfaces(InterfacesBase):
     """ contains a list of interface definitions
     """
 
     def __init__(self, pth=None):
-        self.pth = pth
-        self.ifacecount = []
-        UserDict.__init__(self, {})
-        if not pth:
-            return
-        ift = 'interfaces.txt'
-        if pth:
-            ift = os.path.join(pth, ift)
-        with open(ift, 'r') as ifile:
-            for ln in ifile.readlines():
-                ln = ln.strip()
-                ln = ln.split("\t")
-                name = ln[0]  # will have uart
-                count = int(ln[1])  # will have count of uart
-                # spec looks like this:
-                """
-                [{'name': 'sda', 'outen': True},
-                 {'name': 'scl', 'outen': True},
-                ]
-                """
-                spec, ganged = self.read_spec(pth, name)
-                iface = Interface(name, spec, ganged, count == 1)
-                self.ifaceadd(name, count, iface)
-
-    def getifacetype(self, fname):
-        # finds the interface type, e.g sd_d0 returns "inout"
-        for iface in self.values():
-            typ = iface.getifacetype(fname)
-            if typ:
-                return typ
-        return None
-
-    def ifaceadd(self, name, count, iface, at=None):
-        if at is None:
-            at = len(self.ifacecount)  # ifacecount is a list
-        self.ifacecount.insert(at, (name, count))  # appends the list
-        # with (name,count) *at* times
-        self[name] = iface
-
-    """
-    will check specific files of kind peripheral.txt like spi.txt,
-    uart.txt in test directory
-    """
-
-    def read_spec(self, pth, name):
-        spec = []
-        ganged = {}
-        fname = '%s.txt' % name
-        if pth:
-            ift = os.path.join(pth, fname)
-        with open(ift, 'r') as sfile:
-            for ln in sfile.readlines():
-                ln = ln.strip()
-                ln = ln.split("\t")
-                name = ln[0]
-                d = {'name': name}  # here we start to make the dictionary
-                if ln[1] == 'out':
-                    d['action'] = True  # adding element to the dict
-                elif ln[1] == 'inout':
-                    d['outen'] = True
-                    if len(ln) == 3:
-                        bus = ln[2]
-                        if bus not in ganged:
-                            ganged[bus] = []
-                        ganged[bus].append(name)
-                spec.append(d)
-        return spec, ganged
+        InterfacesBase.__init__(self, Interface, pth)
 
     def ifacedef(self, f, *args):
         for (name, count) in self.ifacecount:
diff --git a/src/ifacebase.py b/src/ifacebase.py
new file mode 100644 (file)
index 0000000..2fb834c
--- /dev/null
@@ -0,0 +1,81 @@
+import os.path
+
+try:
+    from UserDict import UserDict
+except ImportError:
+    from collections import UserDict
+
+
+class InterfacesBase(UserDict):
+    """ contains a list of interface definitions
+    """
+
+    def __init__(self, ifacekls, pth=None):
+        self.pth = pth
+        self.ifacecount = []
+        UserDict.__init__(self, {})
+        if not pth:
+            return
+        ift = 'interfaces.txt'
+        if pth:
+            ift = os.path.join(pth, ift)
+        with open(ift, 'r') as ifile:
+            for ln in ifile.readlines():
+                ln = ln.strip()
+                ln = ln.split("\t")
+                name = ln[0]  # will have uart
+                count = int(ln[1])  # will have count of uart
+                # spec looks like this:
+                """
+                [{'name': 'sda', 'outen': True},
+                 {'name': 'scl', 'outen': True},
+                ]
+                """
+                spec, ganged = self.read_spec(pth, name)
+                iface = ifacekls(name, spec, ganged, count == 1)
+                self.ifaceadd(name, count, iface)
+
+    def getifacetype(self, fname):
+        # finds the interface type, e.g sd_d0 returns "inout"
+        for iface in self.values():
+            typ = iface.getifacetype(fname)
+            if typ:
+                return typ
+        return None
+
+    def ifaceadd(self, name, count, iface, at=None):
+        if at is None:
+            at = len(self.ifacecount)  # ifacecount is a list
+        self.ifacecount.insert(at, (name, count))  # appends the list
+        # with (name,count) *at* times
+        self[name] = iface
+
+    """
+    will check specific files of kind peripheral.txt like spi.txt,
+    uart.txt in test directory
+    """
+
+    def read_spec(self, pth, name):
+        spec = []
+        ganged = {}
+        fname = '%s.txt' % name
+        if pth:
+            ift = os.path.join(pth, fname)
+        with open(ift, 'r') as sfile:
+            for ln in sfile.readlines():
+                ln = ln.strip()
+                ln = ln.split("\t")
+                name = ln[0]
+                d = {'name': name}  # here we start to make the dictionary
+                if ln[1] == 'out':
+                    d['action'] = True  # adding element to the dict
+                elif ln[1] == 'inout':
+                    d['outen'] = True
+                    if len(ln) == 3:
+                        bus = ln[2]
+                        if bus not in ganged:
+                            ganged[bus] = []
+                        ganged[bus].append(name)
+                spec.append(d)
+        return spec, ganged
+
diff --git a/src/myhdl/__init__.py b/src/myhdl/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/myhdl/pinmux_generator.py b/src/myhdl/pinmux_generator.py
new file mode 100644 (file)
index 0000000..a31f97d
--- /dev/null
@@ -0,0 +1,6 @@
+from parse import Parse
+
+def pinmuxgen(pth=None, verify=True):
+    p = Parse(pth, verify)
+    print p, dir(p)
+
index e34b4c557f3e53e6b8ad4a1aa47e9e931e7b3a23..6dcc20dbc5f24b4db383b0d68f637d6d5366a905 100644 (file)
@@ -22,6 +22,7 @@ import sys
 from spec import modules, specgen, dummytest
 
 from bsv.pinmux_generator import pinmuxgen as bsvgen
+from myhdl.pinmux_generator import pinmuxgen as myhdlgen
 
 
 def printhelp():
@@ -94,7 +95,7 @@ if __name__ == '__main__':
             else:
                 specgen(of, output_dir, pinout, bankspec, pinspec, fixedpins)
     else:
-        gentypes = {'bsv': bsvgen}
+        gentypes = {'bsv': bsvgen, 'myhdl': myhdlgen }
         if output_type not in gentypes:
             print ("ERROR: output type '%s' does not exist" % output_type)
             printhelp()