use function abstraction, reduce code a bit
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 20 Jul 2018 07:39:15 +0000 (08:39 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 20 Jul 2018 07:39:15 +0000 (08:39 +0100)
src/bsv/peripheral_gen.py
src/bsv/pinmux_generator.py

index 23db979c1780043fe9c3496a95f59e01cac80f2c..80c1b051d7d4e409839ef1355cdda3b85464bc0f 100644 (file)
@@ -1,6 +1,7 @@
 import types
 from copy import deepcopy
 
+
 class PBase(object):
     pass
 
@@ -40,7 +41,7 @@ class PBase(object):
             return tuple2(True,fromInteger(valueOf({2})));
         else""".format(bname, bend, name)
 
-    def mkslow_peripheral(self, name, ifacenum):
+    def mkslow_peripheral(self):
         return ''
 
 
@@ -140,7 +141,6 @@ class pwm(PBase):
         return "        Ifc_PWM_bus pwm_bus <- mkPWM_bus(sp_clock);"
 
 
-
 class gpio(PBase):
     def __init__(self):
         PBase.__init__(self)
@@ -182,6 +182,7 @@ typedef  TAdd#(Plic_slave_num   ,`ifdef AXIEXP      1 `else 0 `endif )
 typedef TAdd#(AxiExp1_slave_num,1) Num_Slow_Slaves;
 """
 
+
 class CallFn(object):
     def __init__(self, peripheral, name):
         self.peripheral = peripheral
@@ -193,13 +194,14 @@ class CallFn(object):
             return ''
         return getattr(self.peripheral.slow, self.name)(*args[1:])
 
+
 class PeripheralIface(object):
     def __init__(self, ifacename):
         self.slow = None
         slow = slowfactory.getcls(ifacename)
         if slow:
             self.slow = slow()
-        for fname in ['slowimport', 'slowifdecl']:
+        for fname in ['slowimport', 'slowifdecl', 'mkslow_peripheral']:
             fn = CallFn(self, fname)
             setattr(self, fname, types.MethodType(fn, self))
 
@@ -221,10 +223,6 @@ class PeripheralIface(object):
             return ''
         return self.slow.axi_addr_map(self.ifacename, count)
 
-    def mkslow_periph(self, count):
-        if not self.slow:
-            return ''
-        return self.slow.mkslow_peripheral().format(count, self.ifacename)
 
 class PeripheralInterfaces(object):
     def __init__(self):
@@ -276,11 +274,11 @@ class PeripheralInterfaces(object):
                 ret.append(self.data[name].axi_addr_map(i))
         return '\n'.join(list(filter(None, ret)))
 
-    def mkslow_periph(self, *args):
+    def mkslow_peripheral(self, *args):
         ret = []
         for (name, count) in self.ifacecount:
             for i in range(count):
-                ret.append(self.data[name].mkslow_periph(i))
+                ret.append(self.data[name].mkslow_peripheral().format(i))
         return '\n'.join(list(filter(None, ret)))
 
 
index b919719d533756f9ceaa1e29eca3ee84bd89889f..70423ce0fbe5e12ccdf0c807415c4f70ddc7e7c7 100644 (file)
@@ -104,7 +104,7 @@ def write_slow(slow, template, p, ifaces):
     regdef = ifaces.axi_reg_def()
     slavedecl = ifaces.axi_slave_idx()
     fnaddrmap = ifaces.axi_addr_map()
-    mkslow = ifaces.mkslow_periph()
+    mkslow = ifaces.mkslow_peripheral()
     with open(slow, "w") as bsv_file:
         bsv_file.write(template.format(imports, ifdecl, regdef, slavedecl,
                                        fnaddrmap, mkslow))