fix cell bit widths if muxwidth = 1
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 31 Jul 2018 07:20:30 +0000 (08:20 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 31 Jul 2018 07:20:30 +0000 (08:20 +0100)
src/bsv/pinmux_generator.py
src/parse.py

index 79bfc0a038140a6f33b52a589a47696d4e303a92..64ab8851b071b8fc8bb64a945056d1fd96f4f2f0 100644 (file)
@@ -202,7 +202,10 @@ def write_pmp(pmp, p, ifaces, iocells):
 
         for cell in p.muxed_cells:
             cellnum = cell[0]
-            cell_bit_width = bwid_template % p.get_muxwidth(cellnum)
+            bitwidth = p.get_muxbitwidth(cellnum)
+            if bitwidth == 0:
+                continue
+            cell_bit_width = bwid_template % bitwidth
             bsv_file.write(mux_interface.ifacefmt(cellnum, cell_bit_width))
 
         bsv_file.write("\n      endinterface\n")
@@ -275,8 +278,12 @@ def write_pmp(pmp, p, ifaces, iocells):
       // values for each mux assigned to a CELL
 ''')
         for cell in p.muxed_cells:
-            bsv_file.write(mux_interface.wirefmt(
-                cell[0], cell_bit_width))
+            cellnum = cell[0]
+            bitwidth = p.get_muxbitwidth(cellnum)
+            if bitwidth == 0:
+                continue
+            cell_bit_width = bwid_template % bitwidth
+            bsv_file.write(mux_interface.wirefmt(cellnum, cell_bit_width))
 
         iocells.wirefmt(bsv_file)
         ifaces.wirefmt(bsv_file)
@@ -298,9 +305,14 @@ def write_pmp(pmp, p, ifaces, iocells):
     interface mux_lines = interface MuxSelectionLines
 ''')
         for cell in p.muxed_cells:
+            cellnum = cell[0]
+            bitwidth = p.get_muxbitwidth(cellnum)
+            if bitwidth == 0:
+                continue
+            cell_bit_width = bwid_template % bitwidth
             bsv_file.write(
                 mux_interface.ifacedef(
-                    cell[0], cell_bit_width))
+                    cellnum, cell_bit_width))
         bsv_file.write("\n    endinterface;")
 
         bsv_file.write('''
index 2dffeb33b75974257d62c7cd414de90426942428..b2e017ab2dd54e2c75ea6960fc756a7ed2c6c1cc 100644 (file)
@@ -122,6 +122,12 @@ class Parse(object):
     def get_muxwidth(self, cellnum):
         return self.muxed_cells_width[int(cellnum)]
 
+    def get_muxbitwidth(self, cellnum):
+        wid = self.get_muxwidth(cellnum)
+        if wid == 1:
+            return 0
+        return int(math.log(wid + 1, 2))
+
 
 if __name__ == '__main__':
     p = Parse()