remove if brackets
[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
41 for lineno, line in enumerate(pinmapfile):
42 line1 = line.split()
43 if len(line1) <= 1:
44 continue
45 pinnumbers.append(int(line1[0]))
46 if len(line1) == 2: # dedicated
47 dedicated_cells.append(line1)
48 else:
49 muxed_cells.append(line1)
50
51 pinnumbers = sorted(pinnumbers)
52 upper_offset = lower_offset + int(math.log(len(muxed_cells), 2))
53
54 # ============================================= #
55 # ======= Multiple checks to see if the user has not screwed ======#
56 missing_pins = missing_numbers(pinnumbers)
57
58 # Check-1: ensure that no pin is present in both muxed and dedicated pins
59 for muxcell in muxed_cells:
60 for dedcel in dedicated_cells:
61 if(dedcel[1] in muxcell):
62 print("ERROR: " + str(dedcel[1]) + " present \
63 in dedicated & muxed lists")
64 exit(1)
65
66 # Check-2: if pin numbering is consistent:
67 if missing_pins:
68 print("ERROR: Following pins have no assignment: " +
69 str(missing_numbers(pinnumbers)))
70 exit(1)
71 unique = set(pinnumbers)
72 duplicate = False
73 for each in unique:
74 count = pinnumbers.count(each)
75 if(count > 1):
76 print("ERROR: Multiple assignment for pin: " + str(each))
77 duplicate = True
78 if duplicate:
79 exit(1)
80
81 # Check-2: confirm if N_* matches the instances in the pinmap
82 # ============================================================== #
83
84 # == user info after parsin ================= #
85 N_IO = len(dedicated_cells) + len(muxed_cells)
86 print("Max number of IO: " + str(N_IO))
87 print("Muxed IOs: " + str(len(muxed_cells)))
88 print("Dedicated IOs: " + str(len(dedicated_cells)))
89 # ============================================ #
90
91
92 if __name__ == '__main__':
93 p = Parse()
94 print p.N_IO