Skip to content

Commit

Permalink
frontend/stream: Add with_csr parameter to LiteEthUDP2StreamRX, simil…
Browse files Browse the repository at this point in the history
…ar to LiteEthStream2UDPTX.
  • Loading branch information
enjoy-digital committed Jan 2, 2025
1 parent 3897ed0 commit 2d5b333
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions liteeth/frontend/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,30 @@ def add_csr(self):
# UDP to Stream RX ---------------------------------------------------------------------------------

class LiteEthUDP2StreamRX(LiteXModule):
def __init__(self, ip_address=None, udp_port=None, data_width=8, fifo_depth=None, with_broadcast=True):
def __init__(self, ip_address=0, udp_port=0, data_width=8, fifo_depth=None, with_broadcast=True, with_csr=False):
self.sink = sink = stream.Endpoint(eth_udp_user_description(data_width))
self.source = source = stream.Endpoint(eth_tty_rx_description(data_width))

# # #

self.ip_address = Signal(32, reset=convert_ip(ip_address))
self.udp_port = Signal(16, reset=udp_port)
self.enable = Signal(reset=1)

if with_csr:
self.add_csr()

valid = Signal(reset=1)

# Disable RX when enable=0.
self.comb += If(~self.enable, valid.eq(0))

# Check UDP Port.
assert udp_port is not None
self.comb += If(sink.dst_port != udp_port, valid.eq(0))
self.comb += If(sink.dst_port != self.udp_port, valid.eq(0))

# Check IP Address (Optional).
if (ip_address is not None) and (not with_broadcast):
ip_address = convert_ip(ip_address)
self.comb += If(sink.ip_address != ip_address, valid.eq(0))
if not with_broadcast:
self.comb += If(sink.ip_address != self.ip_address, valid.eq(0))

# Data-Path / Buffering (Optional).
if fifo_depth is None:
Expand All @@ -140,6 +148,18 @@ def __init__(self, ip_address=None, udp_port=None, data_width=8, fifo_depth=None
fifo.source.connect(source)
]

def add_csr(self):
self._enable = CSRStorage(1, description="Enable Module", reset=1)
self._ip_address = CSRStorage(32, description="IP Address", reset=self.ip_address.reset.value)
self._udp_port = CSRStorage(16, description="UDP Port", reset=self.udp_port.reset.value)

self.comb += [
self.enable.eq(self._enable.storage),
self.ip_address.eq(self._ip_address.storage),
self.udp_port.eq(self._udp_port.storage),
]


# UDP Streamer -------------------------------------------------------------------------------------

class LiteEthUDPStreamer(LiteXModule):
Expand Down

0 comments on commit 2d5b333

Please sign in to comment.