Skip to content

Commit b9a3751

Browse files
committedMar 14, 2016
interconnect/stream: change Converter parameters to nbits instead of layout, rename chunks to valid_token_count
1 parent f962ed2 commit b9a3751

File tree

2 files changed

+40
-63
lines changed

2 files changed

+40
-63
lines changed
 

Diff for: ‎misoc/cores/liteeth_mini/phy/mii.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
from misoc.cores.liteeth_mini.common import *
77

88

9-
def converter_layout(dw):
10-
return [("data", dw)]
11-
12-
139
class LiteEthPHYMIITX(Module):
1410
def __init__(self, pads):
1511
self.sink = sink = stream.Endpoint(eth_phy_layout(8))
@@ -18,8 +14,7 @@ def __init__(self, pads):
1814

1915
if hasattr(pads, "tx_er"):
2016
self.sync += pads.tx_er.eq(0)
21-
converter = stream.Converter(converter_layout(8),
22-
converter_layout(4))
17+
converter = stream.Converter(8, 4)
2318
self.submodules += converter
2419
self.comb += [
2520
converter.sink.stb.eq(sink.stb),
@@ -39,8 +34,7 @@ def __init__(self, pads):
3934

4035
# # #
4136

42-
converter = stream.Converter(converter_layout(4),
43-
converter_layout(8))
37+
converter = stream.Converter(4, 8)
4438
converter = ResetInserter()(converter)
4539
self.submodules += converter
4640

Diff for: ‎misoc/interconnect/stream.py

+38-55
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ def __init__(self, layout, n):
129129

130130

131131
class _UpConverter(Module):
132-
def __init__(self, layout_from, layout_to, ratio, reverse):
133-
self.sink = sink = Endpoint(layout_from)
134-
self.source = source = Endpoint(layout_to)
135-
self.chunks = Signal(bits_for(ratio))
132+
def __init__(self, nbits_from, nbits_to, ratio, reverse):
133+
self.sink = sink = Endpoint([("data", nbits_from)])
134+
self.source = source = Endpoint([("data", nbits_to)])
135+
self.valid_token_count = Signal(bits_for(ratio))
Has conversations. Original line has conversations.
136136

137137
# # #
138138

@@ -166,26 +166,21 @@ def __init__(self, layout_from, layout_to, ratio, reverse):
166166
]
167167

168168
# data path
169-
source_payload_raw_bits = Signal(len(source.payload.raw_bits()))
170169
cases = {}
171170
for i in range(ratio):
172171
n = ratio-i-1 if reverse else i
173-
width = len(sink.payload.raw_bits())
174-
src = sink.payload.raw_bits()
175-
dst = source_payload_raw_bits[n*width:(n+1)*width]
176-
cases[i] = dst.eq(src)
172+
cases[i] = source.data[n*nbits_from:(n+1)*nbits_from].eq(sink.data)
177173
self.sync += If(load_part, Case(demux, cases))
178-
self.comb += source.payload.raw_bits().eq(source_payload_raw_bits)
179174

180-
# chunks
181-
self.sync += If(load_part, self.chunks.eq(demux + 1))
175+
# valid token count
176+
self.sync += If(load_part, self.valid_token_count.eq(demux + 1))
182177

183178

184179
class _DownConverter(Module):
185-
def __init__(self, layout_from, layout_to, ratio, reverse):
186-
self.sink = sink = Endpoint(layout_from)
187-
self.source = source = Endpoint(layout_to)
188-
self.chunks = Signal()
180+
def __init__(self, nbits_from, nbits_to, ratio, reverse):
181+
self.sink = sink = Endpoint([("data", nbits_from)])
182+
self.source = source = Endpoint([("data", nbits_to)])
183+
self.valid_token_count = Signal()
189184

190185
# # #
191186

@@ -208,49 +203,38 @@ def __init__(self, layout_from, layout_to, ratio, reverse):
208203
)
209204

210205
# data path
211-
sink_payload_raw_bits = Signal(len(sink.payload.raw_bits()))
212-
self.comb += sink_payload_raw_bits.eq(sink.payload.raw_bits())
213206
cases = {}
214207
for i in range(ratio):
215208
n = ratio-i-1 if reverse else i
216-
width = len(source.payload.raw_bits())
217-
src = sink_payload_raw_bits[n*width:(n+1)*width]
218-
dst = source.payload.raw_bits()
219-
cases[i] = dst.eq(src)
209+
cases[i] = source.data.eq(sink.data[n*nbits_to:(n+1)*nbits_to])
220210
self.comb += Case(mux, cases).makedefault()
221211

222-
# chunks
223-
self.comb += self.chunks.eq(last)
212+
# valid token count
213+
self.comb += self.valid_token_count.eq(last)
224214

225215

226216
class _IdentityConverter(Module):
227-
def __init__(self, layout_from, layout_to, ratio, reverse):
228-
self.sink = sink = Endpoint(layout_from)
229-
self.source = source = Endpoint(layout_to)
230-
self.chunks = Signal()
217+
def __init__(self, nbits_from, nbits_to, ratio, reverse):
218+
self.sink = sink = Endpoint([("data", nbits_from)])
219+
self.source = source = Endpoint([("data", nbits_to)])
220+
self.valid_token_count = Signal(reset=1)
231221

232222
# # #
233223

234-
self.comb += [
235-
sink.connect(source),
236-
self.chunks.eq(1)
237-
]
238-
224+
self.comb += sink.connect(source)
239225

240-
def _get_converter_ratio(layout_from, layout_to):
241-
width_from = len(Endpoint(layout_from).payload.raw_bits())
242-
width_to = len(Endpoint(layout_to).payload.raw_bits())
243226

244-
if width_from > width_to:
227+
def _get_converter_ratio(nbits_from, nbits_to):
228+
if nbits_from > nbits_to:
245229
converter_cls = _DownConverter
246-
if width_from % width_to:
230+
if nbits_from % nbits_to:
247231
raise ValueError("Ratio must be an int")
248-
ratio = width_from//width_to
249-
elif width_from < width_to:
232+
ratio = nbits_from//nbits_to
233+
elif nbits_from < nbits_to:
250234
converter_cls = _UpConverter
251-
if width_to % width_from:
235+
if nbits_to % nbits_from:
252236
raise ValueError("Ratio must be an int")
253-
ratio = width_to//width_from
237+
ratio = nbits_to//nbits_from
254238
else:
255239
converter_cls = _IdentityConverter
256240
ratio = 1
@@ -259,20 +243,21 @@ def _get_converter_ratio(layout_from, layout_to):
259243

260244

261245
class Converter(Module):
262-
def __init__(self, layout_from, layout_to, reverse=False, insert_chunks=False):
263-
self.cls, self.ratio = _get_converter_ratio(layout_from, layout_to)
246+
def __init__(self, nbits_from, nbits_to, reverse=False, report_valid_token_count=False):
247+
self.cls, self.ratio = _get_converter_ratio(nbits_from, nbits_to)
264248

265249
# # #
266250

267-
converter = self.cls(layout_from, layout_to, self.ratio, reverse)
251+
converter = self.cls(nbits_from, nbits_to, self.ratio, reverse)
268252
self.submodules += converter
269253

270254
self.sink = converter.sink
271-
if insert_chunks:
272-
self.source = Endpoint(layout_to + [("chunks", bits_for(self.ratio))])
255+
if report_valid_token_count:
256+
self.source = Endpoint([("data", nbits_to),
257+
("valid_token_count", bits_for(self.ratio))])
273258
self.comb += [
274259
converter.source.connect(self.source),
275-
self.source.chunks.eq(converter.chunks)
260+
self.source.valid_token_count.eq(converter.valid_token_count)
276261
]
277262
else:
278263
self.source = converter.source
@@ -285,12 +270,10 @@ def __init__(self, layout_from, layout_to, reverse=False):
285270

286271
# # #
287272

288-
width_from = len(sink.payload.raw_bits())
289-
width_to = len(source.payload.raw_bits())
273+
nbits_from = len(sink.payload.raw_bits())
274+
nbits_to = len(source.payload.raw_bits())
290275

291-
converter = Converter([("data", width_from)],
292-
[("data", width_to)],
293-
reverse)
276+
converter = Converter(nbits_from, nbits_to, reverse)
294277
self.submodules += converter
295278

296279
# cast sink to converter.sink (user fields --> raw bits)
@@ -305,7 +288,7 @@ def __init__(self, layout_from, layout_to, reverse=False):
305288
j = 0
306289
for name, width in layout_to:
307290
src = getattr(sink, name)[i*width:(i+1)*width]
308-
dst = converter.sink.data[i*width_to+j:i*width_to+j+width]
291+
dst = converter.sink.data[i*nbits_to+j:i*nbits_to+j+width]
309292
self.comb += dst.eq(src)
310293
j += width
311294
else:
@@ -323,7 +306,7 @@ def __init__(self, layout_from, layout_to, reverse=False):
323306
for i in range(ratio):
324307
j = 0
325308
for name, width in layout_from:
326-
src = converter.source.data[i*width_from+j:i*width_from+j+width]
309+
src = converter.source.data[i*nbits_from+j:i*nbits_from+j+width]
327310
dst = getattr(source, name)[i*width:(i+1)*width]
328311
self.comb += dst.eq(src)
329312
j += width

0 commit comments

Comments
 (0)
Please sign in to comment.