Skip to content

Commit

Permalink
Merge pull request #127 from rowanG077/master
Browse files Browse the repository at this point in the history
Add core CDC depth and buffered parameters.
  • Loading branch information
enjoy-digital committed Jul 3, 2023
2 parents 6bdc13b + 815c742 commit 322d862
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 21 deletions.
21 changes: 19 additions & 2 deletions liteeth/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# This file is part of LiteEth.
#
# Copyright (c) 2015-2020 Florent Kermarrec <florent@enjoy-digital.fr>
# Copyright (c) 2023 LumiGuide Fietsdetectie B.V. <goemansrowan@gmail.com>
# SPDX-License-Identifier: BSD-2-Clause

from liteeth.common import *
Expand All @@ -17,7 +18,11 @@ class LiteEthIPCore(Module, AutoCSR):
def __init__(self, phy, mac_address, ip_address, clk_freq, dw=8,
with_icmp = True,
with_ip_broadcast = True,
with_sys_datapath = False):
with_sys_datapath = False,
tx_cdc_depth = 32,
tx_cdc_buffered = False,
rx_cdc_depth = 32,
rx_cdc_buffered = False):
# Parameters.
# -----------
ip_address = convert_ip(ip_address)
Expand All @@ -30,6 +35,10 @@ def __init__(self, phy, mac_address, ip_address, clk_freq, dw=8,
interface = "crossbar",
with_preamble_crc = True,
with_sys_datapath = with_sys_datapath,
tx_cdc_depth = tx_cdc_depth,
tx_cdc_buffered = tx_cdc_buffered,
rx_cdc_depth = rx_cdc_depth,
rx_cdc_buffered = rx_cdc_buffered
)

# ARP.
Expand Down Expand Up @@ -67,7 +76,11 @@ class LiteEthUDPIPCore(LiteEthIPCore):
def __init__(self, phy, mac_address, ip_address, clk_freq, dw=8,
with_icmp = True,
with_ip_broadcast = True,
with_sys_datapath = False):
with_sys_datapath = False,
tx_cdc_depth = 32,
tx_cdc_buffered = False,
rx_cdc_depth = 32,
rx_cdc_buffered = False):
# Parameters.
# -----------
ip_address = convert_ip(ip_address)
Expand All @@ -83,6 +96,10 @@ def __init__(self, phy, mac_address, ip_address, clk_freq, dw=8,
dw = dw,
with_ip_broadcast = with_ip_broadcast,
with_sys_datapath = with_sys_datapath,
tx_cdc_depth = tx_cdc_depth,
tx_cdc_buffered = tx_cdc_buffered,
rx_cdc_depth = rx_cdc_depth,
rx_cdc_buffered = rx_cdc_buffered
)
# UDP.
# ----
Expand Down
39 changes: 29 additions & 10 deletions liteeth/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Copyright (c) 2020 Xiretza <xiretza@xiretza.xyz>
# Copyright (c) 2020 Stefan Schrijvers <ximin@ximinity.net>
# Copyright (c) 2022 Victor Suarez Rovere <suarezvictor@gmail.com>
# Copyright (c) 2023 LumiGuide Fietsdetectie B.V. <goemansrowan@gmail.com>
# SPDX-License-Identifier: BSD-2-Clause

"""
Expand Down Expand Up @@ -281,23 +282,32 @@ def __init__(self, platform, core_config):
class MACCore(PHYCore):
def __init__(self, platform, core_config):
# Parameters -------------------------------------------------------------------------------
nrxslots = core_config.get("nrxslots", 2)
ntxslots = core_config.get("ntxslots", 2)
bus_standard = core_config["core"]
nrxslots = core_config.get("nrxslots", 2)
ntxslots = core_config.get("ntxslots", 2)
bus_standard = core_config["core"]
tx_cdc_depth = core_config.get("tx_cdc_depth", 32)
tx_cdc_buffered = core_config.get("tx_cdc_buffered", False)
rx_cdc_depth = core_config.get("rx_cdc_depth", 32)
rx_cdc_buffered = core_config.get("rx_cdc_buffered", False)
assert bus_standard in ["wishbone", "axi-lite"]

# PHY --------------------------------------------------------------------------------------
PHYCore.__init__(self, platform, core_config)

# MAC --------------------------------------------------------------------------------------
self.submodules.ethmac = ethmac = LiteEthMAC(
phy = self.ethphy,
dw = 32,
interface = "wishbone",
endianness = core_config["endianness"],
nrxslots = nrxslots,
ntxslots = ntxslots,
full_memory_we = core_config.get("full_memory_we", False))
phy = self.ethphy,
dw = 32,
interface = "wishbone",
endianness = core_config["endianness"],
nrxslots = nrxslots,
ntxslots = ntxslots,
full_memory_we = core_config.get("full_memory_we", False),
tx_cdc_depth = tx_cdc_depth
tx_cdc_buffered = tx_cdc_buffered
rx_cdc_depth = rx_cdc_depth
rx_cdc_buffered = rx_cdc_buffered
)

if bus_standard == "wishbone":
# Wishbone Interface -----------------------------------------------------------------------
Expand Down Expand Up @@ -328,6 +338,10 @@ def __init__(self, platform, core_config):
from liteeth.frontend.stream import LiteEthUDPStreamer

# Config -----------------------------------------------------------------------------------
tx_cdc_depth = core_config.get("tx_cdc_depth", 32)
tx_cdc_buffered = core_config.get("tx_cdc_buffered", False)
rx_cdc_depth = core_config.get("rx_cdc_depth", 32)
rx_cdc_buffered = core_config.get("rx_cdc_buffered", False)

# MAC Address.
mac_address = core_config.get("mac_address", None)
Expand Down Expand Up @@ -355,6 +369,11 @@ def __init__(self, platform, core_config):
clk_freq = core_config["clk_freq"],
dw = data_width,
with_sys_datapath = (data_width == 32),
tx_cdc_depth = tx_cdc_depth
tx_cdc_buffered = tx_cdc_buffered
rx_cdc_depth = rx_cdc_depth
rx_cdc_buffered = rx_cdc_buffered

)

# DHCP -------------------------------------------------------------------------------------
Expand Down
13 changes: 11 additions & 2 deletions liteeth/mac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# This file is part of LiteEth.
#
# Copyright (c) 2015-2020 Florent Kermarrec <florent@enjoy-digital.fr>
# Copyright (c) 2023 LumiGuide Fietsdetectie B.V. <goemansrowan@gmail.com>
# SPDX-License-Identifier: BSD-2-Clause

from liteeth.common import *
Expand All @@ -21,7 +22,11 @@ def __init__(self, phy, dw,
hw_mac = None,
timestamp = None,
full_memory_we = False,
with_sys_datapath = False):
with_sys_datapath = False,
tx_cdc_depth = 32,
tx_cdc_buffered = False,
rx_cdc_depth = 32,
rx_cdc_buffered = False):

assert dw%8 == 0
assert interface in ["crossbar", "wishbone", "hybrid"]
Expand All @@ -31,7 +36,11 @@ def __init__(self, phy, dw,
phy = phy,
dw = dw,
with_sys_datapath = with_sys_datapath,
with_preamble_crc = with_preamble_crc
with_preamble_crc = with_preamble_crc,
tx_cdc_depth = tx_cdc_depth,
tx_cdc_buffered = tx_cdc_buffered,
rx_cdc_depth = rx_cdc_depth,
rx_cdc_buffered = rx_cdc_buffered
)
self.csrs = []
if interface == "crossbar":
Expand Down
16 changes: 13 additions & 3 deletions liteeth/mac/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Copyright (c) 2015-2017 Sebastien Bourdeauducq <sb@m-labs.hk>
# Copyright (c) 2021 David Sawatzke <d-git@sawatzke.dev>
# Copyright (c) 2017-2018 whitequark <whitequark@whitequark.org>
# Copyright (c) 2023 LumiGuide Fietsdetectie B.V. <goemansrowan@gmail.com>
# SPDX-License-Identifier: BSD-2-Clause

from liteeth.common import *
Expand All @@ -21,7 +22,12 @@ class LiteEthMACCore(Module, AutoCSR):
def __init__(self, phy, dw,
with_sys_datapath = False,
with_preamble_crc = True,
with_padding = True):
with_padding = True,
tx_cdc_depth = 32,
tx_cdc_buffered = False,
rx_cdc_depth = 32,
rx_cdc_buffered = False,
):

# Endpoints.
self.sink = stream.Endpoint(eth_phy_description(dw))
Expand Down Expand Up @@ -57,7 +63,9 @@ def add_cdc(self):
tx_cdc = stream.ClockDomainCrossing(eth_phy_description(core_dw),
cd_from = "sys",
cd_to = "eth_tx",
depth = 32)
depth = tx_cdc_depth,
buffered = tx_cdc_buffered
)
self.submodules += tx_cdc
self.pipeline.append(tx_cdc)

Expand Down Expand Up @@ -186,7 +194,9 @@ def add_cdc(self):
rx_cdc = stream.ClockDomainCrossing(eth_phy_description(core_dw),
cd_from = "eth_rx",
cd_to = "sys",
depth = 32)
depth = rx_cdc_depth,
buffered = rx_cdc_buffered
)
self.submodules += rx_cdc
self.pipeline.append(rx_cdc)

Expand Down
17 changes: 13 additions & 4 deletions liteeth/phy/ecp5rgmii.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def __init__(self, pads, rx_delay=2e-9, with_inband_status=True):
# LiteEth PHY RGMII CRG ----------------------------------------------------------------------------

class LiteEthPHYRGMIICRG(LiteXModule):
def __init__(self, clock_pads, pads, with_hw_init_reset, tx_delay=2e-9):
def __init__(self, clock_pads, pads, with_hw_init_reset, tx_delay=2e-9, with_phy_tx_clock = None):
self._reset = CSRStorage()

# # #
Expand All @@ -159,7 +159,14 @@ def __init__(self, clock_pads, pads, with_hw_init_reset, tx_delay=2e-9):

# TX Clock
self.cd_eth_tx = ClockDomain()
self.comb += self.cd_eth_tx.clk.eq(self.cd_eth_rx.clk)

if isinstance(with_phy_tx_clock, Signal):
phy_tx_clock = with_phy_tx_clock
else:
phy_tx_clock = self.cd_eth_rx.clk

self.comb += self.cd_eth_tx.clk.eq(phy_tx_clock)

tx_delay_taps = int(tx_delay/25e-12) # 25ps per tap
assert tx_delay_taps < 128

Expand Down Expand Up @@ -201,8 +208,10 @@ class LiteEthPHYRGMII(LiteXModule):
def __init__(self, clock_pads, pads, with_hw_init_reset=True,
tx_delay = 2e-9,
rx_delay = 2e-9,
with_inband_status = True):
self.crg = LiteEthPHYRGMIICRG(clock_pads, pads, with_hw_init_reset, tx_delay)
with_inband_status = True,
with_phy_tx_clock = None
):
self.crg = LiteEthPHYRGMIICRG(clock_pads, pads, with_hw_init_reset, tx_delay, with_phy_tx_clock)
self.tx = ClockDomainsRenamer("eth_tx")(LiteEthPHYRGMIITX(pads))
self.rx = ClockDomainsRenamer("eth_rx")(LiteEthPHYRGMIIRX(pads, rx_delay, with_inband_status))
self.sink, self.source = self.tx.sink, self.rx.source
Expand Down

0 comments on commit 322d862

Please sign in to comment.