diff --git a/examples/udp_usp_gth_sgmii.yml b/examples/udp_usp_gth_sgmii.yml index 4dbb403..8c02281 100644 --- a/examples/udp_usp_gth_sgmii.yml +++ b/examples/udp_usp_gth_sgmii.yml @@ -14,6 +14,7 @@ refclk_freq : 156.25e6 clk_freq : 25e6 core : udp data_width : 32 +dhcp : True # UDP Ports -------------------------------------------------------------------- udp_ports: { diff --git a/liteeth/gen.py b/liteeth/gen.py index 84668c8..bcd9aad 100755 --- a/liteeth/gen.py +++ b/liteeth/gen.py @@ -46,6 +46,7 @@ from liteeth.common import * from liteeth import phy as liteeth_phys from liteeth.mac import LiteEthMAC from liteeth.core import LiteEthUDPIPCore +from liteeth.core.dhcp import LiteEthDHCP from liteeth.frontend.etherbone import LiteEthEtherbone @@ -63,6 +64,14 @@ _io = [ # 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)), @@ -327,10 +336,13 @@ class UDPCore(PHYCore): mac_address = platform.request("mac_address") # 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: ip_address = platform.request("ip_address") + else: + assert not dhcp # PHY -------------------------------------------------------------------------------------- PHYCore.__init__(self, platform, core_config) @@ -345,6 +357,23 @@ class UDPCore(PHYCore): with_sys_datapath = (data_width == 32), ) + # 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.submodules.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)