aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--atk16_fpga/.gitignore1
-rw-r--r--atk16_fpga/Makefile5
-rwxr-xr-xatk16_fpga/gen_data_strings_v.py25
-rw-r--r--atk16_fpga/hardware.dot70
-rw-r--r--atk16_fpga/hardware.svg463
-rw-r--r--atk16_fpga/top.v131
6 files changed, 667 insertions, 28 deletions
diff --git a/atk16_fpga/.gitignore b/atk16_fpga/.gitignore
index bba1e09..5fdef91 100644
--- a/atk16_fpga/.gitignore
+++ b/atk16_fpga/.gitignore
@@ -4,3 +4,4 @@
*.out
*.vcd
*.dblite
+data_strings.v
diff --git a/atk16_fpga/Makefile b/atk16_fpga/Makefile
index cada068..2a7e495 100644
--- a/atk16_fpga/Makefile
+++ b/atk16_fpga/Makefile
@@ -1,6 +1,9 @@
BIN ?= program.bin
-hardware.bin: top.v
+data_strings.v: gen_data_strings_v.py
+ python gen_data_strings_v.py > data_strings.v
+
+hardware.bin: top.v data_strings.v
apio verify
apio test
apio build
diff --git a/atk16_fpga/gen_data_strings_v.py b/atk16_fpga/gen_data_strings_v.py
new file mode 100755
index 0000000..afb374e
--- /dev/null
+++ b/atk16_fpga/gen_data_strings_v.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+
+def gen(name, message):
+ for line in message.split('\n'):
+ print(f'// {line}')
+
+ print(f"`define LEN_{name} {len(message)}")
+ print(f"`define STR_{name} \\")
+ print(f" reg [7:0] str_{name} [0:`LEN_{name}-1]; \\")
+ print(f" initial begin \\")
+ for i, c in enumerate(message):
+ print(f" str_{name}[{i}] = 8'd{ord(c)}; \\")
+
+ print(f" end")
+ print("")
+
+gen("welcome", "Welcome to the ATK16 serial programmer. Press 'h' for help.\n")
+gen("help",
+ "Help:\n" +
+ " h - help\n" +
+ " p - program\n"
+)
+gen("program_ready",
+ "Ready to receive program data. Reset device after transmission.\n"
+)
diff --git a/atk16_fpga/hardware.dot b/atk16_fpga/hardware.dot
new file mode 100644
index 0000000..e1f4c58
--- /dev/null
+++ b/atk16_fpga/hardware.dot
@@ -0,0 +1,70 @@
+digraph "top" {
+label="top";
+rankdir="LR";
+remincross=true;
+n13 [ shape=diamond, label="rx_done", color="black", fontcolor="black" ];
+n14 [ shape=diamond, label="data_to_receive", color="black", fontcolor="black" ];
+n15 [ shape=diamond, label="state", color="black", fontcolor="black" ];
+n16 [ shape=diamond, label="letter_a", color="black", fontcolor="black" ];
+n17 [ shape=diamond, label="tx_busy", color="black", fontcolor="black" ];
+n18 [ shape=diamond, label="data_to_send", color="black", fontcolor="black" ];
+n19 [ shape=diamond, label="start_tx", color="black", fontcolor="black" ];
+n20 [ shape=octagon, label="LED2", color="black", fontcolor="black" ];
+n21 [ shape=octagon, label="LED1", color="black", fontcolor="black" ];
+n22 [ shape=octagon, label="SERIAL_TX", color="black", fontcolor="black" ];
+n23 [ shape=octagon, label="SERIAL_RX", color="black", fontcolor="black" ];
+n24 [ shape=octagon, label="SYSCLK", color="black", fontcolor="black" ];
+v0 [ label="1" ];
+v1 [ label="0" ];
+c29 [ shape=record, label="{{<p25> A|<p26> B|<p27> S}|$6\n$mux|{<p28> Y}}", ];
+c30 [ shape=record, label="{{<p25> A|<p26> B}|$5\n$eq|{<p28> Y}}", ];
+c35 [ shape=record, label="{{<p31> clk|<p32> data|<p33> done|<p34> rx}|uart_rx_inst\nuart_rx|{}}", ];
+c39 [ shape=record, label="{{<p36> busy|<p31> clk|<p32> data|<p37> start|<p38> tx}|uart_inst\nuart_tx|{}}", ];
+c40 [ shape=record, label="{{<p25> A}|$4\n$logic_not|{<p28> Y}}", ];
+c41 [ shape=record, label="{{<p25> A}|$3\n$logic_not|{<p28> Y}}", ];
+c42 [ shape=record, label="{{<p25> A}|$2\n$logic_not|{<p28> Y}}", ];
+p2 [shape=box, style=rounded, label="PROC $10\ntop.v:28.15-28.35", ];
+p3 [shape=box, style=rounded, label="PROC $9\ntop.v:19.15-19.31", ];
+p4 [shape=box, style=rounded, label="PROC $8\ntop.v:15.15-15.34", ];
+p5 [shape=box, style=rounded, label="PROC $7\ntop.v:13.9-13.24", ];
+p6 [shape=box, style=rounded, label="PROC $1\ntop.v:31.5-70.8", ];
+x7 [ shape=record, style=rounded, label="<s0> 0:0 - 0:0 ", colorscheme="dark28", color="8", fontcolor="8" ];
+x8 [shape=point, ];
+n13:e -> c35:p33:w [colorscheme="dark28", color="4", fontcolor="4", label=""];
+n13:e -> c42:p25:w [colorscheme="dark28", color="4", fontcolor="4", label=""];
+n13:e -> p6:w [colorscheme="dark28", color="4", fontcolor="4", label=""];
+n14:e -> c30:p25:w [colorscheme="dark28", color="4", fontcolor="4", style="setlinewidth(3)", label=""];
+n14:e -> c35:p32:w [colorscheme="dark28", color="4", fontcolor="4", style="setlinewidth(3)", label=""];
+n14:e -> p6:w [colorscheme="dark28", color="4", fontcolor="4", style="setlinewidth(3)", label=""];
+p2:e -> n15:w [colorscheme="dark28", color="3", fontcolor="3", style="setlinewidth(3)", label=""];
+p6:e -> n15:w [colorscheme="dark28", color="3", fontcolor="3", style="setlinewidth(3)", label=""];
+n15:e -> p6:w [colorscheme="dark28", color="3", fontcolor="3", style="setlinewidth(3)", label=""];
+p3:e -> n16:w [colorscheme="dark28", color="2", fontcolor="2", style="setlinewidth(3)", label=""];
+n16:e -> c30:p26:w [colorscheme="dark28", color="2", fontcolor="2", style="setlinewidth(3)", label=""];
+n17:e -> c39:p36:w [colorscheme="dark28", color="1", fontcolor="1", label=""];
+n17:e -> c40:p25:w [colorscheme="dark28", color="1", fontcolor="1", label=""];
+n17:e -> c41:p25:w [colorscheme="dark28", color="1", fontcolor="1", label=""];
+p4:e -> n18:w [colorscheme="dark28", color="1", fontcolor="1", style="setlinewidth(3)", label=""];
+p6:e -> n18:w [colorscheme="dark28", color="1", fontcolor="1", style="setlinewidth(3)", label=""];
+n18:e -> c39:p32:w [colorscheme="dark28", color="1", fontcolor="1", style="setlinewidth(3)", label=""];
+n18:e -> p6:w [colorscheme="dark28", color="1", fontcolor="1", style="setlinewidth(3)", label=""];
+p5:e -> n19:w [colorscheme="dark28", color="6", fontcolor="6", label=""];
+p6:e -> n19:w [colorscheme="dark28", color="6", fontcolor="6", label=""];
+n19:e -> c39:p37:w [colorscheme="dark28", color="6", fontcolor="6", label=""];
+n19:e -> p6:w [colorscheme="dark28", color="6", fontcolor="6", label=""];
+x8:e -> n20:w [colorscheme="dark28", color="2", fontcolor="2", label=""];
+x7:e -> n21:w [colorscheme="dark28", color="2", fontcolor="2", label=""];
+n21:e -> x8:w [colorscheme="dark28", color="2", fontcolor="2", label=""];
+n22:e -> c39:p38:w [colorscheme="dark28", color="2", fontcolor="2", label=""];
+n23:e -> c35:p34:w [colorscheme="dark28", color="1", fontcolor="1", label=""];
+n24:e -> c35:p31:w [colorscheme="dark28", color="1", fontcolor="1", label=""];
+n24:e -> c39:p31:w [colorscheme="dark28", color="1", fontcolor="1", label=""];
+n24:e -> p6:w [colorscheme="dark28", color="1", fontcolor="1", label=""];
+c29:p28:e -> x7:s0:w [colorscheme="dark28", color="7", fontcolor="7", style="setlinewidth(3)", label=""];
+c30:p28:e -> c29:p27:w [colorscheme="dark28", color="3", fontcolor="3", label=""];
+c40:p28:e -> p6:w [colorscheme="dark28", color="7", fontcolor="7", label=""];
+c41:p28:e -> p6:w [colorscheme="dark28", color="6", fontcolor="6", label=""];
+c42:p28:e -> p6:w [colorscheme="dark28", color="1", fontcolor="1", label=""];
+v0:e -> c29:p26:w [colorscheme="dark28", color="5", fontcolor="5", style="setlinewidth(3)", label=""];
+v1:e -> c29:p25:w [colorscheme="dark28", color="7", fontcolor="7", style="setlinewidth(3)", label=""];
+}
diff --git a/atk16_fpga/hardware.svg b/atk16_fpga/hardware.svg
new file mode 100644
index 0000000..66b633e
--- /dev/null
+++ b/atk16_fpga/hardware.svg
@@ -0,0 +1,463 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<!-- Generated by graphviz version 12.2.1 (20241206.2353)
+ -->
+<!-- Title: top Pages: 1 -->
+<svg width="1157pt" height="702pt"
+ viewBox="0.00 0.00 1156.73 701.50" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 697.5)">
+<title>top</title>
+<polygon fill="white" stroke="none" points="-4,4 -4,-697.5 1152.73,-697.5 1152.73,4 -4,4"/>
+<text text-anchor="middle" x="574.36" y="-7.2" font-family="Times,serif" font-size="14.00">top</text>
+<!-- n13 -->
+<g id="node1" class="node">
+<title>n13</title>
+<polygon fill="none" stroke="black" points="58.15,-317.5 0,-299.5 58.15,-281.5 116.29,-299.5 58.15,-317.5"/>
+<text text-anchor="middle" x="58.15" y="-294.45" font-family="Times,serif" font-size="14.00">rx_done</text>
+</g>
+<!-- c35 -->
+<g id="node17" class="node">
+<title>c35</title>
+<polygon fill="none" stroke="black" points="384.2,-404.5 384.2,-502.5 527.45,-502.5 527.45,-404.5 384.2,-404.5"/>
+<text text-anchor="middle" x="405.33" y="-485.2" font-family="Times,serif" font-size="14.00">clk</text>
+<polyline fill="none" stroke="black" points="384.2,-478 426.45,-478"/>
+<text text-anchor="middle" x="405.33" y="-460.7" font-family="Times,serif" font-size="14.00">data</text>
+<polyline fill="none" stroke="black" points="384.2,-453.5 426.45,-453.5"/>
+<text text-anchor="middle" x="405.33" y="-436.2" font-family="Times,serif" font-size="14.00">done</text>
+<polyline fill="none" stroke="black" points="384.2,-429 426.45,-429"/>
+<text text-anchor="middle" x="405.33" y="-411.7" font-family="Times,serif" font-size="14.00">rx</text>
+<polyline fill="none" stroke="black" points="426.45,-404.5 426.45,-502.5"/>
+<text text-anchor="middle" x="467.08" y="-456.7" font-family="Times,serif" font-size="14.00">uart_rx_inst</text>
+<text text-anchor="middle" x="467.08" y="-440.2" font-family="Times,serif" font-size="14.00">uart_rx</text>
+<polyline fill="none" stroke="black" points="507.7,-404.5 507.7,-502.5"/>
+<text text-anchor="middle" x="517.58" y="-448.7" font-family="Times,serif" font-size="14.00"> </text>
+</g>
+<!-- n13&#45;&gt;c35 -->
+<g id="edge1" class="edge">
+<title>n13:e&#45;&gt;c35:w</title>
+<path fill="none" stroke="#e7298a" d="M116.29,-299.5C179.68,-299.5 102.45,-398.34 152.29,-437.5 230.35,-498.82 277.53,-445.53 372.95,-441.49"/>
+<polygon fill="#e7298a" stroke="#e7298a" points="372.76,-444.99 382.69,-441.28 372.62,-437.99 372.76,-444.99"/>
+</g>
+<!-- c42 -->
+<g id="node21" class="node">
+<title>c42</title>
+<polygon fill="none" stroke="black" points="187.62,-279 187.62,-320 312.87,-320 312.87,-279 187.62,-279"/>
+<text text-anchor="middle" x="200.5" y="-294.7" font-family="Times,serif" font-size="14.00">A</text>
+<polyline fill="none" stroke="black" points="213.37,-279 213.37,-320"/>
+<text text-anchor="middle" x="250.25" y="-302.7" font-family="Times,serif" font-size="14.00">$2</text>
+<text text-anchor="middle" x="250.25" y="-286.2" font-family="Times,serif" font-size="14.00">$logic_not</text>
+<polyline fill="none" stroke="black" points="287.12,-279 287.12,-320"/>
+<text text-anchor="middle" x="300" y="-294.7" font-family="Times,serif" font-size="14.00">Y</text>
+</g>
+<!-- n13&#45;&gt;c42 -->
+<g id="edge2" class="edge">
+<title>n13:e&#45;&gt;c42:w</title>
+<path fill="none" stroke="#e7298a" d="M116.29,-299.5C143.4,-299.5 152.87,-299.69 175.3,-299.74"/>
+<polygon fill="#e7298a" stroke="#e7298a" points="175.1,-303.24 185.11,-299.75 175.11,-296.24 175.1,-303.24"/>
+</g>
+<!-- p6 -->
+<g id="node26" class="node">
+<title>p6</title>
+<path fill="none" stroke="black" d="M493.83,-276C493.83,-276 417.83,-276 417.83,-276 411.83,-276 405.83,-270 405.83,-264 405.83,-264 405.83,-247 405.83,-247 405.83,-241 411.83,-235 417.83,-235 417.83,-235 493.83,-235 493.83,-235 499.83,-235 505.83,-241 505.83,-247 505.83,-247 505.83,-264 505.83,-264 505.83,-270 499.83,-276 493.83,-276"/>
+<text text-anchor="middle" x="455.83" y="-258.7" font-family="Times,serif" font-size="14.00">PROC $1</text>
+<text text-anchor="middle" x="455.83" y="-242.2" font-family="Times,serif" font-size="14.00">top.v:31.5&#45;70.8</text>
+</g>
+<!-- n13&#45;&gt;p6 -->
+<g id="edge3" class="edge">
+<title>n13:e&#45;&gt;p6:w</title>
+<path fill="none" stroke="#e7298a" d="M116.29,-299.5C137.12,-299.5 132.91,-277.13 152.29,-269.5 253.31,-229.73 289.91,-253.72 393.56,-255.41"/>
+<polygon fill="#e7298a" stroke="#e7298a" points="393.29,-258.91 403.31,-255.49 393.34,-251.91 393.29,-258.91"/>
+</g>
+<!-- n14 -->
+<g id="node2" class="node">
+<title>n14</title>
+<polygon fill="none" stroke="black" points="250.25,-520.5 152.29,-502.5 250.25,-484.5 348.2,-502.5 250.25,-520.5"/>
+<text text-anchor="middle" x="250.25" y="-497.45" font-family="Times,serif" font-size="14.00">data_to_receive</text>
+</g>
+<!-- c30 -->
+<g id="node16" class="node">
+<title>c30</title>
+<polygon fill="none" stroke="black" points="412.33,-536 412.33,-585 499.33,-585 499.33,-536 412.33,-536"/>
+<text text-anchor="middle" x="425.2" y="-567.7" font-family="Times,serif" font-size="14.00">A</text>
+<polyline fill="none" stroke="black" points="412.33,-560.5 438.08,-560.5"/>
+<text text-anchor="middle" x="425.2" y="-543.2" font-family="Times,serif" font-size="14.00">B</text>
+<polyline fill="none" stroke="black" points="438.08,-536 438.08,-585"/>
+<text text-anchor="middle" x="455.83" y="-563.7" font-family="Times,serif" font-size="14.00">$5</text>
+<text text-anchor="middle" x="455.83" y="-547.2" font-family="Times,serif" font-size="14.00">$eq</text>
+<polyline fill="none" stroke="black" points="473.58,-536 473.58,-585"/>
+<text text-anchor="middle" x="486.45" y="-555.7" font-family="Times,serif" font-size="14.00">Y</text>
+</g>
+<!-- n14&#45;&gt;c30 -->
+<g id="edge4" class="edge">
+<title>n14:e&#45;&gt;c30:w</title>
+<path fill="none" stroke="#e7298a" stroke-width="3" d="M348.2,-502.5C385.91,-502.5 372.93,-559.21 400.35,-570.72"/>
+<polygon fill="#e7298a" stroke="#e7298a" stroke-width="3" points="396.39,-573.55 406.86,-571.93 397.66,-566.67 396.39,-573.55"/>
+</g>
+<!-- n14&#45;&gt;c35 -->
+<g id="edge5" class="edge">
+<title>n14:e&#45;&gt;c35:w</title>
+<path fill="none" stroke="#e7298a" stroke-width="3" d="M348.2,-502.5C366.42,-502.5 363.94,-479.16 373.76,-469.68"/>
+<polygon fill="#e7298a" stroke="#e7298a" stroke-width="3" points="371.83,-474.15 379.95,-467.35 369.36,-467.6 371.83,-474.15"/>
+</g>
+<!-- n14&#45;&gt;p6 -->
+<g id="edge6" class="edge">
+<title>n14:e&#45;&gt;p6:w</title>
+<path fill="none" stroke="#e7298a" stroke-width="3" d="M348.2,-502.5C400.33,-502.5 356.21,-290.8 394.05,-259.38"/>
+<polygon fill="#e7298a" stroke="#e7298a" stroke-width="3" points="392.33,-263.72 400.55,-257.04 389.96,-257.13 392.33,-263.72"/>
+</g>
+<!-- n15 -->
+<g id="node3" class="node">
+<title>n15</title>
+<polygon fill="none" stroke="black" points="647.65,-300.5 608.33,-282.5 647.65,-264.5 686.98,-282.5 647.65,-300.5"/>
+<text text-anchor="middle" x="647.65" y="-277.45" font-family="Times,serif" font-size="14.00">state</text>
+</g>
+<!-- n15&#45;&gt;p6 -->
+<g id="edge9" class="edge">
+<title>n15:e&#45;&gt;p6:w</title>
+<path fill="none" stroke="#7570b3" stroke-width="3" d="M689.16,-282.5C697.18,-282.5 693.99,-294.99 688.16,-300.5 662.39,-324.88 643.66,-303.75 608.33,-300.5 571.92,-297.15 563.7,-290.26 527.45,-285.5 514.01,-283.73 415.27,-285.72 405.83,-276 403.24,-273.34 401.09,-269.46 400.05,-265.79"/>
+<polygon fill="#7570b3" stroke="#7570b3" stroke-width="3" points="401.88,-270.16 402.92,-259.62 395.53,-267.22 401.88,-270.16"/>
+</g>
+<!-- n16 -->
+<g id="node4" class="node">
+<title>n16</title>
+<polygon fill="none" stroke="black" points="250.25,-574.5 195.72,-556.5 250.25,-538.5 304.77,-556.5 250.25,-574.5"/>
+<text text-anchor="middle" x="250.25" y="-551.45" font-family="Times,serif" font-size="14.00">letter_a</text>
+</g>
+<!-- n16&#45;&gt;c30 -->
+<g id="edge11" class="edge">
+<title>n16:e&#45;&gt;c30:w</title>
+<path fill="none" stroke="#d95f02" stroke-width="3" d="M307.13,-556.5C349.59,-556.5 362.67,-549.61 400.08,-548.42"/>
+<polygon fill="#d95f02" stroke="#d95f02" stroke-width="3" points="396.84,-551.97 406.79,-548.32 396.73,-544.97 396.84,-551.97"/>
+</g>
+<!-- n17 -->
+<g id="node5" class="node">
+<title>n17</title>
+<polygon fill="none" stroke="black" points="58.15,-159.5 1.45,-141.5 58.15,-123.5 114.84,-141.5 58.15,-159.5"/>
+<text text-anchor="middle" x="58.15" y="-136.45" font-family="Times,serif" font-size="14.00">tx_busy</text>
+</g>
+<!-- c39 -->
+<g id="node18" class="node">
+<title>c39</title>
+<polygon fill="none" stroke="black" points="767.86,-137.25 767.86,-259.75 892.36,-259.75 892.36,-137.25 767.86,-137.25"/>
+<text text-anchor="middle" x="788.61" y="-242.45" font-family="Times,serif" font-size="14.00">busy</text>
+<polyline fill="none" stroke="black" points="767.86,-235.25 809.36,-235.25"/>
+<text text-anchor="middle" x="788.61" y="-217.95" font-family="Times,serif" font-size="14.00">clk</text>
+<polyline fill="none" stroke="black" points="767.86,-210.75 809.36,-210.75"/>
+<text text-anchor="middle" x="788.61" y="-193.45" font-family="Times,serif" font-size="14.00">data</text>
+<polyline fill="none" stroke="black" points="767.86,-186.25 809.36,-186.25"/>
+<text text-anchor="middle" x="788.61" y="-168.95" font-family="Times,serif" font-size="14.00">start</text>
+<polyline fill="none" stroke="black" points="767.86,-161.75 809.36,-161.75"/>
+<text text-anchor="middle" x="788.61" y="-144.45" font-family="Times,serif" font-size="14.00">tx</text>
+<polyline fill="none" stroke="black" points="809.36,-137.25 809.36,-259.75"/>
+<text text-anchor="middle" x="840.98" y="-201.7" font-family="Times,serif" font-size="14.00">uart_inst</text>
+<text text-anchor="middle" x="840.98" y="-185.2" font-family="Times,serif" font-size="14.00">uart_tx</text>
+<polyline fill="none" stroke="black" points="872.61,-137.25 872.61,-259.75"/>
+<text text-anchor="middle" x="882.48" y="-193.45" font-family="Times,serif" font-size="14.00"> </text>
+</g>
+<!-- n17&#45;&gt;c39 -->
+<g id="edge12" class="edge">
+<title>n17:e&#45;&gt;c39:w</title>
+<path fill="none" stroke="#1b9e77" d="M116.29,-141.5C137.12,-141.5 132.75,-118.72 152.29,-111.5 308.7,-53.72 361.45,-92.81 527.45,-108.5 619.53,-117.21 661.53,-87.43 731.86,-147.5 764.27,-175.18 729.04,-234.33 756.55,-245.62"/>
+<polygon fill="#1b9e77" stroke="#1b9e77" points="755.93,-249.06 766.36,-247.25 757.08,-242.16 755.93,-249.06"/>
+</g>
+<!-- c40 -->
+<g id="node19" class="node">
+<title>c40</title>
+<polygon fill="none" stroke="black" points="187.62,-121 187.62,-162 312.87,-162 312.87,-121 187.62,-121"/>
+<text text-anchor="middle" x="200.5" y="-136.7" font-family="Times,serif" font-size="14.00">A</text>
+<polyline fill="none" stroke="black" points="213.37,-121 213.37,-162"/>
+<text text-anchor="middle" x="250.25" y="-144.7" font-family="Times,serif" font-size="14.00">$4</text>
+<text text-anchor="middle" x="250.25" y="-128.2" font-family="Times,serif" font-size="14.00">$logic_not</text>
+<polyline fill="none" stroke="black" points="287.12,-121 287.12,-162"/>
+<text text-anchor="middle" x="300" y="-136.7" font-family="Times,serif" font-size="14.00">Y</text>
+</g>
+<!-- n17&#45;&gt;c40 -->
+<g id="edge13" class="edge">
+<title>n17:e&#45;&gt;c40:w</title>
+<path fill="none" stroke="#1b9e77" d="M116.29,-141.5C143.4,-141.5 152.87,-141.69 175.3,-141.74"/>
+<polygon fill="#1b9e77" stroke="#1b9e77" points="175.1,-145.24 185.11,-141.75 175.11,-138.24 175.1,-145.24"/>
+</g>
+<!-- c41 -->
+<g id="node20" class="node">
+<title>c41</title>
+<polygon fill="none" stroke="black" points="187.62,-181 187.62,-222 312.87,-222 312.87,-181 187.62,-181"/>
+<text text-anchor="middle" x="200.5" y="-196.7" font-family="Times,serif" font-size="14.00">A</text>
+<polyline fill="none" stroke="black" points="213.37,-181 213.37,-222"/>
+<text text-anchor="middle" x="250.25" y="-204.7" font-family="Times,serif" font-size="14.00">$3</text>
+<text text-anchor="middle" x="250.25" y="-188.2" font-family="Times,serif" font-size="14.00">$logic_not</text>
+<polyline fill="none" stroke="black" points="287.12,-181 287.12,-222"/>
+<text text-anchor="middle" x="300" y="-196.7" font-family="Times,serif" font-size="14.00">Y</text>
+</g>
+<!-- n17&#45;&gt;c41 -->
+<g id="edge14" class="edge">
+<title>n17:e&#45;&gt;c41:w</title>
+<path fill="none" stroke="#1b9e77" d="M116.29,-141.5C153.27,-141.5 147.35,-190.13 175.61,-200.01"/>
+<polygon fill="#1b9e77" stroke="#1b9e77" points="174.7,-203.41 185.13,-201.51 175.79,-196.5 174.7,-203.41"/>
+</g>
+<!-- n18 -->
+<g id="node6" class="node">
+<title>n18</title>
+<polygon fill="none" stroke="black" points="647.65,-246.5 563.45,-228.5 647.65,-210.5 731.86,-228.5 647.65,-246.5"/>
+<text text-anchor="middle" x="647.65" y="-223.45" font-family="Times,serif" font-size="14.00">data_to_send</text>
+</g>
+<!-- n18&#45;&gt;c39 -->
+<g id="edge17" class="edge">
+<title>n18:e&#45;&gt;c39:w</title>
+<path fill="none" stroke="#1b9e77" stroke-width="3" d="M731.86,-228.5C747.97,-228.5 748.23,-210.55 757.16,-202.42"/>
+<polygon fill="#1b9e77" stroke="#1b9e77" stroke-width="3" points="755.41,-206.79 763.59,-200.06 753,-200.22 755.41,-206.79"/>
+</g>
+<!-- n18&#45;&gt;p6 -->
+<g id="edge18" class="edge">
+<title>n18:e&#45;&gt;p6:w</title>
+<path fill="none" stroke="#1b9e77" stroke-width="3" d="M734.95,-228.5C742.97,-228.5 739.61,-240.83 733.95,-246.5 720.56,-259.94 582.08,-252.87 563.45,-256.5 536.91,-261.67 532.51,-271.61 505.83,-276 483.9,-279.61 421.92,-291.33 405.83,-276 403.14,-273.44 400.97,-269.58 399.95,-265.9"/>
+<polygon fill="#1b9e77" stroke="#1b9e77" stroke-width="3" points="401.82,-270.15 402.9,-259.61 395.48,-267.17 401.82,-270.15"/>
+</g>
+<!-- n19 -->
+<g id="node7" class="node">
+<title>n19</title>
+<polygon fill="none" stroke="black" points="647.65,-192.5 593.13,-174.5 647.65,-156.5 702.18,-174.5 647.65,-192.5"/>
+<text text-anchor="middle" x="647.65" y="-169.45" font-family="Times,serif" font-size="14.00">start_tx</text>
+</g>
+<!-- n19&#45;&gt;c39 -->
+<g id="edge21" class="edge">
+<title>n19:e&#45;&gt;c39:w</title>
+<path fill="none" stroke="#e6ab02" d="M704.54,-174.5C728.5,-174.5 737.16,-174.14 756.58,-174.03"/>
+<polygon fill="#e6ab02" stroke="#e6ab02" points="756.35,-177.53 766.34,-174 756.33,-170.53 756.35,-177.53"/>
+</g>
+<!-- n19&#45;&gt;p6 -->
+<g id="edge22" class="edge">
+<title>n19:e&#45;&gt;p6:w</title>
+<path fill="none" stroke="#e6ab02" d="M704.54,-174.5C712.55,-174.5 709.18,-186.81 703.54,-192.5 681.58,-214.65 591,-186.87 563.45,-201.5 526.48,-221.14 543.41,-257.56 505.83,-276 485.88,-285.79 421.92,-291.33 405.83,-276 403.14,-273.44 400.97,-269.58 399.95,-265.9"/>
+<polygon fill="#e6ab02" stroke="#e6ab02" points="403.1,-267.41 404.18,-256.87 396.77,-264.43 403.1,-267.41"/>
+</g>
+<!-- n20 -->
+<g id="node8" class="node">
+<title>n20</title>
+<polygon fill="none" stroke="black" points="1148.73,-614.04 1148.73,-628.96 1127.53,-639.5 1097.54,-639.5 1076.34,-628.96 1076.34,-614.04 1097.54,-603.5 1127.53,-603.5 1148.73,-614.04"/>
+<text text-anchor="middle" x="1112.54" y="-616.45" font-family="Times,serif" font-size="14.00">LED2</text>
+</g>
+<!-- n21 -->
+<g id="node9" class="node">
+<title>n21</title>
+<polygon fill="none" stroke="black" points="1000.74,-614.04 1000.74,-628.96 979.54,-639.5 949.56,-639.5 928.36,-628.96 928.36,-614.04 949.56,-603.5 979.54,-603.5 1000.74,-614.04"/>
+<text text-anchor="middle" x="964.55" y="-616.45" font-family="Times,serif" font-size="14.00">LED1</text>
+</g>
+<!-- x8 -->
+<g id="node28" class="node">
+<title>x8</title>
+<ellipse fill="black" stroke="black" cx="1038.54" cy="-621.5" rx="1.8" ry="1.8"/>
+</g>
+<!-- n21&#45;&gt;x8 -->
+<g id="edge25" class="edge">
+<title>n21:e&#45;&gt;x8:w</title>
+<path fill="none" stroke="#d95f02" d="M1000.74,-621.5C1012.12,-621.5 1017.43,-621.5 1025.3,-621.5"/>
+<polygon fill="#d95f02" stroke="#d95f02" points="1025.23,-625 1035.23,-621.5 1025.23,-618 1025.23,-625"/>
+</g>
+<!-- n22 -->
+<g id="node10" class="node">
+<title>n22</title>
+<polygon fill="none" stroke="black" points="712.65,-35.04 712.65,-49.96 674.58,-60.5 620.73,-60.5 582.65,-49.96 582.65,-35.04 620.73,-24.5 674.58,-24.5 712.65,-35.04"/>
+<text text-anchor="middle" x="647.65" y="-37.45" font-family="Times,serif" font-size="14.00">SERIAL_TX</text>
+</g>
+<!-- n22&#45;&gt;c39 -->
+<g id="edge26" class="edge">
+<title>n22:e&#45;&gt;c39:w</title>
+<path fill="none" stroke="#d95f02" d="M713.93,-42.5C762.81,-42.5 722.52,-132.67 756.77,-147.46"/>
+<polygon fill="#d95f02" stroke="#d95f02" points="755.9,-150.86 766.37,-149.23 757.17,-143.97 755.9,-150.86"/>
+</g>
+<!-- n23 -->
+<g id="node11" class="node">
+<title>n23</title>
+<polygon fill="none" stroke="black" points="315.8,-403.04 315.8,-417.96 277.4,-428.5 223.09,-428.5 184.69,-417.96 184.69,-403.04 223.09,-392.5 277.4,-392.5 315.8,-403.04"/>
+<text text-anchor="middle" x="250.25" y="-405.45" font-family="Times,serif" font-size="14.00">SERIAL_RX</text>
+</g>
+<!-- n23&#45;&gt;c35 -->
+<g id="edge27" class="edge">
+<title>n23:e&#45;&gt;c35:w</title>
+<path fill="none" stroke="#1b9e77" d="M317.08,-410.5C342.83,-410.5 351.76,-415.12 372.78,-416.41"/>
+<polygon fill="#1b9e77" stroke="#1b9e77" points="372.59,-419.91 382.69,-416.71 372.8,-412.91 372.59,-419.91"/>
+</g>
+<!-- n24 -->
+<g id="node12" class="node">
+<title>n24</title>
+<polygon fill="none" stroke="black" points="300.29,-349.04 300.29,-363.96 270.97,-374.5 229.52,-374.5 200.2,-363.96 200.2,-349.04 229.52,-338.5 270.97,-338.5 300.29,-349.04"/>
+<text text-anchor="middle" x="250.25" y="-351.45" font-family="Times,serif" font-size="14.00">SYSCLK</text>
+</g>
+<!-- n24&#45;&gt;c35 -->
+<g id="edge28" class="edge">
+<title>n24:e&#45;&gt;c35:w</title>
+<path fill="none" stroke="#1b9e77" d="M301.76,-356.5C325.63,-356.5 333.1,-365.01 348.2,-383.5 377.02,-418.8 341.73,-478.27 372.9,-488.67"/>
+<polygon fill="#1b9e77" stroke="#1b9e77" points="372.32,-492.13 382.7,-490.04 373.28,-485.19 372.32,-492.13"/>
+</g>
+<!-- n24&#45;&gt;c39 -->
+<g id="edge29" class="edge">
+<title>n24:e&#45;&gt;c39:w</title>
+<path fill="none" stroke="#1b9e77" d="M301.76,-356.5C494.05,-356.5 581.49,-429.36 731.86,-309.5 760.73,-286.48 733.96,-236.27 756.56,-225.19"/>
+<polygon fill="#1b9e77" stroke="#1b9e77" points="757.22,-228.63 766.37,-223.29 755.89,-221.76 757.22,-228.63"/>
+</g>
+<!-- n24&#45;&gt;p6 -->
+<g id="edge30" class="edge">
+<title>n24:e&#45;&gt;p6:w</title>
+<path fill="none" stroke="#1b9e77" d="M301.76,-356.5C325.63,-356.5 330.28,-345.28 348.2,-329.5 376,-305.01 366.24,-265.12 393.51,-256.98"/>
+<polygon fill="#1b9e77" stroke="#1b9e77" points="393.86,-260.46 403.33,-255.7 392.96,-253.52 393.86,-260.46"/>
+</g>
+<!-- v0 -->
+<g id="node13" class="node">
+<title>v0</title>
+<ellipse fill="none" stroke="black" cx="455.83" cy="-621.5" rx="27" ry="18"/>
+<text text-anchor="middle" x="455.83" y="-616.45" font-family="Times,serif" font-size="14.00">1</text>
+</g>
+<!-- c29 -->
+<g id="node15" class="node">
+<title>c29</title>
+<polygon fill="none" stroke="black" points="598.15,-584.75 598.15,-658.25 697.15,-658.25 697.15,-584.75 598.15,-584.75"/>
+<text text-anchor="middle" x="611.03" y="-640.95" font-family="Times,serif" font-size="14.00">A</text>
+<polyline fill="none" stroke="black" points="598.15,-633.75 623.9,-633.75"/>
+<text text-anchor="middle" x="611.03" y="-616.45" font-family="Times,serif" font-size="14.00">B</text>
+<polyline fill="none" stroke="black" points="598.15,-609.25 623.9,-609.25"/>
+<text text-anchor="middle" x="611.03" y="-591.95" font-family="Times,serif" font-size="14.00">S</text>
+<polyline fill="none" stroke="black" points="623.9,-584.75 623.9,-658.25"/>
+<text text-anchor="middle" x="647.65" y="-624.7" font-family="Times,serif" font-size="14.00">$6</text>
+<text text-anchor="middle" x="647.65" y="-608.2" font-family="Times,serif" font-size="14.00">$mux</text>
+<polyline fill="none" stroke="black" points="671.4,-584.75 671.4,-658.25"/>
+<text text-anchor="middle" x="684.28" y="-616.45" font-family="Times,serif" font-size="14.00">Y</text>
+</g>
+<!-- v0&#45;&gt;c29 -->
+<g id="edge36" class="edge">
+<title>v0:e&#45;&gt;c29:w</title>
+<path fill="none" stroke="#66a61e" stroke-width="3" d="M484.08,-621.5C530.31,-621.5 544.65,-621.5 585.77,-621.5"/>
+<polygon fill="#66a61e" stroke="#66a61e" stroke-width="3" points="582.61,-625 592.61,-621.5 582.61,-618 582.61,-625"/>
+</g>
+<!-- v1 -->
+<g id="node14" class="node">
+<title>v1</title>
+<ellipse fill="none" stroke="black" cx="455.83" cy="-675.5" rx="27" ry="18"/>
+<text text-anchor="middle" x="455.83" y="-670.45" font-family="Times,serif" font-size="14.00">0</text>
+</g>
+<!-- v1&#45;&gt;c29 -->
+<g id="edge37" class="edge">
+<title>v1:e&#45;&gt;c29:w</title>
+<path fill="none" stroke="#a6761d" stroke-width="3" d="M484.08,-675.5C531.96,-675.5 543.52,-650.43 585.72,-646.51"/>
+<polygon fill="#a6761d" stroke="#a6761d" stroke-width="3" points="582.78,-650.15 592.62,-646.2 582.47,-643.15 582.78,-650.15"/>
+</g>
+<!-- x7 -->
+<g id="node27" class="node">
+<title>x7</title>
+<path fill="none" stroke="#666666" d="M810.86,-603.5C810.86,-603.5 849.36,-603.5 849.36,-603.5 855.36,-603.5 861.36,-609.5 861.36,-615.5 861.36,-615.5 861.36,-627.5 861.36,-627.5 861.36,-633.5 855.36,-639.5 849.36,-639.5 849.36,-639.5 810.86,-639.5 810.86,-639.5 804.86,-639.5 798.86,-633.5 798.86,-627.5 798.86,-627.5 798.86,-615.5 798.86,-615.5 798.86,-609.5 804.86,-603.5 810.86,-603.5"/>
+<text text-anchor="middle" x="830.11" y="-616.7" font-family="Times,serif" font-size="14.00" fill="#666666">0:0 &#45; 0:0</text>
+</g>
+<!-- c29&#45;&gt;x7 -->
+<g id="edge31" class="edge">
+<title>c29:e&#45;&gt;x7:w</title>
+<path fill="none" stroke="#a6761d" stroke-width="3" d="M698.15,-621.5C738.49,-621.5 751.29,-621.71 786.67,-621.74"/>
+<polygon fill="#a6761d" stroke="#a6761d" stroke-width="3" points="783.31,-625.24 793.32,-621.75 783.32,-618.24 783.31,-625.24"/>
+</g>
+<!-- c30&#45;&gt;c29 -->
+<g id="edge32" class="edge">
+<title>c30:e&#45;&gt;c29:w</title>
+<path fill="none" stroke="#7570b3" d="M500.33,-560.75C542.15,-560.75 549.99,-590.78 585.7,-596.17"/>
+<polygon fill="#7570b3" stroke="#7570b3" points="585.42,-599.66 595.64,-596.89 585.92,-592.68 585.42,-599.66"/>
+</g>
+<!-- c40&#45;&gt;p6 -->
+<g id="edge33" class="edge">
+<title>c40:e&#45;&gt;p6:w</title>
+<path fill="none" stroke="#a6761d" d="M313.87,-141.75C374.43,-141.75 344.63,-241.31 393.54,-254.14"/>
+<polygon fill="#a6761d" stroke="#a6761d" points="392.98,-257.6 403.32,-255.32 393.81,-250.65 392.98,-257.6"/>
+</g>
+<!-- c41&#45;&gt;p6 -->
+<g id="edge34" class="edge">
+<title>c41:e&#45;&gt;p6:w</title>
+<path fill="none" stroke="#e6ab02" d="M313.87,-201.75C356.79,-201.75 358.01,-246.66 393.76,-254.38"/>
+<polygon fill="#e6ab02" stroke="#e6ab02" points="393.02,-257.82 403.32,-255.35 393.73,-250.86 393.02,-257.82"/>
+</g>
+<!-- c42&#45;&gt;p6 -->
+<g id="edge35" class="edge">
+<title>c42:e&#45;&gt;p6:w</title>
+<path fill="none" stroke="#1b9e77" d="M313.87,-299.75C354.79,-299.75 359.33,-263.09 393.71,-256.51"/>
+<polygon fill="#1b9e77" stroke="#1b9e77" points="393.68,-260.02 403.32,-255.64 393.04,-253.05 393.68,-260.02"/>
+</g>
+<!-- p2 -->
+<g id="node22" class="node">
+<title>p2</title>
+<path fill="none" stroke="black" d="M500.58,-335C500.58,-335 411.08,-335 411.08,-335 405.08,-335 399.08,-329 399.08,-323 399.08,-323 399.08,-306 399.08,-306 399.08,-300 405.08,-294 411.08,-294 411.08,-294 500.58,-294 500.58,-294 506.58,-294 512.58,-300 512.58,-306 512.58,-306 512.58,-323 512.58,-323 512.58,-329 506.58,-335 500.58,-335"/>
+<text text-anchor="middle" x="455.83" y="-317.7" font-family="Times,serif" font-size="14.00">PROC $10</text>
+<text text-anchor="middle" x="455.83" y="-301.2" font-family="Times,serif" font-size="14.00">top.v:28.15&#45;28.35</text>
+</g>
+<!-- p2&#45;&gt;n15 -->
+<g id="edge7" class="edge">
+<title>p2:e&#45;&gt;n15:w</title>
+<path fill="none" stroke="#7570b3" stroke-width="3" d="M513.58,-314.5C553.03,-314.5 561.25,-288.22 594.84,-283.29"/>
+<polygon fill="#7570b3" stroke="#7570b3" stroke-width="3" points="591.88,-287.01 601.61,-282.82 591.39,-280.02 591.88,-287.01"/>
+</g>
+<!-- p3 -->
+<g id="node23" class="node">
+<title>p3</title>
+<path fill="none" stroke="black" d="M102.9,-577C102.9,-577 13.4,-577 13.4,-577 7.4,-577 1.4,-571 1.4,-565 1.4,-565 1.4,-548 1.4,-548 1.4,-542 7.4,-536 13.4,-536 13.4,-536 102.9,-536 102.9,-536 108.9,-536 114.9,-542 114.9,-548 114.9,-548 114.9,-565 114.9,-565 114.9,-571 108.9,-577 102.9,-577"/>
+<text text-anchor="middle" x="58.15" y="-559.7" font-family="Times,serif" font-size="14.00">PROC $9</text>
+<text text-anchor="middle" x="58.15" y="-543.2" font-family="Times,serif" font-size="14.00">top.v:19.15&#45;19.31</text>
+</g>
+<!-- p3&#45;&gt;n16 -->
+<g id="edge10" class="edge">
+<title>p3:e&#45;&gt;n16:w</title>
+<path fill="none" stroke="#d95f02" stroke-width="3" d="M115.9,-556.5C146.16,-556.5 156.47,-556.5 181.9,-556.5"/>
+<polygon fill="#d95f02" stroke="#d95f02" stroke-width="3" points="178.82,-560 188.82,-556.5 178.82,-553 178.82,-560"/>
+</g>
+<!-- p4 -->
+<g id="node24" class="node">
+<title>p4</title>
+<path fill="none" stroke="black" d="M500.58,-217C500.58,-217 411.08,-217 411.08,-217 405.08,-217 399.08,-211 399.08,-205 399.08,-205 399.08,-188 399.08,-188 399.08,-182 405.08,-176 411.08,-176 411.08,-176 500.58,-176 500.58,-176 506.58,-176 512.58,-182 512.58,-188 512.58,-188 512.58,-205 512.58,-205 512.58,-211 506.58,-217 500.58,-217"/>
+<text text-anchor="middle" x="455.83" y="-199.7" font-family="Times,serif" font-size="14.00">PROC $8</text>
+<text text-anchor="middle" x="455.83" y="-183.2" font-family="Times,serif" font-size="14.00">top.v:15.15&#45;15.34</text>
+</g>
+<!-- p4&#45;&gt;n18 -->
+<g id="edge15" class="edge">
+<title>p4:e&#45;&gt;n18:w</title>
+<path fill="none" stroke="#1b9e77" stroke-width="3" d="M513.58,-196.5C535.59,-196.5 537.25,-218.86 552.58,-226.2"/>
+<polygon fill="#1b9e77" stroke="#1b9e77" stroke-width="3" points="548.5,-228.91 559.01,-227.56 549.95,-222.06 548.5,-228.91"/>
+</g>
+<!-- p5 -->
+<g id="node25" class="node">
+<title>p5</title>
+<path fill="none" stroke="black" d="M497.2,-158C497.2,-158 414.45,-158 414.45,-158 408.45,-158 402.45,-152 402.45,-146 402.45,-146 402.45,-129 402.45,-129 402.45,-123 408.45,-117 414.45,-117 414.45,-117 497.2,-117 497.2,-117 503.2,-117 509.2,-123 509.2,-129 509.2,-129 509.2,-146 509.2,-146 509.2,-152 503.2,-158 497.2,-158"/>
+<text text-anchor="middle" x="455.83" y="-140.7" font-family="Times,serif" font-size="14.00">PROC $7</text>
+<text text-anchor="middle" x="455.83" y="-124.2" font-family="Times,serif" font-size="14.00">top.v:13.9&#45;13.24</text>
+</g>
+<!-- p5&#45;&gt;n19 -->
+<g id="edge19" class="edge">
+<title>p5:e&#45;&gt;n19:w</title>
+<path fill="none" stroke="#e6ab02" d="M510.2,-137.5C545.45,-137.5 550.58,-167.11 579.47,-173.35"/>
+<polygon fill="#e6ab02" stroke="#e6ab02" points="578.96,-176.82 589.26,-174.35 579.67,-169.85 578.96,-176.82"/>
+</g>
+<!-- p6&#45;&gt;n15 -->
+<g id="edge8" class="edge">
+<title>p6:e&#45;&gt;n15:w</title>
+<path fill="none" stroke="#7570b3" stroke-width="3" d="M506.83,-255.5C548.46,-255.5 558.69,-277.87 594.68,-281.89"/>
+<polygon fill="#7570b3" stroke="#7570b3" stroke-width="3" points="591.44,-285.22 601.61,-282.26 591.81,-278.23 591.44,-285.22"/>
+</g>
+<!-- p6&#45;&gt;n18 -->
+<g id="edge16" class="edge">
+<title>p6:e&#45;&gt;n18:w</title>
+<path fill="none" stroke="#1b9e77" stroke-width="3" d="M506.83,-255.5C530.35,-255.5 534.64,-236.28 552.16,-230.27"/>
+<polygon fill="#1b9e77" stroke="#1b9e77" stroke-width="3" points="549.63,-234.21 558.97,-229.2 548.54,-227.3 549.63,-234.21"/>
+</g>
+<!-- p6&#45;&gt;n19 -->
+<g id="edge20" class="edge">
+<title>p6:e&#45;&gt;n19:w</title>
+<path fill="none" stroke="#e6ab02" d="M506.83,-255.5C554.42,-255.5 541.68,-187.24 579.38,-176.05"/>
+<polygon fill="#e6ab02" stroke="#e6ab02" points="579.83,-179.52 589.27,-174.7 578.89,-172.58 579.83,-179.52"/>
+</g>
+<!-- x7&#45;&gt;n21 -->
+<g id="edge24" class="edge">
+<title>x7:e&#45;&gt;n21:w</title>
+<path fill="none" stroke="#d95f02" d="M862.36,-621.5C887.45,-621.5 896.44,-621.5 916.88,-621.5"/>
+<polygon fill="#d95f02" stroke="#d95f02" points="916.84,-625 926.84,-621.5 916.84,-618 916.84,-625"/>
+</g>
+<!-- x8&#45;&gt;n20 -->
+<g id="edge23" class="edge">
+<title>x8:e&#45;&gt;n20:w</title>
+<path fill="none" stroke="#d95f02" d="M1040.34,-621.5C1051.72,-621.5 1057.03,-621.5 1064.9,-621.5"/>
+<polygon fill="#d95f02" stroke="#d95f02" points="1064.83,-625 1074.83,-621.5 1064.83,-618 1064.83,-625"/>
+</g>
+</g>
+</svg>
diff --git a/atk16_fpga/top.v b/atk16_fpga/top.v
index c67ade2..6fcbddd 100644
--- a/atk16_fpga/top.v
+++ b/atk16_fpga/top.v
@@ -9,28 +9,37 @@ module top (
output LED2
);
- // One-cycle pulse to trigger transmission.
- reg start_tx = 1'b0;
- // Data byte to be transmitted.
- reg [7:0] data_to_send = 8'b0;
- // Busy flag from the transmitter.
- wire tx_busy;
+ // State machine states.
+ localparam RX_START = 0;
+ localparam WAIT_RX_DONE = 1;
+ localparam START_TX = 2;
+ localparam TX_IN_PROG = 3;
+ localparam WAIT_TX_DONE = 4;
+ localparam HANDLE_RX_DATA = 5;
+ localparam SEND_STRING_WELCOME = 6;
+ localparam SEND_STRING_HELP = 7;
+ localparam SEND_STRING_PROGRAM_READY = 8;
+ localparam RECEIVE_PROGRAM_DATA = 9;
- reg [7:0] letter_a = 8'd97;
+ reg [7:0] state = SEND_STRING_WELCOME;
- // State machine states.
- localparam WAIT_RX_BUSY = 3'd0;
- localparam WAIT_RX_DONE = 3'd1;
- localparam START_TX_1 = 3'd2;
- localparam START_TX_2 = 3'd3;
- localparam WAIT_TX_DONE = 3'd4;
+ // SEND_WELCOME data
+ `STR_welcome
+ reg [7:0] welcome_index = 0;
+
+ // SEND_STRING_HELP data
+ `STR_help
+ reg [7:0] help_index = 0;
- reg [2:0] state = WAIT_RX_BUSY;
+ // SEND_STRING_PROGRAM_READY data
+ `STR_program_ready
+ reg [7:0] program_ready_index = 0;
// Synchronous state machine with reset.
always @(posedge SYSCLK) begin
case (state)
- WAIT_RX_BUSY: begin
+ // STATES FOR RX
+ RX_START: begin
if (!rx_done) begin
state <= WAIT_RX_DONE;
end
@@ -38,21 +47,20 @@ module top (
WAIT_RX_DONE: begin
if (rx_done) begin
- state <= START_TX_1;
+ state <= state_after_rx;
end
end
- START_TX_1: begin
+ // STATES FOR TX
+ START_TX: begin
if (!tx_busy) begin
- //data_to_send <= letter_a;
- data_to_send <= data_to_receive;
start_tx <= 1'b1; // trigger transmission
- state <= START_TX_2;
+ state <= TX_IN_PROG;
end
end
// After issuing the start pulse, wait for tx_busy to go high.
- START_TX_2: begin
+ TX_IN_PROG: begin
start_tx <= 1'b0; // ensure pulse is only one cycle.
state <= WAIT_TX_DONE;
end
@@ -60,35 +68,104 @@ module top (
// Wait for the transmitter to finish sending the byte.
WAIT_TX_DONE: begin
if (!tx_busy) begin
- state <= WAIT_RX_BUSY;
+ state <= state_after_tx;
end
end
- default: state <= WAIT_RX_BUSY;
+ // STATES FOR PROCESSING DATA
+ HANDLE_RX_DATA: begin
+ if (data_rx == cmd_program) begin
+ state <= SEND_STRING_PROGRAM_READY;
+ end else if (data_rx == cmd_help) begin
+ state <= SEND_STRING_HELP;
+ end else begin
+ state <= RX_START;
+ end
+ end
+
+ SEND_STRING_WELCOME: begin
+ if (welcome_index < 8'd`LEN_welcome) begin
+ data_tx <= str_welcome[welcome_index];
+ welcome_index <= welcome_index + 1;
+ state <= START_TX;
+ state_after_tx <= SEND_STRING_WELCOME;
+ end else begin
+ welcome_index <= 0;
+ state <= RX_START;
+ state_after_tx <= RX_START;
+ end
+ end
+
+ SEND_STRING_HELP: begin
+ if (help_index < 8'd`LEN_help) begin
+ data_tx <= str_help[help_index];
+ help_index <= help_index + 1;
+ state <= START_TX;
+ state_after_tx <= SEND_STRING_HELP;
+ end else begin
+ help_index <= 0;
+ state <= RX_START;
+ state_after_tx <= RX_START;
+ end
+ end
+
+ SEND_STRING_PROGRAM_READY: begin
+ if (program_ready_index < 8'd`LEN_program_ready) begin
+ data_tx <= str_program_ready[program_ready_index];
+ program_ready_index <= program_ready_index + 1;
+ state <= START_TX;
+ state_after_tx <= SEND_STRING_PROGRAM_READY;
+ end else begin
+ program_ready_index <= 0;
+ state <= RECEIVE_PROGRAM_DATA;
+ state_after_tx <= RX_START;
+ end
+ end
+
+ RECEIVE_PROGRAM_DATA: begin
+ // TODO write data to flash
+ state <= RX_START;
+ state_after_rx <= RECEIVE_PROGRAM_DATA;
+ end
+
+ default: state <= RX_START;
endcase
end
+ // One-cycle pulse to trigger transmission.
+ reg start_tx = 1'b0;
+ // Data byte to be transmitted.
+ reg [7:0] data_tx = 8'b0;
+ // Busy flag from the transmitter.
+ wire tx_busy;
+ // State to transition to after TX done.
+ reg [7:0] state_after_tx = RX_START;
+
+ reg [7:0] cmd_help = 8'd104; // h
+ reg [7:0] cmd_program = 8'd112; // p
+
// Instantiate the UART transmitter.
uart_tx uart_inst (
.clk (SYSCLK),
.start(start_tx), // One-cycle pulse to start transmission.
- .data (data_to_send),
+ .data (data_tx),
.tx (SERIAL_TX),
.busy (tx_busy)
);
- wire [7:0] data_to_receive;
+ wire [7:0] data_rx;
wire rx_done;
+ reg [7:0] state_after_rx = HANDLE_RX_DATA;
uart_rx uart_rx_inst (
.clk (SYSCLK),
.rx (SERIAL_RX),
- .data(data_to_receive),
+ .data(data_rx),
.done(rx_done)
);
- assign LED1 = data_to_receive == letter_a ? 1 : 0;
+ assign LED1 = data_rx == cmd_program;
assign LED2 = LED1;
endmodule