X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fparse.py;h=a11e45dff5081091884082dbf30eee6b018c929d;hb=708d9a316464aa8fab9a3c5d3bc6f497c9f5869d;hp=cd4a3fe09d97b2cd66178bab632258cd3c2ce8a9;hpb=bc6eb8c0fb6c41d7bc36b05e9da465b299937de8;p=pinmux.git diff --git a/src/parse.py b/src/parse.py index cd4a3fe..a11e45d 100644 --- a/src/parse.py +++ b/src/parse.py @@ -1,11 +1,4 @@ -# == Parameters == # -N_MUX = 1 # number of selection lines for the mux per io -N_IO = 0 -N_MUX_IO = 0 -N_UART = 4 -N_SPI = 1 -N_TWI = 2 -# ================ # +import math def missing_numbers(num_list): @@ -14,53 +7,88 @@ def missing_numbers(num_list): return (list(num_list ^ set(original_list))) -# == capture the number of IO cells required == # -pinmapfile = open('pinmap.txt', 'r') -max_io = 0 -muxed_cells = [] -dedicated_cells = [] -pinnumbers = [] -for lineno, line in enumerate(pinmapfile): - line1 = line.split() - if(len(line1) > 1): +class Parse(object): + # == Parameters == # + N_MUX = 1 # number of selection lines for the mux per io + N_IO = 0 + N_MUX_IO = 0 + 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) + + # == capture the number of IO cells required == # + pinmapfile = open('pinmap.txt', 'r') + max_io = 0 + muxed_cells = [] + dedicated_cells = [] + pinnumbers = [] + + for lineno, line in enumerate(pinmapfile): + line1 = line.split() + if len(line1) <= 1: + continue pinnumbers.append(int(line1[0])) - if(len(line1) == 2): # dedicated + if len(line1) == 2: # dedicated dedicated_cells.append(line1) - if(len(line1) > 2): + else: muxed_cells.append(line1) -# ============================================= # -# ======= Multiple checks to see if the user has not screwed ======# -missing_pins = missing_numbers(pinnumbers) -# Check-1: ensure that no pin is present in both muxed and dedicated pins -for muxcell in muxed_cells: - for dedcel in dedicated_cells: - if(dedcel[1] in muxcell): - print("ERROR: " + str(dedcel[1]) + " present \ - in dedicated & muxed lists") - exit(1) + 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) + + # Check-1: ensure that no pin is present in both muxed and dedicated pins + for muxcell in muxed_cells: + for dedcel in dedicated_cells: + if(dedcel[1] in muxcell): + print("ERROR: " + str(dedcel[1]) + " present \ + in dedicated & muxed lists") + exit(1) + + # Check-2: if pin numbering is consistent: + if missing_pins: + print("ERROR: Following pins have no assignment: " + + str(missing_numbers(pinnumbers))) + exit(1) + unique = set(pinnumbers) + duplicate = False + for each in unique: + count = pinnumbers.count(each) + if(count > 1): + print("ERROR: Multiple assignment for pin: " + str(each)) + duplicate = True + if(duplicate): + exit(1) + + # Check-2: confirm if N_* matches the instances in the pinmap + # ============================================================== # -# Check-2: if pin numbering is consistent: -if missing_pins: - print("ERROR: Following pins have no assignment: " + - str(missing_numbers(pinnumbers))) - exit(1) -unique = set(pinnumbers) -duplicate = False -for each in unique: - count = pinnumbers.count(each) - if(count > 1): - print("ERROR: Multiple assignment for pin: " + str(each)) - duplicate = True -if(duplicate): - exit(1) + # == user info after parsin ================= # + N_IO = len(dedicated_cells) + len(muxed_cells) + print("Max number of IO: " + str(N_IO)) + print("Muxed IOs: " + str(len(muxed_cells))) + print("Dedicated IOs: " + str(len(dedicated_cells))) + # ============================================ # -# Check-2: confirm if N_* matches the instances in the pinmap -# ============================================================== # -# == user info after parsin ================= # -N_IO = len(dedicated_cells) + len(muxed_cells) -print("Max number of IO: " + str(N_IO)) -print("Muxed IOs: " + str(len(muxed_cells))) -print("Dedicated IOs: " + str(len(dedicated_cells))) -# ============================================ # +if __name__ == '__main__': + p = Parse() + print p.N_IO