Skip to content

Commit

Permalink
phy: Rework data_i_ce sampling logic (was too complicated and off by …
Browse files Browse the repository at this point in the history
…one cycle).
  • Loading branch information
enjoy-digital committed Sep 2, 2024
1 parent fefee15 commit 5f0250d
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions litesdcard/phy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# SPDX-License-Identifier: BSD-2-Clause

from migen import *
from migen.genlib.cdc import MultiReg
from migen.genlib.resetsync import AsyncResetSynchronizer

from litex.gen import *
Expand Down Expand Up @@ -505,17 +506,16 @@ def __init__(self, sys_clk_freq, data_timeout):
# SDCard PHY IO ------------------------------------------------------------------------------------

class SDPHYIO(LiteXModule):
def __init__(self, clocker, sdpads, round_trip_latency=2):
# Generate a data_i_ce pulse round_trip_latency cycles after clocker.clk goes high so that
# the data input effectively get sampled on the first sys_clk after the SDCard clk goes high.
clocker_clk_delay = Signal(round_trip_latency)
self.sync += clocker_clk_delay.eq(Cat(clocker.clk, clocker_clk_delay))
self.sync += sdpads.data_i_ce.eq(clocker_clk_delay[-1] & ~clocker_clk_delay[-2])

def add_data_i_ce(self, clocker, sdpads):
# Sample Data on first Sys Clk after SDCard Clk rising edge.
clk_i = Signal()
clk_i_d = Signal()
self.specials += MultiReg(~clocker.clk, clk_i, n=2, odomain="sys") # n = 2 = SDROutput + SDRTristate delay.
self.sync += clk_i_d.eq(clk_i)
self.comb += sdpads.data_i_ce.eq(clk_i & ~clk_i_d) # Rising Edge.

class SDPHYIOGen(SDPHYIO):
def __init__(self, clocker, sdpads, pads):
SDPHYIO.__init__(self, clocker, sdpads, round_trip_latency=2)
# Rst
if hasattr(pads, "rst"):
self.comb += pads.rst.eq(0)
Expand Down Expand Up @@ -545,6 +545,7 @@ def __init__(self, clocker, sdpads, pads):
oe = sdpads.data.oe,
i = sdpads.data.i[i],
)
self.add_data_i_ce(clocker, sdpads)

# Direction (optional)
if hasattr(pads, "cmd_dir"):
Expand All @@ -570,7 +571,6 @@ def __init__(self, clocker, sdpads, pads):

class SDPHYIOEmulator(SDPHYIO):
def __init__(self, clocker, sdpads, pads):
SDPHYIO.__init__(self, clocker, sdpads, round_trip_latency=2) # FIXME: check round_trip_latency.
# Clk
self.comb += pads.clk.eq(clocker.clk)

Expand All @@ -588,6 +588,7 @@ def __init__(self, clocker, sdpads, pads):
If(sdpads.data.oe, pads.dat_i.eq(sdpads.data.o)),
sdpads.data.i.eq(0b1111),
]
self.data_i_ce(clocker, sdpads)
for i in range(4):
self.comb += If(~pads.dat_t[i], sdpads.data.i[i].eq(pads.dat_o[i]))

Expand Down

0 comments on commit 5f0250d

Please sign in to comment.