summaryrefslogtreecommitdiff
path: root/tb/top
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2022-09-18 17:16:46 -0600
committerAlejandro Soto <alejandro@34project.org>2022-09-18 17:16:46 -0600
commit503957e2883e754fc8424c420c3d9838bd639ed3 (patch)
treef4b0bad5928fee6a43b73f246df875e14b3f6728 /tb/top
parent54544911601351465a6a887a045f3baddcb90dc6 (diff)
Fix memory simulation
Diffstat (limited to 'tb/top')
-rw-r--r--tb/top/conspiracion.cpp66
1 files changed, 55 insertions, 11 deletions
diff --git a/tb/top/conspiracion.cpp b/tb/top/conspiracion.cpp
index b8f803c..bce5546 100644
--- a/tb/top/conspiracion.cpp
+++ b/tb/top/conspiracion.cpp
@@ -1,11 +1,14 @@
-#include <verilated.h>
#include <cstdio>
+#include <verilated.h>
+#include <verilated_vcd_c.h>
+
#include "Vconspiracion.h"
#include "Vconspiracion_conspiracion.h"
#include "Vconspiracion_platform.h"
#include "../avalon.hpp"
+#include "../mem.hpp"
int main(int argc, char **argv)
{
@@ -14,18 +17,49 @@ int main(int argc, char **argv)
Verilated::commandArgs(argc, argv);
Vconspiracion top;
+
+#ifdef TRACE
+ Verilated::traceEverOn(true);
+ VerilatedVcdC trace;
+
+ top.trace(&trace, 0);
+ trace.open("trace.vcd");
+#endif
+
interconnect<Vconspiracion_platform> avl(*top.conspiracion->plat);
+ mem hps_ddr3(0x0000'0000, 512 << 20);
+
+ avl.attach(hps_ddr3);
int time = 0;
+ top.clk_clk = 1;
+
auto tick = [&]()
{
- top.clk_clk = 0;
- top.eval();
- top.clk_clk = 1;
+ top.clk_clk = !top.clk_clk;
top.eval();
- avl.tick();
+ avl.tick(top.clk_clk);
+#ifdef TRACE
+ trace.dump(time++);
+#endif
+ };
+
+ auto cycle = [&]()
+ {
+ tick();
+ tick();
+ std::printf("[%02d] out=0x%02x, done=%d\n", time, top.out, top.done);
+ };
- std::printf("[%02d] out=0x%02x, done=%d\n", ++time, top.out, top.done);
+ auto io = [&]()
+ {
+ top.io = 0;
+ cycle();
+ top.io = 1;
+ for(int i = 0; i < 4; ++i)
+ {
+ cycle();
+ }
};
top.dir = 1;
@@ -36,14 +70,24 @@ int main(int argc, char **argv)
for(int i = 0; i < 5; ++i)
{
top.add = 0;
- tick();
+ cycle();
top.add = 1;
- tick();
+ cycle();
}
- top.io = 0;
- tick();
- tick();
+ io();
+
+ top.clr = 0;
+ cycle();
+ top.clr = 1;
+ cycle();
+
+ top.dir = 0;
+ io();
+
+#ifdef TRACE
+ trace.close();
+#endif
top.final();
}