3d508d651b63612de1385adb7f42076f1faa99aa
5 def missing_numbers(num_list
):
6 original_list
= [x
for x
in range(num_list
[0], num_list
[-1] + 1)]
7 num_list
= set(num_list
)
8 return (list(num_list ^
set(original_list
)))
13 N_MUX
= 1 # number of selection lines for the mux per io
21 # Generating the number of bits for memory map #
23 if Addressing
== 'BYTE':
25 elif Addressing
== 'HWORD':
27 elif Addressing
== 'WORD':
29 elif Addressing
== 'DWORD':
32 print('ERROR: Addressing should be one of: BYTE, HWORD, WORD, DWORD')
35 def __init__(self
, pth
=None, verify
=True):
39 self
.dedicated_cells
= []
42 # == capture the number of IO cells required == #
45 fname
= os
.path
.join(pth
, fname
)
46 with
open(fname
) as pinmapfile
:
47 for lineno
, line
in enumerate(pinmapfile
):
48 line1
= line
[:-1].split('\t')
51 self
.pinnumbers
.append(int(line1
[0]))
52 if len(line1
) == 2: # dedicated
53 self
.dedicated_cells
.append(line1
)
55 self
.muxed_cells
.append(line1
)
57 self
.pinnumbers
= sorted(self
.pinnumbers
)
58 self
.upper_offset
= self
.lower_offset
+ \
59 int(math
.log(len(self
.muxed_cells
), 2))
64 self
.cell_bitwidth
= self
.get_cell_bit_width()
66 # == user info after parsing ================= #
67 self
.N_IO
= len(self
.dedicated_cells
) + len(self
.muxed_cells
)
68 print("Max number of IO: " + str(self
.N_IO
))
69 print("Muxer bit width: " + str(self
.cell_bitwidth
))
70 print("Muxed IOs: " + str(len(self
.muxed_cells
)))
71 print("Dedicated IOs: " + str(len(self
.dedicated_cells
)))
74 """ Multiple checks to see if the user has not screwed up
76 missing_pins
= missing_numbers(self
.pinnumbers
)
78 # Check-1: ensure no pin is present in both muxed and dedicated pins
79 for muxcell
in self
.muxed_cells
:
80 for dedcel
in self
.dedicated_cells
:
81 if dedcel
[1] in muxcell
:
82 print("ERROR: " + str(dedcel
[1]) + " present \
83 in dedicated & muxed lists")
86 # Check-2: if pin numbering is consistent:
88 print("ERROR: Following pins have no assignment: " +
89 str(missing_numbers(self
.pinnumbers
)))
91 unique
= set(self
.pinnumbers
)
94 count
= self
.pinnumbers
.count(each
)
96 print("ERROR: Multiple assignment for pin: " + str(each
))
101 # Check-3: confirm if N_* matches the instances in the pinmap
102 # ============================================================== #
106 def get_cell_bit_width(self
):
108 for cell
in self
.muxed_cells
:
109 max_num_cells
= max(len(cell
) - 1, max_num_cells
)
110 return int(math
.log(max_num_cells
+ 1, 2))
113 if __name__
== '__main__':