Skip to content

Commit

Permalink
frontend/stream: Add packet support and remove send_level.
Browse files Browse the repository at this point in the history
TX packets are now sent when we have a full packet of when the FIFO is full.
Last can always be asserted from user-side when packet needs to be immediately
transmitted, the behavior will then be similar to previous implementation.

Errors are now also reported on RX.
  • Loading branch information
enjoy-digital committed Jul 29, 2022
1 parent 6d742e7 commit 6cf7759
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
6 changes: 5 additions & 1 deletion liteeth/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ def eth_etherbone_mmap_description(dw):
return EndpointDescription(payload_layout, param_layout)

# TTY
def eth_tty_description(dw):
def eth_tty_tx_description(dw):
payload_layout = [("data", dw)]
return EndpointDescription(payload_layout)

def eth_tty_rx_description(dw):
payload_layout = [("data", dw), ("error", 1)]
return EndpointDescription(payload_layout)
20 changes: 12 additions & 8 deletions liteeth/frontend/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
# Stream to UDP TX -----------------------------------------------------------------------------------

class LiteEthStream2UDPTX(Module):
def __init__(self, ip_address, udp_port, data_width=8, fifo_depth=None, send_level=1):
self.sink = sink = stream.Endpoint(eth_tty_description(data_width))
def __init__(self, ip_address, udp_port, data_width=8, fifo_depth=None):
self.sink = sink = stream.Endpoint(eth_tty_tx_description(data_width))
self.source = source = stream.Endpoint(eth_udp_user_description(data_width))

# # #

ip_address = convert_ip(ip_address)

if fifo_depth is None:
assert send_level == 1
self.comb += [
sink.connect(source, keep={"valid", "ready", "data"}),
source.last.eq(1),
Expand All @@ -36,7 +35,8 @@ def __init__(self, ip_address, udp_port, data_width=8, fifo_depth=None, send_lev

self.submodules.fsm = fsm = FSM(reset_state="IDLE")
fsm.act("IDLE",
If(fifo.level >= send_level,
# Send FIFO contents when we have a full-packet or when FIFO is full.
If((fifo.source.valid & fifo.source.last) | ~fifo.sink.ready,
NextValue(level, fifo.level),
NextValue(counter, 0),
NextState("SEND")
Expand Down Expand Up @@ -65,7 +65,7 @@ def __init__(self, ip_address, udp_port, data_width=8, fifo_depth=None, send_lev
class LiteEthUDP2StreamRX(Module):
def __init__(self, ip_address=None, udp_port=None, data_width=8, fifo_depth=None, with_broadcast=True):
self.sink = sink = stream.Endpoint(eth_udp_user_description(data_width))
self.source = source = stream.Endpoint(eth_tty_description(data_width))
self.source = source = stream.Endpoint(eth_tty_rx_description(data_width))

# # #

Expand All @@ -83,14 +83,18 @@ def __init__(self, ip_address=None, udp_port=None, data_width=8, fifo_depth=None
# Data-Path / Buffering (Optional).
if fifo_depth is None:
self.comb += [
sink.connect(source, keep={"last", "data"}),
sink.connect(source, keep={"last", "data", "error"}),
source.valid.eq(sink.valid & valid),
sink.ready.eq(source.ready | ~valid)
]
else:
self.submodules.fifo = fifo = stream.SyncFIFO([("data", data_width)], fifo_depth, buffered=True)
self.submodules.fifo = fifo = stream.SyncFIFO(
layout = [("data", data_width), ("error", 1)],
depth = fifo_depth,
buffered = True,
)
self.comb += [
sink.connect(fifo.sink, keep={"last", "data"}),
sink.connect(fifo.sink, keep={"last", "data", "error"}),
fifo.sink.valid.eq(sink.valid & valid),
sink.ready.eq(fifo.sink.ready | ~valid),
fifo.source.connect(source)
Expand Down
4 changes: 3 additions & 1 deletion liteeth/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def get_udp_port_ios(name, data_width, dynamic_params=False):
Subsignal("source_last", Pins(1)),
Subsignal("source_ready", Pins(1)),
Subsignal("source_data", Pins(data_width)),
Subsignal("source_error", Pins(1)),
),
]

Expand Down Expand Up @@ -342,7 +343,8 @@ def __init__(self, platform, core_config):
port_ios.source_valid.eq(udp_streamer.source.valid),
port_ios.source_last.eq(udp_streamer.source.last),
udp_streamer.source.ready.eq(port_ios.source_ready),
port_ios.source_data.eq(udp_streamer.source.data)
port_ios.source_data.eq(udp_streamer.source.data),
port_ios.source_error.eq(udp_streamer.source.error),
]

# Build --------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 6cf7759

Please sign in to comment.