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

index 5d3182d80c68b25c1ed8c88177d43894a551299e..4e16fa1349600730e4efbda7b11a8843803fbf1c 100644 (file)
@@ -20,6 +20,7 @@ class Pin(object):
     """
 
     def __init__(self, name,
+                 name_ = None,
                  ready=True,
                  enabled=True,
                  io=False,
@@ -27,6 +28,7 @@ class Pin(object):
                  bitspec=None,
                  outenmode=False):
         self.name = name
+        self.name_ = name_
         self.ready = ready
         self.enabled = enabled
         self.io = io
@@ -41,6 +43,18 @@ class Pin(object):
                        Action io0_inputval (Bit#(1) in);
     """
 
+    def ifacepfmt(self, fmtfn):
+        res = '          '
+        status = []
+        res += "interface "
+        name = fmtfn(self.name_)
+        if self.action:
+            res += "Put"
+        else:
+            res += "Get"
+        res += "#(%s) %s;" % (self.bitspec, name)
+        return res
+
     def ifacefmt(self, fmtfn):
         res = '    '
         status = []
@@ -134,6 +148,7 @@ class Interface(PeripheralIface):
                 del _p['outen']
                 for psuffix in ['out', 'outen', 'in']:
                     # changing the name (like sda) to (twi_sda_out)
+                    _p['name_'] = "%s_%s" % (p['name'], psuffix)
                     _p['name'] = "%s_%s" % (self.pname(p['name']), psuffix)
                     _p['action'] = psuffix != 'in'
                     self.pins.append(Pin(**_p))
@@ -142,6 +157,7 @@ class Interface(PeripheralIface):
                     #{'name': 'twi_sda_in', 'action': False}
                     # NOTice - outen key is removed
             else:
+                _p['name_'] = p['name']
                 _p['name'] = self.pname(p['name'])
                 self.pins.append(Pin(**_p))
 
@@ -213,10 +229,17 @@ class Interface(PeripheralIface):
         res += '\n'
         return '\n' + res
 
+    def ifacepfmt(self, *args):
+        res = '\n'.join(map(self.ifacepfmtdecpin, self.pins)).format(*args)
+        return '\n' + res  # pins is a list
+
     def ifacefmt(self, *args):
         res = '\n'.join(map(self.ifacefmtdecpin, self.pins)).format(*args)
         return '\n' + res  # pins is a list
 
+    def ifacepfmtdecfn(self, name):
+        return name
+
     def ifacefmtdecfn(self, name):
         return name  # like: uart
 
@@ -237,6 +260,9 @@ class Interface(PeripheralIface):
         return pin.wirefmt(self.ifacefmtoutfn, self.ifacefmtinfn,
                            self.ifacefmtdecfn2)
 
+    def ifacepfmtdecpin(self, pin):
+        return pin.ifacepfmt(self.ifacepfmtdecfn)
+
     def ifacefmtdecpin(self, pin):
         return pin.ifacefmt(self.ifacefmtdecfn)
 
@@ -298,6 +324,16 @@ class Interfaces(InterfacesBase, PeripheralInterfaces):
                 bf = self.data[name].busfmt(i)
                 f.write(bf)
 
+    def ifacepfmt(self, f, *args):
+        comment = '''
+      // interface declaration between {0} and pinmux
+      (*always_ready,always_enabled*)
+      interface PeripheralSide{0};'''
+        for (name, count) in self.ifacecount:
+            f.write(comment.format(name.upper()))
+            f.write(self.data[name].ifacepfmt(0))
+            f.write("\n      endinterface\n")
+
     def ifacefmt(self, f, *args):
         comment = '''
           // interface declaration between %s-{0} and pinmux'''
index 3a3fe251e045d0226d43b8541e8f54f88ae0ca45..a74eee16a555a211415da314323a7f4571d6f1fa 100644 (file)
@@ -39,6 +39,8 @@ copyright = '''
 header = copyright + '''
 package pinmux;
 
+import GetPut::*;
+
 '''
 footer = '''
    endmodule
@@ -134,7 +136,8 @@ def write_pmp(pmp, p, ifaces, iocells):
 
         cell_bit_width = 'Bit#(%d)' % p.cell_bitwidth
         bsv_file.write('''\
-   interface MuxSelectionLines;
+      (*always_ready,always_enabled*)
+      interface MuxSelectionLines;
 
       // declare the method which will capture the user pin-mux
       // selection values.The width of the input is dependent on the number
@@ -159,9 +162,10 @@ def write_pmp(pmp, p, ifaces, iocells):
         # ===== finish interface definition and start module definition=======
         bsv_file.write("\n      endinterface\n")
 
+        ifaces.ifacepfmt(bsv_file)
         # ===== io cell definition =======
         bsv_file.write('''
-
+      (*always_ready,always_enabled*)
       interface PeripheralSide;
       // declare the interface to the peripherals
       // Each peripheral's function will be either an input, output
index 6e3e5e05e50e14bd640388f28b6d35490a5b9db2..49bee6f6cf358376da5504da18ae02f3a173ca9b 100644 (file)
@@ -12,7 +12,7 @@ package pinmux_experiment;
 import GetPut::*;
 
       (*always_ready,always_enabled*)
-   interface MuxSelectionLines;
+      interface MuxSelectionLines;
 
       // declare the method which will capture the user pin-mux
       // selection values.The width of the input is dependent on the number
@@ -45,19 +45,16 @@ import GetPut::*;
                        Action io2_cell_in (Bit#(1) in);
       endinterface
 
-
+      // interface declaration between UART and pinmux
       (*always_ready,always_enabled*)
       interface PeripheralSideUART;
-          // interface declaration between UART and pinmux
           interface Put#(Bit#(1)) tx;
           interface Get#(Bit#(1)) rx;
-//    (*always_ready,always_enabled*) method  Action tx (Bit#(1) in);
-//    (*always_ready,always_enabled*) method  Bit#(1) rx;
       endinterface
 
+      // interface declaration between GPIOA and pinmux
       (*always_ready,always_enabled*)
       interface PeripheralSideGPIOA;
-          // interface declaration between GPIOA-0 and pinmux
           interface Put#(Bit#(1)) a0_out;
           interface Put#(Bit#(1)) a0_outen;
           interface Get#(Bit#(1)) a0_in;
@@ -67,11 +64,11 @@ import GetPut::*;
           interface Put#(Bit#(1)) a2_out;
           interface Put#(Bit#(1)) a2_outen;
           interface Get#(Bit#(1)) a2_in;
-        endinterface
+      endinterface
 
+      // interface declaration between TWI and pinmux
       (*always_ready,always_enabled*)
       interface PeripheralSideTWI;
-          // interface declaration between TWI and pinmux
           interface Put#(Bit#(1)) sda_out;
           interface Put#(Bit#(1)) sda_outen;
           interface Get#(Bit#(1)) sda_in;
@@ -392,12 +389,5 @@ import GetPut::*;
 
 
       endinterface;
-//    interface peripheral_side = interface PeripheralSide
-//
-//      interface uart = peripherals.uart;
-//      interface gpioa = peripherals.gpioa;
-//      interface twi = peripherals.twi;
-//
-//     endinterface;
    endmodule
 endpackage