# Hello world
MEMORY_SIZE=8192
-RAM_INIT_FILE=hello_world/hello_world.bin
+#RAM_INIT_FILE=hello_world/hello_world.bin
RAM_INIT_FILE=coldboot/coldboot.bin
SIM_MAIN_BRAM=false
ifeq ($(FPGA_TARGET), verilator)
RESET_LOW=true
-CLK_INPUT=50000000
-CLK_FREQUENCY=50000000
+CLK_INPUT=100000000
+CLK_FREQUENCY=100000000
clkgen=fpga/clk_gen_bypass.vhd
endif
# a multiplier factor on sleep loops. this allows simulations to run
# at much shorter intervals
-LONG_TIMER_MULT ?= 100000
-SHORT_TIMER_MULT ?= 1000
+LONG_TIMER_MULT ?= 10000
+SHORT_TIMER_MULT ?= 100
#LONG_TIMER_MULT ?= 1
#SHORT_TIMER_MULT ?= 1
}
int main(void) {
- const int kNumIterations = 65536;
+ const int kNumIterations = 14;
int res, failcnt = 0;
uint32_t tmp;
volatile uint32_t *ram = DRAM_BASE;
console_init();
- puts("Firmware launched...\n");
+ //puts("Firmware launched...\n");
puts("DRAM init... ");
struct gramCtx ctx;
.mode_registers = {
0x320, 0x6, 0x200, 0x0
},
- .rdly_p0 = 2,
- .rdly_p1 = 2,
+ .rdly_p0 = 0,
+ .rdly_p1 = 0,
};
struct gramProfile profile2;
gram_init(&ctx, &profile, (void*)DRAM_BASE, //0x10000000,
(void*)DRAM_INIT_BASE); //0x00008000);
puts("done\n");
+#if 0
+ // quick write/read
+ writel(0xDEAF0000, (unsigned long)&(ram[0]));
+ tmp = readl((unsigned long)&(ram[0]));
+ puts("read ");
+ uart_writeuint32(tmp);
+
+ return 0;
+#endif
+
+#if 0
puts("Rdly\np0: ");
for (size_t i = 0; i < 8; i++) {
profile2.rdly_p0 = i;
gram_load_calibration(&ctx, &profile2);
- puts("loaded ");
gram_reset_burstdet(&ctx);
- puts("burstreset ");
+
for (size_t j = 0; j < 128; j++) {
- tmp = readl((unsigned long)&ram[i]);
+ tmp = readl((unsigned long)&(ram[i]));
}
if (gram_read_burstdet(&ctx, 0)) {
puts("1");
for (size_t i = 0; i < 8; i++) {
profile2.rdly_p1 = i;
gram_load_calibration(&ctx, &profile2);
- puts("loaded ");
gram_reset_burstdet(&ctx);
- puts("burstreset ");
for (size_t j = 0; j < 128; j++) {
- tmp = readl((unsigned long)&ram[i]);
+ tmp = readl((unsigned long)&(ram[i]));
}
if (gram_read_burstdet(&ctx, 1)) {
puts("1");
}
puts("done\n");
+#endif
+
puts("Auto calibration profile:");
puts("p0 rdly:");
uart_writeuint32(profile2.rdly_p0);
puts("DRAM test... \n");
for (size_t i = 0; i < kNumIterations; i++) {
- ram[i] = 0xDEAF0000 | i*4;
+ writel(0xDEAF0000 | i*4, (unsigned long)&(ram[i]));
}
for (size_t i = 0; i < kNumIterations; i++) {
- if (ram[i] != (0xDEAF0000 | i*4)) {
+ if (readl((unsigned long)&(ram[i])) != (0xDEAF0000 | i*4)) {
puts("fail : *(0x");
uart_writeuint32(&ram[i]);
puts(") = ");
uart_writeuint32(ram[i]);
- putchar('\n');
+ puts("\n");
failcnt++;
if (failcnt > 10) {
}
puts("done\n");
- while (1);
-
return 0;
}
}
. = ALIGN(0x1000);
.text : { *(.text) *(.text.*) *(.rodata) *(.rodata.*) }
- . = ALIGN(0x1000);
+ . = ALIGN(0x10);
.data : { *(.data) *(.data.*) *(.got) *(.toc) }
- . = ALIGN(0x80);
+ . = ALIGN(0x10);
__bss_start = .;
.bss : {
*(.dynsbss)
*(.common)
*(.bss.*)
}
- . = ALIGN(0x80);
+ . = ALIGN(0x10);
__bss_end = .;
- . = . + 0x4000;
+ . = . + 0x5000;
__stack_top = .;
}
int putchar(int c)
{
+ return c;
if (uart_is_std) {
while(std_uart_tx_full())
/* Do Nothing */;
profile->rdly_p0 = rdly;
gram_load_calibration(ctx, profile);
gram_reset_burstdet(ctx);
- puts("reset burst");
+ //puts("reset burst");
for (i = 0; i < 128; i++) {
- tmp = readl(&ram[i]);
+ tmp = readl((unsigned long)&(ram[i]));
}
- puts("read burst?");
+ //puts("read burst?");
if (gram_read_burstdet(ctx, 0)) {
min_rdly_p0 = rdly;
break;
gram_reset_burstdet(ctx);
for (i = 0; i < 128; i++) {
- tmp = readl(&ram[i]);
+ tmp = readl((unsigned long)&(ram[i]));
}
if (!gram_read_burstdet(ctx, 0)) {
gram_reset_burstdet(ctx);
for (i = 0; i < 128; i++) {
- tmp = readl(&ram[i]);
+ tmp = readl((unsigned long)&(ram[i]));
}
if (!gram_read_burstdet(ctx, 1)) {
void gram_load_calibration(const struct gramCtx *ctx, const struct gramProfile *profile) {
dfii_setsw(ctx, true);
- puts("set rdly 0?");
set_rdly(ctx, 0, profile->rdly_p0);
- puts("set rdly 1?");
set_rdly(ctx, 1, profile->rdly_p1);
- puts("set hw");
dfii_setsw(ctx, false);
}
#endif
}
+void dfii_rst(const struct gramCtx *ctx) {
+ dfii_setcontrol(ctx, DFII_CONTROL_ODT| DFII_CONTROL_RESET);
+}
+
void dfii_setsw(const struct gramCtx *ctx, bool software_control) {
if (software_control) {
dfii_setcontrol(ctx, DFII_CONTROL_CKE|DFII_CONTROL_ODT|
#ifdef GRAM_RW_FUNC
gram_write(ctx, (void*)&(ctx->core->phases[0].address), val);
#else
- writel(val, (unsigned long)&ctx->core->phases[0].address);
+ writel(val, (unsigned long)&(ctx->core->phases[0].address));
#endif
}
#ifdef GRAM_RW_FUNC
gram_write(ctx, (void*)&(ctx->core->phases[0].baddress), val);
#else
- writel(val, (unsigned long)&ctx->core->phases[0].baddress);
+ writel(val, (unsigned long)&(ctx->core->phases[0].baddress));
#endif
}
gram_write(ctx, (void*)&(ctx->core->phases[0].command), cmd);
gram_write(ctx, (void*)&(ctx->core->phases[0].command_issue), 1);
#else
- writel(cmd, (unsigned long)&ctx->core->phases[0].command);
- writel(1, (unsigned long)&ctx->core->phases[0].command_issue);
+ writel(cmd, (unsigned long)&(ctx->core->phases[0].command));
+ writel(1, (unsigned long)&(ctx->core->phases[0].command_issue));
#endif
}
/* Release reset */
dfii_set_p0_address(ctx, 0x0);
dfii_set_p0_baddress(ctx, 0);
- dfii_setcontrol(ctx, DFII_CONTROL_ODT);
+ dfii_setcontrol(ctx, DFII_CONTROL_ODT|DFII_CONTROL_RESET);
cdelay(5*LONG_TIMER_MULT);
/* Bring CKE high */
dfii_set_p0_address(ctx, 0x0);
dfii_set_p0_baddress(ctx, 0);
- dfii_setcontrol(ctx, DFII_CONTROL_CKE|DFII_CONTROL_ODT);
+ dfii_setcontrol(ctx, DFII_CONTROL_CKE|DFII_CONTROL_ODT|DFII_CONTROL_RESET);
cdelay(1*LONG_TIMER_MULT);
/* Load Mode Register 2, CWL=5 */
#define DFII_COMMAND_RAS (1 << 3)
#define DFII_COMMAND_WRDATA (1 << 4)
+void dfii_reset(const struct gramCtx *ctx);
void dfii_setsw(const struct gramCtx *ctx, bool software_control);
void dfii_initseq(const struct gramCtx *ctx, const struct gramProfile *profile);
void dfii_set_p0_address(const struct gramCtx *ctx, uint32_t val);
#include <gram.h>
#include "dfii.h"
#include "console.h"
+#include "hw_regs.h"
+#include "helpers.h"
+
+extern void uart_writeuint32(uint32_t val);
int gram_init(struct gramCtx *ctx, const struct gramProfile *profile, void *ddr_base, void *core_base, void *phy_base) {
ctx->ddr_base = ddr_base;
ctx->core = core_base;
ctx->phy = phy_base;
+ //puts("phy base");
+ //uart_writeuint32((unsigned long)&(ctx->phy));
+ //puts("bdet");
+ //uart_writeuint32((unsigned long)&(ctx->phy->burstdet));
+
+ //dfii_reset(ctx);
+ //puts("reset\n");
dfii_setsw(ctx, true);
- puts("dfii_setsw\n");
+ //puts("dfii_setsw\n");
dfii_initseq(ctx, profile);
puts("initseq\n");
gram_load_calibration(ctx, profile);
- puts("cal");
- dfii_setsw(ctx, false);
return GRAM_ERR_NONE;
}
# ibus dbus
# | |
# +--+--+
- # |
+ # |
# 64to32DownCvt
# |
# arbiter
self.dramcore = drs(dramcore)
self._decoder.add(self.dramcore.bus, addr=dramcore_addr)
- # map the DRAM onto Wishbone
- drambone = gramWishbone(dramcore)
+ # map the DRAM onto Wishbone, XXX use stall but set classic below
+ drambone = gramWishbone(dramcore, features={'stall'})
if fpga == 'sim':
self.drambone = drambone
else:
if hasattr(self, "ddrphy"):
m.submodules.ddrphy = self.ddrphy
m.submodules.dramcore = self.dramcore
- m.submodules.drambone = self.drambone
+ m.submodules.drambone = drambone = self.drambone
+ # grrr, same problem with drambone: not WB4-pipe compliant
+ comb += drambone.bus.stall.eq(drambone.bus.cyc & ~drambone.bus.ack)
+
# add blinky lights so we know FPGA is alive
if platform is not None:
m.submodules.blinky = Blinky()
ddr3 #(
.check_strict_timing(0)
) ram_chip (
- .rst_n(~dram_rst),
+ .rst_n(dram_rst),
.ck(dram_ck),
.ck_n(~dram_ck),
.cke(dram_cke),