cores/hyperbus: Simplify #1288 and add parameter retro-compatibility.

sys_clk_freq is set to 10e6 when passed to None.
This commit is contained in:
Florent Kermarrec 2022-05-02 16:43:02 +02:00
parent 25e7569cd1
commit 8f63a64a86
1 changed files with 13 additions and 29 deletions

View File

@ -7,7 +7,7 @@
# SPDX-License-Identifier: BSD-2-Clause # SPDX-License-Identifier: BSD-2-Clause
from migen import * from migen import *
from migen.genlib.misc import timeline from migen.genlib.misc import WaitTimer
from litex.build.io import DifferentialOutput from litex.build.io import DifferentialOutput
@ -16,6 +16,7 @@ from litex.soc.interconnect import wishbone
# HyperRAM ----------------------------------------------------------------------------------------- # HyperRAM -----------------------------------------------------------------------------------------
class HyperRAM(Module): class HyperRAM(Module):
tCSM = 4e-6
"""HyperRAM """HyperRAM
Provides a very simple/minimal HyperRAM core that should work with all FPGA/HyperRam chips: Provides a very simple/minimal HyperRAM core that should work with all FPGA/HyperRam chips:
@ -24,7 +25,7 @@ class HyperRAM(Module):
This core favors portability and ease of use over performance. This core favors portability and ease of use over performance.
""" """
def __init__(self, frequency, pads, latency=6, Tcsm=4e-6): def __init__(self, pads, latency=6, sys_clk_freq=None):
self.pads = pads self.pads = pads
self.bus = bus = wishbone.Interface() self.bus = bus = wishbone.Interface()
@ -61,24 +62,10 @@ class HyperRAM(Module):
else: else:
self.specials += DifferentialOutput(clk, pads.clk_p, pads.clk_n) self.specials += DifferentialOutput(clk, pads.clk_p, pads.clk_n)
# Timeout counter -------------------------------------------------------------------------- # Burst Timer ------------------------------------------------------------------------------
timeout_value = int(Tcsm * frequency) sys_clk_freq = 10e6 if sys_clk_freq is None else sys_clk_freq
timeout_cnt = Signal(32) burst_timer = WaitTimer(int(sys_clk_freq*self.tCSM))
timeout_rst = Signal() self.submodules += burst_timer
timeout = Signal()
self.sync += [
If(timeout_rst,
timeout_cnt.eq(0),
timeout.eq(0)
).Else(
If(timeout_cnt < timeout_value,
timeout_cnt.eq(timeout_cnt + 1)
).Else(
timeout.eq(1)
)
),
]
# Clock Generation (sys_clk/4) ------------------------------------------------------------- # Clock Generation (sys_clk/4) -------------------------------------------------------------
self.sync += clk_phase.eq(clk_phase + 1) self.sync += clk_phase.eq(clk_phase + 1)
@ -141,7 +128,6 @@ class HyperRAM(Module):
first = Signal() first = Signal()
self.submodules.fsm = fsm = FSM(reset_state="IDLE") self.submodules.fsm = fsm = FSM(reset_state="IDLE")
fsm.act("IDLE", fsm.act("IDLE",
timeout_rst.eq(1),
NextValue(first, 1), NextValue(first, 1),
If(bus.cyc & bus.stb, If(bus.cyc & bus.stb,
If(clk_phase == 0, If(clk_phase == 0,
@ -159,9 +145,7 @@ class HyperRAM(Module):
# Wait for 6*2 cycles... # Wait for 6*2 cycles...
If(cycles == (6*2 - 1), If(cycles == (6*2 - 1),
NextState("WAIT-LATENCY") NextState("WAIT-LATENCY")
), )
# Always check if bus cycle is still active
If(~bus.cyc, NextState("IDLE"))
) )
fsm.act("WAIT-LATENCY", fsm.act("WAIT-LATENCY",
# Set CSn. # Set CSn.
@ -173,13 +157,13 @@ class HyperRAM(Module):
# Early Write Ack (to allow bursting). # Early Write Ack (to allow bursting).
bus.ack.eq(bus.we), bus.ack.eq(bus.we),
NextState("READ-WRITE-DATA0") NextState("READ-WRITE-DATA0")
), )
# Always check if bus cycle is still active
If(~bus.cyc, NextState("IDLE"))
) )
states = {8:4, 16:2}[dw] states = {8:4, 16:2}[dw]
for n in range(states): for n in range(states):
fsm.act(f"READ-WRITE-DATA{n}", fsm.act(f"READ-WRITE-DATA{n}",
# Enable Burst Timer.
burst_timer.wait.eq(1),
# Set CSn. # Set CSn.
cs.eq(1), cs.eq(1),
# Send Data on DQ/RWDS (for write). # Send Data on DQ/RWDS (for write).
@ -196,13 +180,13 @@ class HyperRAM(Module):
If(n == (states - 1), If(n == (states - 1),
NextValue(first, 0), NextValue(first, 0),
# Continue burst when a consecutive access is ready. # Continue burst when a consecutive access is ready.
If(bus.stb & bus.cyc & (bus.we == bus_we) & (bus.adr == (bus_adr + 1)) & ~timeout, If(bus.stb & bus.cyc & (bus.we == bus_we) & (bus.adr == (bus_adr + 1)) & (~burst_timer.done),
# Latch Bus. # Latch Bus.
bus_latch.eq(1), bus_latch.eq(1),
# Early Write Ack (to allow bursting). # Early Write Ack (to allow bursting).
bus.ack.eq(bus.we) bus.ack.eq(bus.we)
# Else end the burst. # Else end the burst.
).Elif(bus_we | ~first, ).Elif(bus_we | (~first) | burst_timer.done,
NextState("IDLE") NextState("IDLE")
) )
), ),