add pin-to-litex json map
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 13 Apr 2021 16:02:52 +0000 (17:02 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 13 Apr 2021 16:02:52 +0000 (17:02 +0100)
src/pinmux_generator.py
src/spec/base.py
src/spec/ifaceprint.py
src/spec/ls180.py

index 94357b0b6701cc9d675118fd9d1e7b90ab59d6c4..04d3cf98981e45b77d4b9e0a044671e491239e58 100644 (file)
@@ -19,6 +19,7 @@
 import getopt
 import os.path
 import sys
+import json
 from spec import modules, specgen, dummytest
 
 
@@ -88,15 +89,20 @@ if __name__ == '__main__':
         with open(fname, "w") as of:
             with open(pyname, "w") as pyf:
                 ps = module.pinspec()
+                pm, chip = module.pinparse(ps, pinspec)
+                litexmap = ps.pywrite(pyf, pm)
                 pinout, bankspec, pin_spec, fixedpins = ps.write(of)
+                chip['litex.map'] = litexmap
+                chip = json.dumps(chip)
+                with open("%s/litex_pinpads.json" % pinspec, "w") as f:
+                    f.write(chip)
+
                 if testing:
                     dummytest(ps, output_dir, output_type)
                 else:
                     specgen(of, output_dir, pinout,
                             bankspec, ps.muxwidths, pin_spec, fixedpins,
                             ps.fastbus)
-                pm = module.pinparse(ps, pinspec)
-                ps.pywrite(pyf, pm)
     else:
         if output_type == 'bsv':
             from bsv.pinmux_generator import pinmuxgen as gentypes
index c6f4ccb32e4c007c24fd62c3f5aef3388f20b8b6..3207b409af188451dc99c5c8957f17905fcb8da8 100644 (file)
@@ -38,8 +38,7 @@ class PinSpec(Pinouts):
         self.scenarios.append((name, needed, eint, pwm, descriptions))
 
     def pywrite(self, pyf, pinmap):
-
-        python_dict_fns(pyf, pinmap, self, self.function_names)
+        return python_dict_fns(pyf, pinmap, self, self.function_names)
 
     def write(self, of):
 
index 3d3cfb4b27662b58e348dacc8202eb8e2184c0bc..808985ce5f4fa884939bbb217e73672508f385dd 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 
 from copy import deepcopy
-
+from collections import OrderedDict
 
 def display(of, pins, banksel=None, muxwidth=4):
     of.write("""\
@@ -89,6 +89,7 @@ def map_name(pinmap, fn, fblower, pin, rename):
 
 def python_pindict(of, pinmap, pins, function_names, dname, remap):
 
+    res = OrderedDict()
     of.write("\n%s = OrderedDict()\n" % dname)
 
     for k, pingroup in pins.byspec.items():
@@ -97,9 +98,12 @@ def python_pindict(of, pinmap, pins, function_names, dname, remap):
             a = "%s%s" % (a, n)
         fblower = a.lower()
         of.write("%s['%s'] = [ " % (dname, fblower))
+        res[fblower] = []
         count = 0
         for i, p in enumerate(pingroup):
-            of.write("'%s', " % map_name(pinmap, k[0], fblower, p, remap))
+            name = map_name(pinmap, k[0], fblower, p, remap)
+            res[fblower].append(name)
+            of.write("'%s', " % name)
             count += 1
             if count == 4 and i != len(pingroup)-1:
                 of.write("\n                ")
@@ -107,6 +111,7 @@ def python_pindict(of, pinmap, pins, function_names, dname, remap):
         of.write("]\n")
         print "    dict %s" % dname, a, n, pingroup
     of.write("\n\n")
+    return res
 
 def python_dict_fns(of, pinmap, pins, function_names):
     of.write("# auto-generated by Libre-SOC pinmux program: do not edit\n")
@@ -129,8 +134,28 @@ def python_dict_fns(of, pinmap, pins, function_names):
     print "by spec", pins.byspec
     print pinmap
 
-    python_pindict(of, {}, pins, function_names, 'pindict', False)
-    python_pindict(of, pinmap, pins, function_names, 'litexdict', True)
+    pd = python_pindict(of, {}, pins, function_names, 'pindict', False)
+    ld = python_pindict(of, pinmap, pins, function_names, 'litexdict', True)
+
+    print "pd", pd
+    print "ld", ld
+    # process results and create name map
+    litexmap = OrderedDict()
+    for k in pd.keys():
+        pl = pd[k]
+        ll = ld[k]
+        for pname, lname in zip(pl, ll):
+            pname = "%s_%s" % (k, pname[:-1]) # strip direction +/-/*
+            lname = lname[:-1] # strip direction +/-/*
+            if k in ['eint', 'pwm', 'gpio', 'vdd', 'vss']: # sigh
+                lname = "%s_%s" % (k, lname)
+            litexmap[pname] = lname
+    print "litexmap", litexmap
+    of.write("litexmap = {\n")
+    for k, v in litexmap.items():
+        of.write("\t'%s': '%s',\n" % (k, v))
+    of.write("}\n")
+    return litexmap
 
 
 def display_fns(of, bankspec, pins, function_names):
index e69a131360f1faff3d1a24a11e835f6093afeebd..15f9353c45708d5b6b2cf32a14bb0d84dc170c51 100644 (file)
@@ -418,8 +418,4 @@ def pinparse(psp, pinspec):
               'chip.n_extpower': n_extpower,
            }
 
-    chip = json.dumps(chip)
-    with open("ls180/litex_pinpads.json", "w") as f:
-        f.write(chip)
-
-    return pinmap
+    return pinmap, chip