mirror of
https://github.com/enjoy-digital/usb3_pipe.git
synced 2025-01-04 10:18:41 +08:00
143 lines
5.1 KiB
Python
Executable File
143 lines
5.1 KiB
Python
Executable File
# This file is Copyright (c) 2019 Florent Kermarrec <florent@enjoy-digital.fr>
|
|
# License: BSD
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
from migen import *
|
|
|
|
from litex.build.generic_platform import *
|
|
from litex.build.xilinx import XilinxPlatform
|
|
|
|
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 litex.soc.cores.uart import UARTWishboneBridge
|
|
|
|
|
|
from litescope import LiteScopeAnalyzer
|
|
|
|
from usb3_pipe.serdes import A7USB3SerDes
|
|
from usb3_pipe.lfps import LFPSUnit
|
|
from usb3_pipe.ordered_set import OrderedSetUnit
|
|
from usb3_pipe.ltssm import LTSSM
|
|
|
|
# IOs ----------------------------------------------------------------------------------------------
|
|
|
|
_io = [
|
|
("clk100", 0, Pins("R4"), IOStandard("LVCMOS33")),
|
|
|
|
("user_led", 0, Pins("AB1"), IOStandard("LVCMOS33")),
|
|
("user_led", 1, Pins("AB8"), IOStandard("LVCMOS33")),
|
|
|
|
("user_btn", 0, Pins("AA1"), IOStandard("LVCMOS33")),
|
|
("user_btn", 1, Pins("AB6"), IOStandard("LVCMOS33")),
|
|
|
|
("serial", 0,
|
|
Subsignal("tx", Pins("T1")),
|
|
Subsignal("rx", Pins("U1")),
|
|
IOStandard("LVCMOS33"),
|
|
),
|
|
|
|
("pcie_tx", 0,
|
|
Subsignal("p", Pins("B6")),
|
|
Subsignal("n", Pins("A6")),
|
|
),
|
|
|
|
("pcie_rx", 0,
|
|
Subsignal("p", Pins("B10")),
|
|
Subsignal("n", Pins("A10")),
|
|
),
|
|
]
|
|
|
|
# Platform -----------------------------------------------------------------------------------------
|
|
|
|
class Platform(XilinxPlatform):
|
|
def __init__(self):
|
|
XilinxPlatform.__init__(self, "xc7a35t-fgg484-2", _io, toolchain="vivado")
|
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
|
|
|
class _CRG(Module):
|
|
def __init__(self, platform, sys_clk_freq):
|
|
self.clock_domains.cd_sys = ClockDomain()
|
|
self.clock_domains.cd_oob = ClockDomain()
|
|
self.clock_domains.cd_clk125 = ClockDomain()
|
|
|
|
# # #
|
|
|
|
clk100 = platform.request("clk100")
|
|
platform.add_period_constraint(clk100, 1e9/100e6)
|
|
|
|
self.cd_sys.clk.attr.add("keep")
|
|
self.cd_clk125.clk.attr.add("keep")
|
|
|
|
self.submodules.pll = pll = S7PLL(speedgrade=-2)
|
|
pll.register_clkin(clk100, 100e6)
|
|
pll.create_clkout(self.cd_sys, sys_clk_freq)
|
|
pll.create_clkout(self.cd_oob, sys_clk_freq/8)
|
|
pll.create_clkout(self.cd_clk125, 125e6)
|
|
|
|
# USB3SoC ------------------------------------------------------------------------------------------
|
|
|
|
class USB3SoC(SoCMini):
|
|
def __init__(self, platform,
|
|
with_analyzer=False):
|
|
|
|
sys_clk_freq = int(100e6)
|
|
SoCMini.__init__(self, platform, sys_clk_freq, ident="USB3SoC", ident_version=True)
|
|
|
|
# CRG --------------------------------------------------------------------------------------
|
|
self.submodules.crg = _CRG(platform, sys_clk_freq)
|
|
|
|
# Serial bridge ----------------------------------------------------------------------------
|
|
self.submodules.serial_bridge = UARTWishboneBridge(platform.request("serial"), sys_clk_freq)
|
|
self.add_wb_master(self.serial_bridge.wishbone)
|
|
|
|
# SerDes -----------------------------------------------------------------------------------
|
|
serdes = A7USB3SerDes(platform,
|
|
sys_clk = self.crg.cd_sys.clk,
|
|
sys_clk_freq = sys_clk_freq,
|
|
refclk_pads = ClockSignal("clk125"),
|
|
refclk_freq = 125e6,
|
|
tx_pads = platform.request("pcie_tx"),
|
|
rx_pads = platform.request("pcie_rx"))
|
|
self.submodules += serdes
|
|
|
|
# LFPS Unit --------------------------------------------------------------------------------
|
|
lfps_unit = LFPSUnit(sys_clk_freq=sys_clk_freq, serdes=serdes)
|
|
self.submodules += lfps_unit
|
|
|
|
# OrderedSet Unit --------------------------------------------------------------------------
|
|
ordered_set_unit = OrderedSetUnit(serdes=serdes)
|
|
self.submodules += ordered_set_unit
|
|
|
|
# LTSSM ------------------------------------------------------------------------------------
|
|
ltssm = LTSSM(lfps_unit=lfps_unit, ordered_set_unit=ordered_set_unit)
|
|
self.submodules += ltssm
|
|
|
|
# Leds -------------------------------------------------------------------------------------
|
|
self.comb += platform.request("user_led", 0).eq(serdes.ready)
|
|
self.comb += platform.request("user_led", 1).eq(ltssm.polling_fsm.idle)
|
|
|
|
# Analyzer ---------------------------------------------------------------------------------
|
|
if with_analyzer:
|
|
analyzer_signals = [
|
|
ltssm.polling_fsm,
|
|
serdes.source,
|
|
serdes.sink,
|
|
]
|
|
self.submodules.analyzer = LiteScopeAnalyzer(analyzer_signals, 4096, csr_csv="tools/analyzer.csv")
|
|
self.add_csr("analyzer")
|
|
|
|
# Build --------------------------------------------------------------------------------------------
|
|
|
|
def main():
|
|
platform = Platform()
|
|
soc = USB3SoC(platform)
|
|
builder = Builder(soc, output_dir="build", csr_csv="tools/csr.csv")
|
|
vns = builder.build()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|