add in quart
[pinmux.git] / src / bsv / peripheral_gen.py
index 09392933f7e390873daf36c2b3f05d234e0046a5..5326144bcae74927cbc0ae2fb704eafcdf5d5e38 100644 (file)
@@ -9,6 +9,9 @@ class PBase(object):
     def slowifdeclmux(self):
         return ''
 
+    def slowifinstance(self):
+        return ''
+
     def slowimport(self):
         return ''
 
@@ -184,31 +187,51 @@ class uart(PBase):
         return {'rx': 'coe_rs232.sin'}.get(pname, '')
 
 
-class qquart(PBase):
+class quart(PBase):
 
     def slowimport(self):
         return "          import Uart16550         :: *;"
 
     def slowifdecl(self):
-        return "            interface RS232_PHY_Ifc uart{0}_coe;\n" + \
-               "            method Bit#(1) uart{0}_intr;"
+        return "            interface RS232_PHY_Ifc quart{0}_coe;\n" + \
+               "            method Bit#(1) quart{0}_intr;"
 
     def num_axi_regs32(self):
         return 8
 
     def mkslow_peripheral(self, size=0):
-        return "        Uart16550_AXI4_Lite_Ifc uart{0} <- \n" + \
+        return "        Uart16550_AXI4_Lite_Ifc quart{0} <- \n" + \
                "                mkUart16550(clocked_by sp_clock,\n" + \
                "                    reset_by uart_reset, sp_clock, sp_reset);"
 
     def _mk_connection(self, name=None, count=0):
-        return "uart{0}.slave_axi_uart"
+        return "quart{0}.slave_axi_uart"
 
     def pinname_out(self, pname):
-        return {'tx': 'coe_rs232.sout'}.get(pname, '')
+        return {'tx' : 'coe_rs232.modem_output_stx',
+                'rts': 'coe_rs232.modem_output_rts',
+               }.get(pname, '')
 
-    def pinname_in(self, pname):
-        return {'rx': 'coe_rs232.sin'}.get(pname, '')
+    def _pinname_in(self, pname):
+        return {'rx': 'coe_rs232.modem_input.srx', 
+                'cts': 'coe_rs232.modem_input.cts'
+               }.get(pname, '')
+
+    def mk_pincon(self, name, count):
+        ret = [PBase.mk_pincon(self, name, count)]
+        size = len(self.peripheral.pinspecs)
+        ret.append(eint_pincon_template.format(size))
+        ret.append("    rule con_%s%d_io_in;" % (name, count))
+        ret.append("       {0}{1}.coe_rs232.modem_input(".format(name, count))
+        for idx, pname in enumerate(['rx', 'cts']):
+            sname = self.peripheral.pname(pname).format(count)
+            ps = "pinmux.peripheral_side.%s" % sname
+            ret.append("            {0},".format(ps))
+        ret.append("            1'b1,1'b0,1'b1")
+        ret.append("        );")
+        ret.append("    endrule")
+
+        return '\n'.join(ret)
 
 
 class rs232(PBase):
@@ -331,6 +354,39 @@ eint_pincon_template = '''\
 '''
 
 
+class jtag(PBase):
+
+    def axi_slave_name(self, name, ifacenum):
+        return ''
+
+    def axi_slave_idx(self, idx, name, ifacenum):
+        return ('', 0)
+
+    def axi_addr_map(self, name, ifacenum):
+        return ''
+
+    def slowifdeclmux(self):
+        return "            method  Action jtag_ms (Bit#(1) in);\n" +  \
+               "            method  Bit#(1) jtag_di;\n" + \
+               "            method  Action jtag_do (Bit#(1) in);\n" + \
+               "            method  Action jtag_ck (Bit#(1) in);"
+
+    def slowifinstance(self):
+        return jtag_method_template # bit of a lazy hack this...
+
+jtag_method_template = """\
+    method  Action jtag_ms (Bit#(1) in);
+      pinmux.peripheral_side.jtag_ms(in);
+    endmethod
+    method  Bit#(1) jtag_di=pinmux.peripheral_side.jtag_di;
+    method  Action jtag_do (Bit#(1) in);
+      pinmux.peripheral_side.jtag_do(in);
+    endmethod
+    method  Action jtag_ck (Bit#(1) in);
+      pinmux.peripheral_side.jtag_ck(in);
+    endmethod
+"""
+
 class sdmmc(PBase):
 
     def slowimport(self):
@@ -350,14 +406,16 @@ class sdmmc(PBase):
         return "sd{0}.slave"
 
     def pinname_in(self, pname):
-        return "out.%s_in" % pname
+        return "%s_in" % pname
 
     def pinname_out(self, pname):
-        return "out.%s_out" % pname
+        if pname.startswith('d'):
+            return "%s_out" % pname
+        return pname
 
     def pinname_outen(self, pname):
         if pname.startswith('d'):
-            return "out.%s_outen" % pname
+            return "%s_outen" % pname
 
 
 class spi(PBase):
@@ -618,7 +676,8 @@ class PeripheralIface(object):
         if slow:
             self.slow = slow(ifacename)
             self.slow.peripheral = self
-        for fname in ['slowimport', 'slowifdecl', 'slowifdeclmux',
+        for fname in ['slowimport', 
+                      'slowifinstance', 'slowifdecl', 'slowifdeclmux',
                       'mkslow_peripheral',
                       'mk_connection', 'mk_cellconn', 'mk_pincon']:
             fn = CallFn(self, fname)
@@ -659,6 +718,13 @@ class PeripheralInterfaces(object):
             ret.append(self.data[name].slowimport())
         return '\n'.join(list(filter(None, ret)))
 
+    def slowifinstance(self, *args):
+        ret = []
+        for (name, count) in self.ifacecount:
+            #print "slowimport", name, self.data[name].slowimport
+            ret.append(self.data[name].slowifinstance())
+        return '\n'.join(list(filter(None, ret)))
+
     def slowifdeclmux(self, *args):
         ret = []
         for (name, count) in self.ifacecount:
@@ -755,11 +821,13 @@ class PFactory(object):
         for k, v in {'uart': uart,
                      'rs232': rs232,
                      'twi': twi,
+                     'quart': quart,
                      'qspi': qspi,
                      'spi': spi,
                      'pwm': pwm,
                      'eint': eint,
                      'sd': sdmmc,
+                     'jtag': jtag,
                      'gpio': gpio
                      }.items():
             if name.startswith(k):