correct flexbus connections
[pinmux.git] / src / bsv / peripheral_gen / base.py
index e7de1965accbb0ebd52bf40a4bbf8b723decc346..51902fcf6c126dd46223ee59c22ec524941cadc6 100644 (file)
@@ -45,7 +45,7 @@ class PBase(object):
         if not irqname:
             return ''
         pirqname = self.irq_name().format(count)
-        template = "   {0}_interrupt.send(\n" + \
+        template = "   {0}.send(\n" + \
                    "           slow_peripherals.{1});"
         return template.format(irqname, pirqname)
 
@@ -196,6 +196,25 @@ else"""
                     ret += cn
         return '\n'.join(ret)
 
+    def _mk_vpincon(self, name, count, ptyp, typ, pname, stype=None):
+        if stype is None:
+            stype = pname
+        ret = []
+        ret.append("//%s %s %s %s %s" % (name, ptyp, typ, pname, stype))
+        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)
+        if typ == 'in':
+            n = "{0}.{1}".format(n, stype)
+        ps_ = "{0}.{1}".format(ps, pname)
+        ret += self._mk_actual_connection(typ, name, count, typ,
+                                          pname, ps_, n, stype)
+        return '\n'.join(ret)
+
     def _mk_actual_connection(self, ctype, name, count, typ,
                               pname, ps, n, fname):
         ret = []
@@ -227,12 +246,17 @@ else"""
                             sync, n))
         return ret
 
-    def mk_clk_con(self, name, count):
+
+    def _mk_clk_con(self, name, count, ctype):
         ret = []
         ck = self.get_clock_reset(name, count)
         if ck == PBase.get_clock_reset(self, name, count):
             return ''
-        spc = "sp_clock, sp_reset"
+        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});"""
@@ -241,6 +265,9 @@ Ifc_sync#({0}) {1}_sync <-mksyncconnection(
             pname = p['name']
             n = name  
             if typ == 'out' or typ == 'inout':
+                fname = self.pinname_out(pname)
+                if not fname:
+                    continue
                 if not n.startswith('gpio'):  # XXX EURGH! horrible hack
                     n_ = "{0}{1}".format(n, count)
                 else:
@@ -248,6 +275,9 @@ Ifc_sync#({0}) {1}_sync <-mksyncconnection(
                 n_ = '{0}_{1}'.format(n_, pname)
                 ret.append(template.format("Bit#(1)", n_, ck, spc))
             if typ == 'in' or typ == 'inout':
+                fname = self.pinname_in(pname)
+                if not fname:
+                    continue
                 #fname = self.pinname_in(pname)
                 n_ = "{0}{1}".format(n, count)
                 n_ = '{0}_{1}'.format(n_, pname)
@@ -255,6 +285,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 ''
@@ -449,7 +496,7 @@ class PeripheralIface(object):
                       'mk_dma_sync', 'mk_dma_connect', 'mk_dma_rule',
                       'mkfast_peripheral',
                       'mk_plic', 'mk_ext_ifacedef',
-                      'mk_clk_con', 'mk_ext_ifacedef',
+                      '_mk_clk_con', 'mk_ext_ifacedef',
                       'mk_connection', 'mk_cellconn', '_mk_pincon']:
             fn = CallFn(self, fname)
             setattr(self, fname, types.MethodType(fn, self))
@@ -792,13 +839,19 @@ class PeripheralInterfaces(object):
     def mk_sloirqsdef(self):
         return "    `define NUM_SLOW_IRQS {0}".format(self.num_slow_irqs)
 
-    def mk_clk_con(self):
+    def mk_fastclk_con(self):
+        return self._mk_clk_con("fast")
+
+    def mk_slowclk_con(self):
+        return self._mk_clk_con("slow")
+
+    def _mk_clk_con(self, ctype):
         ret = []
         for (name, count) in self.ifacecount:
             for i in range(count):
                 if self.is_on_fastbus(name, i):
                     continue
-                txt = self.data[name].mk_clk_con(name, i)
+                txt = self.data[name]._mk_clk_con(name, i, ctype)
                 ret.append(txt)
         return '\n'.join(li(list(filter(None, ret)), 8))