create new get/put interface pinmux declaration
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 23 Jul 2018 06:25:11 +0000 (07:25 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 23 Jul 2018 06:25:11 +0000 (07:25 +0100)
src/bsv/interface_decl.py
src/bsv/pinmux_generator.py
src/test_bsv/pinmux_experiment.bsv

index f87bdd979552a51bbdb44401983a473980fc1727..0ae52abbdda82e0116eac5b6b07a13fbac714f5b 100644 (file)
@@ -82,13 +82,6 @@ class Pin(object):
         res += ";"
         return res
 
-    # sample bsv method definition :
-    """
-    method Action  cell0_mux(Bit#(2) in);
-        wrcell0_mux<=in;
-    endmethod
-    """
-
     def ifacedef(self, fmtoutfn, fmtinfn, fmtdecfn):
         res = '      method '
         if self.action:
@@ -102,6 +95,13 @@ class Pin(object):
             fmtname = fmtoutfn(self.name)
             res += "%s=%s;" % (self.name, fmtname)
         return res
+    # sample bsv method definition :
+    """
+    method Action  cell0_mux(Bit#(2) in);
+        wrcell0_mux<=in;
+    endmethod
+    """
+
     # sample bsv wire (wire definiton):
     """
     Wire#(Bit#(2)) wrcell0_mux<-mkDWire(0);
@@ -116,6 +116,26 @@ class Pin(object):
         res += "<-mkDWire(0);"
         return res
 
+    def ifacedef2(self, fmtoutfn, fmtinfn, fmtdecfn):
+        if self.action:
+            fmtname = fmtinfn(self.name)
+            res =  "            interface %s = interface Put\n" % self.name_
+            res += '              method '
+            res += "Action put"
+            #res += fmtdecfn(self.name)
+            res += '(%s in);\n' % self.bitspec
+            res += '                %s<=in;\n' % fmtname
+            res += '              endmethod\n'
+            res += '            endinterface;'
+        else:
+            fmtname = fmtoutfn(self.name)
+            res =  "            interface %s = interface Get\n" % self.name_
+            res += '              method ActionValue#'
+            res += '(%s) get;\n' % self.bitspec
+            res += "                return %s;\n" % (fmtname)
+            res += '              endmethod\n'
+            res += '            endinterface;'
+        return res
 
 class Interface(PeripheralIface):
     """ create an interface from a list of pinspecs.
@@ -285,11 +305,26 @@ class Interface(PeripheralIface):
         return pin.ifacedef(outfn, self.ifacefmtinfn,
                             decfn)
 
+    def ifacedef2pin(self, pin):
+        decfn = self.ifacefmtdecfn2
+        outfn = self.ifacefmtoutfn
+        # print pin, pin.outenmode
+        if pin.outenmode:
+            decfn = self.ifacefmtdecfn3
+            outfn = self.ifacefmtoutenfn
+        return pin.ifacedef2(outfn, self.ifacefmtinfn,
+                            decfn)
+
     def ifacedef(self, *args):
         res = '\n'.join(map(self.ifacefmtpin, self.pins))
         res = res.format(*args)
         return '\n' + res + '\n'
 
+    def ifacedef2(self, *args):
+        res = '\n'.join(map(self.ifacedef2pin, self.pins))
+        res = res.format(*args)
+        return '\n' + res + '\n'
+
 
 class MuxInterface(Interface):
 
@@ -326,6 +361,15 @@ class Interfaces(InterfacesBase, PeripheralInterfaces):
             for i in range(count):
                 f.write(self.data[name].ifacedef(i))
 
+    def ifacedef2(self, f, *args):
+        c = "        interface {0} = interface PeripheralSide{1}"
+        for (name, count) in self.ifacecount:
+            for i in range(count):
+                iname = self.data[name].iname().format(i)
+                f.write(c.format(iname, name.upper()))
+                f.write(self.data[name].ifacedef2(i))
+                f.write("        endinterface;\n\n")
+
     def busfmt(self, f, *args):
         f.write("import BUtils::*;\n\n")
         for (name, count) in self.ifacecount:
index 69a19c565468759fd0cc016bcb162a71c82cb244..67e018c78ef4796d1523b33da1f56fa7e4e9039c 100644 (file)
@@ -256,7 +256,7 @@ def write_pmp(pmp, p, ifaces, iocells):
 
      interface peripheral_side = interface PeripheralSide
 ''')
-        ifaces.ifacedef(bsv_file)
+        ifaces.ifacedef2(bsv_file)
         bsv_file.write("\n      endinterface;")
 
         bsv_file.write(footer)
index 94c880f35dd088992aeaca78f29ce1249a136ced..975f86d60c24f3a6ee000be6e8e588c6a230fb18 100644 (file)
@@ -291,98 +291,95 @@ import GetPut::*;
 
      interface peripheral_side = interface PeripheralSide
         interface uart = interface PeripheralSideUART
-            // interface declaration between UART and pinmux
             interface tx = interface Put
               method Action put(Bit#(1) in);
                 wruart_tx<=in;
               endmethod
             endinterface;
-            interface  rx = interface Get
+            interface rx = interface Get
               method ActionValue#(Bit#(1)) get;
                 return wruart_rx;
               endmethod
             endinterface;
         endinterface;
 
-        interface twi = interface PeripheralSideTWI
-            // interface declaration between TWI and pinmux
-            interface sda_out = interface Put
+        interface gpioa = interface PeripheralSideGPIOA
+            interface a0_out = interface Put
               method Action put(Bit#(1) in);
-                wrtwi_sda_out<=in;
+                wrgpioa_a0_out<=in;
               endmethod
             endinterface;
-            interface sda_outen = interface Put
+            interface a0_outen = interface Put
               method Action put(Bit#(1) in);
-                wrtwi_sda_outen<=in;
+                wrgpioa_a0_outen<=in;
               endmethod
             endinterface;
-            interface  sda_in = interface Get
+            interface a0_in = interface Get
               method ActionValue#(Bit#(1)) get;
-                return wrtwi_sda_in;
+                return wrgpioa_a0_in;
               endmethod
             endinterface;
-            interface scl_out = interface Put
+            interface a1_out = interface Put
               method Action put(Bit#(1) in);
-                wrtwi_scl_out<=in;
+                wrgpioa_a1_out<=in;
               endmethod
             endinterface;
-            interface scl_outen = interface Put
+            interface a1_outen = interface Put
               method Action put(Bit#(1) in);
-                wrtwi_scl_outen<=in;
+                wrgpioa_a1_outen<=in;
               endmethod
             endinterface;
-            interface  scl_in = interface Get
+            interface a1_in = interface Get
               method ActionValue#(Bit#(1)) get;
-                return wrtwi_scl_in;
+                return wrgpioa_a1_in;
               endmethod
             endinterface;
-         endinterface;
-
-        interface gpioa = interface PeripheralSideGPIOA
-
-            interface a0_out = interface Put
+            interface a2_out = interface Put
               method Action put(Bit#(1) in);
-                wrgpioa_a0_out<=in;
+                wrgpioa_a2_out<=in;
               endmethod
             endinterface;
-            interface a0_outen = interface Put
+            interface a2_outen = interface Put
               method Action put(Bit#(1) in);
-                wrgpioa_a0_outen<=in;
+                wrgpioa_a2_outen<=in;
               endmethod
             endinterface;
-            interface  a0_in = interface Get
+            interface a2_in = interface Get
               method ActionValue#(Bit#(1)) get;
-                return wrgpioa_a0_in;
+                return wrgpioa_a2_in;
               endmethod
             endinterface;
-            interface a1_out = interface Put
+        endinterface;
+
+        interface twi = interface PeripheralSideTWI
+            interface sda_out = interface Put
               method Action put(Bit#(1) in);
-                wrgpioa_a1_out<=in;
+                wrtwi_sda_out<=in;
               endmethod
             endinterface;
-            interface a1_outen = interface Put
+            interface sda_outen = interface Put
               method Action put(Bit#(1) in);
-                wrgpioa_a1_outen<=in;
+                wrtwi_sda_outen<=in;
               endmethod
             endinterface;
-            interface  a1_in = interface Get
+            interface sda_in = interface Get
               method ActionValue#(Bit#(1)) get;
-                return wrgpioa_a1_in;
+                return wrtwi_sda_in;
               endmethod
             endinterface;
-            interface a2_out = interface Put
+            interface scl_out = interface Put
               method Action put(Bit#(1) in);
-                wrgpioa_a2_out<=in;
+                wrtwi_scl_out<=in;
               endmethod
             endinterface;
-            interface a2_outen = interface Put
+            interface scl_outen = interface Put
               method Action put(Bit#(1) in);
-                wrgpioa_a2_outen<=in;
+                wrtwi_scl_outen<=in;
               endmethod
             endinterface;
-            interface  a2_in = interface Get
+            interface scl_in = interface Get
               method ActionValue#(Bit#(1)) get;
-                return wrgpioa_a2_in;
+                return wrtwi_scl_in;
               endmethod
             endinterface;
         endinterface;