aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWojciech Kosior <kwojtus@protonmail.com>2020-11-21 21:35:54 +0100
committerWojciech Kosior <kwojtus@protonmail.com>2020-11-21 21:35:54 +0100
commitb44a3a201ee2b524f31aa93abfe4abd8b756a533 (patch)
tree3e51f9fa39e54139b913351d81fc0fe1cf299c53 /tests
parent8999a1a82eddb97fa2d4aa7de12e88a3205d0e3d (diff)
downloadAGH-engineering-thesis-b44a3a201ee2b524f31aa93abfe4abd8b756a533.tar.gz
AGH-engineering-thesis-b44a3a201ee2b524f31aa93abfe4abd8b756a533.zip
add miscellaneous module, which controls led2 and button2 and provides a timer; include a testbench for timer and led
Diffstat (limited to 'tests')
-rw-r--r--tests/soc_measure_time/Makefile8
-rw-r--r--tests/soc_measure_time/instructions.s.tcl57
-rw-r--r--tests/soc_measure_time/test.v82
3 files changed, 147 insertions, 0 deletions
diff --git a/tests/soc_measure_time/Makefile b/tests/soc_measure_time/Makefile
new file mode 100644
index 0000000..3f76875
--- /dev/null
+++ b/tests/soc_measure_time/Makefile
@@ -0,0 +1,8 @@
+DEPENDS = instructions.mem sram.v vga_display.v flash_memory.v \
+ soc_with_peripherals.v ../../design/*.v messages.vh
+
+IVFLAGS = -DROM_WORDS_COUNT=$(call FILE_LINES,instructions.mem)
+
+TOP = soc_test
+
+include ../../Makefile.test
diff --git a/tests/soc_measure_time/instructions.s.tcl b/tests/soc_measure_time/instructions.s.tcl
new file mode 100644
index 0000000..b1f8511
--- /dev/null
+++ b/tests/soc_measure_time/instructions.s.tcl
@@ -0,0 +1,57 @@
+## also look at stack_machine_cond_jump test
+
+## we're going to write numbers from 0 to 639 at addresses h100000 to h1009FC
+## and then write non-zero value at h100A00
+
+# this will translate to 2 16-bit instructions
+set_sp h100000
+
+## load current value of timer, in a loop
+## this is address 4 we later jump to
+# this will translate to 2 16-bit instructions
+loadwzx h1C0008
+
+## loop until timer exceeds 500
+# this will translate to 2 16-bit instructions
+const 500
+# this will translate to 1 16-bit instruction
+lt
+# this will translate to 1 16-bit instruction
+cond_jump 4
+
+## now, light led2
+# this will translate to 1 16-bit instruction
+const 1
+# this will translate to 2 16-bit instructions
+storew h1C0006
+
+## second loop, analogous to the first one
+## this is address 22 we later jump to
+# this will translate to 2 16-bit instructions
+loadwzx h1C0008
+
+## loop until timer exceeds 1000
+# this will translate to 2 16-bit instructions
+const 1000
+# this will translate to 1 16-bit instruction
+lt
+# this will translate to 1 16-bit instruction
+cond_jump 22
+
+## now, switch led2 off
+# this will translate to 1 16-bit instruction
+const 0
+# this will translate to 2 16-bit instructions
+storew h1C0006
+
+## third loop, analogous to the first two
+## this is address 40 we later jump to
+loadwzx h1C0008
+
+## loop until timer exceeds 1500
+const 1500
+lt
+cond_jump 40
+
+## finish operation (will also put led1 on)
+halt
diff --git a/tests/soc_measure_time/test.v b/tests/soc_measure_time/test.v
new file mode 100644
index 0000000..b4f1082
--- /dev/null
+++ b/tests/soc_measure_time/test.v
@@ -0,0 +1,82 @@
+`default_nettype none
+`timescale 1ns/1ns
+
+`include "messages.vh"
+
+`ifndef SIMULATION
+ `error_SIMULATION_not_defined
+; /* Cause syntax error */
+`endif
+
+module soc_test();
+ wire [9:0] image_writes;
+
+ reg clock_100mhz;
+ reg reset;
+
+ wire led1;
+ wire led2;
+
+ soc_with_peripherals
+ #(
+ .FONT_FILE("../../design/font.mem"),
+ .EMBEDDED_ROM_FILE("instructions.mem")
+ ) soc
+ (
+ .clock_100mhz(clock_100mhz),
+
+ .button1(!reset),
+ .button2(1'b1),
+
+ .led1(led1),
+ .led2(led2),
+
+ .image_writes(image_writes)
+ );
+
+ integer i;
+ integer current_time;
+
+ initial begin
+ reset <= 1;
+ clock_100mhz <= 0;
+
+ for (i = 0; i < 25_000; i++) begin
+ #5;
+
+ if (clock_100mhz)
+ reset <= 0;
+
+ clock_100mhz <= ~clock_100mhz;
+
+ /*
+ * Soc's clock is 12.5 MHz. One tick of that clock takes 80 ns.
+ * This means 1000th, 2000th and 3000th ticks happen at
+ * 80_000, 160_000 and 240_000 ns, respectively.
+ */
+ current_time = $time;
+ if (current_time < 40_000) begin
+ if (!led2) begin
+ `MSG(("error: led2 on before 1000 timer ticks passed"));
+ $finish;
+ end
+ end
+ if (current_time > 50_000 && current_time < 80_000) begin
+ if (led2) begin
+ `MSG(("error: led2 not on, while it should be"));
+ $finish;
+ end
+ end
+ if (current_time > 130_000) begin
+ if (!led2) begin
+ `MSG(("error: led2 hasn't been switched off on time"));
+ $finish;
+ end
+ end
+ end // for (i = 0; i < 12_500; i++)
+
+ if (led1)
+ `MSG(("error: stack machine in soc hasn't finished working in 125us"));
+ $finish;
+ end // initial begin
+endmodule // soc_test