Demonstrates adding extra debug signals traces to the dump file
authorCesar Strauss <cestrauss@gmail.com>
Fri, 14 Aug 2020 11:06:49 +0000 (08:06 -0300)
committerCesar Strauss <cestrauss@gmail.com>
Sat, 15 Aug 2020 09:27:26 +0000 (06:27 -0300)
At simulation time, you can declare a new signal, and use it inside
the test case, as any other signal. By including it in the "traces"
parameter of Simulator.write_vcd, it is included in the trace dump file.

Useful for adding "printf" style debugging for GTKWave.

src/soc/experiment/alu_fsm.py

index 3a3d9db111af3d9152d21017b96048746662562f..2cdc7c324855d69f13395caef3362892d4df2631 100644 (file)
@@ -212,6 +212,7 @@ def write_gtkw(base_name, top_dut_name, loc):
     # color styles
     style_input = GTKWColor.orange
     style_output = GTKWColor.yellow
+    style_debug = GTKWColor.red
     with open(base_name + ".gtkw", "wt") as gtkw_file:
         gtkw = GTKWSave(gtkw_file)
         gtkw.comment("Auto-generated by " + loc)
@@ -231,6 +232,11 @@ def write_gtkw(base_name, top_dut_name, loc):
                        datafmt='dec')
             gtkw.trace(dut + "p_valid_i", color=style_input)
             gtkw.trace(dut + "p_ready_o", color=style_output)
+        with gtkw.group("debug"):
+            gtkw.blank("Some debug statements")
+            # change the displayed name in the panel
+            gtkw.trace("top.zero", alias='zero delay shift',
+                       color=style_debug)
         with gtkw.group("internal"):
             gtkw.trace(dut + "fsm_state")
             gtkw.trace(dut + "count[3:0]")
@@ -260,6 +266,11 @@ def test_shifter():
     sim = Simulator(m)
     sim.add_clock(1e-6)
 
+    # demonstrates adding extra debug signal traces
+    # they end up in the top module
+    #
+    zero = Signal()  # mark an interesting place
+
     def send(data, shift, direction):
         # present input data and assert valid_i
         yield dut.p.data_i.data.eq(data)
@@ -306,12 +317,18 @@ def test_shifter():
         # 3 << 4 = 48
         yield from receive(48)
         # 21 << 0 = 21
+        # you can look for the rising edge of this signal to quickly
+        # locate this point in the traces
+        yield zero.eq(1)
         yield from receive(21)
+        yield zero.eq(0)
 
     sim.add_sync_process(producer)
     sim.add_sync_process(consumer)
     sim_writer = sim.write_vcd(
         "test_shifter.vcd",
+        # include additional signals in the trace dump
+        traces=[zero]
     )
     with sim_writer:
         sim.run()