2013-05-22 11:10:13 -04:00
|
|
|
from migen.fhdl.std import *
|
2012-02-17 17:50:10 -05:00
|
|
|
from migen.bus import dfi
|
|
|
|
from migen.bank.description import *
|
|
|
|
|
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))
|
2012-02-23 15:21:07 -05:00
|
|
|
|
2013-03-10 14:32:38 -04:00
|
|
|
###
|
|
|
|
|
|
|
|
self.comb += [
|
2012-10-09 13:08:37 -04:00
|
|
|
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(
|
2013-03-10 14:32:38 -04:00
|
|
|
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),
|
2013-03-10 14:32:38 -04:00
|
|
|
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):
|
2013-03-10 14:32:38 -04:00
|
|
|
def __init__(self, a, ba, d, nphases=1):
|
|
|
|
inti = dfi.Interface(a, ba, d, nphases)
|
2012-02-17 17:50:10 -05:00
|
|
|
self.slave = dfi.Interface(a, ba, d, nphases)
|
|
|
|
self.master = dfi.Interface(a, ba, d, nphases)
|
|
|
|
|
2014-08-08 09:56:35 -04:00
|
|
|
self._control = CSRStorage(4) # sel, cke, odt, reset_n
|
2012-02-17 17:50:10 -05:00
|
|
|
|
2013-03-10 14:32:38 -04:00
|
|
|
for n, phase in enumerate(inti.phases):
|
|
|
|
setattr(self.submodules, "pi" + str(n), PhaseInjector(phase))
|
|
|
|
|
|
|
|
###
|
2012-02-17 17:50:10 -05: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")]
|