add SVG generator
[pinmux.git] / src / pinmux_generator.py
index c88146be844fd7b8e3207cc9fd205c27c1710dc1..859634eb4a76f1e83666d32945d20504ff9c8630 100644 (file)
@@ -19,9 +19,9 @@
 import getopt
 import os.path
 import sys
-from spec import modules, specgen
-
-from bsv.pinmux_generator import pinmuxgen as bsvgen
+import json
+from spec import modules, specgen, dummytest
+from spec.ifaceprint import create_sv
 
 
 def printhelp():
@@ -43,6 +43,7 @@ if __name__ == '__main__':
             'o:vht:s:',
             ['output=',
              'validate',
+             'test',
              'outputtype=',
              'spec=',
              'help',
@@ -58,6 +59,7 @@ if __name__ == '__main__':
     validate = False
     spec = None
     pinspec = None
+    testing = False
     for opt, arg in options:
         if opt in ('-o', '--output'):
             output_dir = arg
@@ -67,6 +69,8 @@ if __name__ == '__main__':
             output_type = arg
         elif opt in ('-v', '--validate'):
             validate = True
+        elif opt in ('--test',):
+            testing = True
         elif opt in ('-h', '--help'):
             printhelp()
             sys.exit(0)
@@ -79,16 +83,35 @@ if __name__ == '__main__':
         module = modules[pinspec]
 
         fname = os.path.join(output_dir or '', "%s.mdwn" % pinspec)
+        pyname = os.path.join(output_dir or '', "%s_pins.py" % pinspec)
         d = os.path.split(fname)[0]
         if not os.path.exists(d):
             os.makedirs(d)
         with open(fname, "w") as of:
-            pinout, bankspec, pinspec, fixedpins = module.pinspec(of)
-            specgen(of, output_dir, pinout, bankspec, pinspec, fixedpins)
+            with open(pyname, "w") as pyf:
+                ps = module.pinspec()
+                pinout, bankspec, pin_spec, fixedpins = ps.write(of)
+                #chip['litex.map'] = litexmap
+                if testing:
+                    dummytest(ps, output_dir, output_type)
+                else:
+                    specgen(of, output_dir, pinout,
+                            bankspec, ps.muxwidths, pin_spec, fixedpins,
+                            ps.fastbus)
+                pm, chip = module.pinparse(ps, pinspec)
+                litexmap = ps.pywrite(pyf, pm)
+                jchip = json.dumps(chip)
+                with open("%s/litex_pinpads.json" % pinspec, "w") as f:
+                    f.write(jchip)
+                create_sv("%s/%s.svg" % (pinspec, pinspec), chip)
     else:
-        gentypes = {'bsv': bsvgen}
-        if output_type not in gentypes:
+        if output_type == 'bsv':
+            from bsv.pinmux_generator import pinmuxgen as gentypes
+        elif output_type == 'myhdl':
+            from myhdlgen.pinmux_generator import pinmuxgen as gentypes
+        else:
             print ("ERROR: output type '%s' does not exist" % output_type)
             printhelp()
             sys.exit(0)
-        gentypes[output_type](output_dir, validate)
+
+        gentypes(output_dir, validate)