Skip to content

Commit

Permalink
soc/core/hyperbus: Report Clk Ratio on Status register and use it in …
Browse files Browse the repository at this point in the history
…software to configure latency.
  • Loading branch information
enjoy-digital committed Aug 21, 2024
1 parent 5587f59 commit ecd9eee
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
44 changes: 27 additions & 17 deletions litex/soc/cores/hyperbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,6 @@ def __init__(self, pads, latency=6, latency_mode="variable", sys_clk_freq=10e6,
self.pads = pads
self.bus = bus = wishbone.Interface(data_width=32, address_width=32, addressing="word")

# Config/Reg Interface.
# ---------------------
self.conf_rst = Signal()
self.conf_latency = Signal(8, reset=latency)
self.stat_latency_mode = Signal(reset={"fixed": 0, "variable": 1}[latency_mode])
self.reg_write = Signal()
self.reg_read = Signal()
self.reg_addr = Signal(2)
self.reg_write_done = Signal()
self.reg_read_done = Signal()
self.reg_write_data = Signal(16)
self.reg_read_data = Signal(16)
if with_csr:
self.add_csr(default_latency=latency)

# # #

# Parameters.
Expand All @@ -80,6 +65,21 @@ def __init__(self, pads, latency=6, latency_mode="variable", sys_clk_freq=10e6,
}[clk_ratio]
self.sync_io = sync_io = getattr(self.sync, cd_io)

# Config/Reg Interface.
# ---------------------
self.conf_rst = Signal()
self.conf_latency = Signal(8, reset=latency)
self.stat_latency_mode = Signal(reset={"fixed": 0, "variable": 1}[latency_mode])
self.reg_write = Signal()
self.reg_read = Signal()
self.reg_addr = Signal(2)
self.reg_write_done = Signal()
self.reg_read_done = Signal()
self.reg_write_data = Signal(16)
self.reg_read_data = Signal(16)
if with_csr:
self.add_csr(default_latency=latency)

# Internal Signals.
# -----------------
clk = Signal()
Expand Down Expand Up @@ -411,9 +411,19 @@ def add_csr(self, default_latency=6):
CSRField("latency_mode", offset=0, size=1, values=[
("``0b0``", "Fixed Latency."),
("``0b1``", "Variable Latency."),
])
]),
CSRField("clk_ratio", offset=1, size=4, values=[
("``4``", "HyperRAM Clk = Sys Clk/4."),
("``2``", "HyperRAM Clk = Sys Clk/2."),
]),
])
self.comb += self.status.fields.latency_mode.eq(self.stat_latency_mode)
self.comb += [
self.status.fields.latency_mode.eq(self.stat_latency_mode),
self.status.fields.clk_ratio.eq({
"sys" : 4,
"sys2x": 2,
}[self.cd_io]),
]

# Reg Interface.
# --------------
Expand Down
7 changes: 5 additions & 2 deletions litex/soc/software/libbase/hyperram.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ static uint16_t hyperram_get_chip_latency_setting(uint32_t clk_freq) {

static void hyperram_configure_latency(void) {
uint16_t config_reg_0 = 0x8f2f;
uint8_t core_clk_ratio;
uint16_t core_latency_setting;
uint16_t chip_latency_setting;

/* Compute Latency settings */
core_latency_setting = hyperram_get_core_latency_setting(CONFIG_CLOCK_FREQUENCY/2);
chip_latency_setting = hyperram_get_chip_latency_setting(CONFIG_CLOCK_FREQUENCY/2);
core_clk_ratio = (hyperram_status_read() >> CSR_HYPERRAM_STATUS_CLK_RATIO_OFFSET & 0xf);
printf("HyperRAM Clk Ratio %d:1.\n", core_clk_ratio);
core_latency_setting = hyperram_get_core_latency_setting(CONFIG_CLOCK_FREQUENCY/core_clk_ratio);
chip_latency_setting = hyperram_get_chip_latency_setting(CONFIG_CLOCK_FREQUENCY/core_clk_ratio);

/* Write Latency to HyperRAM Core */
printf("HyperRAM Core Latency: %d CK (X1).\n", core_latency_setting);
Expand Down

0 comments on commit ecd9eee

Please sign in to comment.