litex icon indicating copy to clipboard operation
litex copied to clipboard

stream: make use of reverse parameter for changing byte endianness

Open ozel opened this issue 5 months ago • 0 comments

When stream.Convert() operates on equal data widths (nbits_from = nbits_to) the reverse parameter wasn't used so far in _IdentityConverter(). Only in case of up/down conversion, e.g. from 8 to 32 bit width and vice versa, reverse could be used to swap byte endianness.

With this PR, Convert(...,reverse=True) can be used to reverse byte order of equally-sized LiteX streams. I have not seen an alternative LiteX stream module that could do this. This is handy for dealing with UDP streams as the etherbone/UDP core of LiteEth converts Ethernet payloads to little endian already on reception and independently of downstream processing in a CPU core (see https://github.com/enjoy-digital/liteeth/pull/82).

There should be a built-in LiteX feature to convert a streams' byte order like this commit. Please let me know if there is a more canonical way that I've missed.

ozel avatar Oct 08 '25 15:10 ozel