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