vectorise pincon sync
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 30 Jul 2018 06:19:26 +0000 (07:19 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 30 Jul 2018 06:19:26 +0000 (07:19 +0100)
src/bsv/peripheral_gen/base.py
src/bsv/peripheral_gen/rgbttl.py

index 7b8ca982095b0ba526c929c007f9d51521df5ff9..fd3038478791830c4ca2556f25ee5f75dddb6dd3 100644 (file)
@@ -196,6 +196,20 @@ else"""
                     ret += cn
         return '\n'.join(ret)
 
+    def _mk_vpincon(self, name, count, ptyp, typ, pname):
+        ret = []
+        if ptyp == 'fast':
+            sname = self.get_iname(count)
+            ps = "slow_peripherals.%s" % sname
+        else:
+            sname = self.peripheral.iname().format(count)
+            ps = "pinmux.peripheral_side.%s" % sname
+        n = self.get_iname(count)
+        ps_ = "{0}.{1}".format(ps, pname)
+        ret += self._mk_actual_connection(typ, name, count, typ,
+                                          pname, ps_, n, pname)
+        return '\n'.join(ret)
+
     def _mk_actual_connection(self, ctype, name, count, typ,
                               pname, ps, n, fname):
         ret = []
@@ -227,6 +241,7 @@ else"""
                             sync, n))
         return ret
 
+
     def _mk_clk_con(self, name, count, ctype):
         ret = []
         ck = self.get_clock_reset(name, count)
@@ -265,6 +280,23 @@ Ifc_sync#({0}) {1}_sync <-mksyncconnection(
                 ret.append(template.format("Bit#(1)", n_, spc, ck))
         return '\n'.join(ret)
 
+    def _mk_clk_vcon(self, name, count, ctype, typ, pname, bitspec):
+        ck = self.get_clock_reset(name, count)
+        if ck == PBase.get_clock_reset(self, name, count):
+            return ''
+        if ctype == 'slow':
+            spc = "sp_clock, sp_reset"
+        else:
+            spc = ck
+            ck = "core_clock, core_reset"
+        template = """\
+Ifc_sync#({0}) {1}_sync <-mksyncconnection(
+            {2}, {3});"""
+
+        n_ = "{0}{1}".format(name, count)
+        n_ = '{0}_{1}'.format(n_, pname)
+        return template.format(bitspec,  n_, ck, spc)
+
 
     def mk_cellconn(self, *args):
         return ''
index 91f2eb9be9a014ed28df1af86044e087ab006d7f..9c917e775aec9de4145c415be6861d43542ec88b 100644 (file)
@@ -29,39 +29,16 @@ class rgbttl(PBase):
 
     def _mk_pincon(self, name, count, ptyp):
         ret = [PBase._mk_pincon(self, name, count, ptyp)]
-        if ptyp == 'fast':
-            sname = self.get_iname(count)
-            ps = "slow_peripherals.%s" % sname
-        else:
-            sname = self.peripheral.iname().format(count)
-            ps = "pinmux.peripheral_side.%s" % sname
-        n = self.get_iname(count)
-        for ptype in ['data_out']:
-            ps_ = "{0}.{1}".format(ps, ptype)
-            ret += self._mk_actual_connection('out', name, count, 'out',
-                                              ptype, ps_, n, ptype)
+        txt = self._mk_vpincon(name, count, ptyp, "out", "data_out")
+        ret.append(txt)
         return '\n'.join(ret)
 
     def _mk_clk_con(self, name, count, ctype):
         ret = [PBase._mk_clk_con(self, name, count, ctype)]
-        ck = self.get_clock_reset(name, count)
-        if ck == PBase.get_clock_reset(self, name, count):
-            return ret
-        if ctype == 'slow':
-            spc = "sp_clock, sp_reset"
-        else:
-            spc = ck
-            ck = "core_clock, core_reset"
-        template = """\
-Ifc_sync#({0}) {1}_sync <-mksyncconnection(
-            {2}, {3});"""
 
-        # one pin, data_out, might as well hard-code it
-        typ = 'out'
-        pname = 'data_out'
-        n = name
-        n_ = "{0}{1}".format(n, count)
-        n_ = '{0}_{1}'.format(n_, pname)
+        # data_out (hard-coded)
         sz = len(self.peripheral.pinspecs) - 4  # subtract CK, DE, HS, VS
-        ret.append(template.format("Bit#(%d)" % sz, n_, ck, spc))
+        bitspec = "Bit#(%d)" % sz
+        txt = self._mk_clk_vcon(name, count, ctype, "out", "data_out", bitspec)
+        ret.append(txt)
         return '\n'.join(ret)