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