targets/colorlight_5a_75b: switch to add_ethernet/add_etherbone methods.

This commit is contained in:
Florent Kermarrec 2020-03-21 21:50:05 +01:00
parent 7bba5caab0
commit a95a4eed3f
1 changed files with 23 additions and 38 deletions

View File

@ -30,8 +30,6 @@ from litex.soc.integration.soc_core import *
from litex.soc.integration.builder import * from litex.soc.integration.builder import *
from liteeth.phy.ecp5rgmii import LiteEthPHYRGMII from liteeth.phy.ecp5rgmii import LiteEthPHYRGMII
from liteeth.core import LiteEthUDPIPCore
from liteeth.frontend.etherbone import LiteEthEtherbone
# CRG ---------------------------------------------------------------------------------------------- # CRG ----------------------------------------------------------------------------------------------
@ -56,7 +54,7 @@ class _CRG(Module):
# BaseSoC ------------------------------------------------------------------------------------------ # BaseSoC ------------------------------------------------------------------------------------------
class BaseSoC(SoCCore): class BaseSoC(SoCCore):
def __init__(self, revision, **kwargs): def __init__(self, revision, with_ethernet=False, with_etherbone=False, **kwargs):
platform = colorlight_5a_75b.Platform(revision=revision) platform = colorlight_5a_75b.Platform(revision=revision)
sys_clk_freq = int(125e6) sys_clk_freq = int(125e6)
@ -66,42 +64,27 @@ class BaseSoC(SoCCore):
# CRG -------------------------------------------------------------------------------------- # CRG --------------------------------------------------------------------------------------
self.submodules.crg = _CRG(platform, sys_clk_freq) self.submodules.crg = _CRG(platform, sys_clk_freq)
# Ethernet ---------------------------------------------------------------------------------
if with_ethernet:
self.submodules.ethphy = LiteEthPHYRGMII(
clock_pads = self.platform.request("eth_clocks"),
pads = self.platform.request("eth"))
self.add_csr("ethphy")
self.add_ethernet(phy=self.ethphy)
# Etherbone --------------------------------------------------------------------------------
if with_etherbone:
self.submodules.ethphy = LiteEthPHYRGMII(
clock_pads = self.platform.request("eth_clocks"),
pads = self.platform.request("eth"))
self.add_csr("ethphy")
self.add_etherbone(phy=self.ethphy)
# Led -------------------------------------------------------------------------------------- # Led --------------------------------------------------------------------------------------
led_counter = Signal(32) led_counter = Signal(32)
self.sync += led_counter.eq(led_counter + 1) self.sync += led_counter.eq(led_counter + 1)
self.comb += platform.request("user_led_n", 0).eq(led_counter[26]) self.comb += platform.request("user_led_n", 0).eq(led_counter[26])
# EtherboneSoC -------------------------------------------------------------------------------------
class EtherboneSoC(BaseSoC):
def __init__(self, eth_phy=0, **kwargs):
BaseSoC.__init__(self, **kwargs)
# Ethernet ---------------------------------------------------------------------------------
# phy
self.submodules.ethphy = LiteEthPHYRGMII(
clock_pads = self.platform.request("eth_clocks", eth_phy),
pads = self.platform.request("eth", eth_phy),
tx_delay = 0e-9, # 0ns FPGA delay (Clk delay added by PHY)
rx_delay = 2e-9) # 2ns FPGA delay to compensate Clk routing to IDDRX1F
self.add_csr("ethphy")
# core
self.submodules.ethcore = LiteEthUDPIPCore(
phy = self.ethphy,
mac_address = 0x10e2d5000000,
ip_address = "192.168.1.50",
clk_freq = self.clk_freq)
# etherbone
self.submodules.etherbone = LiteEthEtherbone(self.ethcore.udp, 1234)
self.add_wb_master(self.etherbone.wishbone.bus)
# timing constraints
self.platform.add_period_constraint(self.ethphy.crg.cd_eth_rx.clk, 1e9/125e6)
self.platform.add_period_constraint(self.ethphy.crg.cd_eth_tx.clk, 1e9/125e6)
self.platform.add_false_path_constraints(
self.crg.cd_sys.clk,
self.ethphy.crg.cd_eth_rx.clk,
self.ethphy.crg.cd_eth_tx.clk)
# Load --------------------------------------------------------------------------------------------- # Load ---------------------------------------------------------------------------------------------
def load(): def load():
@ -129,6 +112,7 @@ def main():
soc_core_args(parser) soc_core_args(parser)
trellis_args(parser) trellis_args(parser)
parser.add_argument("--revision", default="7.0", type=str, help="Board revision 7.0 (default) or 6.1") parser.add_argument("--revision", default="7.0", type=str, help="Board revision 7.0 (default) or 6.1")
parser.add_argument("--with-ethernet", action="store_true", help="enable Ethernet support")
parser.add_argument("--with-etherbone", action="store_true", help="enable Etherbone support") parser.add_argument("--with-etherbone", action="store_true", help="enable Etherbone support")
parser.add_argument("--eth-phy", default=0, type=int, help="Ethernet PHY 0 or 1 (default=0)") parser.add_argument("--eth-phy", default=0, type=int, help="Ethernet PHY 0 or 1 (default=0)")
parser.add_argument("--load", action="store_true", help="load bitstream") parser.add_argument("--load", action="store_true", help="load bitstream")
@ -137,10 +121,11 @@ def main():
if args.load: if args.load:
load() load()
if args.with_etherbone: assert not (args.with_ethernet and args.with_etherbone)
soc = EtherboneSoC(eth_phy=args.eth_phy, revision=args.revision, **soc_core_argdict(args)) soc = BaseSoC(revision=args.revision,
else: with_ethernet = args.with_ethernet,
soc = BaseSoC(args.revision, **soc_core_argdict(args)) with_etherbone = args.with_etherbone,
**soc_core_argdict(args))
builder = Builder(soc, **builder_argdict(args)) builder = Builder(soc, **builder_argdict(args))
builder.build(**trellis_argdict(args)) builder.build(**trellis_argdict(args))