Skip to content

Commit

Permalink
phy: use common cs control for sdr and ddr
Browse files Browse the repository at this point in the history
use common cs control for sdr and ddr

Signed-off-by: Fin Maaß <[email protected]>
  • Loading branch information
maass-hamburg committed Nov 14, 2024
1 parent dcd9c19 commit 9ac685b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
22 changes: 22 additions & 0 deletions litespi/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
from migen import *
from migen.genlib.cdc import MultiReg

from litex.gen import *
from litex.gen.genlib.misc import WaitTimer
from litex.build.io import SDROutput

# Core <-> PHY Layouts -----------------------------------------------------------------------------

"""
Expand Down Expand Up @@ -41,3 +45,21 @@ def __init__(self, src, dst, clock_domain):
self.comb += dst.eq(src)
else:
self.specials += MultiReg(src, dst, clock_domain)

# LiteSPI CS Control -------------------------------------------------------------------------------

class LiteSPICSControl(LiteXModule):
def __init__(self, pads, cs, cs_delay):
self.enable = enable = Signal()
cs_n = Signal().like(pads.cs_n)

self.timer = timer = WaitTimer(cs_delay + 1) # Ensure cs_delay cycles between XFers.

self.comb += timer.wait.eq(cs != 0)
self.comb += enable.eq(timer.done)
self.comb += cs_n.eq(~(Replicate(enable, len(pads.cs_n)) & self.cs))

self.specials += SDROutput(
i = cs_n,
o = pads.cs_n
)
13 changes: 2 additions & 11 deletions litespi/phy/generic_ddr.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,7 @@ def __init__(self, pads, flash, cs_delay, extra_latency=0):
self.clkgen = clkgen = DDRLiteSPIClkGen(pads)

# CS control.
self.cs_timer = cs_timer = WaitTimer(cs_delay + 1) # Ensure cs_delay cycles between XFers.
cs_enable = Signal()
self.comb += cs_timer.wait.eq(self.cs != 0)
self.comb += cs_enable.eq(cs_timer.done)
cs_n = Signal().like(pads.cs_n)
self.comb += cs_n.eq(~(Replicate(cs_enable, len(pads.cs_n)) & self.cs))
self.specials += SDROutput(
i = cs_n,
o = pads.cs_n
)
self.cs_control = cs_control = LiteSPICSControl(pads, self.cs, cs_delay)

dq_o = Array([Signal(len(pads.dq)) for _ in range(2)])
dq_i = Array([Signal(len(pads.dq)) for _ in range(2)])
Expand Down Expand Up @@ -143,7 +134,7 @@ def __init__(self, pads, flash, cs_delay, extra_latency=0):
# Stop Clk.
NextValue(clkgen.en, 0),
# Wait for CS and a CMD from the Core.
If(cs_enable & sink.valid,
If(cs_control.enable & sink.valid,
# Load Shift Register Count/Data Out.
NextValue(sr_cnt, sink.len - sink.width),
sr_out_load.eq(1),
Expand Down
13 changes: 2 additions & 11 deletions litespi/phy/generic_sdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,7 @@ def __init__(self, pads, flash, device, clock_domain, default_divisor, cs_delay)
self.comb += clkgen.div.eq(spi_clk_divisor)

# CS control.
self.cs_timer = cs_timer = WaitTimer(cs_delay + 1) # Ensure cs_delay cycles between XFers.
cs_enable = Signal()
self.comb += cs_timer.wait.eq(self.cs != 0)
self.comb += cs_enable.eq(cs_timer.done)
cs_n = Signal().like(pads.cs_n)
self.comb += cs_n.eq(~(Replicate(cs_enable, len(pads.cs_n)) & self.cs))
self.specials += SDROutput(
i = cs_n,
o = pads.cs_n
)
self.cs_control = cs_control = LiteSPICSControl(pads, self.cs, cs_delay)

if hasattr(pads, "mosi"):
dq_o = Signal()
Expand Down Expand Up @@ -165,7 +156,7 @@ def __init__(self, pads, flash, device, clock_domain, default_divisor, cs_delay)
self.fsm = fsm = FSM(reset_state="WAIT-CMD-DATA")
fsm.act("WAIT-CMD-DATA",
# Wait for CS and a CMD from the Core.
If(cs_enable & sink.valid,
If(cs_control.enable & sink.valid,
# Load Shift Register Count/Data Out.
NextValue(sr_cnt, sink.len - sink.width),
NextValue(dq_oe, sink.mask),
Expand Down

0 comments on commit 9ac685b

Please sign in to comment.