python2 print conversion
[pinmux.git] / src / bsv / pinmux_generator.py
index 9890f3f007514596009e5e75cfd278c79800eac0..745c7eb1e1aad323dd296c78a9949ec91c43aedc 100644 (file)
@@ -74,6 +74,8 @@ def pinmuxgen(pth=None, verify=True):
     # copy over template and library files
     shutil.copyfile(os.path.join(cwd, 'Makefile.template'),
                     os.path.join(bp, 'Makefile'))
+    shutil.copyfile(os.path.join(cwd, 'Makefile.peripherals.template'),
+                    os.path.join(bp, 'Makefile.peripherals'))
     cwd = os.path.join(cwd, 'bsv_lib')
     for fname in []:
         shutil.copyfile(os.path.join(cwd, fname),
@@ -85,10 +87,19 @@ def pinmuxgen(pth=None, verify=True):
     idef = os.path.join(bp, 'instance_defines.bsv')
     slow = os.path.join(bp, 'slow_peripherals.bsv')
     slowt = os.path.join(cwd, 'slow_peripherals_template.bsv')
+
     slowmf = os.path.join(bp, 'slow_memory_map.bsv')
     slowmt = os.path.join(cwd, 'slow_tuple2_template.bsv')
+
+    slowid = os.path.join(bp, 'slow_instance_defines.bsv')
+    slowit = os.path.join(cwd, 'slow_instance_defines_template.bsv')
+
     fastmf = os.path.join(bp, 'fast_memory_map.bsv')
     fastmt = os.path.join(cwd, 'fast_tuple2_template.bsv')
+
+    fastid = os.path.join(bp, 'fast_instance_defines.bsv')
+    fastit = os.path.join(cwd, 'fast_instance_defines_template.bsv')
+
     soc = os.path.join(bp, 'socgen.bsv')
     soct = os.path.join(cwd, 'soc_template.bsv')
 
@@ -96,11 +107,20 @@ def pinmuxgen(pth=None, verify=True):
     write_bvp(bvp, p, ifaces)
     write_bus(bus, p, ifaces)
     write_instances(idef, p, ifaces)
-    write_slow(slow, slowt, slowmf, slowmt, p, ifaces, iocells)
-    write_soc(soc, soct, fastmf, fastmt, p, ifaces, iocells)
-
-
-def write_slow(slow, slowt, slowmf, slowmt, p, ifaces, iocells):
+    write_slow(slow, slowt, slowmf, slowmt, slowid, slowit, p, ifaces, iocells)
+    write_soc(soc, soct, fastmf, fastmt, fastid, fastit, p, ifaces, iocells)
+
+
+def write_slow(
+        slow,
+        slowt,
+        slowmf,
+        slowmt,
+        slowid,
+        slowit,
+        p,
+        ifaces,
+        iocells):
     """ write out the slow_peripherals.bsv file.
         joins all the peripherals together into one AXI Lite interface
     """
@@ -130,13 +150,18 @@ def write_slow(slow, slowt, slowmf, slowmt, p, ifaces, iocells):
                                     numsloirqs, ifacedef,
                                     inst2, clockcon))
 
+    with open(slowid, "w") as bsv_file:
+        with open(slowit) as f:
+            slowit = f.read()
+        bsv_file.write(slowit.format(regdef))
+
     with open(slowmf, "w") as bsv_file:
         with open(slowmt) as f:
             slowmt = f.read()
-        bsv_file.write(slowmt.format(regdef, slavedecl, fnaddrmap))
+        bsv_file.write(slowmt.format(fnaddrmap, slavedecl))
 
 
-def write_soc(soc, soct, fastmf, fastmt, p, ifaces, iocells):
+def write_soc(soc, soct, fastmf, fastmt, fastid, fastit, p, ifaces, iocells):
     """ write out the soc.bsv file.
         joins all the peripherals together as AXI Masters
     """
@@ -171,10 +196,15 @@ def write_soc(soc, soct, fastmf, fastmt, p, ifaces, iocells):
                                    clockcon, mkmstcon,
                                    ))
 
+    with open(fastid, "w") as bsv_file:
+        with open(fastit) as f:
+            fastit = f.read()
+        bsv_file.write(fastit.format(regdef))
+
     with open(fastmf, "w") as bsv_file:
         with open(fastmt) as f:
             fastmt = f.read()
-        bsv_file.write(fastmt.format(regdef, slavedecl, mastdecl, fnaddrmap))
+        bsv_file.write(fastmt.format(slavedecl, mastdecl, fnaddrmap))
 
 
 def write_bus(bus, p, ifaces):
@@ -370,10 +400,10 @@ def write_bvp(bvp, p, ifaces):
             decl.append(muxdec .format(npins, bank))
             idec.append(gpioifc.format(bank))
             idec.append(muxifc.format(bank))
-        print dir(ifaces)
-        print ifaces.items()
-        print dir(ifaces['gpioa'])
-        print ifaces['gpioa'].pinspecs
+        print (dir(ifaces))
+        print (ifaces.items())
+        print (dir(ifaces['gpioa']))
+        print (ifaces['gpioa'].pinspecs)
         gpiodecl = '\n'.join(decl) + '\n' + '\n'.join(idec)
         gpiocfg = '\n'.join(cfg)
         bsv_file.write(axi4_lite.format(gpiodecl, gpiocfg))