defined the user-interface for the memory mapped registers
[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 Addressing = 'WORD'
12 ADDR_WIDTH = 32
13 DATA_WIDTH = 32
14 # ================ #
15
16 # Generating the number of bits for memory map #
17 lower_offset = 0
18 if(Addressing == 'BYTE'):
19 lower_offset = 0
20 elif(Addressing == 'HWORD'):
21 lower_offset = 1
22 elif(Addressing == 'WORD'):
23 lower_offset = 2
24 elif(Addressing == 'DWORD'):
25 lower_offset = 3
26 else:
27 print('ERROR: Addressing should be one of: BYTE, HWORD, WORD, DWORD')
28 exit(1)
29
30
31 def missing_numbers(num_list):
32 original_list = [x for x in range(num_list[0], num_list[-1] + 1)]
33 num_list = set(num_list)
34 return (list(num_list ^ set(original_list)))
35
36
37 # == capture the number of IO cells required == #
38 pinmapfile = open('pinmap.txt', 'r')
39 max_io = 0
40 muxed_cells = []
41 dedicated_cells = []
42 pinnumbers = []
43 for lineno, line in enumerate(pinmapfile):
44 line1 = line.split()
45 if(len(line1) > 1):
46 pinnumbers.append(int(line1[0]))
47 if(len(line1) == 2): # dedicated
48 dedicated_cells.append(line1)
49 if(len(line1) > 2):
50 muxed_cells.append(line1)
51 pinnumbers = sorted(pinnumbers)
52
53 upper_offset = lower_offset + int(math.log(len(muxed_cells), 2))
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 # ============================================ #