remove manual dictionary, use interface txt file definitions
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 28 Mar 2018 14:16:06 +0000 (15:16 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 28 Mar 2018 14:16:06 +0000 (15:16 +0100)
src/bsv/actual_pinmux.py
src/bsv/interface_decl.py
src/bsv/pinmux_generator.py

index 76a0e2e0ca686f5bf7e132e30b88d501b1d775f9..2be8fc99688fe22515f2e97d7abb9174efecfd74 100644 (file)
@@ -5,23 +5,6 @@ except ImportError:
     maketrans = str.maketrans
 
 
-# dictionary of properties of signals that are supported.
-dictionary = {
-    "uart_rx"  : "input",
-    "uart_tx"  : "output",
-    "spi_sclk" : "output",
-    "spi_mosi" : "output",
-    "spi_ss"   : "output",
-    "spi_miso" : "input",
-    "twi_sda"  : "inout",
-    "twi_scl"  : "inout",
-    "sd_clk": "output",
-    "sd_cmd": "output",
-    "sd_d": "inout",
-    "pwm_pwm": "output"
-}
-
-
 # ============== common bsv templates ============ #
 # first argument is the io-cell number being assigned.
 # second argument is the mux value.
@@ -44,7 +27,15 @@ def cn(idx):
     return "cell%s_mux" % str(idx)
 
 
-def init(p):
+def transfn(temp):
+    temp = temp.split('_')
+    if len(temp) == 2:
+        temp[0] = temp[0].translate(digits)
+        temp[0] = temp[0] .replace(' ', '')
+    return '_'.join(temp)
+
+
+def init(p, ifaces):
     p.pinmux = ' '
     global dedicated_wire
     for cell in p.muxed_cells:
@@ -62,28 +53,28 @@ def init(p):
         # since the interfaces are always standard and cannot change from
         # user-to-user. Plus this also reduces human-error as well :)
         for i in range(0, len(cell) - 1):
-            temp = cell[i + 1].translate(digits)
-            temp = temp.replace(' ', '')
-            x = dictionary.get(temp)
+            cname = cell[i+1]
+            temp = transfn(cname)
+            x = ifaces.getifacetype(temp)
+            print cname, temp, x
             assert x is not None, "ERROR: The signal : " + \
-                str(cell[i + 1]) + \
+                str(cname) + \
                 " of pinmap.txt isn't present \nin the current" + \
                 " dictionary. Update dictionary or fix-typo."
             if x == "input":
                 p.pinmux += \
-                    mux_wire.format(cell[0], i, "wr" + cell[i + 1]) + "\n"
+                    mux_wire.format(cell[0], i, "wr" + cname) + "\n"
             elif x == "inout":
                 p.pinmux += \
-                    mux_wire.format(cell[0], i, "wr" + cell[i + 1] +
+                    mux_wire.format(cell[0], i, "wr" + cname +
                                                 "_in") + "\n"
     # ============================================================ #
 
     # ==================  Logic for dedicated pins ========= #
     for cell in p.dedicated_cells:
-        p.pinmux += "      %s" % cn(cell[0]) + \
-            "_out=" + cell[1] + "_io;\n"
+        p.pinmux += "      %s_out=%s_io;\n" % (cn(cell[0]), cell[1])
         temp = cell[1].translate(digits)
-        x = dictionary.get(temp)
+        x = ifaces.getifacetype(temp)
         if x == "input":
             pinmux = pinmux + \
                 dedicated_wire.format(cell[0], "wr" + cell[1]) + "\n"
index 51e56b2eb2d735895ed1e9cb297b746a88f0ba2c..c10fa9a2b737904fbff795b6904be2e142558edf 100644 (file)
@@ -99,6 +99,18 @@ class Interface(object):
                 _p['name'] = self.pname(p['name'])
                 self.pins.append(Pin(**_p))
 
+    def getifacetype(self, name):
+        for p in self.pinspecs:
+            fname = "%s_%s" % (self.ifacename, p['name'])
+            print "search", self.ifacename, name, fname
+            if fname == name:
+                if p.get('action'):
+                    return 'out'
+                elif p.get('outen'):
+                    return 'inout'
+                return 'input'
+        return None
+
     def pname(self, name):
         return '%s{0}_%s' % (self.ifacename, name)
 
@@ -203,6 +215,14 @@ class Interfaces(UserDict):
                 spec = self.read_spec(pth, name)
                 self.ifaceadd(name, count, Interface(name, spec))
 
+    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)
index 5957ad882b125378d5de86568dafa1ec0077a7c4..7f8f1a518babfbd1297620733f0eac3803acd1aa 100644 (file)
@@ -63,9 +63,9 @@ def pinmuxgen(pth=None, verify=True):
     """
 
     p = Parse(pth, verify)
-    init(p)
     ifaces = Interfaces(pth)
     ifaces.ifaceadd('io', p.N_IO, io_interface, 0)
+    init(p, ifaces)
 
     bp = 'bsv_src'
     if pth: