2020-04-11 17:39:16 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
from migen import *
|
2020-07-16 17:58:31 +08:00
|
|
|
from migen.build.generic_platform import *
|
2020-07-08 19:58:13 +08:00
|
|
|
from migen.genlib.resetsync import AsyncResetSynchronizer
|
|
|
|
from migen.genlib.cdc import MultiReg
|
2020-04-11 17:39:16 +08:00
|
|
|
from migen_axi.integration.soc_core import SoCCore
|
|
|
|
from migen_axi.platforms import zc706
|
2020-07-08 19:58:13 +08:00
|
|
|
from misoc.interconnect.csr import *
|
2020-04-11 17:39:16 +08:00
|
|
|
from misoc.integration import cpu_interface
|
|
|
|
|
2020-05-07 17:05:00 +08:00
|
|
|
from artiq.gateware import rtio, nist_clock, nist_qc2
|
|
|
|
from artiq.gateware.rtio.phy import ttl_simple, ttl_serdes_7series, dds, spi2
|
2020-04-11 17:39:16 +08:00
|
|
|
|
2020-07-13 10:37:17 +08:00
|
|
|
import dma
|
2020-07-15 23:06:34 +08:00
|
|
|
import analyzer
|
2020-07-13 10:37:17 +08:00
|
|
|
|
|
|
|
|
2020-07-08 19:58:13 +08:00
|
|
|
class RTIOCRG(Module, AutoCSR):
|
|
|
|
def __init__(self, platform, rtio_internal_clk):
|
|
|
|
self.clock_sel = CSRStorage()
|
|
|
|
self.pll_reset = CSRStorage(reset=1)
|
|
|
|
self.pll_locked = CSRStatus()
|
|
|
|
self.clock_domains.cd_rtio = ClockDomain()
|
|
|
|
self.clock_domains.cd_rtiox4 = ClockDomain(reset_less=True)
|
|
|
|
|
|
|
|
rtio_external_clk = Signal()
|
|
|
|
user_sma_clock = platform.request("user_sma_clock")
|
|
|
|
platform.add_period_constraint(user_sma_clock.p, 8.0)
|
|
|
|
self.specials += Instance("IBUFDS",
|
|
|
|
i_I=user_sma_clock.p, i_IB=user_sma_clock.n,
|
|
|
|
o_O=rtio_external_clk)
|
|
|
|
|
|
|
|
pll_locked = Signal()
|
|
|
|
rtio_clk = Signal()
|
|
|
|
rtiox4_clk = Signal()
|
|
|
|
self.specials += [
|
|
|
|
Instance("PLLE2_ADV",
|
|
|
|
p_STARTUP_WAIT="FALSE", o_LOCKED=pll_locked,
|
|
|
|
|
|
|
|
p_REF_JITTER1=0.01,
|
|
|
|
p_CLKIN1_PERIOD=8.0, p_CLKIN2_PERIOD=8.0,
|
|
|
|
i_CLKIN1=rtio_internal_clk, i_CLKIN2=rtio_external_clk,
|
|
|
|
# Warning: CLKINSEL=0 means CLKIN2 is selected
|
|
|
|
i_CLKINSEL=~self.clock_sel.storage,
|
|
|
|
|
|
|
|
# VCO @ 1GHz when using 125MHz input
|
|
|
|
p_CLKFBOUT_MULT=8, p_DIVCLK_DIVIDE=1,
|
|
|
|
i_CLKFBIN=self.cd_rtio.clk,
|
|
|
|
i_RST=self.pll_reset.storage,
|
|
|
|
|
|
|
|
o_CLKFBOUT=rtio_clk,
|
|
|
|
|
|
|
|
p_CLKOUT0_DIVIDE=2, p_CLKOUT0_PHASE=0.0,
|
|
|
|
o_CLKOUT0=rtiox4_clk),
|
|
|
|
Instance("BUFG", i_I=rtio_clk, o_O=self.cd_rtio.clk),
|
|
|
|
Instance("BUFG", i_I=rtiox4_clk, o_O=self.cd_rtiox4.clk),
|
|
|
|
AsyncResetSynchronizer(self.cd_rtio, ~pll_locked),
|
|
|
|
MultiReg(pll_locked, self.pll_locked.status)
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-04-11 17:39:16 +08:00
|
|
|
class ZC706(SoCCore):
|
|
|
|
def __init__(self):
|
|
|
|
platform = zc706.Platform()
|
2020-04-11 21:20:38 +08:00
|
|
|
platform.toolchain.bitstream_commands.extend([
|
|
|
|
"set_property BITSTREAM.GENERAL.COMPRESS True [current_design]",
|
|
|
|
])
|
2020-07-07 17:22:07 +08:00
|
|
|
SoCCore.__init__(self, platform=platform, csr_data_width=32, ident=self.__class__.__name__)
|
2020-04-11 17:39:16 +08:00
|
|
|
|
|
|
|
platform.add_platform_command("create_clock -name clk_fpga_0 -period 8 [get_pins \"PS7/FCLKCLK[0]\"]")
|
|
|
|
platform.add_platform_command("set_input_jitter clk_fpga_0 0.24")
|
2020-07-08 19:58:13 +08:00
|
|
|
|
|
|
|
self.submodules.rtio_crg = RTIOCRG(self.platform, self.ps7.cd_sys.clk)
|
|
|
|
self.csr_devices.append("rtio_crg")
|
2020-07-08 20:37:53 +08:00
|
|
|
self.platform.add_period_constraint(self.rtio_crg.cd_rtio.clk, 8.)
|
|
|
|
self.platform.add_false_path_constraints(
|
|
|
|
self.ps7.cd_sys.clk,
|
|
|
|
self.rtio_crg.cd_rtio.clk)
|
2020-04-11 17:39:16 +08:00
|
|
|
|
|
|
|
def add_rtio(self, rtio_channels):
|
|
|
|
self.submodules.rtio_tsc = rtio.TSC("async", glbl_fine_ts_width=3)
|
|
|
|
self.submodules.rtio_core = rtio.Core(self.rtio_tsc, rtio_channels)
|
|
|
|
self.csr_devices.append("rtio_core")
|
2020-04-26 16:10:32 +08:00
|
|
|
self.submodules.rtio = rtio.KernelInitiator(self.rtio_tsc, now64=True)
|
2020-07-13 10:37:17 +08:00
|
|
|
self.submodules.rtio_dma = dma.DMA(self.ps7.s_axi_hp0)
|
2020-04-11 17:39:16 +08:00
|
|
|
self.csr_devices.append("rtio")
|
2020-07-13 10:37:17 +08:00
|
|
|
self.csr_devices.append("rtio_dma")
|
2020-04-11 17:39:16 +08:00
|
|
|
|
2020-07-13 10:37:17 +08:00
|
|
|
self.submodules.cri_con = rtio.CRIInterconnectShared(
|
|
|
|
[self.rtio.cri, self.rtio_dma.cri],
|
|
|
|
[self.rtio_core.cri])
|
|
|
|
self.csr_devices.append("cri_con")
|
2020-04-11 17:39:16 +08:00
|
|
|
|
2020-04-24 13:36:36 +08:00
|
|
|
self.submodules.rtio_moninj = rtio.MonInj(rtio_channels)
|
|
|
|
self.csr_devices.append("rtio_moninj")
|
|
|
|
|
2020-07-15 23:06:34 +08:00
|
|
|
self.submodules.rtio_analyzer = analyzer.Analyzer(self.rtio_tsc, self.rtio_core.cri,
|
|
|
|
self.ps7.s_axi_hp1)
|
|
|
|
self.csr_devices.append("rtio_analyzer")
|
|
|
|
|
2020-04-11 17:39:16 +08:00
|
|
|
|
2020-05-07 17:05:00 +08:00
|
|
|
class Simple(ZC706):
|
|
|
|
def __init__(self):
|
|
|
|
ZC706.__init__(self)
|
|
|
|
|
|
|
|
platform = self.platform
|
|
|
|
|
|
|
|
rtio_channels = []
|
|
|
|
for i in range(4):
|
2020-07-16 17:36:27 +08:00
|
|
|
phy = ttl_simple.Output(platform.request("user_led", i))
|
2020-05-07 17:05:00 +08:00
|
|
|
self.submodules += phy
|
|
|
|
rtio_channels.append(rtio.Channel.from_phy(phy))
|
2020-07-19 14:05:35 +08:00
|
|
|
|
|
|
|
self.config["RTIO_LOG_CHANNEL"] = len(rtio_channels)
|
|
|
|
rtio_channels.append(rtio.LogChannel())
|
|
|
|
|
2020-05-07 17:05:00 +08:00
|
|
|
self.add_rtio(rtio_channels)
|
|
|
|
|
|
|
|
|
2020-07-16 17:58:31 +08:00
|
|
|
# The NIST backplanes require setting VADJ to 3.3V by reprogramming the power supply.
|
|
|
|
# This also changes the I/O standard for some on-board LEDs.
|
|
|
|
leds_fmc33 = [
|
|
|
|
("user_led_33", 0, Pins("Y21"), IOStandard("LVCMOS33")),
|
|
|
|
("user_led_33", 1, Pins("G2"), IOStandard("LVCMOS15")),
|
|
|
|
("user_led_33", 2, Pins("W21"), IOStandard("LVCMOS33")),
|
|
|
|
("user_led_33", 3, Pins("A17"), IOStandard("LVCMOS15")),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-05-07 17:05:00 +08:00
|
|
|
class NIST_CLOCK(ZC706):
|
|
|
|
"""
|
|
|
|
NIST clock hardware, with old backplane and 11 DDS channels
|
|
|
|
"""
|
|
|
|
def __init__(self):
|
|
|
|
ZC706.__init__(self)
|
|
|
|
|
|
|
|
platform = self.platform
|
|
|
|
platform.add_extension(nist_clock.fmc_adapter_io)
|
2020-07-16 17:58:31 +08:00
|
|
|
platform.add_extension(leds_fmc33)
|
2020-05-07 17:05:00 +08:00
|
|
|
|
|
|
|
rtio_channels = []
|
2020-07-16 17:36:27 +08:00
|
|
|
|
|
|
|
for i in range(4):
|
2020-07-16 17:58:31 +08:00
|
|
|
phy = ttl_simple.Output(platform.request("user_led_33", i))
|
2020-07-16 17:36:27 +08:00
|
|
|
self.submodules += phy
|
|
|
|
rtio_channels.append(rtio.Channel.from_phy(phy))
|
|
|
|
|
2020-05-07 17:05:00 +08:00
|
|
|
for i in range(16):
|
|
|
|
if i % 4 == 3:
|
2020-07-08 20:02:46 +08:00
|
|
|
phy = ttl_serdes_7series.InOut_8X(platform.request("ttl", i))
|
2020-05-07 17:05:00 +08:00
|
|
|
self.submodules += phy
|
|
|
|
rtio_channels.append(rtio.Channel.from_phy(phy, ififo_depth=512))
|
|
|
|
else:
|
2020-07-08 20:02:46 +08:00
|
|
|
phy = ttl_serdes_7series.Output_8X(platform.request("ttl", i))
|
2020-05-07 17:05:00 +08:00
|
|
|
self.submodules += phy
|
|
|
|
rtio_channels.append(rtio.Channel.from_phy(phy))
|
|
|
|
|
|
|
|
for i in range(2):
|
2020-07-08 20:02:46 +08:00
|
|
|
phy = ttl_serdes_7series.InOut_8X(platform.request("pmt", i))
|
2020-05-07 17:05:00 +08:00
|
|
|
self.submodules += phy
|
|
|
|
rtio_channels.append(rtio.Channel.from_phy(phy, ififo_depth=512))
|
|
|
|
|
|
|
|
phy = ttl_simple.ClockGen(platform.request("la32_p"))
|
|
|
|
self.submodules += phy
|
|
|
|
rtio_channels.append(rtio.Channel.from_phy(phy))
|
|
|
|
|
|
|
|
for i in range(3):
|
|
|
|
phy = spi2.SPIMaster(self.platform.request("spi", i))
|
|
|
|
self.submodules += phy
|
|
|
|
rtio_channels.append(rtio.Channel.from_phy(
|
|
|
|
phy, ififo_depth=128))
|
|
|
|
|
|
|
|
phy = dds.AD9914(platform.request("dds"), 11, onehot=True)
|
|
|
|
self.submodules += phy
|
|
|
|
rtio_channels.append(rtio.Channel.from_phy(phy, ififo_depth=4))
|
|
|
|
|
2020-07-19 14:05:35 +08:00
|
|
|
self.config["RTIO_LOG_CHANNEL"] = len(rtio_channels)
|
|
|
|
rtio_channels.append(rtio.LogChannel())
|
|
|
|
|
2020-05-07 17:05:00 +08:00
|
|
|
self.add_rtio(rtio_channels)
|
|
|
|
|
|
|
|
|
|
|
|
class NIST_QC2(ZC706):
|
|
|
|
"""
|
|
|
|
NIST QC2 hardware, as used in Quantum I and Quantum II, with new backplane
|
|
|
|
and 24 DDS channels. Two backplanes are used.
|
|
|
|
"""
|
|
|
|
def __init__(self):
|
|
|
|
ZC706.__init__(self)
|
|
|
|
|
|
|
|
platform = self.platform
|
|
|
|
platform.add_extension(nist_qc2.fmc_adapter_io)
|
2020-07-16 17:58:31 +08:00
|
|
|
platform.add_extension(leds_fmc33)
|
2020-05-07 17:05:00 +08:00
|
|
|
|
|
|
|
rtio_channels = []
|
2020-07-16 17:36:27 +08:00
|
|
|
|
|
|
|
for i in range(4):
|
2020-07-16 17:58:31 +08:00
|
|
|
phy = ttl_simple.Output(platform.request("user_led_33", i))
|
2020-07-16 17:36:27 +08:00
|
|
|
self.submodules += phy
|
|
|
|
rtio_channels.append(rtio.Channel.from_phy(phy))
|
2020-05-07 17:05:00 +08:00
|
|
|
|
|
|
|
# All TTL channels are In+Out capable
|
|
|
|
for i in range(40):
|
2020-07-08 20:02:46 +08:00
|
|
|
phy = ttl_serdes_7series.InOut_8X(platform.request("ttl", i))
|
2020-05-07 17:05:00 +08:00
|
|
|
self.submodules += phy
|
|
|
|
rtio_channels.append(rtio.Channel.from_phy(phy, ififo_depth=512))
|
|
|
|
|
|
|
|
# CLK0, CLK1 are for clock generators, on backplane SMP connectors
|
|
|
|
for i in range(2):
|
|
|
|
phy = ttl_simple.ClockGen(
|
|
|
|
platform.request("clkout", i))
|
|
|
|
self.submodules += phy
|
2020-07-16 17:36:27 +08:00
|
|
|
rtio_channels.append(rtio.Channel.from_phy(phy))
|
2020-05-07 17:05:00 +08:00
|
|
|
|
|
|
|
for i in range(4):
|
|
|
|
phy = spi2.SPIMaster(self.platform.request("spi", i))
|
|
|
|
self.submodules += phy
|
|
|
|
rtio_channels.append(rtio.Channel.from_phy(
|
|
|
|
phy, ififo_depth=128))
|
|
|
|
|
|
|
|
for backplane_offset in range(2):
|
|
|
|
phy = dds.AD9914(
|
|
|
|
platform.request("dds", backplane_offset), 12, onehot=True)
|
|
|
|
self.submodules += phy
|
|
|
|
rtio_channels.append(rtio.Channel.from_phy(phy, ififo_depth=4))
|
|
|
|
|
2020-07-19 14:05:35 +08:00
|
|
|
self.config["RTIO_LOG_CHANNEL"] = len(rtio_channels)
|
|
|
|
rtio_channels.append(rtio.LogChannel())
|
|
|
|
|
2020-05-07 17:05:00 +08:00
|
|
|
self.add_rtio(rtio_channels)
|
|
|
|
|
|
|
|
|
|
|
|
VARIANTS = {cls.__name__.lower(): cls for cls in [Simple, NIST_CLOCK, NIST_QC2]}
|
|
|
|
|
|
|
|
|
2020-04-11 17:39:16 +08:00
|
|
|
def write_csr_file(soc, filename):
|
|
|
|
with open(filename, "w") as f:
|
|
|
|
f.write(cpu_interface.get_csr_rust(
|
|
|
|
soc.get_csr_regions(), soc.get_csr_groups(), soc.get_constants()))
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="ARTIQ port to the ZC706 Zynq development kit")
|
2020-05-01 10:07:38 +08:00
|
|
|
parser.add_argument("-r", default=None,
|
|
|
|
help="build Rust interface into the specified file")
|
2020-05-07 13:52:40 +08:00
|
|
|
parser.add_argument("-g", default=None,
|
|
|
|
help="build gateware into the specified directory")
|
2020-05-07 17:05:00 +08:00
|
|
|
parser.add_argument("-V", "--variant", default="simple",
|
|
|
|
help="variant: "
|
|
|
|
"simple/nist_clock/nist_qc2 "
|
|
|
|
"(default: %(default)s)")
|
2020-04-11 17:39:16 +08:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2020-05-07 17:05:00 +08:00
|
|
|
try:
|
|
|
|
cls = VARIANTS[args.variant.lower()]
|
|
|
|
except KeyError:
|
|
|
|
raise SystemExit("Invalid variant (-V/--variant)")
|
|
|
|
|
|
|
|
soc = cls()
|
2020-04-11 17:39:16 +08:00
|
|
|
soc.finalize()
|
|
|
|
|
2020-05-07 13:52:40 +08:00
|
|
|
if args.g is not None:
|
|
|
|
soc.build(build_dir=args.g)
|
2020-05-01 10:07:38 +08:00
|
|
|
if args.r is not None:
|
|
|
|
write_csr_file(soc, args.r)
|
2020-04-11 17:39:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|