add qcxxrtl compile
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 8 Apr 2021 12:05:17 +0000 (13:05 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 8 Apr 2021 12:05:17 +0000 (13:05 +0100)
small_jtag_test/.gitignore [new file with mode: 0644]
small_jtag_test/Makefile [new file with mode: 0644]
small_jtag_test/README.txt [new file with mode: 0644]
small_jtag_test/add.py [new file with mode: 0644]
small_jtag_test/main.cpp [new file with mode: 0644]

diff --git a/small_jtag_test/.gitignore b/small_jtag_test/.gitignore
new file mode 100644 (file)
index 0000000..6e4bc45
--- /dev/null
@@ -0,0 +1,5 @@
+add.cpp
+add.v
+tb
+*.o
+.*.sw?
diff --git a/small_jtag_test/Makefile b/small_jtag_test/Makefile
new file mode 100644 (file)
index 0000000..4cc26cc
--- /dev/null
@@ -0,0 +1,19 @@
+
+YOSYS                  = yosys
+YOSYS_INCLUDE  = $(shell yosys-config --datdir)/include
+
+all: tb
+       ./tb
+
+tb: main.cpp add.cpp
+       clang++ -g -O3 -std=c++14 -I $(YOSYS_INCLUDE) $< -o $@
+
+add.cpp: add.v
+       $(YOSYS) -p "read_verilog $<; write_cxxrtl $@"
+
+# build verilog from nmigen
+add.v: add.py
+       python3 add.py
+
+clean:
+       \rm -f add.cpp tb add.v
diff --git a/small_jtag_test/README.txt b/small_jtag_test/README.txt
new file mode 100644 (file)
index 0000000..43c62c6
--- /dev/null
@@ -0,0 +1,4 @@
+This experiment uses soclayout experiment10_verilog as a quick proof of
+concept test of doing a JTAG cxxrtl openocd "jtagremote" interface
+
+
diff --git a/small_jtag_test/add.py b/small_jtag_test/add.py
new file mode 100644 (file)
index 0000000..aa7b487
--- /dev/null
@@ -0,0 +1,58 @@
+# generate add.il ilang file with: python3 add.py
+#
+
+from nmigen import Elaboratable, Signal, Module, Const
+from nmigen.cli import verilog
+
+# to get c4m-jtag
+# clone with $ git clone gitolite3@git.libre-soc.org:c4m-jtag.git
+#            $ git clone gitolite3@git.libre-soc.org:nmigen-soc.git
+# for each:  $ python3 setup.py develop --user
+
+from c4m.nmigen.jtag.tap import TAP, IOType
+
+
+class ADD(Elaboratable):
+    def __init__(self, width):
+        self.a      = Signal(width)
+        self.b      = Signal(width)
+        self.f      = Signal(width)
+
+        # set up JTAG
+        self.jtag = TAP(ir_width=4)
+        self.jtag.bus.tck.name = 'tck'
+        self.jtag.bus.tms.name = 'tms'
+        self.jtag.bus.tdo.name = 'tdo'
+        self.jtag.bus.tdi.name = 'tdi'
+
+        # have to create at least one shift register
+        self.sr = self.jtag.add_shiftreg(ircode=4, length=3)
+
+        # sigh and one iotype
+        self.ios = self.jtag.add_io(name="test", iotype=IOType.In)
+
+    def elaborate(self, platform):
+        m = Module()
+
+        m.submodules.jtag = jtag = self.jtag
+        m.d.comb += self.sr.i.eq(self.sr.o) # loopback test
+
+        # do a simple "add"
+        m.d.sync += self.f.eq(self.a + self.b)
+        m.d.sync += self.f[0].eq(Const(0, 1))
+
+        return m
+
+
+def create_ilang(dut, ports, test_name):
+    vl = verilog.convert(dut, name=test_name, ports=ports)
+    with open("%s.v" % test_name, "w") as f:
+        f.write(vl)
+
+if __name__ == "__main__":
+    alu = ADD(width=4)
+    create_ilang(alu, [alu.a, alu.b, alu.f,
+                       alu.jtag.bus.tck,
+                        alu.jtag.bus.tms,
+                        alu.jtag.bus.tdo,
+                        alu.jtag.bus.tdi], "add")
diff --git a/small_jtag_test/main.cpp b/small_jtag_test/main.cpp
new file mode 100644 (file)
index 0000000..ef1e523
--- /dev/null
@@ -0,0 +1,32 @@
+
+#include <iostream>
+#include "add.cpp"
+
+using namespace std;
+
+int main()
+{
+    cxxrtl_design::p_add top;
+
+    bool prev_led = 0;
+
+    top.step();
+    for(int cycle=0;cycle<1000;++cycle){
+
+        top.p_clk.set<bool>(false);
+        top.step();
+        top.p_clk.set<bool>(true);
+        top.step();
+
+/*
+        bool cur_led        = top.p_led.get<bool>();
+        uint32_t counter    = top.p_counter.get<uint32_t>();
+
+        if (cur_led != prev_led){
+            cout << "cycle " << cycle << " - led: " << cur_led << ", counter: " << counter << endl;
+        }
+        prev_led = cur_led;
+*/
+    }
+}
+