from nmigen import Signal, Cat
-# TODO: turn this into a module
+# TODO: turn this into a module?
def byte_reverse(m, name, data, length):
"""byte_reverse: unlike nmigen word_select this takes a dynamic length
comb = m.d.comb
data_r = Signal.like(data, name=name)
+ # if length is a static integer, we do not require a Case statement
if isinstance(length, int):
j = length
rev = []
comb += data_r.eq(Cat(*rev))
return data_r
+ # Switch statement needed: dynamic length had better be = 1,2,4 or 8
with m.Switch(length):
for j in [1,2,4,8]:
with m.Case(j):
comb += data_r.eq(Cat(*rev))
return data_r
-