Skip to content

Commit

Permalink
litedram_gen: add more memtype asserts, remove csr_alignment (now fix…
Browse files Browse the repository at this point in the history
…ed to 32-bit).
  • Loading branch information
enjoy-digital committed Jun 3, 2020
1 parent a595fe0 commit 1b56dcf
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions litedram/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def __init__(self):

class LiteDRAMECP5DDRPHYCRG(Module):
def __init__(self, platform, core_config):
assert core_config["memtype"] in ["DDR3"]
self.clock_domains.cd_init = ClockDomain()
self.clock_domains.cd_por = ClockDomain(reset_less=True)
self.clock_domains.cd_sys = ClockDomain()
Expand Down Expand Up @@ -255,13 +256,17 @@ def __init__(self, platform, core_config):

class LiteDRAMS7DDRPHYCRG(Module):
def __init__(self, platform, core_config):
assert core_config["memtype"] in ["DDR2", "DDR3"]
self.clock_domains.cd_sys = ClockDomain()
if core_config["memtype"] == "DDR3":
if core_config["memtype"] == "DDR2":
self.clock_domains.cd_sys2x = ClockDomain(reset_less=True)
self.clock_domains.cd_sys2x_dqs = ClockDomain(reset_less=True)
elif core_config["memtype"] == "DDR3":
self.clock_domains.cd_sys4x = ClockDomain(reset_less=True)
self.clock_domains.cd_sys4x_dqs = ClockDomain(reset_less=True)
else:
self.clock_domains.cd_sys2x = ClockDomain(reset_less=True)
self.clock_domains.cd_sys2x_dqs = ClockDomain(reset_less=True)
raise NotImplementedError

self.clock_domains.cd_iodelay = ClockDomain()

# # #
Expand All @@ -273,12 +278,15 @@ def __init__(self, platform, core_config):
self.comb += sys_pll.reset.eq(rst)
sys_pll.register_clkin(clk, core_config["input_clk_freq"])
sys_pll.create_clkout(self.cd_sys, core_config["sys_clk_freq"])
if core_config["memtype"] == "DDR3":
sys_pll.create_clkout(self.cd_sys4x, 4*core_config["sys_clk_freq"])
if core_config["memtype"] == "DDR2":
sys_pll.create_clkout(self.cd_sys2x, 2*core_config["sys_clk_freq"])
sys_pll.create_clkout(self.cd_sys2x_dqs, 2*core_config["sys_clk_freq"], phase=90)
elif core_config["memtype"] == "DDR3":
sys_pll.create_clkout(self.cd_sys4x, 4*core_config["sys_clk_freq"])
sys_pll.create_clkout(self.cd_sys4x_dqs, 4*core_config["sys_clk_freq"], phase=90)
else:
sys_pll.create_clkout(self.cd_sys2x, 2*core_config["sys_clk_freq"])
sys_pll.create_clkout(self.cd_sys2x_dqs, 2*core_config["sys_clk_freq"], phase=90)
raise NotImplementedError

self.comb += platform.request("pll_locked").eq(sys_pll.locked)

self.submodules.iodelay_pll = iodelay_pll = S7PLL(speedgrade=core_config["speedgrade"])
Expand All @@ -304,7 +312,6 @@ def __init__(self, platform, core_config, **kwargs):
sys_clk_freq = core_config["sys_clk_freq"]
cpu_type = core_config["cpu"]
cpu_variant = core_config.get("cpu_variant", "standard")
csr_alignment = core_config.get("csr_alignment", 32)
csr_data_width = core_config.get("csr_data_width", 8)
if cpu_type is None:
kwargs["integrated_rom_size"] = 0
Expand All @@ -318,7 +325,6 @@ def __init__(self, platform, core_config, **kwargs):
cpu_type = cpu_type,
cpu_variant = cpu_variant,
csr_data_width = csr_data_width,
csr_alignment = csr_alignment,
**kwargs)

# CRG --------------------------------------------------------------------------------------
Expand All @@ -331,8 +337,8 @@ def __init__(self, platform, core_config, **kwargs):

# DRAM -------------------------------------------------------------------------------------
platform.add_extension(get_dram_ios(core_config))
sdram_module = core_config["sdram_module"](sys_clk_freq,
"1:4" if core_config["memtype"] == "DDR3" else "1:2")
sdram_module = core_config["sdram_module"](sys_clk_freq, rate={"DDR3": "1:4", "DDR2": "1:2"}[core_config["memtype"]])

# Sim
if isinstance(platform, SimPlatform):
from litex.tools.litex_sim import get_sdram_phy_settings
Expand All @@ -345,7 +351,8 @@ def __init__(self, platform, core_config, **kwargs):
module = sdram_module,
settings = phy_settings,
clk_freq = sdram_clk_freq)
# ECP5DDRPHY

# ECP5DDRPHY
elif core_config["sdram_phy"] in [litedram_phys.ECP5DDRPHY]:
assert core_config["memtype"] in ["DDR3"]
self.submodules.ddrphy = core_config["sdram_phy"](
Expand All @@ -354,6 +361,7 @@ def __init__(self, platform, core_config, **kwargs):
self.comb += crg.stop.eq(self.ddrphy.init.stop)
self.add_constant("ECP5DDRPHY")
sdram_module = core_config["sdram_module"](sys_clk_freq, "1:2")

# S7DDRPHY
elif core_config["sdram_phy"] in [litedram_phys.A7DDRPHY, litedram_phys.K7DDRPHY, litedram_phys.V7DDRPHY]:
assert core_config["memtype"] in ["DDR2", "DDR3"]
Expand All @@ -373,7 +381,7 @@ def __init__(self, platform, core_config, **kwargs):
self.add_csr("ddrphy")

controller_settings = controller_settings = ControllerSettings(
cmd_buffer_depth=core_config["cmd_buffer_depth"])
cmd_buffer_depth = core_config["cmd_buffer_depth"])
self.add_sdram("sdram",
phy = self.ddrphy,
module = sdram_module,
Expand Down Expand Up @@ -402,7 +410,7 @@ def __init__(self, platform, core_config, **kwargs):
# User ports -------------------------------------------------------------------------------
self.comb += [
platform.request("user_clk").eq(ClockSignal()),
platform.request("user_rst").eq(ResetSignal())
platform.request("user_rst").eq(ResetSignal()),
]
for name, port in core_config["user_ports"].items():
# Native -------------------------------------------------------------------------------
Expand Down

0 comments on commit 1b56dcf

Please sign in to comment.