create flexbus interface
[pinmux.git] / src / bsv / interface_decl.py
index 1b75e21cca0d59a318f461cba8b5166c765fb706..ad1413996d840d52167bd93bbb5e5c528c9527cf 100644 (file)
@@ -359,7 +359,7 @@ class Interface(PeripheralIface):
             plens = range(len(pins))
         else:
             for i in range(0, len(pins), 3):
-                plens += [i/3, i/3, i/3]
+                plens += [i / 3, i / 3, i / 3]
         for (typ, txt) in map(self.ifacedef3pin, plens, pins):
             if typ == 'tput':
                 tput.append(txt)
@@ -378,14 +378,14 @@ class Interface(PeripheralIface):
                  endmethod
                endinterface;
 """,
-"""\
+                    """\
                interface {3} = interface Put#({0})
                  method Action put({2} in);
 {1}
                  endmethod
                endinterface;
 """,
-"""\
+                    """\
                interface {3} = interface Get#({0})
                  method ActionValue#({2}) get;
                    {2} tget;
@@ -429,7 +429,7 @@ class InterfaceBus(object):
     def __init__(self, namelist, bitspec, filterbus):
         self.namelist = namelist
         self.bitspec = bitspec
-        self.fbus = filterbus # filter identifying which are bus pins
+        self.fbus = filterbus  # filter identifying which are bus pins
 
     def get_nonbuspins(self):
         return filter(lambda x: not x.name_.startswith(self.fbus), self.pins)
@@ -446,7 +446,7 @@ class InterfaceBus(object):
         plen = self.get_n_iopins(pins)
 
         res += '\n'
-        template = "          interface {1}#(Bit#({0})) {2};\n"
+        template = "          interface {1}#(%s) {2};\n" % self.bitspec
         for i, n in enumerate(self.namelist):
             if not n:
                 continue
@@ -462,9 +462,9 @@ class InterfaceBus(object):
 
         pins = self.get_buspins()
         plen = self.get_n_iopins(pins)
-        bitspec = "Bit#({0})".format(plen)
-        return '\n' + res + self.vectorifacedef2(pins, plen,
-                                    self.namelist, bitspec, *args) + '\n'
+        bitspec = self.bitspec.format(plen)
+        return '\n' + res + self.vectorifacedef2(
+            pins, plen, self.namelist, bitspec, *args) + '\n'
 
     def ifacedef3pin(self, idx, pin):
         decfn = self.ifacefmtdecfn2
@@ -484,8 +484,30 @@ class InterfaceLCD(InterfaceBus, Interface):
                               "Bit#({0})", "out")
         Interface.__init__(self, *args)
 
-    def get_n_iopins(self, pins): # HACK! assume in/out/outen so div by 3
-        return len(pins) 
+    def get_n_iopins(self, pins):  # HACK! assume in/out/outen so div by 3
+        return len(pins)
+
+
+class InterfaceFlexBus(InterfaceBus, Interface):
+
+    def __init__(self, *args):
+        InterfaceBus.__init__(self, ['ad_out', 'ad_out_en', 'ad_in'],
+                              "Bit#({0})", "ad")
+        Interface.__init__(self, *args)
+
+    def get_n_iopins(self, pins):  # HACK! assume in/out/outen so div by 3
+        return len(pins) / 3
+
+
+class InterfaceSD(InterfaceBus, Interface):
+
+    def __init__(self, *args):
+        InterfaceBus.__init__(self, ['out', 'out_en', 'in'],
+                              "Bit#({0})", "d")
+        Interface.__init__(self, *args)
+
+    def get_n_iopins(self, pins):  # HACK! assume in/out/outen so div by 3
+        return len(pins) / 3
 
 
 class InterfaceNSPI(InterfaceBus, Interface):
@@ -495,13 +517,14 @@ class InterfaceNSPI(InterfaceBus, Interface):
                               "Bit#({0})", "io")
         Interface.__init__(self, *args)
 
-    def get_n_iopins(self, pins): # HACK! assume in/out/outen so div by 3
+    def get_n_iopins(self, pins):  # HACK! assume in/out/outen so div by 3
         return len(pins) / 3
 
 
 class InterfaceEINT(Interface):
     """ uses old-style (non-get/put) for now
     """
+
     def ifacepfmt(self, *args):
         res = '\n'.join(map(self.ifacefmtdecpin, self.pins)).format(*args)
         return '\n' + res  # pins is a list
@@ -510,30 +533,18 @@ class InterfaceEINT(Interface):
         return self.ifacedef(*args)
 
 
+class InterfaceGPIO(InterfaceBus, Interface):
+    """ note: the busfilter cuts out everything as the entire set of pins
+        is a bus, but it's less code.  get_nonbuspins returns empty list.
+    """
 
-class InterfaceGPIO(Interface):
-
-    def ifacepfmt(self, *args):
-        return """
-          interface Put#(Vector#({0}, Bit#(1))) out;
-          interface Put#(Vector#({0}, Bit#(1))) out_en;
-          interface Get#(Vector#({0}, Bit#(1))) in;
-""".format(len(self.pinspecs))
-
-    def ifacedef2(self, *args):
-        return self.vectorifacedef2(self.pins, len(self.pinspecs),
-                        ['out', 'out_en', 'in'],
-                                    "Vector#({0},Bit#(1))", *args)
+    def __init__(self, ifacename, pinspecs, ganged=None, single=False):
+        InterfaceBus.__init__(self, ['out', 'out_en', 'in'],
+                              "Vector#({0},Bit#(1))", ifacename[-1])
+        Interface.__init__(self, ifacename, pinspecs, ganged, single)
 
-    def ifacedef3pin(self, idx, pin):
-        decfn = self.ifacefmtdecfn2
-        outfn = self.ifacefmtoutfn
-        # print pin, pin.outenmode
-        if pin.outenmode:
-            decfn = self.ifacefmtdecfn3
-            outfn = self.ifacefmtoutenfn
-        return pin.ifacedef3(idx, outfn, self.ifacefmtinfn,
-                             decfn)
+    def get_n_iopins(self, pins):  # HACK! assume in/out/outen so div by 3
+        return len(pins) / 3
 
 
 class Interfaces(InterfacesBase, PeripheralInterfaces):
@@ -544,8 +555,12 @@ class Interfaces(InterfacesBase, PeripheralInterfaces):
         InterfacesBase.__init__(self, Interface, pth,
                                 {'gpio': InterfaceGPIO,
                                  'spi': InterfaceNSPI,
+                                 'mspi': InterfaceNSPI,
                                  'lcd': InterfaceLCD,
+                                 'sd': InterfaceSD,
+                                 'fb': InterfaceFlexBus,
                                  'qspi': InterfaceNSPI,
+                                 'mqspi': InterfaceNSPI,
                                  'eint': InterfaceEINT})
         PeripheralInterfaces.__init__(self)