arp: rx and decoding OK

This commit is contained in:
Florent Kermarrec 2015-01-30 10:48:56 +01:00
parent 18a7d66b5e
commit a7d4427de4
4 changed files with 15 additions and 10 deletions

View File

@ -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 = []

View File

@ -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

View File

@ -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 = []

View File

@ -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)