Skip to content

Commit

Permalink
core/udp: Add with_dhcp argument and remove dhcp plumbing from core…
Browse files Browse the repository at this point in the history
… generator
  • Loading branch information
rowanG077 committed Mar 4, 2024
1 parent 8be662e commit 991335e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 38 deletions.
4 changes: 2 additions & 2 deletions examples/udp_raw_ecp5rgmii.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ device: LFE5U-25F-6BG256C
vendor: lattice
toolchain: trellis
# Core -------------------------------------------------------------------------
clk_freq: 125e6
clk_freq: 50e6
core: udp

mac_address: 0x10e2d5000000
ip_address: 172.30.0.1
dhcp: True

tx_cdc_depth: 16
tx_cdc_buffered: True
Expand Down
22 changes: 16 additions & 6 deletions liteeth/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def __init__(self, phy, mac_address, ip_address, clk_freq, arp_entries=1, dw=8,
class LiteEthUDPIPCore(LiteEthIPCore):
def __init__(self, phy, mac_address, ip_address, clk_freq, arp_entries=1, dw=8,
with_icmp = True,
with_dhcp = False,
with_ip_broadcast = True,
with_sys_datapath = False,
tx_cdc_depth = 32,
Expand All @@ -90,9 +91,15 @@ def __init__(self, phy, mac_address, ip_address, clk_freq, arp_entries=1, dw=8,
interface = "crossbar",
endianness = "big",
):
# Ensure either IP is external or DHCP is used
assert((ip_address is None) == with_dhcp)

# Parameters.
# -----------
ip_address = convert_ip(ip_address)
if ip_address is not None:
ip_address = convert_ip(ip_address)
else:
ip_address = Signal(32)

# Core: MAC + ARP + IP + (ICMP).
# ------------------------------
Expand All @@ -113,10 +120,13 @@ def __init__(self, phy, mac_address, ip_address, clk_freq, arp_entries=1, dw=8,
rx_cdc_depth = rx_cdc_depth,
rx_cdc_buffered = rx_cdc_buffered,
)
# UDP.
# ----
# UDP + (DHCP).
# -------------
self.submodules.udp = LiteEthUDP(
ip = self.ip,
ip_address = ip_address,
dw = dw,
ip = self.ip,
mac_address = mac_address,
ip_address = ip_address,
clk_freq = clk_freq,
with_dhcp = with_dhcp,
dw = dw,
)
11 changes: 10 additions & 1 deletion liteeth/core/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from liteeth.common import *
from liteeth.crossbar import LiteEthCrossbar
from liteeth.packet import Depacketizer, Packetizer
from liteeth.core.dhcp import DHCP_CLIENT_PORT, LiteEthDHCP

# UDP Crossbar -------------------------------------------------------------------------------------

Expand Down Expand Up @@ -231,7 +232,7 @@ def __init__(self, ip_address, dw=8):
# UDP ----------------------------------------------------------------------------------------------

class LiteEthUDP(LiteXModule):
def __init__(self, ip, ip_address, dw=8):
def __init__(self, ip, ip_address, mac_address, clk_freq, with_dhcp = False, dw=8):
self.tx = tx = LiteEthUDPTX(ip_address, dw)
self.rx = rx = LiteEthUDPRX(ip_address, dw)
ip_port = ip.crossbar.get_port(udp_protocol, dw)
Expand All @@ -244,3 +245,11 @@ def __init__(self, ip, ip_address, dw=8):
crossbar.master.source.connect(tx.sink),
rx.source.connect(crossbar.master.sink)
]

if with_dhcp:
dhcp_udp_port = self.crossbar.get_port(DHCP_CLIENT_PORT, dw=32, cd="sys")
self.dhcp = dhcp = LiteEthDHCP(dhcp_udp_port, clk_freq)
self.comb += [
dhcp.mac_address.eq(mac_address),
ip_address.eq(dhcp.ip_address),
]
32 changes: 3 additions & 29 deletions liteeth/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@
# Interrupt
("interrupt", 0, Pins(1)),

# DHCP.
("dhcp", 0,
Subsignal("start", Pins(1)),
Subsignal("done", Pins(1)),
Subsignal("timeout", Pins(1)),
Subsignal("ip_address", Pins(32)),
),

# MII PHY Pads
("mii_clocks", 0,
Subsignal("tx", Pins(1)),
Expand Down Expand Up @@ -520,11 +512,9 @@ def __init__(self, platform, core_config):
# IP Address.
dhcp = core_config.get("dhcp", False)
ip_address = core_config.get("ip_address", None)
# Get IP Address from IOs when not specified.
if ip_address is None:
# Get IP Address from IOs when not specified and DHCP is not used
if ip_address is None and not dhcp:
ip_address = platform.request("ip_address")
else:
assert not dhcp

# PHY --------------------------------------------------------------------------------------
PHYCore.__init__(self, platform, core_config)
Expand All @@ -534,6 +524,7 @@ def __init__(self, platform, core_config):
self.core = LiteEthUDPIPCore(self.ethphy,
mac_address = mac_address,
ip_address = ip_address,
with_dhcp = dhcp,
clk_freq = core_config["clk_freq"],
dw = data_width,
with_sys_datapath = (data_width == 32),
Expand All @@ -543,23 +534,6 @@ def __init__(self, platform, core_config):
rx_cdc_buffered = rx_cdc_buffered,
)

# DHCP -------------------------------------------------------------------------------------

if dhcp:
dhcp_pads = platform.request("dhcp")
dhcp_port = self.core.udp.crossbar.get_port(68, dw=32, cd="sys")
if isinstance(mac_address, Signal):
dhcp_mac_address = mac_address
else:
dhcp_mac_address = Signal(48, reset=0x10e2d5000001)
self.dhcp = LiteEthDHCP(udp_port=dhcp_port, sys_clk_freq=self.sys_clk_freq)
self.comb += [
self.dhcp.start.eq(dhcp_pads.start),
dhcp_pads.done.eq(self.dhcp.done),
dhcp_pads.timeout.eq(self.dhcp.timeout),
dhcp_pads.ip_address.eq(self.dhcp.ip_address),
]

# Etherbone --------------------------------------------------------------------------------

etherbone = core_config.get("etherbone", False)
Expand Down

0 comments on commit 991335e

Please sign in to comment.