ed7a9701b3cbaf6f4f6bf42ffda73fec73b0eb30
[pinmux.git] / src / parse.py
1 # == Parameters == #
2 N_MUX = 1 # number of selection lines for the mux per io
3 N_IO = 0
4 N_MUX_IO = 0
5 N_UART = 4
6 N_SPI = 1
7 N_TWI = 2
8 N_SD = 2
9 # ================ #
10
11
12 def missing_numbers(num_list):
13 original_list = [x for x in range(num_list[0], num_list[-1] + 1)]
14 num_list = set(num_list)
15 return (list(num_list ^ set(original_list)))
16
17
18 # == capture the number of IO cells required == #
19 pinmapfile = open('pinmap.txt', 'r')
20 max_io = 0
21 muxed_cells = []
22 dedicated_cells = []
23 pinnumbers = []
24 for lineno, line in enumerate(pinmapfile):
25 line1 = line.split()
26 if(len(line1) > 1):
27 pinnumbers.append(int(line1[0]))
28 if(len(line1) == 2): # dedicated
29 dedicated_cells.append(line1)
30 if(len(line1) > 2):
31 muxed_cells.append(line1)
32 pinnumbers = sorted(pinnumbers)
33 # ============================================= #
34 # ======= Multiple checks to see if the user has not screwed ======#
35 missing_pins = missing_numbers(pinnumbers)
36
37 # Check-1: ensure that no pin is present in both muxed and dedicated pins
38 for muxcell in muxed_cells:
39 for dedcel in dedicated_cells:
40 if(dedcel[1] in muxcell):
41 print("ERROR: " + str(dedcel[1]) + " present \
42 in dedicated & muxed lists")
43 exit(1)
44
45 # Check-2: if pin numbering is consistent:
46 if missing_pins:
47 print("ERROR: Following pins have no assignment: " +
48 str(missing_numbers(pinnumbers)))
49 exit(1)
50 unique = set(pinnumbers)
51 duplicate = False
52 for each in unique:
53 count = pinnumbers.count(each)
54 if(count > 1):
55 print("ERROR: Multiple assignment for pin: " + str(each))
56 duplicate = True
57 if(duplicate):
58 exit(1)
59
60 # Check-2: confirm if N_* matches the instances in the pinmap
61 # ============================================================== #
62
63 # == user info after parsin ================= #
64 N_IO = len(dedicated_cells) + len(muxed_cells)
65 print("Max number of IO: " + str(N_IO))
66 print("Muxed IOs: " + str(len(muxed_cells)))
67 print("Dedicated IOs: " + str(len(dedicated_cells)))
68 # ============================================ #