stream: make use of reverse parameter for changing byte endianness - #2346
Open
ozel wants to merge 2 commits into
Open
stream: make use of reverse parameter for changing byte endianness#2346ozel wants to merge 2 commits into
ozel wants to merge 2 commits into
Conversation
Comment on lines
+475
to
+479
| if reverse: | ||
| # reverse order/endianness of bytes | ||
| if nbits_from % 8: | ||
| raise ValueError("When reversing ratio=1 streams, data width must be a multiple of 8 bits") | ||
| self.comb += source.data.eq(reverse_bytes(sink.data)), |
Contributor
There was a problem hiding this comment.
you could put this after sink.connect(source)
that way it overwrites the source.data.eq(sink.data) of sink.connect(source), just like in verilog
Author
There was a problem hiding this comment.
ah sure, yes of course! Do you think enabling reversal of byte order in streams this way is generally acceptable?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
stream.Convert()operates on equal data widths (nbits_from = nbits_to) thereverseparameter 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,reversecould 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 enjoy-digital/liteeth#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.