litex/misoclib/mem/sdram/phy/dfii.py

59 lines
2.0 KiB
Python
Raw Normal View History

2013-05-22 11:10:13 -04:00
from migen.fhdl.std import *
2012-02-17 17:50:10 -05:00
from migen.bank.description import *
from misoclib.mem.sdram.phy import dfi
2013-03-30 12:28:15 -04:00
class PhaseInjector(Module, AutoCSR):
2012-02-23 15:21:07 -05:00
def __init__(self, phase):
2013-03-30 12:28:15 -04:00
self._command = CSRStorage(6) # cs, we, cas, ras, wren, rden
self._command_issue = CSR()
2013-05-22 11:10:13 -04:00
self._address = CSRStorage(flen(phase.address))
self._baddress = CSRStorage(flen(phase.bank))
self._wrdata = CSRStorage(flen(phase.wrdata))
self._rddata = CSRStatus(flen(phase.rddata))
2014-10-17 05:14:35 -04:00
###
self.comb += [
If(self._command_issue.re,
2013-03-30 12:28:15 -04:00
phase.cs_n.eq(~self._command.storage[0]),
phase.we_n.eq(~self._command.storage[1]),
phase.cas_n.eq(~self._command.storage[2]),
phase.ras_n.eq(~self._command.storage[3])
2012-02-23 15:21:07 -05:00
).Else(
phase.cs_n.eq(1),
phase.we_n.eq(1),
phase.cas_n.eq(1),
phase.ras_n.eq(1)
2012-02-23 15:21:07 -05:00
),
2013-03-30 12:28:15 -04:00
phase.address.eq(self._address.storage),
phase.bank.eq(self._baddress.storage),
2013-06-11 09:26:47 -04:00
phase.wrdata_en.eq(self._command_issue.re & self._command.storage[4]),
2013-03-30 12:28:15 -04:00
phase.rddata_en.eq(self._command_issue.re & self._command.storage[5]),
phase.wrdata.eq(self._wrdata.storage),
phase.wrdata_mask.eq(0)
2012-02-23 15:21:07 -05:00
]
2013-06-11 09:26:47 -04:00
self.sync += If(phase.rddata_valid, self._rddata.status.eq(phase.rddata))
2012-02-17 17:50:10 -05:00
2013-03-30 12:28:15 -04:00
class DFIInjector(Module, AutoCSR):
def __init__(self, addressbits, bankbits, databits, nphases=1):
inti = dfi.Interface(addressbits, bankbits, databits, nphases)
self.slave = dfi.Interface(addressbits, bankbits, databits, nphases)
self.master = dfi.Interface(addressbits, bankbits, databits, nphases)
2014-10-17 05:14:35 -04:00
2014-08-08 09:56:35 -04:00
self._control = CSRStorage(4) # sel, cke, odt, reset_n
2014-10-17 05:14:35 -04:00
for n, phase in enumerate(inti.phases):
setattr(self.submodules, "pi" + str(n), PhaseInjector(phase))
2014-10-17 05:14:35 -04:00
###
2014-10-17 05:14:35 -04:00
2013-04-01 18:15:42 -04:00
self.comb += If(self._control.storage[0],
self.slave.connect(self.master)
).Else(
inti.connect(self.master)
)
2013-03-30 12:28:15 -04:00
self.comb += [phase.cke.eq(self._control.storage[1]) for phase in inti.phases]
2014-08-08 09:56:35 -04:00
self.comb += [phase.odt.eq(self._control.storage[2]) for phase in inti.phases if hasattr(phase, "odt")]
self.comb += [phase.reset_n.eq(self._control.storage[3]) for phase in inti.phases if hasattr(phase, "reset_n")]