ck = self.phy.ck
clk_phase = Signal(2)
+ ck_active = Signal()
cs = self.phy.cs
ca = Signal(48)
ca_active = Signal()
sync += clk_phase.eq(clk_phase + 1)
with m.Switch(clk_phase):
with m.Case(1):
- sync += ck.eq(cs)
+ sync += ck.eq(ck_active)
with m.Case(3):
sync += ck.eq(0)
bus_we = Signal()
bus_sel = Signal(4)
bus_latch = Signal()
+ cs_latch = Signal.like(cs)
with m.If(bus_latch):
with m.If(bus.we):
sync += sr.eq(Cat(Const(0, 16), bus.dat_w))
sync += [ bus_we.eq(bus.we),
bus_sel.eq(bus.sel),
- bus_adr.eq(bus.adr)
+ bus_adr.eq(bus.adr),
+ cs_latch.eq(cs)
]
with m.State("SEND-COMMAND-ADDRESS"):
sync += cycles.eq(cycles+1)
comb += cs.eq(1) # Set CSn.
+ comb += ck_active.eq(1) # Activate clock
comb += ca_active.eq(1) # Send Command on DQ.
comb += dq_oe.eq(1), # Wait for 6*2 cycles...
with m.If(cycles == (6*2 - 1)):
with m.State("WAIT-LATENCY"):
sync += cycles.eq(cycles+1)
- comb += cs.eq(1) # Set CSn.
+ comb += cs.eq(1) # Set CSn directly (not via latch)
+ comb += ck_active.eq(1) # Activate clock
# Wait for Latency cycles...
with m.If(cycles == (latency_cycles - 1)):
- comb += bus_latch.eq(1) # Latch Bus.
+ comb += bus_latch.eq(1) # Latch Bus (and cs)
# Early Write Ack (to allow bursting).
comb += bus.ack.eq(bus.we)
m.next = "READ-WRITE-DATA0"
for n in range(states):
with m.State("READ-WRITE-DATA%d" % n):
sync += cycles.eq(cycles+1)
- comb += cs.eq(1), # Set CSn.
+ comb += cs.eq(cs_latch), # Set CSn from Latch
+ comb += ck_active.eq(1) # Activate clock
# Send Data on DQ/RWDS (for write).
with m.If(bus_we):
comb += dq_oe.eq(1)
with m.If(bus.stb & bus.cyc &
(bus.we == bus_we) &
(bus.adr == (bus_adr + 1))):
- comb += bus_latch.eq(1), # Latch Bus.
+ comb += bus_latch.eq(1), # Latch Bus (and cs)
# Early Write Ack (to allow bursting).
comb += bus.ack.eq(bus.we)
# Else end the burst.
with m.Elif(bus_we | nfirst):
m.next = "IDLE"
- sync += cycles.eq(0)
+ sync += cycles.eq(0) # reset to start
+ sync += cs_latch.eq(0) # helps debugging
# Read Ack (when dat_r ready).
if n == 0:
comb += bus.ack.eq(nfirst & ~bus_we)