lpddr4/utils: rework `once` helper function to be more generic

This commit is contained in:
Jędrzej Boczar 2021-02-15 16:33:04 +01:00
parent 4473335954
commit 1b65e858b3
2 changed files with 11 additions and 15 deletions

View File

@ -9,7 +9,7 @@ from litex.soc.interconnect.stream import ClockDomainCrossing
from litex.soc.interconnect.csr import AutoCSR from litex.soc.interconnect.csr import AutoCSR
from litedram.common import TappedDelayLine, tXXDController from litedram.common import TappedDelayLine, tXXDController
from litedram.phy.lpddr4.utils import delayed, once, SimLogger from litedram.phy.lpddr4.utils import delayed, edge, SimLogger
from litedram.phy.lpddr4.commands import MPC from litedram.phy.lpddr4.commands import MPC
@ -75,14 +75,11 @@ class PulseTiming(Module):
tctrl = tXXDController(t) tctrl = tXXDController(t)
self.submodules += tctrl self.submodules += tctrl
self.sync += [ self.sync += If(self.trigger, triggered.eq(1)),
If(self.trigger, triggered.eq(1)),
ready_d.eq(tctrl.ready),
]
self.comb += [ self.comb += [
self.ready.eq(triggered & tctrl.ready), self.ready.eq(triggered & tctrl.ready),
self.ready_p.eq(self.ready & ~ready_d), self.ready_p.eq(edge(self, self.ready)),
once(self, self.trigger, tctrl.valid.eq(1)), tctrl.valid.eq(edge(self, self.trigger)),
] ]
@ -223,7 +220,7 @@ class CommandsSim(Module, AutoCSR): # clock domain: clk_p
fsm.act("NORMAL", fsm.act("NORMAL",
cmds_enabled.eq(1), cmds_enabled.eq(1),
self.tzqlat.trigger.eq(1), self.tzqlat.trigger.eq(1),
once(self, init_delays & self.handle_cmd & ~self.tzqlat.ready, If(init_delays & self.handle_cmd & ~self.tzqlat.ready,
self.log.warn("tZQLAT violated") self.log.warn("tZQLAT violated")
), ),
) )

View File

@ -24,10 +24,11 @@ def delayed(mod, sig, cycles=1, **kwargs):
mod.submodules += delay mod.submodules += delay
return delay.output return delay.output
def once(mod, cond, *ops): def edge(mod, cond):
sig = Signal() """Get a signal that is high on a rising edge of `cond`"""
mod.sync += If(cond, sig.eq(1)) cond_d = Signal()
return If(~sig & cond, *ops) mod.sync += cond_d.eq(cond)
return ~cond_d & cond
class ConstBitSlip(Module): class ConstBitSlip(Module):
def __init__(self, dw, i=None, o=None, slp=None, cycles=1): def __init__(self, dw, i=None, o=None, slp=None, cycles=1):
@ -203,9 +204,7 @@ class SimLogger(Module, AutoCSR):
def log(self, fmt, *args, level=DEBUG, once=True): def log(self, fmt, *args, level=DEBUG, once=True):
cond = Signal() cond = Signal()
if once: # make the condition be triggered only on rising edge if once: # make the condition be triggered only on rising edge
cond_d = Signal() condition = edge(self, cond)
self.sync += cond_d.eq(cond)
condition = ~cond_d & cond
else: else:
condition = cond condition = cond