Skip to content

Commit

Permalink
soc/cores/hyperbus: Simplify CS and make it synchronous to allow IO Reg.
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoy-digital committed Aug 20, 2024
1 parent 1998c74 commit eb29b40
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions litex/soc/cores/hyperbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,8 @@ def __init__(self, pads, latency=6, latency_mode="variable", sys_clk_freq=10e6,
self.sync += pads.rst_n.eq(1 & ~self.conf_rst)

# CSn.
self.comb += [
# Set reset value.
pads.cs_n.eq(2**len(pads.cs_n)),
# Set CSn.
pads.cs_n[0].eq(~cs)
]
pads.cs_n.reset = 2**len(pads.cs_n) - 1
self.sync += pads.cs_n[0].eq(~cs) # Only supporting 1 CS.

# Clk.
pads_clk = Signal()
Expand All @@ -144,7 +140,7 @@ def __init__(self, pads, latency=6, latency_mode="variable", sys_clk_freq=10e6,
clk_phase.eq(clk_phase + 1)
).Else(
# Else set Clk Phase to default value.
clk_phase.eq(0b01)
clk_phase.eq(0b00)
)
]
cases = {
Expand Down Expand Up @@ -254,8 +250,6 @@ def __init__(self, pads, latency=6, latency_mode="variable", sys_clk_freq=10e6,
)
)
fsm.act("SEND-COMMAND-ADDRESS",
# Set CSn.
cs.eq(1),
# Send Command on DQ.
ca_oe.eq(1),
dq_oe.eq(1),
Expand All @@ -272,8 +266,6 @@ def __init__(self, pads, latency=6, latency_mode="variable", sys_clk_freq=10e6,
)
)
fsm.act("REG-WRITE-0",
# Set CSn.
cs.eq(1),
# Send Reg on DQ.
ca_oe.eq(1),
dq_oe.eq(1),
Expand All @@ -284,8 +276,6 @@ def __init__(self, pads, latency=6, latency_mode="variable", sys_clk_freq=10e6,
)
)
fsm.act("REG-WRITE-1",
# Set CSn.
cs.eq(1),
# Send Reg on DQ.
ca_oe.eq(1),
dq_oe.eq(1),
Expand All @@ -297,8 +287,6 @@ def __init__(self, pads, latency=6, latency_mode="variable", sys_clk_freq=10e6,
)
)
fsm.act("WAIT-LATENCY",
# Set CSn.
cs.eq(1),
# Wait for 1X or 2X Latency cycles... (-4 since count start in the middle of the command).
If(((cycles == 2*(self.conf_latency * 4) - 4 - 1) & refresh) | # 2X Latency (No DRAM refresh required).
((cycles == 1*(self.conf_latency * 4) - 4 - 1) & ~refresh) , # 1X Latency ( DRAM refresh required).
Expand All @@ -316,8 +304,6 @@ def __init__(self, pads, latency=6, latency_mode="variable", sys_clk_freq=10e6,
fsm.act(f"READ-WRITE-DATA{n}",
# Enable Burst Timer.
burst_timer.wait.eq(1),
# Set CSn.
cs.eq(1),
ca_oe.eq(reg_read_req),
# Send Data on DQ/RWDS (for write).
If(bus_we,
Expand Down Expand Up @@ -356,6 +342,13 @@ def __init__(self, pads, latency=6, latency_mode="variable", sys_clk_freq=10e6,
)
)
)

# CS --------------------------------------------------------------------------------------
self.comb += If(~fsm.ongoing("IDLE"), cs.eq(1)) # CS when not in IDLE state.
self.comb += If(fsm.before_leaving("IDLE"), cs.eq(1)) # Early Set.
self.comb += If(fsm.before_entering("IDLE"), cs.eq(0)) # Early Clr.

# FSM Cycles -------------------------------------------------------------------------------
fsm.finalize()
self.sync += cycles.eq(cycles + 1)
self.sync += If(fsm.next_state != fsm.state, cycles.eq(0))
Expand Down

0 comments on commit eb29b40

Please sign in to comment.