boards/targets/sim: get SDRAM working in simulation with sdram/model

This commit is contained in:
Florent Kermarrec 2015-11-10 12:55:51 +01:00
parent 4afe4a07e4
commit 3297210e48
4 changed files with 42 additions and 16 deletions

View File

@ -7,18 +7,19 @@ from litex.gen import *
from litex.boards.platforms import sim
from litex.gen.genlib.io import CRG
from litex.soc.integration.soc_core import *
from litex.soc.integration.soc_sdram import *
from litex.soc.integration.builder import *
from litex.soc.cores import uart
from litex.soc.cores.sdram.settings import PhySettings, IS42S16160
from litex.soc.cores.sdram.model import SDRAMPHYModel
class BaseSoC(SoCCore):
class BaseSoC(SoCSDRAM):
def __init__(self, **kwargs):
platform = sim.Platform()
SoCCore.__init__(self, platform,
SoCSDRAM.__init__(self, platform,
clk_freq=int((1/(platform.default_clk_period))*1000000000),
integrated_rom_size=0x8000,
integrated_main_ram_size=16*1024,
with_uart=False,
**kwargs)
self.submodules.crg = CRG(platform.request(platform.default_clk_name))
@ -26,14 +27,33 @@ class BaseSoC(SoCCore):
self.submodules.uart_phy = uart.RS232PHYModel(platform.request("serial"))
self.submodules.uart = uart.UART(self.uart_phy)
if not self.integrated_main_ram_size:
sdram_module = IS42S16160(self.clk_freq)
phy_settings = PhySettings(
memtype="SDR",
dfi_databits=1*16,
nphases=1,
rdphase=0,
wrphase=0,
rdcmdphase=0,
wrcmdphase=0,
cl=2,
read_latency=4,
write_latency=0
)
self.submodules.sdrphy = SDRAMPHYModel(sdram_module, phy_settings)
self.register_sdram(self.sdrphy, "minicon",
sdram_module.geom_settings, sdram_module.timing_settings)
def main():
parser = argparse.ArgumentParser(description="Generic LiteX SoC Simulation")
builder_args(parser)
soc_core_args(parser)
soc_sdram_args(parser)
args = parser.parse_args()
soc = BaseSoC(**soc_core_argdict(args))
soc = BaseSoC(**soc_sdram_argdict(args))
builder = Builder(soc, **builder_argdict(args))
builder.build()

View File

@ -1,2 +1,2 @@
from litex.build.xilinx.platform import XilinxPlatform
from litex.build.xilinx.programmer import UrJTAG, XC3SProg, FpgaProg, VivadoProgrammer, iMPACT, Adept
from litex.build.xilinx.programmer import XC3SProg, FpgaProg, VivadoProgrammer, iMPACT

View File

@ -8,8 +8,10 @@
from litex.gen import *
from litex.gen.fhdl.specials import *
from litex.soc.mem.sdram.phy.dfi import *
from litex.soc.mem import sdram
from litex.soc.interconnect.dfi import *
from functools import reduce
from operator import or_
class Bank(Module):
@ -27,7 +29,8 @@ class Bank(Module):
self.read_col = Signal(max=ncols)
self.read_data = Signal(data_width)
###
# # #
active = Signal()
row = Signal(max=nrows)
@ -74,7 +77,8 @@ class DFIPhase(Module):
self.write = Signal()
self.read = Signal()
###
# # #
self.comb += [
If(~phase.cs_n & ~phase.ras_n & phase.cas_n,
self.activate.eq(phase.we_n),
@ -87,7 +91,7 @@ class DFIPhase(Module):
]
class SDRAMPHYSim(Module):
class SDRAMPHYModel(Module):
def __init__(self, module, settings):
if settings.memtype in ["SDR"]:
burst_length = settings.nphases*1 # command multiplication*SDR
@ -104,7 +108,8 @@ class SDRAMPHYSim(Module):
self.dfi = Interface(addressbits, bankbits, self.settings.dfi_databits, self.settings.nphases)
###
# # #
nbanks = 2**bankbits
nrows = 2**rowbits
ncols = 2**colbits
@ -171,9 +176,10 @@ class SDRAMPHYSim(Module):
banks_read = Signal()
banks_read_data = Signal(data_width)
self.comb += [
banks_read.eq(optree("|", [bank.read for bank in banks])),
banks_read_data.eq(optree("|", [bank.read_data for bank in banks]))
banks_read.eq(reduce(or_, [bank.read for bank in banks])),
banks_read_data.eq(reduce(or_, [bank.read_data for bank in banks]))
]
# simulate read latency
for i in range(self.settings.read_latency):
new_banks_read = Signal()

View File

@ -423,7 +423,7 @@ int sdrlevel(void)
#endif /* CSR_DDRPHY_BASE */
#define TEST_DATA_SIZE (2*1024*1024)
#define TEST_DATA_SIZE (32*1024) // FIXME add #define
#define TEST_DATA_RANDOM 1
#define TEST_ADDR_SIZE (32*1024)