2016-04-29 10:48:35 -04:00
|
|
|
from litex.gen import *
|
2016-05-13 09:46:15 -04:00
|
|
|
from litex.soc.interconnect import stream
|
2016-04-29 10:48:35 -04:00
|
|
|
|
2016-04-29 13:22:06 -04:00
|
|
|
class PhySettings:
|
|
|
|
def __init__(self, memtype, dfi_databits,
|
|
|
|
nphases,
|
|
|
|
rdphase, wrphase,
|
|
|
|
rdcmdphase, wrcmdphase,
|
|
|
|
cl, read_latency, write_latency, cwl=0):
|
|
|
|
self.memtype = memtype
|
|
|
|
self.dfi_databits = dfi_databits
|
|
|
|
|
|
|
|
self.nphases = nphases
|
|
|
|
self.rdphase = rdphase
|
|
|
|
self.wrphase = wrphase
|
|
|
|
self.rdcmdphase = rdcmdphase
|
|
|
|
self.wrcmdphase = wrcmdphase
|
|
|
|
|
|
|
|
self.cl = cl
|
|
|
|
self.read_latency = read_latency
|
|
|
|
self.write_latency = write_latency
|
|
|
|
self.cwl = cwl
|
|
|
|
|
2016-04-29 13:08:56 -04:00
|
|
|
|
2016-04-29 13:22:06 -04:00
|
|
|
class GeomSettings:
|
|
|
|
def __init__(self, bankbits, rowbits, colbits):
|
|
|
|
self.bankbits = bankbits
|
|
|
|
self.rowbits = rowbits
|
|
|
|
self.colbits = colbits
|
|
|
|
self.addressbits = max(rowbits, colbits)
|
2016-04-29 13:08:56 -04:00
|
|
|
|
|
|
|
|
2016-04-29 13:22:06 -04:00
|
|
|
class TimingSettings:
|
|
|
|
def __init__(self, tRP, tRCD, tWR, tWTR, tREFI, tRFC):
|
|
|
|
self.tRP = tRP
|
|
|
|
self.tRCD = tRCD
|
|
|
|
self.tWR = tWR
|
|
|
|
self.tWTR = tWTR
|
|
|
|
self.tREFI = tREFI
|
|
|
|
self.tRFC = tRFC
|
2016-04-29 13:08:56 -04:00
|
|
|
|
2016-05-03 13:24:33 -04:00
|
|
|
|
2016-05-02 03:20:12 -04:00
|
|
|
def cmd_layout(aw):
|
|
|
|
return [
|
2016-05-03 11:02:59 -04:00
|
|
|
("valid", 1, DIR_M_TO_S),
|
|
|
|
("ready", 1, DIR_S_TO_M),
|
|
|
|
("we", 1, DIR_M_TO_S),
|
|
|
|
("adr", aw, DIR_M_TO_S),
|
2016-05-13 09:27:12 -04:00
|
|
|
("lock", 1, DIR_S_TO_M), # only used internally
|
2016-05-03 11:02:59 -04:00
|
|
|
|
|
|
|
("wdata_ready", 1, DIR_S_TO_M),
|
2016-05-13 09:46:15 -04:00
|
|
|
("rdata_valid", 1, DIR_S_TO_M)
|
2016-05-02 03:20:12 -04:00
|
|
|
]
|
2016-04-29 10:48:35 -04:00
|
|
|
|
2016-05-02 03:20:12 -04:00
|
|
|
|
|
|
|
def data_layout(dw):
|
|
|
|
return [
|
2016-05-03 11:02:59 -04:00
|
|
|
("wdata", dw, DIR_M_TO_S),
|
|
|
|
("wdata_we", dw//8, DIR_M_TO_S),
|
|
|
|
("rdata", dw, DIR_S_TO_M)
|
2016-05-02 03:20:12 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2016-05-03 13:24:33 -04:00
|
|
|
class LiteDRAMInterface(Record):
|
2016-05-02 15:38:18 -04:00
|
|
|
def __init__(self, address_align, settings):
|
|
|
|
self.aw = settings.geom.rowbits + settings.geom.colbits - address_align
|
|
|
|
self.dw = settings.phy.dfi_databits*settings.phy.nphases
|
|
|
|
self.nbanks = 2**settings.geom.bankbits
|
|
|
|
self.settings = settings
|
|
|
|
|
|
|
|
layout = [("bank"+str(i), cmd_layout(self.aw)) for i in range(self.nbanks)]
|
|
|
|
layout += data_layout(self.dw)
|
2016-05-02 03:20:12 -04:00
|
|
|
Record.__init__(self, layout)
|
|
|
|
|
2016-05-13 09:46:15 -04:00
|
|
|
def cmd_description(aw):
|
|
|
|
return [
|
|
|
|
("we", 1),
|
|
|
|
("adr", aw)
|
|
|
|
]
|
|
|
|
|
|
|
|
def wdata_description(dw):
|
|
|
|
return [
|
|
|
|
("data", dw),
|
|
|
|
("we", dw//8)
|
|
|
|
]
|
2016-05-02 03:20:12 -04:00
|
|
|
|
2016-05-13 09:46:15 -04:00
|
|
|
def rdata_description(dw):
|
|
|
|
return [("data", dw)]
|
|
|
|
|
|
|
|
|
|
|
|
class LiteDRAMPort:
|
2016-06-15 11:51:46 -04:00
|
|
|
def __init__(self, mode, aw, dw, cd="sys"):
|
|
|
|
self.mode = mode
|
2016-05-02 03:20:12 -04:00
|
|
|
self.aw = aw
|
|
|
|
self.dw = dw
|
2016-05-13 09:27:12 -04:00
|
|
|
self.cd = cd
|
2016-05-02 03:20:12 -04:00
|
|
|
|
2016-05-13 09:46:15 -04:00
|
|
|
self.lock = Signal()
|
|
|
|
|
|
|
|
self.cmd = stream.Endpoint(cmd_description(aw))
|
|
|
|
self.wdata = stream.Endpoint(wdata_description(dw))
|
|
|
|
self.rdata = stream.Endpoint(rdata_description(dw))
|
2016-05-02 03:13:09 -04:00
|
|
|
|
|
|
|
|
2016-06-15 11:51:46 -04:00
|
|
|
class LiteDRAMWritePort(LiteDRAMPort):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
LiteDRAMPort.__init__(self, "write", *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class LiteDRAMReadPort(LiteDRAMPort):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
LiteDRAMPort.__init__(self, "read", *args, **kwargs)
|
|
|
|
|
|
|
|
|
2016-05-02 06:18:56 -04:00
|
|
|
def cmd_request_layout(a, ba):
|
|
|
|
return [
|
|
|
|
("a", a),
|
|
|
|
("ba", ba),
|
|
|
|
("cas", 1),
|
|
|
|
("ras", 1),
|
|
|
|
("we", 1)
|
|
|
|
]
|
|
|
|
|
2016-05-03 13:24:33 -04:00
|
|
|
|
2016-05-02 06:18:56 -04:00
|
|
|
def cmd_request_rw_layout(a, ba):
|
|
|
|
return cmd_request_layout(a, ba) + [
|
|
|
|
("is_cmd", 1),
|
|
|
|
("is_read", 1),
|
|
|
|
("is_write", 1)
|
|
|
|
]
|