2014-07-04 23:49:08 +08:00
|
|
|
from migen.fhdl.std import *
|
2014-12-01 18:53:29 +08:00
|
|
|
from migen.bank.description import *
|
2014-11-30 22:31:55 +08:00
|
|
|
from migen.bank import wbgen
|
2014-07-17 09:13:11 +08:00
|
|
|
from mibuild.generic_platform import *
|
2014-07-04 23:49:08 +08:00
|
|
|
|
2015-04-02 17:19:00 +08:00
|
|
|
from misoclib.com import gpio
|
2015-04-11 21:32:01 +08:00
|
|
|
from misoclib.soc import mem_decoder
|
2015-03-22 06:21:49 +08:00
|
|
|
from misoclib.mem.sdram.core.minicon import MiniconSettings
|
2014-08-03 12:26:15 +08:00
|
|
|
from targets.ppro import BaseSoC
|
2014-07-04 23:49:08 +08:00
|
|
|
|
2015-04-07 00:07:53 +08:00
|
|
|
from artiq.gateware import rtio, ad9858, nist_qc1
|
2014-07-17 09:13:11 +08:00
|
|
|
|
2014-09-05 17:06:41 +08:00
|
|
|
|
2014-09-17 19:53:55 +08:00
|
|
|
class _TestGen(Module):
|
|
|
|
def __init__(self, pad):
|
|
|
|
divc = Signal(15)
|
|
|
|
ce = Signal()
|
|
|
|
self.sync += Cat(divc, ce).eq(divc + 1)
|
|
|
|
|
|
|
|
sr = Signal(8, reset=0b10101000)
|
|
|
|
self.sync += If(ce, sr.eq(Cat(sr[1:], sr[0])))
|
|
|
|
self.comb += pad.eq(sr[0])
|
|
|
|
|
|
|
|
|
2014-12-01 18:53:29 +08:00
|
|
|
class _RTIOMiniCRG(Module, AutoCSR):
|
2014-11-30 01:00:27 +08:00
|
|
|
def __init__(self, platform):
|
2015-04-02 18:22:18 +08:00
|
|
|
self._clock_sel = CSRStorage()
|
2014-11-30 01:00:27 +08:00
|
|
|
self.clock_domains.cd_rtio = ClockDomain()
|
2014-12-01 18:53:29 +08:00
|
|
|
|
2014-11-30 01:00:27 +08:00
|
|
|
# 80MHz -> 125MHz
|
2014-12-01 18:53:29 +08:00
|
|
|
rtio_internal_clk = Signal()
|
2014-11-30 01:00:27 +08:00
|
|
|
self.specials += Instance("DCM_CLKGEN",
|
2014-12-01 18:53:29 +08:00
|
|
|
p_CLKFXDV_DIVIDE=2,
|
|
|
|
p_CLKFX_DIVIDE=16, p_CLKFX_MD_MAX=1.6, p_CLKFX_MULTIPLY=25,
|
|
|
|
p_CLKIN_PERIOD=12.5, p_SPREAD_SPECTRUM="NONE",
|
|
|
|
p_STARTUP_WAIT="FALSE",
|
2014-11-30 01:00:27 +08:00
|
|
|
|
2014-12-01 18:53:29 +08:00
|
|
|
i_CLKIN=ClockSignal(), o_CLKFX=rtio_internal_clk,
|
2014-11-30 01:00:27 +08:00
|
|
|
i_FREEZEDCM=0, i_RST=ResetSignal())
|
2014-12-01 18:53:29 +08:00
|
|
|
|
|
|
|
rtio_external_clk = platform.request("xtrig")
|
|
|
|
platform.add_period_constraint(rtio_external_clk, 8.0)
|
|
|
|
self.specials += Instance("BUFGMUX",
|
|
|
|
i_I0=rtio_internal_clk,
|
|
|
|
i_I1=rtio_external_clk,
|
2015-04-02 18:22:18 +08:00
|
|
|
i_S=self._clock_sel.storage,
|
2014-12-01 18:53:29 +08:00
|
|
|
o_O=self.cd_rtio.clk)
|
|
|
|
|
2014-11-30 01:00:27 +08:00
|
|
|
platform.add_platform_command("""
|
|
|
|
NET "{rtio_clk}" TNM_NET = "GRPrtio_clk";
|
|
|
|
NET "sys_clk" TNM_NET = "GRPsys_clk";
|
|
|
|
TIMESPEC "TSfix_ise1" = FROM "GRPrtio_clk" TO "GRPsys_clk" TIG;
|
|
|
|
TIMESPEC "TSfix_ise2" = FROM "GRPsys_clk" TO "GRPrtio_clk" TIG;
|
2014-12-01 18:53:29 +08:00
|
|
|
""", rtio_clk=rtio_internal_clk)
|
2014-11-30 01:00:27 +08:00
|
|
|
|
|
|
|
|
2015-04-07 00:07:53 +08:00
|
|
|
class UP(BaseSoC):
|
2014-09-05 12:03:22 +08:00
|
|
|
csr_map = {
|
2014-12-01 18:53:29 +08:00
|
|
|
"rtio": None, # mapped on Wishbone instead
|
|
|
|
"rtiocrg": 13
|
2014-09-05 12:03:22 +08:00
|
|
|
}
|
|
|
|
csr_map.update(BaseSoC.csr_map)
|
2015-04-11 21:32:01 +08:00
|
|
|
mem_map = {
|
|
|
|
"rtio": 0x20000000, # (shadow @0xa0000000)
|
|
|
|
"dds": 0x50000000, # (shadow @0xd0000000)
|
|
|
|
}
|
2015-04-11 21:59:29 +08:00
|
|
|
mem_map.update(BaseSoC.mem_map)
|
2014-09-05 12:03:22 +08:00
|
|
|
|
2015-02-28 09:02:21 +08:00
|
|
|
def __init__(self, platform, cpu_type="or1k",
|
2014-11-28 10:21:43 +08:00
|
|
|
with_test_gen=False, **kwargs):
|
|
|
|
BaseSoC.__init__(self, platform,
|
2015-03-22 06:21:49 +08:00
|
|
|
cpu_type=cpu_type,
|
|
|
|
sdram_controller_settings=MiniconSettings(),
|
2014-11-28 10:21:43 +08:00
|
|
|
**kwargs)
|
2015-04-07 00:07:53 +08:00
|
|
|
platform.add_extension(nist_qc1.papilio_adapter_io)
|
2014-09-05 12:03:22 +08:00
|
|
|
|
2014-09-05 17:06:41 +08:00
|
|
|
self.submodules.leds = gpio.GPIOOut(Cat(
|
|
|
|
platform.request("user_led", 0),
|
2015-04-07 00:07:53 +08:00
|
|
|
platform.request("ext_led", 0)))
|
2014-09-05 12:03:22 +08:00
|
|
|
|
2014-09-11 23:11:22 +08:00
|
|
|
fud = Signal()
|
2014-11-30 15:50:57 +08:00
|
|
|
self.comb += [
|
|
|
|
platform.request("ttl_l_tx_en").eq(1),
|
|
|
|
platform.request("ttl_h_tx_en").eq(1)
|
|
|
|
]
|
|
|
|
rtio_ins = [platform.request("pmt") for i in range(2)]
|
2015-04-09 00:35:11 +08:00
|
|
|
rtio_outs = [platform.request("ttl", i) for i in range(5)]
|
|
|
|
self.add_constant("RTIO_FUD_CHANNEL", len(rtio_ins) + len(rtio_outs))
|
|
|
|
rtio_outs.append(fud)
|
2014-11-30 15:50:57 +08:00
|
|
|
|
2014-11-30 01:00:27 +08:00
|
|
|
self.submodules.rtiocrg = _RTIOMiniCRG(platform)
|
2014-09-05 17:06:41 +08:00
|
|
|
self.submodules.rtiophy = rtio.phy.SimplePHY(
|
2014-11-30 15:50:57 +08:00
|
|
|
rtio_ins + rtio_outs,
|
|
|
|
output_only_pads=set(rtio_outs))
|
|
|
|
self.submodules.rtio = rtio.RTIO(self.rtiophy,
|
|
|
|
clk_freq=125000000,
|
2015-03-12 20:10:35 +08:00
|
|
|
counter_width=32,
|
2014-11-30 15:50:57 +08:00
|
|
|
ififo_depth=512)
|
2014-09-05 12:03:22 +08:00
|
|
|
|
2014-11-30 22:31:55 +08:00
|
|
|
rtio_csrs = self.rtio.get_csrs()
|
|
|
|
self.submodules.rtiowb = wbgen.Bank(rtio_csrs)
|
2015-04-11 21:32:01 +08:00
|
|
|
self.add_wb_slave(mem_decoder(self.mem_map["rtio"]), self.rtiowb.bus)
|
|
|
|
self.add_csr_region("rtio", self.mem_map["rtio"] + 0x80000000, 32, rtio_csrs)
|
2014-11-30 22:31:55 +08:00
|
|
|
|
2014-09-17 19:53:55 +08:00
|
|
|
if with_test_gen:
|
2014-11-30 15:50:57 +08:00
|
|
|
self.submodules.test_gen = _TestGen(platform.request("ttl", 8))
|
2014-09-17 19:53:55 +08:00
|
|
|
|
2014-09-11 23:11:22 +08:00
|
|
|
dds_pads = platform.request("dds")
|
|
|
|
self.submodules.dds = ad9858.AD9858(dds_pads)
|
2015-04-11 21:32:01 +08:00
|
|
|
self.add_wb_slave(mem_decoder(self.mem_map["dds"]), self.dds.bus)
|
|
|
|
self.add_memory_region("dds", self.mem_map["dds"] + 0x80000000, 64*4)
|
2014-09-11 23:11:22 +08:00
|
|
|
self.comb += dds_pads.fud_n.eq(~fud)
|
2014-07-06 04:44:20 +08:00
|
|
|
|
2015-04-07 00:07:53 +08:00
|
|
|
|
|
|
|
default_subtarget = UP
|