add vectorised gpio interface
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 23 Jul 2018 11:50:59 +0000 (12:50 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 23 Jul 2018 11:50:59 +0000 (12:50 +0100)
src/bsv/interface_decl.py
src/bsv/pinmux_generator.py

index 8746c8ae85da2632a8aed8dba942232218fead89..892e1f03aa00607eb68f3370d589874f9f6fecd3 100644 (file)
@@ -141,16 +141,17 @@ class Pin(object):
 
     def ifacedef3(self, fmtoutfn, fmtinfn, fmtdecfn):
         if self.action:
+            fmtname = fmtinfn(self.name)
             if self.name.endswith('outen'):
                 name = "tputen"
             else:
                 name = "tput"
-            fmtname = fmtinfn(self.name)
-            res = "              %s <= %s[%d];" % (fmtname, name, self.idx)
+            res = "                   %s <= in[%d];" % (fmtname, self.idx)
         else:
             fmtname = fmtoutfn(self.name)
-            res = "              tget[%d] = %s;" % (self.idx, fmtname)
-        return res
+            res = "                   tget[%d] <= %s;" % (self.idx, fmtname)
+            name = 'tget'
+        return (name, res)
 
 class Interface(PeripheralIface):
     """ create an interface from a list of pinspecs.
@@ -370,32 +371,40 @@ class IOInterface(Interface):
 class InterfaceGPIO(Interface):
 
     def ifacedef2(self, *args):
-        res = '\n'.join(map(self.ifacedef2pin, self.pins))
-        res = res.format(*args)
+        tput = []
+        tget = []
+        tputen = []
+        for (typ, txt) in map(self.ifacedef2pin, self.pins):
+            if typ == 'tput':
+                tput.append(txt)
+            elif typ == 'tget':
+                tget.append(txt)
+            elif typ == 'tputen':
+                tputen.append(txt)
+        tput = '\n'.join(tput).format(*args)
+        tget = '\n'.join(tget).format(*args)
+        tputen = '\n'.join(tputen).format(*args)
 
-        tdecl = """\
-              Vector#({0},Bit#(1)) tput;
-              Vector#({0},Bit#(1)) tputen;
-              Vector#({0},Bit#(1)) tget;
-""".format(len(self.pinspecs))
         template = """\
-              interface gpio_out = interface Put#
+              interface gpio_out = interface Put#({0})
                  method Action put(Vector#({0},Bit#(1)) in);
-                   tput<=in;
+{1}
                  endmethod
                endinterface;
-               interface gpio_outen = interface Put#
+               interface gpio_outen = interface Put#({0})
                  method Action put(Vector#({0},Bit#(1)) in);
-                   tputen<=in;
+{2}
                  endmethod
                endinterface;
-               interface gpio_in = interface Get#
+               interface gpio_in = interface Get#({0})
                  method ActionValue#(Vector#({0},Bit#(1))) get;
+                   Vector#({0},Bit#(1)) tputen;
+{3}
                    return tget;
                  endmethod
                endinterface;
-""".format(len(self.pinspecs))
-        return '\n' + tdecl + res + '\n' + template + '\n'
+""".format(len(self.pinspecs), tput, tputen, tget)
+        return '\n' + template + '\n'
 
     def ifacedef2pin(self, pin):
         decfn = self.ifacefmtdecfn2
index 67e018c78ef4796d1523b33da1f56fa7e4e9039c..881f99b2b56e8fe3ccc9aa26b33d24b70e8f371d 100644 (file)
@@ -40,6 +40,7 @@ header = copyright + '''
 package pinmux;
 
 import GetPut::*;
+import Vector::*;
 
 '''
 footer = '''