2015-02-27 13:21:58 -05:00
|
|
|
from migen.fhdl.std import *
|
|
|
|
|
2015-03-21 11:56:53 -04:00
|
|
|
from misoclib.mem.sdram.module import IS42S16160
|
2015-02-28 03:02:28 -05:00
|
|
|
from misoclib.mem.sdram.phy import gensdrphy
|
2015-03-21 17:51:24 -04:00
|
|
|
from misoclib.mem.sdram.core.lasmicon import LASMIconSettings
|
2015-02-28 06:04:51 -05:00
|
|
|
from misoclib.soc.sdram import SDRAMSoC
|
2015-02-27 13:21:58 -05:00
|
|
|
|
2015-04-13 10:47:22 -04:00
|
|
|
|
2015-02-27 13:21:58 -05:00
|
|
|
class _PLL(Module):
|
2015-04-13 10:19:55 -04:00
|
|
|
def __init__(self, period_in, name, phase_shift, operation_mode):
|
|
|
|
self.clk_in = Signal()
|
|
|
|
self.clk_out = Signal()
|
2015-02-27 13:21:58 -05:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
self.specials += Instance("ALTPLL",
|
2015-04-13 11:56:51 -04:00
|
|
|
p_bandwidth_type = "AUTO",
|
|
|
|
p_clk0_divide_by = 1,
|
|
|
|
p_clk0_duty_cycle = 50,
|
|
|
|
p_clk0_multiply_by = 2,
|
|
|
|
p_clk0_phase_shift = "{}".format(str(phase_shift)),
|
|
|
|
p_compensate_clock = "CLK0",
|
|
|
|
p_inclk0_input_frequency = int(period_in*1000),
|
|
|
|
p_intended_device_family = "Cyclone IV E",
|
|
|
|
p_lpm_hint = "CBX_MODULE_PREFIX={}_pll".format(name),
|
|
|
|
p_lpm_type = "altpll",
|
|
|
|
p_operation_mode = operation_mode,
|
|
|
|
i_inclk=self.clk_in,
|
|
|
|
o_clk=self.clk_out,
|
|
|
|
i_areset=0,
|
|
|
|
i_clkena=0x3f,
|
|
|
|
i_clkswitch=0,
|
|
|
|
i_configupdate=0,
|
|
|
|
i_extclkena=0xf,
|
|
|
|
i_fbin=1,
|
|
|
|
i_pfdena=1,
|
|
|
|
i_phasecounterselect=0xf,
|
|
|
|
i_phasestep=1,
|
|
|
|
i_phaseupdown=1,
|
|
|
|
i_pllena=1,
|
|
|
|
i_scanaclr=0,
|
|
|
|
i_scanclk=0,
|
|
|
|
i_scanclkena=1,
|
|
|
|
i_scandata=0,
|
|
|
|
i_scanread=0,
|
|
|
|
i_scanwrite=0
|
2015-04-13 10:19:55 -04:00
|
|
|
)
|
2015-02-27 13:21:58 -05:00
|
|
|
|
2015-04-13 10:47:22 -04:00
|
|
|
|
2015-02-27 13:21:58 -05:00
|
|
|
class _CRG(Module):
|
2015-04-13 10:19:55 -04:00
|
|
|
def __init__(self, platform):
|
|
|
|
self.clock_domains.cd_sys = ClockDomain()
|
|
|
|
self.clock_domains.cd_sys_ps = ClockDomain()
|
|
|
|
self.clock_domains.cd_por = ClockDomain(reset_less=True)
|
2015-02-27 13:21:58 -05:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
clk50 = platform.request("clk50")
|
2015-02-27 13:21:58 -05:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
sys_pll = _PLL(20, "sys", 0, "NORMAL")
|
|
|
|
self.submodules += sys_pll
|
|
|
|
self.comb += [
|
|
|
|
sys_pll.clk_in.eq(clk50),
|
|
|
|
self.cd_sys.clk.eq(sys_pll.clk_out)
|
|
|
|
]
|
2015-02-27 13:21:58 -05:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
sdram_pll = _PLL(20, "sdram", -3000, "ZERO_DELAY_BUFFER")
|
|
|
|
self.submodules += sdram_pll
|
|
|
|
self.comb += [
|
|
|
|
sdram_pll.clk_in.eq(clk50),
|
|
|
|
self.cd_sys_ps.clk.eq(sdram_pll.clk_out)
|
|
|
|
]
|
2015-02-27 13:21:58 -05:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
# Power on Reset (vendor agnostic)
|
|
|
|
rst_n = Signal()
|
|
|
|
self.sync.por += rst_n.eq(1)
|
|
|
|
self.comb += [
|
|
|
|
self.cd_por.clk.eq(self.cd_sys.clk),
|
|
|
|
self.cd_sys.rst.eq(~rst_n),
|
|
|
|
self.cd_sys_ps.rst.eq(~rst_n)
|
|
|
|
]
|
2015-02-27 13:21:58 -05:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
self.comb += platform.request("sdram_clock").eq(self.cd_sys_ps.clk)
|
2015-02-27 13:21:58 -05:00
|
|
|
|
2015-04-13 10:47:22 -04:00
|
|
|
|
2015-02-27 13:21:58 -05:00
|
|
|
class BaseSoC(SDRAMSoC):
|
2015-04-13 10:19:55 -04:00
|
|
|
default_platform = "de0nano"
|
2015-02-27 13:21:58 -05:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
def __init__(self, platform, sdram_controller_settings=LASMIconSettings(), **kwargs):
|
|
|
|
SDRAMSoC.__init__(self, platform,
|
2015-04-13 11:56:51 -04:00
|
|
|
clk_freq=100*1000000,
|
|
|
|
integrated_rom_size=0x8000,
|
|
|
|
sdram_controller_settings=sdram_controller_settings,
|
|
|
|
**kwargs)
|
2015-02-27 13:21:58 -05:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
self.submodules.crg = _CRG(platform)
|
2015-02-27 13:21:58 -05:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
if not self.integrated_main_ram_size:
|
2015-04-13 11:56:51 -04:00
|
|
|
self.submodules.sdrphy = gensdrphy.GENSDRPHY(platform.request("sdram"),
|
|
|
|
IS42S16160(self.clk_freq))
|
2015-04-13 10:19:55 -04:00
|
|
|
self.register_sdram_phy(self.sdrphy)
|
2015-02-27 13:21:58 -05:00
|
|
|
|
|
|
|
default_subtarget = BaseSoC
|