From: Neel Date: Mon, 19 Mar 2018 10:36:56 +0000 (+0530) Subject: defined the user-interface for the memory mapped registers X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3c9f40523337a03bff4657ca76cb2ce690c45bc5;p=pinmux.git defined the user-interface for the memory mapped registers Support is provided to address registers using 8-bit, 16-bit, 32-bit or 64-bit addressing scheme. Need to add support for a compressed scheme as well. --- diff --git a/src/parse.py b/src/parse.py index a9913ae..babf31d 100644 --- a/src/parse.py +++ b/src/parse.py @@ -1,3 +1,4 @@ +import math # == Parameters == # N_MUX = 1 # number of selection lines for the mux per io N_IO = 0 @@ -7,8 +8,25 @@ N_SPI = 1 N_TWI = 2 N_SD = 2 N_JTAG = 2 +Addressing = 'WORD' +ADDR_WIDTH = 32 +DATA_WIDTH = 32 # ================ # +# Generating the number of bits for memory map # +lower_offset = 0 +if(Addressing == 'BYTE'): + lower_offset = 0 +elif(Addressing == 'HWORD'): + lower_offset = 1 +elif(Addressing == 'WORD'): + lower_offset = 2 +elif(Addressing == 'DWORD'): + lower_offset = 3 +else: + print('ERROR: Addressing should be one of: BYTE, HWORD, WORD, DWORD') + exit(1) + def missing_numbers(num_list): original_list = [x for x in range(num_list[0], num_list[-1] + 1)] @@ -31,6 +49,8 @@ for lineno, line in enumerate(pinmapfile): if(len(line1) > 2): muxed_cells.append(line1) pinnumbers = sorted(pinnumbers) + +upper_offset = lower_offset + int(math.log(len(muxed_cells), 2)) # ============================================= # # ======= Multiple checks to see if the user has not screwed ======# missing_pins = missing_numbers(pinnumbers) diff --git a/src/pinmux_generator.py b/src/pinmux_generator.py index 55795c9..f52f803 100644 --- a/src/pinmux_generator.py +++ b/src/pinmux_generator.py @@ -33,8 +33,7 @@ if not os.path.exists("bsv_src"): bsv_file = open("./bsv_src/pinmux.bsv", "w") - -header = ''' +copyright = ''' /* This BSV file has been generated by the PinMux tool available at: https://bitbucket.org/casl/pinmux. @@ -42,6 +41,8 @@ header = ''' Authors: Neel Gala, Luke Date of generation: ''' + time.strftime("%c") + ''' */ +''' +header = copyright+''' package pinmux; typedef struct{ @@ -214,16 +215,74 @@ print("BSV file successfully generated: bsv_src/pinmux.bsv") # ====================================================================== bsv_file.close() -bsv_file = open('bsv_src/PinTop.bsv','w') -bsv_file.write(''' +bsv_file = open('bsv_src/PinTop.bsv', 'w') +bsv_file.write(copyright+''' package PinTop; import pinmux::*; interface Ifc_PintTop; + method ActionValue#(Bool) write(Bit#({0}) addr, Bit#({1}) data); + method Tuple2#(Bool,Bit#({1})) read(Bit#({0}) addr); interface PeripheralSide peripheral_side; endinterface module mkPinTop(Ifc_PintTop); + // instantiate the pin-mux module here Ifc_pinmux pinmux <-mkpinmux; + + // declare the registers which will be used to mux the IOs +'''.format(ADDR_WIDTH, DATA_WIDTH)) + +for cell in muxed_cells: + bsv_file.write(''' + Reg#(Bit#({0})) rg_muxio_{1} <-mkReg(0);'''.format( + int(math.log(len(cell) - 1, 2)), cell[0])) + +bsv_file.write(''' + // rule to connect the registers to the selection lines of the + // pin-mux module + rule connect_selection_registers;''') + +for cell in muxed_cells: + bsv_file.write(''' + pinmux.mux_lines.cell{0}_mux(rg_muxio_{0});'''.format(cell[0])) + +bsv_file.write(''' + endrule + // method definitions for the write user interface + method ActionValue#(Bool) write(Bit#({2}) addr, Bit#({3}) data); + Bool err=False; + case (addr[{0}:{1}])'''.format(upper_offset, lower_offset, + ADDR_WIDTH, DATA_WIDTH)) +index = 0 +for cell in muxed_cells: + bsv_file.write(''' + {0}: rg_muxio_{1}<=truncate(data);'''.format(index, cell[0])) + index = index + 1 + +bsv_file.write(''' + default: err=True; + endcase + return err; + endmethod''') + +bsv_file.write(''' + // method definitions for the read user interface + method Tuple2#(Bool,Bit#({3})) read(Bit#({2}) addr); + Bool err=False; + Bit#(32) data=0; + case (addr[{0}:{1}])'''.format(upper_offset, lower_offset, + ADDR_WIDTH, DATA_WIDTH)) +index = 0 +for cell in muxed_cells: + bsv_file.write(''' + {0}: data=zeroExtend(rg_muxio_{1});'''.format(index, cell[0])) + index = index + 1 + +bsv_file.write(''' + default:err=True; + endcase + return tuple2(err,data); + endmethod interface peripheral_side=pinmux.peripheral_side; endmodule endpackage