liteeth/examples/targets/base.py

117 lines
4.3 KiB
Python
Raw Normal View History

2019-11-23 13:49:23 -05:00
# This file is Copyright (c) 2015-2019 Florent Kermarrec <florent@enjoy-digital.fr>
# License: BSD
from migen.genlib.io import CRG
2015-09-07 07:28:02 -04:00
2015-11-11 19:45:37 -05:00
from litex.build.xilinx.vivado import XilinxVivadoToolchain
from litex.soc.interconnect import wishbone
from litex.soc.integration.soc_core import SoCCore
2017-04-19 04:39:52 -04:00
from litex.soc.cores.uart import UARTWishboneBridge
2015-09-07 07:28:02 -04:00
2015-09-08 03:50:45 -04:00
from liteeth.common import *
from liteeth.phy import LiteEthPHY
from liteeth.core import LiteEthUDPIPCore
2015-09-07 07:28:02 -04:00
2019-11-23 13:49:23 -05:00
# BaseSoC ------------------------------------------------------------------------------------------
2015-09-07 07:28:02 -04:00
2015-11-11 19:45:37 -05:00
class BaseSoC(SoCCore):
2019-11-23 13:49:23 -05:00
def __init__(self, platform, clk_freq=int(166e6),
mac_address = 0x10e2d5000000,
ip_address = "192.168.1.50"):
sys_clk_freq = int((1/(platform.default_clk_period))*1e9)
2015-11-11 19:45:37 -05:00
SoCCore.__init__(self, platform, clk_freq,
2019-11-23 13:49:23 -05:00
cpu_type = None,
csr_data_width = 32,
with_uart = False,
ident = "LiteEth Base Design",
with_timer = False
2015-09-07 07:28:02 -04:00
)
2019-11-23 13:49:23 -05:00
# Serial Wishbone Bridge
serial_bridge = UARTWishboneBridge(platform.request("serial"), sys_clk_freq, baudrate=115200)
self.submodules += serial_bridge
self.add_wb_master(serial_bridge.wishbone)
2015-09-07 07:28:02 -04:00
self.submodules.crg = CRG(platform.request(platform.default_clk_name))
2019-11-23 13:49:23 -05:00
# Ethernet PHY and UDP/IP stack
self.submodules.ethphy = ethphy = LiteEthPHY(
clock_pads = platform.request("eth_clocks"),
pads = platform.request("eth"),
clk_freq = clk_freq)
self.add_csr("ethphy")
self.submodules.ethcore = ethcore = LiteEthUDPIPCore(
phy = ethphy,
mac_address = mac_address,
ip_address = ip_address,
clk_freq = clk_freq)
self.add_csr("ethcore")
2015-09-07 07:28:02 -04:00
if isinstance(platform.toolchain, XilinxVivadoToolchain):
2017-03-30 08:46:54 -04:00
self.crg.cd_sys.clk.attr.add("keep")
2019-11-23 13:49:23 -05:00
ethphy.crg.cd_eth_rx.clk.attr.add("keep")
ethphy.crg.cd_eth_tx.clk.attr.add("keep")
platform.add_period_constraint(self.ethphy.crg.cd_eth_rx.clk, 1e9/125e6)
platform.add_period_constraint(self.ethphy.crg.cd_eth_tx.clk, 1e9/125e6)
platform.add_false_path_constraints(
self.crg.cd_sys.clk,
ethphy.crg.cd_eth_rx.clk,
ethphy.crg.cd_eth_tx.clk)
2015-09-07 07:28:02 -04:00
2019-11-23 13:49:23 -05:00
# BaseSoCDevel -------------------------------------------------------------------------------------
2015-09-07 07:28:02 -04:00
class BaseSoCDevel(BaseSoC):
def __init__(self, platform):
2016-03-31 15:27:08 -04:00
from litescope import LiteScopeAnalyzer
2015-09-07 07:28:02 -04:00
BaseSoC.__init__(self, platform)
2019-11-23 13:49:23 -05:00
analyzer_signals = [
2015-09-07 07:28:02 -04:00
# MAC interface
2019-11-23 13:49:23 -05:00
self.ethcore.mac.core.sink.valid,
self.ethcore.mac.core.sink.last,
self.ethcore.mac.core.sink.ready,
self.ethcore.mac.core.sink.data,
2015-09-07 07:28:02 -04:00
2019-11-23 13:49:23 -05:00
self.ethcore.mac.core.source.valid,
self.ethcore.mac.core.source.last,
self.ethcore.mac.core.source.ready,
self.ethcore.mac.core.source.data,
2015-09-07 07:28:02 -04:00
# ICMP interface
2019-11-23 13:49:23 -05:00
self.ethcore.icmp.echo.sink.valid,
self.ethcore.icmp.echo.sink.last,
self.ethcore.icmp.echo.sink.ready,
self.ethcore.icmp.echo.sink.data,
2015-09-07 07:28:02 -04:00
2019-11-23 13:49:23 -05:00
self.ethcore.icmp.echo.source.valid,
self.ethcore.icmp.echo.source.last,
self.ethcore.icmp.echo.source.ready,
self.ethcore.icmp.echo.source.data,
2015-09-07 07:28:02 -04:00
# IP interface
2019-11-23 13:49:23 -05:00
self.ethcore.ip.crossbar.master.sink.valid,
self.ethcore.ip.crossbar.master.sink.last,
self.ethcore.ip.crossbar.master.sink.ready,
self.ethcore.ip.crossbar.master.sink.data,
self.ethcore.ip.crossbar.master.sink.ip_address,
self.ethcore.ip.crossbar.master.sink.protocol,
2015-09-07 07:28:02 -04:00
# State machines
2019-11-23 13:49:23 -05:00
self.ethcore.icmp.rx.fsm,
self.ethcore.icmp.tx.fsm,
2015-09-07 07:28:02 -04:00
2019-11-23 13:49:23 -05:00
self.ethcore.arp.rx.fsm,
self.ethcore.arp.tx.fsm,
self.ethcore.arp.table.fsm,
2015-09-07 07:28:02 -04:00
2019-11-23 13:49:23 -05:00
self.ethcore.ip.rx.fsm,
self.ethcore.ip.tx.fsm,
2015-09-07 07:28:02 -04:00
2019-11-23 13:49:23 -05:00
self.ethcore.udp.rx.fsm,
self.ethcore.udp.tx.fsm
2016-03-31 15:27:08 -04:00
]
2019-11-23 13:49:23 -05:00
self.submodules.analyzer = LiteScopeAnalyzer(analyzer_signals, 4096, csr_csv="test/analyzer.csv")
2019-11-23 09:47:42 -05:00
self.add_csr("analyzer")
2015-09-07 07:28:02 -04:00
default_subtarget = BaseSoC