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ß <f.maass@vogl-electronic.com>
  • Loading branch information
maass-hamburg committed Nov 15, 2024
1 parent dcd9c19 commit d98c742
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
27 changes: 27 additions & 0 deletions litespi/cscontrol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# This file is part of LiteSPI
#
# Copyright (c) 2024 Fin Maaß <f.maass@vogl-electronic.com>
# SPDX-License-Identifier: BSD-2-Clause

from migen import *

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

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)) & cs))

self.specials += SDROutput(
i = cs_n,
o = pads.cs_n
)
16 changes: 4 additions & 12 deletions litespi/phy/generic_ddr.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

from litespi.common import *
from litespi.clkgen import DDRLiteSPIClkGen
from litespi.cscontrol import LiteSPICSControl

from litex.soc.interconnect import stream

from litex.build.io import DDRTristate, SDROutput
from litex.build.io import DDRTristate

# LiteSPI DDR PHY Core -----------------------------------------------------------------------------

Expand Down Expand Up @@ -73,16 +74,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 +135,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
16 changes: 3 additions & 13 deletions litespi/phy/generic_sdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

from litex.gen import *

from litex.gen.genlib.misc import WaitTimer

from litespi.common import *
from litespi.clkgen import LiteSPIClkGen
from litespi.cscontrol import LiteSPICSControl

from litex.soc.interconnect import stream
from litex.soc.interconnect.csr import *
Expand Down Expand Up @@ -92,16 +91,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 +155,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 d98c742

Please sign in to comment.