From: Florent Kermarrec Date: Wed, 29 May 2019 08:25:25 +0000 (+0200) Subject: soc/interconnect/gearbox: add msb_first/lsb_first order X-Git-Tag: 24jan2021_ls180~1194 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=08a811b1a5040d9d864ed388363587f4c7040d0a;p=litex.git soc/interconnect/gearbox: add msb_first/lsb_first order --- diff --git a/litex/soc/interconnect/stream.py b/litex/soc/interconnect/stream.py index 0c185a19..99ddaa88 100644 --- a/litex/soc/interconnect/stream.py +++ b/litex/soc/interconnect/stream.py @@ -369,7 +369,7 @@ def inc_mod(s, m): class Gearbox(Module): - def __init__(self, i_dw, o_dw): + def __init__(self, i_dw, o_dw, msb_first=True): self.sink = sink = Endpoint([("data", i_dw)]) self.source = source = Endpoint([("data", o_dw)]) @@ -406,14 +406,24 @@ class Gearbox(Module): shift_register = Signal(io_lcm) i_cases = {} + i_data = Signal(i_dw) + if msb_first: + self.comb += i_data.eq(sink.data) + else: + self.comb += i_data.eq(sink.data[::-1]) for i in range(io_lcm//i_dw): - i_cases[i] = shift_register[io_lcm - i_dw*(i+1):io_lcm - i_dw*i].eq(sink.data) + i_cases[i] = shift_register[io_lcm - i_dw*(i+1):io_lcm - i_dw*i].eq(i_data) self.sync += If(sink.valid & sink.ready, Case(i_count, i_cases)) o_cases = {} + o_data = Signal(o_dw) for i in range(io_lcm//o_dw): - o_cases[i] = source.data.eq(shift_register[io_lcm - o_dw*(i+1):io_lcm - o_dw*i]) + o_cases[i] = o_data.eq(shift_register[io_lcm - o_dw*(i+1):io_lcm - o_dw*i]) self.comb += Case(o_count, o_cases) + if msb_first: + self.comb += source.data.eq(o_data) + else: + self.comb += source.data.eq(o_data[::-1]) # TODO: clean up code below # XXX