add VCD output
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 8 Apr 2021 14:43:16 +0000 (15:43 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 8 Apr 2021 14:43:16 +0000 (15:43 +0100)
small_jtag_test/main.cpp

index 7859f647da0e7ffef4fa80972332ac91504d1437..987b742e9f0ced6c2cb9c841ed53aad5f7974e57 100644 (file)
 #include <netinet/tcp.h>
 
 #include <iostream>
+#include <fstream>
+
 #include "add.cpp"
 
+#define VCD
+
+#ifdef VCD
+#include <backends/cxxrtl/cxxrtl_vcd.h>
+#endif
+
 using namespace std;
 
 extern "C" {
@@ -150,17 +158,44 @@ int read_openocd_jtagremote(cxxrtl_design::p_add &top, int sock)
 int main()
 {
     cxxrtl_design::p_add top;
+    int steps = 0;
+
+#ifdef VCD
+    // Load the debug items of the top down the whole design hierarchy
+    cxxrtl::debug_items all_debug_items;
+    top.debug_info(all_debug_items);
+
+    // set up vcdwriter with 1ns resu
+    cxxrtl::vcd_writer vcd;
+    vcd.timescale(1, "us");
+#endif
 
     int listenfd = setup_socket();
     int sock = -1;
 
+#ifdef VCD
+    //vcd.add_without_memories(all_debug_items);
+    vcd.add(all_debug_items);
+    std::ofstream waves("waves.vcd");
+#endif
+
     top.step();
+#ifdef VCD
+    vcd.sample(0);
+#endif
     while (true) {
 
         top.p_clk.set<bool>(false);
         top.step();
+#ifdef VCD
+        vcd.sample(steps*2 + 0);
+#endif
         top.p_clk.set<bool>(true);
         top.step();
+#ifdef VCD
+        vcd.sample(steps*2 + 1);
+#endif
+        steps++;
 
         // if no current connection see if there is one
         if (sock == -1) {
@@ -177,6 +212,9 @@ int main()
 
         cout << "f " << f << endl;
         */
+
+        waves << vcd.buffer;
+        vcd.buffer.clear();
     }
 }