From 9d91e31b4fea9f759fdcb1aeba0145f28c3083da Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Tue, 20 Mar 2018 17:39:44 +0000 Subject: [PATCH] use with statement on bsv_file --- src/pinmux_generator.py | 200 ++++++++++++++++++++-------------------- 1 file changed, 99 insertions(+), 101 deletions(-) diff --git a/src/pinmux_generator.py b/src/pinmux_generator.py index 1fb7df2..017b049 100644 --- a/src/pinmux_generator.py +++ b/src/pinmux_generator.py @@ -32,8 +32,6 @@ from bus_transactors import * if not os.path.exists("bsv_src"): os.makedirs("bsv_src") -bsv_file = open("./bsv_src/pinmux.bsv", "w") - copyright = ''' /* This BSV file has been generated by the PinMux tool available at: @@ -69,65 +67,66 @@ endpackage # ============================================# # package and interface declaration followed by the generic io_cell definition -bsv_file.write(header) +with open("./bsv_src/pinmux.bsv", "w") as bsv_file: + bsv_file.write(header) -bsv_file.write(''' + bsv_file.write(''' // declare the method which will capture the user pin-mux // selection values.The width of the input is dependent on the number // of muxes happening per IO. For now we have a generalized width // where each IO will have the same number of muxes.''') -for cell in muxed_cells: - bsv_file.write(mux_interface.format(cell[0], + for cell in muxed_cells: + bsv_file.write(mux_interface.format(cell[0], int(math.log(len(cell) - 1, 2)))) -bsv_file.write(''' + bsv_file.write(''' endinterface interface PeripheralSide; // declare the interface to the IO cells. // Each IO cell will have 8 input field (output from pin mux // and on output field (input to pinmux)''') -for i in range(0, N_IO): - bsv_file.write('''\n // interface for IO CEll-{0}''') - bsv_file.write(io_interface.format(i)) -# ============================================================== - -# == create method definitions for all peripheral interfaces ==# -for i in range(0, N_UART): + for i in range(0, N_IO): + bsv_file.write('''\n // interface for IO CEll-{0}''') + bsv_file.write(io_interface.format(i)) + # ============================================================== + + # == create method definitions for all peripheral interfaces ==# + for i in range(0, N_UART): + bsv_file.write(''' + // interface declaration between UART-{0} and pinmux'''.format(i)) + bsv_file.write(uartinterface_decl.format(i)) + + for i in range(0, N_SPI): + bsv_file.write(''' + // interface declaration between SPI-{0} and pinmux'''.format(i)) + bsv_file.write(spiinterface_decl.format(i)) + + for i in range(0, N_TWI): + bsv_file.write(''' + // interface declaration between TWI-{0} and pinmux'''.format(i)) + bsv_file.write(twiinterface_decl.format(i)) + + for i in range(0, N_SD): + bsv_file.write(''' + // interface declaration between SD-{0} and pinmux'''.format(i)) + bsv_file.write(sdinterface_decl.format(i)) + + for i in range(0, N_JTAG): + bsv_file.write(''' + // interface declaration between JTAG-{0} and pinmux'''.format(i)) + bsv_file.write(jtaginterface_decl.format(i)) + + for i in range(0, N_PWM): + bsv_file.write(''' + // interface declaration between PWM-{0} and pinmux'''.format(i)) + bsv_file.write(pwminterface_decl.format(i)) + # ============================================================== + + # ===== finish interface definition and start module definition======= bsv_file.write(''' - // interface declaration between UART-{0} and pinmux'''.format(i)) - bsv_file.write(uartinterface_decl.format(i)) - -for i in range(0, N_SPI): - bsv_file.write(''' - // interface declaration between SPI-{0} and pinmux'''.format(i)) - bsv_file.write(spiinterface_decl.format(i)) - -for i in range(0, N_TWI): - bsv_file.write(''' - // interface declaration between TWI-{0} and pinmux'''.format(i)) - bsv_file.write(twiinterface_decl.format(i)) - -for i in range(0, N_SD): - bsv_file.write(''' - // interface declaration between SD-{0} and pinmux'''.format(i)) - bsv_file.write(sdinterface_decl.format(i)) - -for i in range(0, N_JTAG): - bsv_file.write(''' - // interface declaration between JTAG-{0} and pinmux'''.format(i)) - bsv_file.write(jtaginterface_decl.format(i)) - -for i in range(0, N_PWM): - bsv_file.write(''' - // interface declaration between PWM-{0} and pinmux'''.format(i)) - bsv_file.write(pwminterface_decl.format(i)) -# ============================================================== - -# ===== finish interface definition and start module definition======= -bsv_file.write(''' endinterface interface Ifc_pinmux; @@ -137,97 +136,96 @@ bsv_file.write(''' (*synthesize*) module mkpinmux(Ifc_pinmux); ''') -# ==================================================================== + # ==================================================================== -# ======================= create wire and registers =================# -bsv_file.write(''' + # ======================= create wire and registers =================# + bsv_file.write(''' // the followins wires capture the pin-mux selection // values for each mux assigned to a CELL ''') -for cell in muxed_cells: - bsv_file.write(muxwire.format(cell[0], int(math.log(len(cell) - 1, 2)))) + for cell in muxed_cells: + bsv_file.write(muxwire.format(cell[0], int(math.log(len(cell) - 1, 2)))) -bsv_file.write( - '''\n // following wires capture the values sent to the IO Cell''') -for i in range(0, N_IO): - bsv_file.write(generic_io.format(i)) - -for i in range(0, N_UART): bsv_file.write( + '''\n // following wires capture the values sent to the IO Cell''') + for i in range(0, N_IO): + bsv_file.write(generic_io.format(i)) + + for i in range(0, N_UART): + bsv_file.write( '''\n // following wires capture signals to IO CELL if uart-{0} is // allotted to it'''.format(i)) - bsv_file.write(uartwires.format(i)) + bsv_file.write(uartwires.format(i)) -for i in range(0, N_SPI): - bsv_file.write( + for i in range(0, N_SPI): + bsv_file.write( '''\n // following wires capture signals to IO CELL if spi-{0} is // allotted to it'''.format(i)) - bsv_file.write(spiwires.format(i)) + bsv_file.write(spiwires.format(i)) -for i in range(0, N_TWI): - bsv_file.write( + for i in range(0, N_TWI): + bsv_file.write( '''\n // following wires capture signals to IO CELL if twi-{0} is // allotted to it'''.format(i)) bsv_file.write(twiwires.format(i)) -for i in range(0, N_SD): - bsv_file.write( + for i in range(0, N_SD): + bsv_file.write( '''\n // following wires capture signals to IO CELL if sd-{0} is // allotted to it'''.format(i)) - bsv_file.write(sdwires.format(i)) + bsv_file.write(sdwires.format(i)) -for i in range(0, N_JTAG): - bsv_file.write( + for i in range(0, N_JTAG): + bsv_file.write( '''\n // following wires capture signals to IO CELL if jtag-{0} is // allotted to it'''.format(i)) - bsv_file.write(jtagwires.format(i)) + bsv_file.write(jtagwires.format(i)) -for i in range(0, N_PWM): - bsv_file.write( + for i in range(0, N_PWM): + bsv_file.write( '''\n // following wires capture signals to IO CELL if pwm-{0} is // allotted to it'''.format(i)) - bsv_file.write(pwmwires.format(i)) -bsv_file.write("\n") -# ==================================================================== -# ========================= Actual pinmuxing ========================# -bsv_file.write(''' + bsv_file.write(pwmwires.format(i)) + bsv_file.write("\n") + # ==================================================================== + # ========================= Actual pinmuxing ========================# + bsv_file.write(''' /*====== This where the muxing starts for each io-cell======*/ ''') -bsv_file.write(pinmux) -bsv_file.write(''' + bsv_file.write(pinmux) + bsv_file.write(''' /*============================================================*/ ''') -# ==================================================================== -# ================= interface definitions for each method =============# -bsv_file.write(''' + # ==================================================================== + # ================= interface definitions for each method =============# + bsv_file.write(''' interface mux_lines = interface MuxSelectionLines ''') -for cell in muxed_cells: - bsv_file.write(mux_interface_def.format(cell[0], + for cell in muxed_cells: + bsv_file.write(mux_interface_def.format(cell[0], int(math.log(len(cell) - 1, 2)))) -bsv_file.write(''' + bsv_file.write(''' endinterface; interface peripheral_side = interface PeripheralSide ''') -for i in range(0, N_IO): - bsv_file.write(io_interface_def.format(i)) -for i in range(0, N_UART): - bsv_file.write(uartinterface_def.format(i)) -for i in range(0, N_SPI): - bsv_file.write(spiinterface_def.format(i)) -for i in range(0, N_TWI): - bsv_file.write(twiinterface_def.format(i)) -for i in range(0, N_SD): - bsv_file.write(sdinterface_def.format(i)) -for i in range(0, N_JTAG): - bsv_file.write(jtaginterface_def.format(i)) -for i in range(0, N_PWM): - bsv_file.write(pwminterface_def.format(i)) -bsv_file.write(footer) -print("BSV file successfully generated: bsv_src/pinmux.bsv") -# ====================================================================== -bsv_file.close() + for i in range(0, N_IO): + bsv_file.write(io_interface_def.format(i)) + for i in range(0, N_UART): + bsv_file.write(uartinterface_def.format(i)) + for i in range(0, N_SPI): + bsv_file.write(spiinterface_def.format(i)) + for i in range(0, N_TWI): + bsv_file.write(twiinterface_def.format(i)) + for i in range(0, N_SD): + bsv_file.write(sdinterface_def.format(i)) + for i in range(0, N_JTAG): + bsv_file.write(jtaginterface_def.format(i)) + for i in range(0, N_PWM): + bsv_file.write(pwminterface_def.format(i)) + bsv_file.write(footer) + print("BSV file successfully generated: bsv_src/pinmux.bsv") + # ====================================================================== bsv_file = open('bsv_src/PinTop.bsv', 'w') bsv_file.write(copyright+''' -- 2.30.2