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
17 ADDR_WIDTH
= 64 # TODO parameterise
18 PADDR_WIDTH
= 32 # TODO parameterise
19 DATA_WIDTH
= 64 # TODO parameterise
22 # Generating the number of bits for memory map #
24 if Addressing
== 'BYTE':
26 elif Addressing
== 'HWORD':
28 elif Addressing
== 'WORD':
30 elif Addressing
== 'DWORD':
33 print('ERROR: Addressing should be one of: BYTE, HWORD, WORD, DWORD')
36 def __init__(self
, pth
=None, verify
=True):
40 self
.dedicated_cells
= []
43 # == capture the number of IO cells required == #
46 fname
= os
.path
.join(pth
, fname
)
47 with
open(fname
) as pinmapfile
:
48 for lineno
, line
in enumerate(pinmapfile
):
49 line1
= line
[:-1].split('\t')
52 self
.pinnumbers
.append(int(line1
[0]))
53 # XXX TODO: dedicated pins in separate file
54 #if len(line1) == 2: # dedicated
55 # self.dedicated_cells.append(line1)
57 for i
in range(1, len(line1
)):
59 if line1
[i
].startswith('pwm'):
60 line1
[i
] = 'pwm%s_out' % line1
[i
][4:]
61 self
.muxed_cells
.append(line1
)
63 self
.pinnumbers
= sorted(self
.pinnumbers
)
64 self
.upper_offset
= self
.lower_offset
+ \
65 int(math
.log(len(self
.muxed_cells
), 2))
70 self
.cell_bitwidth
= self
.get_cell_bit_width()
72 # == user info after parsing ================= #
73 self
.N_IO
= len(self
.dedicated_cells
) + len(self
.muxed_cells
)
74 print("Max number of IO: " + str(self
.N_IO
))
75 print("Muxer bit width: " + str(self
.cell_bitwidth
))
76 print("Muxed IOs: " + str(len(self
.muxed_cells
)))
77 print("Dedicated IOs: " + str(len(self
.dedicated_cells
)))
80 """ Multiple checks to see if the user has not screwed up
82 missing_pins
= missing_numbers(self
.pinnumbers
)
84 # Check-1: ensure no pin is present in both muxed and dedicated pins
85 for muxcell
in self
.muxed_cells
:
86 for dedcel
in self
.dedicated_cells
:
87 if dedcel
[1] in muxcell
:
88 print("ERROR: " + str(dedcel
[1]) + " present \
89 in dedicated & muxed lists")
92 # Check-2: if pin numbering is consistent:
94 print("ERROR: Following pins have no assignment: " +
95 str(missing_numbers(self
.pinnumbers
)))
97 unique
= set(self
.pinnumbers
)
100 count
= self
.pinnumbers
.count(each
)
102 print("ERROR: Multiple assignment for pin: " + str(each
))
107 # Check-3: confirm if N_* matches the instances in the pinmap
108 # ============================================================== #
112 def get_cell_bit_width(self
):
114 for cell
in self
.muxed_cells
:
115 max_num_cells
= max(len(cell
) - 1, max_num_cells
)
116 return int(math
.log(max_num_cells
+ 1, 2))
119 if __name__
== '__main__':