2021-07-02 07:00:43 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
#
|
|
|
|
# This file is part of LiteEth.
|
|
|
|
#
|
2023-06-13 08:13:03 -04:00
|
|
|
# Copyright (c) 2021-2023 Florent Kermarrec <florent@enjoy-digital.fr>
|
2021-07-02 07:00:43 -04:00
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
|
|
import os
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
from migen.genlib.resetsync import AsyncResetSynchronizer
|
|
|
|
|
2023-06-13 08:13:03 -04:00
|
|
|
from litex.gen import *
|
|
|
|
|
2021-07-02 07:00:43 -04:00
|
|
|
from litex.build.generic_platform import *
|
2022-05-02 07:09:28 -04:00
|
|
|
from litex_boards.platforms import sqrl_xcu1525
|
2021-07-02 07:00:43 -04:00
|
|
|
|
|
|
|
from litex.soc.cores.clock import *
|
|
|
|
from litex.soc.interconnect.csr import *
|
|
|
|
from litex.soc.integration.soc_core import *
|
|
|
|
from litex.soc.integration.builder import *
|
|
|
|
|
|
|
|
from liteeth.phy.usp_1000basex import USP_1000BASEX
|
|
|
|
|
|
|
|
# IOs ----------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
_qsfp_io = [
|
|
|
|
# QSFP0
|
|
|
|
("qsfp_fs", 0, Pins("AT20 AU22"), IOStandard("LVCMOS12")),
|
|
|
|
("qsfp", 0,
|
|
|
|
Subsignal("txp", Pins("N9")),
|
|
|
|
Subsignal("txn", Pins("N8")),
|
|
|
|
Subsignal("rxp", Pins("N4")),
|
|
|
|
Subsignal("rxn", Pins("N3"))
|
|
|
|
),
|
|
|
|
]
|
|
|
|
|
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
|
|
|
|
2023-06-13 08:13:03 -04:00
|
|
|
class _CRG(LiteXModule):
|
2021-07-02 07:00:43 -04:00
|
|
|
def __init__(self, platform, sys_clk_freq):
|
2023-06-13 08:13:03 -04:00
|
|
|
self.cd_sys = ClockDomain()
|
|
|
|
self.cd_eth = ClockDomain()
|
2021-07-02 07:00:43 -04:00
|
|
|
|
|
|
|
# # #
|
|
|
|
|
|
|
|
# Main PLL.
|
2023-06-13 08:13:03 -04:00
|
|
|
self.main_pll = main_pll = USPMMCM(speedgrade=-2)
|
2021-07-02 07:00:43 -04:00
|
|
|
main_pll.register_clkin(platform.request("clk300"), 300e6)
|
|
|
|
main_pll.create_clkout(self.cd_sys, sys_clk_freq)
|
|
|
|
main_pll.create_clkout(self.cd_eth, 200e6)
|
|
|
|
|
|
|
|
# Bench SoC ----------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class BenchSoC(SoCCore):
|
|
|
|
def __init__(self, sys_clk_freq=int(125e6)):
|
2022-05-02 07:09:28 -04:00
|
|
|
platform = sqrl_xcu1525.Platform()
|
2021-07-02 07:00:43 -04:00
|
|
|
platform.add_extension(_qsfp_io)
|
|
|
|
|
|
|
|
# SoCMini ----------------------------------------------------------------------------------
|
|
|
|
SoCMini.__init__(self, platform, clk_freq=sys_clk_freq,
|
|
|
|
ident = "LiteEth bench on XCU1525",
|
|
|
|
ident_version = True
|
|
|
|
)
|
|
|
|
|
2023-06-08 11:56:37 -04:00
|
|
|
# UARTBone ---------------------------------------------------------------------------------
|
|
|
|
self.add_uartbone()
|
|
|
|
|
2021-07-02 07:00:43 -04:00
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2023-06-13 08:13:03 -04:00
|
|
|
self.crg = _CRG(platform, sys_clk_freq)
|
2021-07-02 07:00:43 -04:00
|
|
|
|
|
|
|
# Etherbone --------------------------------------------------------------------------------
|
2023-06-13 08:13:03 -04:00
|
|
|
self.ethphy = USP_1000BASEX(self.crg.cd_eth.clk,
|
2021-07-02 07:00:43 -04:00
|
|
|
data_pads = self.platform.request("qsfp", 0),
|
|
|
|
sys_clk_freq = self.clk_freq)
|
2023-06-12 10:28:17 -04:00
|
|
|
self.comb += self.platform.request("qsfp_fs").eq(0b01)
|
2021-07-02 07:00:43 -04:00
|
|
|
self.add_etherbone(phy=self.ethphy, buffer_depth=255)
|
|
|
|
|
|
|
|
# SRAM -------------------------------------------------------------------------------------
|
|
|
|
self.add_ram("sram", 0x20000000, 0x1000)
|
|
|
|
|
|
|
|
# Leds -------------------------------------------------------------------------------------
|
|
|
|
from litex.soc.cores.led import LedChaser
|
2023-06-13 08:13:03 -04:00
|
|
|
self.leds = LedChaser(
|
2021-07-02 07:00:43 -04:00
|
|
|
pads = platform.request_all("user_led"),
|
2023-06-08 11:56:37 -04:00
|
|
|
sys_clk_freq = sys_clk_freq
|
|
|
|
)
|
|
|
|
|
|
|
|
# Litescope --------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
from litescope import LiteScopeAnalyzer
|
|
|
|
analyzer_signals = self.ethphy.debug
|
2023-06-13 08:13:03 -04:00
|
|
|
self.analyzer = LiteScopeAnalyzer(analyzer_signals,
|
2023-06-08 11:56:37 -04:00
|
|
|
depth = 256,
|
|
|
|
clock_domain = "sys",
|
|
|
|
csr_csv = "analyzer.csv"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-07-02 07:00:43 -04:00
|
|
|
|
|
|
|
# Main ---------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description="LiteEth Bench on XCU1525")
|
|
|
|
parser.add_argument("--build", action="store_true", help="Build bitstream")
|
|
|
|
parser.add_argument("--load", action="store_true", help="Load bitstream")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
soc = BenchSoC()
|
|
|
|
builder = Builder(soc, csr_csv="csr.csv")
|
|
|
|
builder.build(run=args.build)
|
|
|
|
|
|
|
|
if args.load:
|
|
|
|
prog = soc.platform.create_programmer()
|
|
|
|
prog.load_bitstream(os.path.join(builder.gateware_dir, soc.build_name + ".bit"))
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|