From: Florent Kermarrec Date: Fri, 30 Jan 2015 09:48:56 +0000 (+0100) Subject: arp: rx and decoding OK X-Git-Tag: 24jan2021_ls180~2604^2~105 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a7d4427de4f7b54d18c70d578ba5fe46b4469cbd;p=litex.git arp: rx and decoding OK --- diff --git a/liteeth/common.py b/liteeth/common.py index e68e4c49..ddb14e2d 100644 --- a/liteeth/common.py +++ b/liteeth/common.py @@ -77,6 +77,13 @@ udp_header = { "checksum": HField( 6, 0, 16) } +def reverse_bytes(v): + n = math.ceil(flen(v)//8) + r = [] + for i in reversed(range(n)): + r.append(v[i*8:min((i+1)*8, flen(v))]) + return Cat(iter(r)) + # layouts def _layout_from_header(header): _layout = [] diff --git a/liteeth/generic/depacketizer.py b/liteeth/generic/depacketizer.py index e4525a0c..39d11136 100644 --- a/liteeth/generic/depacketizer.py +++ b/liteeth/generic/depacketizer.py @@ -5,7 +5,7 @@ def _decode_header(h_dict, h_signal, obj): for k, v in sorted(h_dict.items()): start = v.byte*8+v.offset end = start+v.width - r.append(getattr(obj, k).eq(h_signal[start:end])) + r.append(getattr(obj, k).eq(reverse_bytes(h_signal[start:end]))) return r class LiteEthDepacketizer(Module): @@ -18,6 +18,12 @@ class LiteEthDepacketizer(Module): counter = Counter(max=header_length) self.submodules += counter + self.sync += [ + If(shift, + header.eq(Cat(header[8:], sink.data)) + ) + ] + fsm = FSM(reset_state="IDLE") self.submodules += fsm diff --git a/liteeth/generic/packetizer.py b/liteeth/generic/packetizer.py index 2aa161ef..4fb788f1 100644 --- a/liteeth/generic/packetizer.py +++ b/liteeth/generic/packetizer.py @@ -1,12 +1,4 @@ from liteeth.common import * -import math - -def reverse_bytes(v): - n = math.ceil(flen(v)//8) - r = [] - for i in reversed(range(n)): - r.append(v[i*8:min((i+1)*8, flen(v))]) - return Cat(iter(r)) def _encode_header(h_dict, h_signal, obj): r = [] diff --git a/liteeth/test/arp_tb.py b/liteeth/test/arp_tb.py index b4629c89..e11a1101 100644 --- a/liteeth/test/arp_tb.py +++ b/liteeth/test/arp_tb.py @@ -51,4 +51,4 @@ class TB(Module): selfp.arp.table.request.stb = 1 if __name__ == "__main__": - run_simulation(TB(), ncycles=256, vcd_name="my.vcd", keep_files=True) + run_simulation(TB(), ncycles=1024, vcd_name="my.vcd", keep_files=True)