auto-generate bus.bsv with new GPIO/MUX configs
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 16 Jul 2018 11:13:38 +0000 (12:13 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 16 Jul 2018 11:13:38 +0000 (12:13 +0100)
src/bsv/bus_transactors.py
src/bsv/pinmux_generator.py
src/parse.py

index b4ebefd5d4d37ed7b9b842382f16c5e9e8841792..8c73cdc68ff62809d1dda03f120689a357eb3c1f 100644 (file)
@@ -18,22 +18,14 @@ package gpio_instance;
 
   // instantiation template
     interface GPIO_real;
-    interface PeripheralSide peripheral_side;
-    interface GPIO_config#(32) bankA_config;
-        interface AXI4_Lite_Slave_IFC#({0},{1},{2}) bankA_slave;
-    interface GPIO_config#(15) bankB_config;
-        interface AXI4_Lite_Slave_IFC#({0},{1},{2}) bankB_slave;
-
-    interface MUX_config#(32) muxbankA_config;
-        interface AXI4_Lite_Slave_IFC#({0},{1},{2}) muxbankA_slave;
-    interface MUX_config#(15) muxbankB_config;
-        interface AXI4_Lite_Slave_IFC#({0},{1},{2}) muxbankB_slave;
+        interface PeripheralSide peripheral_side;
+{1}
     endinterface
   (*synthesize*)
   module mkgpio_real(GPIO_real);
     Ifc_pinmux pinmux <-mkpinmux;
     // gpio/mux declarations
-{3}
+{0}
     interface peripheral_side=pinmux.peripheral_side;
   endmodule
 endpackage
index bfcc09eb2ad7a58a83d9b5769910fd529d0aa1a1..9fe54eb13ed92529183adbeef9d3e897746cc9c6 100644 (file)
@@ -303,9 +303,45 @@ endpackage
 
 def write_bvp(bvp, p, ifaces):
     # ######## Generate bus transactors ################
+    gpiocfg = '\t\tinterface GPIO_config#({4}) bank{3}_config\n;' \
+              '\t\tinterface AXI4_Lite_Slave_IFC#({0},{1},{2}) bank{3}_slave;'
+    muxcfg  = '\t\tinterface MUX_config#({4}) muxb{3}_config;\n' \
+              '\t\tinterface AXI4_Lite_Slave_IFC#({0},{1},{2}) muxb{3}_slave;'
+
+    gpiodec = '\tGPIO#({0} mygpio{1} <- mkgpio();'
+    muxdec  = '\tMUX#({0} mymux{1} <- mkgpio();'
+    gpioifc = '\tinterface bank{0}_config=mygpio{0}.pad_config;\n' \
+              '\tinterface bank{0}A_slave=mygpio{0}.axi_slave;'
+    muxifc  = '\tinterface muxb{0}_config=mymux{0}.pad_config;\n' \
+              '\tinterface muxb{0}A_slave=mymux{0}.axi_slave;'
     with open(bvp, 'w') as bsv_file:
-        gpiodecl = '// TODO'
-        bsv_file.write(axi4_lite.format(p.ADDR_WIDTH, p.DATA_WIDTH,
+        # assume here that all muxes have a 1:1 gpio
+        cfg = []
+        decl = []
+        idec = []
+        iks = ifaces.keys()
+        iks.sort()
+        for iname in iks:
+            if not iname.startswith('gpio'): # TODO: declare other interfaces
+                continue
+            bank = iname[4:]
+            ifc = ifaces[iname]
+            npins = len(ifc.pinspecs)
+            cfg.append(gpiocfg.format(p.ADDR_WIDTH, p.DATA_WIDTH,
                                         0, # USERSPACE
-                                        gpiodecl))
+                                        bank, npins))
+            cfg.append(muxcfg.format(p.ADDR_WIDTH, p.DATA_WIDTH,
+                                        0, # USERSPACE
+                                        bank, npins))
+            decl.append(gpiodec.format(npins, bank))
+            decl.append(muxdec .format(npins, bank))
+            idec.append(gpioifc.format(bank))
+            idec.append(muxifc.format(bank))
+        print dir(ifaces)
+        print ifaces.items()
+        print dir(ifaces['gpioa'])
+        print ifaces['gpioa'].pinspecs
+        gpiodecl = '\n'.join(decl) + '\n' + '\n'.join(idec)
+        gpiocfg = '\n'.join(cfg) 
+        bsv_file.write(axi4_lite.format(gpiodecl, gpiocfg))
     # ##################################################
index 3d508d651b63612de1385adb7f42076f1faa99aa..42886a6d6111468fb7641bcb1151fc614b09eb0f 100644 (file)
@@ -14,8 +14,8 @@ class Parse(object):
     N_IO = 0
     N_MUX_IO = 0
     Addressing = 'WORD'
-    ADDR_WIDTH = 32
-    DATA_WIDTH = 32
+    ADDR_WIDTH = 32 # TODO parameterise
+    DATA_WIDTH = 32 # TODO parameterise
     # ================ #
 
     # Generating the number of bits for memory map #