whitespace, autopep8
[pinmux.git] / src / parse.py
1 import math
2
3
4 def missing_numbers(num_list):
5 original_list = [x for x in range(num_list[0], num_list[-1] + 1)]
6 num_list = set(num_list)
7 return (list(num_list ^ set(original_list)))
8
9
10 class Parse(object):
11 # == Parameters == #
12 N_MUX = 1 # number of selection lines for the mux per io
13 N_IO = 0
14 N_MUX_IO = 0
15 Addressing = 'WORD'
16 ADDR_WIDTH = 32
17 DATA_WIDTH = 32
18 # ================ #
19
20 # Generating the number of bits for memory map #
21 lower_offset = 0
22 if(Addressing == 'BYTE'):
23 lower_offset = 0
24 elif(Addressing == 'HWORD'):
25 lower_offset = 1
26 elif(Addressing == 'WORD'):
27 lower_offset = 2
28 elif(Addressing == 'DWORD'):
29 lower_offset = 3
30 else:
31 print('ERROR: Addressing should be one of: BYTE, HWORD, WORD, DWORD')
32 exit(1)
33
34 # == capture the number of IO cells required == #
35 pinmapfile = open('pinmap.txt', 'r')
36 max_io = 0
37 muxed_cells = []
38 dedicated_cells = []
39 pinnumbers = []
40 for lineno, line in enumerate(pinmapfile):
41 line1 = line.split()
42 if(len(line1) > 1):
43 pinnumbers.append(int(line1[0]))
44 if(len(line1) == 2): # dedicated
45 dedicated_cells.append(line1)
46 if(len(line1) > 2):
47 muxed_cells.append(line1)
48 pinnumbers = sorted(pinnumbers)
49
50 upper_offset = lower_offset + int(math.log(len(muxed_cells), 2))
51 # ============================================= #
52 # ======= Multiple checks to see if the user has not screwed ======#
53 missing_pins = missing_numbers(pinnumbers)
54
55 # Check-1: ensure that no pin is present in both muxed and dedicated pins
56 for muxcell in muxed_cells:
57 for dedcel in dedicated_cells:
58 if(dedcel[1] in muxcell):
59 print("ERROR: " + str(dedcel[1]) + " present \
60 in dedicated & muxed lists")
61 exit(1)
62
63 # Check-2: if pin numbering is consistent:
64 if missing_pins:
65 print("ERROR: Following pins have no assignment: " +
66 str(missing_numbers(pinnumbers)))
67 exit(1)
68 unique = set(pinnumbers)
69 duplicate = False
70 for each in unique:
71 count = pinnumbers.count(each)
72 if(count > 1):
73 print("ERROR: Multiple assignment for pin: " + str(each))
74 duplicate = True
75 if(duplicate):
76 exit(1)
77
78 # Check-2: confirm if N_* matches the instances in the pinmap
79 # ============================================================== #
80
81 # == user info after parsin ================= #
82 N_IO = len(dedicated_cells) + len(muxed_cells)
83 print("Max number of IO: " + str(N_IO))
84 print("Muxed IOs: " + str(len(muxed_cells)))
85 print("Dedicated IOs: " + str(len(dedicated_cells)))
86 # ============================================ #
87
88
89 if __name__ == '__main__':
90 p = Parse()
91 print p.N_IO