From c44e94da5d5cf593d188f638fab37c804f55c642 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Thu, 14 Jul 2022 16:04:40 +0200 Subject: [PATCH] Add patched liteeth.core module to allow hybrid mode https://github.com/enjoy-digital/liteeth/pull/116 --- gen_liteeth.py | 2 +- liteeth_cores.py | 96 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 liteeth_cores.py diff --git a/gen_liteeth.py b/gen_liteeth.py index 45d514f..620d6f5 100755 --- a/gen_liteeth.py +++ b/gen_liteeth.py @@ -27,7 +27,7 @@ from liteeth.common import * from liteeth import phy as liteeth_phys from liteeth.mac import LiteEthMAC -from liteeth.core import LiteEthUDPIPCore +from liteeth_cores import LiteEthUDPIPCore from liteeth.core.udp import LiteEthUDP # IOs ---------------------------------------------------------------------------------------------- diff --git a/liteeth_cores.py b/liteeth_cores.py new file mode 100644 index 0000000..856fd4d --- /dev/null +++ b/liteeth_cores.py @@ -0,0 +1,96 @@ +# +# This file is part of LiteEth. +# +# Copyright (c) 2015-2020 Florent Kermarrec +# SPDX-License-Identifier: BSD-2-Clause + +from liteeth.common import * +from liteeth.mac import LiteEthMAC +from liteeth.core.arp import LiteEthARP +from liteeth.core.ip import LiteEthIP +from liteeth.core.udp import LiteEthUDP +from liteeth.core.icmp import LiteEthICMP + +# IP Core ------------------------------------------------------------------------------------------ + +class LiteEthIPCore(Module, AutoCSR): + def __init__(self, phy, mac_address, ip_address, clk_freq, dw=8, + hybrid = False, + with_icmp = True, + with_ip_broadcast = True, + with_sys_datapath = False): + # Parameters. + # ----------- + ip_address = convert_ip(ip_address) + + # MAC. + # ---- + self.submodules.mac = LiteEthMAC( + phy = phy, + dw = dw, + interface = "hybrid" if hybrid else "crossbar", + with_preamble_crc = True, + with_sys_datapath = with_sys_datapath, + ) + + # ARP. + # ---- + self.submodules.arp = LiteEthARP( + mac = self.mac, + mac_address = mac_address, + ip_address = ip_address, + clk_freq = clk_freq, + dw = dw, + ) + + # IP. + # --- + self.submodules.ip = LiteEthIP( + mac = self.mac, + mac_address = mac_address, + ip_address = ip_address, + arp_table = self.arp.table, + with_broadcast = with_ip_broadcast, + dw = dw, + ) + # ICMP (Optional). + # ---------------- + if with_icmp: + self.submodules.icmp = LiteEthICMP( + ip = self.ip, + ip_address = ip_address, + dw = dw, + ) + +# UDP IP Core -------------------------------------------------------------------------------------- + +class LiteEthUDPIPCore(LiteEthIPCore): + def __init__(self, phy, mac_address, ip_address, clk_freq, dw=8, + hybrid=False, + with_icmp = True, + with_ip_broadcast = True, + with_sys_datapath = False): + # Parameters. + # ----------- + ip_address = convert_ip(ip_address) + + # Core: MAC + ARP + IP + (ICMP). + # ------------------------------ + LiteEthIPCore.__init__(self, + phy = phy, + mac_address = mac_address, + ip_address = ip_address, + clk_freq = clk_freq, + hybrid = hybrid, + with_icmp = with_icmp, + dw = dw, + with_ip_broadcast = with_ip_broadcast, + with_sys_datapath = with_sys_datapath, + ) + # UDP. + # ---- + self.submodules.udp = LiteEthUDP( + ip = self.ip, + ip_address = ip_address, + dw = dw, + )