aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorWojciech Kosior <kwojtus@protonmail.com>2020-12-24 09:22:34 +0100
committerWojciech Kosior <kwojtus@protonmail.com>2020-12-24 09:22:34 +0100
commitf122fa70e30a7d7744b38fa22bd1d5aa949e8277 (patch)
tree8d0ed8590eb5bb6cbb85ded102a4e4e440f28913 /examples
parent6abc6fd5a869976b4e31e12908e835827399deec (diff)
downloadAGH-engineering-thesis-f122fa70e30a7d7744b38fa22bd1d5aa949e8277.tar.gz
AGH-engineering-thesis-f122fa70e30a7d7744b38fa22bd1d5aa949e8277.zip
prepare makefile infrastructure for writing examples
Diffstat (limited to 'examples')
-rw-r--r--examples/example1_blink_led/Makefile3
-rw-r--r--examples/example1_blink_led/instructions.s.tcl57
-rw-r--r--examples/example_toplevel.v142
3 files changed, 202 insertions, 0 deletions
diff --git a/examples/example1_blink_led/Makefile b/examples/example1_blink_led/Makefile
new file mode 100644
index 0000000..9755f33
--- /dev/null
+++ b/examples/example1_blink_led/Makefile
@@ -0,0 +1,3 @@
+SIMFLAGS += -DFINISH_ON_LED1=1 -DFINISH_ON_LED2=0
+
+include ../../Makefile.example
diff --git a/examples/example1_blink_led/instructions.s.tcl b/examples/example1_blink_led/instructions.s.tcl
new file mode 100644
index 0000000..13c51e2
--- /dev/null
+++ b/examples/example1_blink_led/instructions.s.tcl
@@ -0,0 +1,57 @@
+## adapted from soc_measure_time 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/examples/example_toplevel.v b/examples/example_toplevel.v
new file mode 100644
index 0000000..1da1750
--- /dev/null
+++ b/examples/example_toplevel.v
@@ -0,0 +1,142 @@
+`default_nettype none
+`timescale 1ns/1ns
+
+`include "messages.vh"
+
+`ifndef SIMULATION
+ `error_SIMULATION_not_defined
+; /* Cause syntax error */
+`endif
+
+`ifndef ROM_WORDS_COUNT
+ `error_ROM_WORDS_COUNT_must_be_defined
+; /* Cause syntax error */
+`endif
+
+`ifndef EMBEDDED_ROM_FILE
+ `error_EMBEDDED_ROM_FILE_not_defined
+; /* Cause syntax error */
+`endif
+
+`ifndef FONT_FILE
+ `error_FONT_FILE_not_defined
+; /* Cause syntax error */
+`endif
+
+`ifndef FINISH_ON_IMAGE_WRITES
+ `define FINISH_ON_IMAGE_WRITES 0
+`else
+ `define FINISH_RULE_PROVIDED 1
+`endif
+
+`ifndef FINISH_ON_LED1
+ `define FINISH_ON_LED1 -1
+`else
+ `define FINISH_RULE_PROVIDED 1
+`endif
+
+`ifndef FINISH_ON_LED2
+ `define FINISH_ON_LED2 -1
+`else
+ `define FINISH_RULE_PROVIDED 1
+`endif
+
+`ifndef FINISH_RULE_PROVIDED
+ `define FINISH_RULE_PROVIDED 0
+`endif
+
+`ifndef MIN_TIME_NS
+ `define MIN_TIME_NS 1000
+`endif
+
+`ifndef MAX_TIME_NS
+ `define MAX_TIME_NS 250_000_000
+`endif
+
+module example();
+ wire [9:0] image_writes;
+ wire can_finish;
+
+ reg clock_100mhz;
+ reg reset;
+
+ wire led1;
+ wire led2;
+
+ soc_with_peripherals
+ #(
+ .FONT_FILE(`FONT_FILE),
+ .EMBEDDED_ROM_WORDS_COUNT(`ROM_WORDS_COUNT),
+ .EMBEDDED_ROM_FILE(`EMBEDDED_ROM_FILE)
+ ) soc
+ (
+ .clock_100mhz(clock_100mhz),
+
+ .button1(!reset),
+ .button2(1'b1),
+
+ .led1(led1),
+ .led2(led2),
+
+ .image_writes(image_writes)
+ );
+
+ integer i;
+
+ initial begin
+ reset <= 1;
+ clock_100mhz <= 0;
+
+ if (!`FINISH_RULE_PROVIDED) begin
+ `MSG(("No finish rule provided, simulation will terminate after %0d ns,",
+ `MAX_TIME_NS));
+ end
+
+ for (i = 0; i < `MAX_TIME_NS; i = i + 5) begin
+ #5;
+
+ if (clock_100mhz)
+ reset <= 0;
+
+ clock_100mhz <= ~clock_100mhz;
+ end
+
+ `MSG(("%0d ns passed, finishing", `MAX_TIME_NS));
+ $finish;
+ end
+
+ assign can_finish = i >= `MIN_TIME_NS;
+
+ always @ (led1) begin
+ if (i > 0) begin
+ if (!led1)
+ `MSG(("LED1 goes on, stack machine finished operation"));
+ else
+ `MSG(("LED1 goes off, stack machine resets"));
+ end
+ end
+
+ always @ (led2) begin
+ if (i > 35) begin
+ if (!led2)
+ `MSG(("LED2 goes on"));
+ else
+ `MSG(("LED2 goes off"));
+ end
+ end
+
+ generate
+ if (`FINISH_RULE_PROVIDED) begin
+ always @ (image_writes or led1 or led2 or can_finish) begin
+ if ((image_writes >= `FINISH_ON_IMAGE_WRITES) &&
+ (`FINISH_ON_LED1 < 0 || `FINISH_ON_LED1 == !led1) &&
+ (`FINISH_ON_LED2 < 0 || `FINISH_ON_LED2 == !led2) &&
+ can_finish) begin
+ #1;
+ `MSG(("finishing"));
+ $finish;
+ end
+ end
+ end // if (`FINISH_RULE_PROVIDED)
+ endgenerate
+endmodule // example