use class iterator for mk_connection (all of them)
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 5 Aug 2018 17:33:55 +0000 (18:33 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 5 Aug 2018 17:33:55 +0000 (18:33 +0100)
src/bsv/peripheral_gen/base.py
src/bsv/peripheral_gen/gpio.py

index 56ccd95f3484ad5227401a8f6c1267df863dd050..582a035016560882fa6e4dca52b8000786e1cb32 100644 (file)
@@ -431,11 +431,9 @@ else"""
         con = con.format(count, aname)
         return txt.format(con, aname, fabricname)
 
-    def mk_master_connection(self, count, fabricname, typ, name=None):
+    def mk_master_connection(self, name, count, fabricname, typ):
         if not self.has_axi_master():
             return ''
-        if name is None:
-            name = self.name
         print "PBase mk_master_conn", self.name, count
         aname = self.axi_master_name(name, count, typ)
         ret = []
@@ -447,10 +445,10 @@ else"""
                                                    fabricname))
         return '\n'.join(ret)
 
-    def mk_connection(self, count, fabricname, typ, name=None):
-        if name is None:
-            name = self.name
-        print "PBase mk_conn", self.name, count
+    def mk_connection(self, name, count, fabricname, typ, name_override=None):
+        if name_override: # needed for GPIO
+            name = name_override
+        print "PBase mk_conn", name, count
         ret = []
         connections = self._mk_connection(name, count)
         if not isinstance(connections, list):
@@ -823,16 +821,8 @@ class PeripheralInterfaces(object):
     def _mk_connection(self, fabric, typ, indent, master, *args):
         ret = []
         for (name, count) in self.ifacecount:
-            for i in range(count):
-                if self.is_on_fastbus(name, i):
-                    continue
-                if master:
-                    txt = self.data[name].mk_master_connection(i, fabric, typ)
-                else:
-                    txt = self.data[name].mk_connection(i, fabric, typ)
-                if name == 'gpioa':
-                    print "txt", txt
-                ret.append(txt)
+            ret += list(MkConnection(self, name, count,
+                            fabric, typ, master, *args))
         return '\n'.join(li(list(filter(None, ret)), indent))
 
     def mk_master_connection(self, *args):
@@ -978,6 +968,7 @@ class IfaceIter(object):
             if self.i >= self.maxcount:
                 raise StopIteration
             if self.check(self.name, self.i):
+                #print self.item, self.args
                 res = self.item(self.name, self.i, *self.args)
                 if res:
                     self.i += 1
@@ -987,6 +978,20 @@ class IfaceIter(object):
     def next(self):
         return self.__next__()
 
+class MkConnection(IfaceIter):
+
+    def __init__(self, ifaces, name, count, *args):
+        self.ifaces = ifaces
+        IfaceIter.__init__(self, name, count, *args)
+
+    def check(self, name, i):
+        return not self.ifaces.is_on_fastbus(name, i)
+
+    def item(self, name, i, fabric, typ, master):
+        if master:
+            return self.ifaces.data[name].mk_master_connection(name,
+                                i, fabric, typ)
+        return self.ifaces.data[name].mk_connection(name, i, fabric, typ)
 
 class MkExtIface(IfaceIter):
 
index 73fd2a3efd4d8bb0d99e89cc44b9c8125c7b656f..50b9f63c3f7dd2a25885e94ddd4ebac8e37e4610 100644 (file)
@@ -43,12 +43,13 @@ class gpio(PBase):
         return "MUX#(%d) mux{0} <- mkmux('b%s);\n" % (size, dflt) + \
                "GPIO#(%d) gpio{0} <- mkgpio();" % size
 
-    def mk_connection(self, count, fabricname, typ):
+    def mk_connection(self, name, count, fabricname, typ):
         print "GPIO mk_conn", self.name, count
         res = []
         dname = self.mksuffix(self.name, count)
         for i, n in enumerate(['gpio' + dname, 'mux' + dname]):
-            res.append(PBase.mk_connection(self, count, fabricname, typ, n))
+            res.append(PBase.mk_connection(self, name, count, fabricname, typ,
+                                           name_override=n))
         return '\n'.join(res)
 
     def _mk_connection(self, name=None, count=0):