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