sort out mess of trying to access the Pin resource instead of the pad
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 2 Dec 2021 12:18:47 +0000 (12:18 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 2 Dec 2021 12:19:49 +0000 (12:19 +0000)
it was connected to.  faillllll

src/spec/jtag.py
src/spec/testing_stage1.py

index 1766b67017003f6f87a98e5bc2845c83e1bfc3f8..539faa4ac2bb2f99744c9894f6793560a5ded275 100644 (file)
@@ -7,7 +7,7 @@ Pinmux documented here https://libre-soc.org/docs/pinmux/
 
 from nmigen.build.res import ResourceManager
 from nmigen.hdl.rec import Layout
-from collections import OrderedDict
+from collections import OrderedDict, defaultdict
 from nmigen.cli import rtlil
 
 from nmigen import (Module, Signal, Elaboratable, Cat)
@@ -156,7 +156,7 @@ class JTAG(TAP, Pins):
         # record resource lookup between core IO names and pads
         self.padlookup = {}
         self.requests_made = []
-        self.boundary_scan_pads = []
+        self.boundary_scan_pads = defaultdict(dict)
         self.resource_table = {}
         self.resource_table_pads = {}
         self.eqs = []                 # list of BS to core/pad connections
@@ -203,12 +203,14 @@ class JTAG(TAP, Pins):
     def boundary_elaborate(self, m, platform):
         jtag_resources = self.pad_mgr.resources
         core_resources = self.core_mgr.resources
+        self.asic_resources = {}
 
         # platform requested: make the exact same requests,
         # then add JTAG afterwards
         if platform is not None:
             for (name, number, dir, xdr) in self.requests_made:
                 asicpad = platform.request(name, number, dir=dir, xdr=xdr)
+                self.asic_resources[(name, number)] = asicpad
                 jtagpad = self.resource_table_pads[(name, number)]
                 print ("jtagpad", jtagpad, jtagpad.layout)
                 m.d.comb += recurse_down(asicpad, jtagpad)
@@ -242,7 +244,8 @@ class JTAG(TAP, Pins):
         yield self.bus.tdo
         yield self.bus.tck
         yield self.bus.tms
-        yield from self.boundary_scan_pads
+        for pad in self.boundary_scan_pads.values():
+            yield from pad.values()
 
     def request(self, name, number=0, *, dir=None, xdr=None):
         """looks like ResourceManager.request but can be called multiple times.
@@ -324,7 +327,7 @@ class JTAG(TAP, Pins):
                 self.eqs += [corepin.i.eq(io.core.i)]
                 # and padpin to JTAG pad
                 self.eqs += [io.pad.i.eq(padpin.i)]
-                self.boundary_scan_pads.append(padpin.i)
+                self.boundary_scan_pads[padpin.name]['i'] = padpin.i
             elif padpin.dir == 'o':
                 print ("jtag_request add output pin", padpin)
                 print ("                    corepin", corepin)
@@ -334,7 +337,7 @@ class JTAG(TAP, Pins):
                 self.eqs += [io.core.o.eq(corepin.o)]
                 # and JTAG pad to padpin
                 self.eqs += [padpin.o.eq(io.pad.o)]
-                self.boundary_scan_pads.append(padpin.o)
+                self.boundary_scan_pads[padpin.name]['o'] = padpin.o
             elif padpin.dir == 'io':
                 print ("jtag_request add io    pin", padpin)
                 print ("                   corepin", corepin)
@@ -353,9 +356,9 @@ class JTAG(TAP, Pins):
                 # and JTAG pad to padpin
                 self.eqs += [padpin.oe.eq(io.pad.oe)]
 
-                self.boundary_scan_pads.append(padpin.i)
-                self.boundary_scan_pads.append(padpin.o)
-                self.boundary_scan_pads.append(padpin.oe)
+                self.boundary_scan_pads[padpin.name]['i'] = padpin.i
+                self.boundary_scan_pads[padpin.name]['o'] = padpin.o
+                self.boundary_scan_pads[padpin.name]['oe'] = padpin.oe
 
         # finally record the *CORE* value just like ResourceManager.request()
         # so that the module using this can connect to *CORE* i/o to the
index 225cd6ef0dd9893b4c447d2ac2304c2887278459..0ff5510d23d32a8eb0428026db047f9095cbe5a2 100644 (file)
@@ -512,7 +512,9 @@ def test_case1():
 def test_gpios():
     print("Starting GPIO test case!")
     # Grab GPIO pad resource from JTAG BS
-    gpios_pad = top.jtag.resource_table_pads[('gpio', 0)]
+    print (top.jtag.boundary_scan_pads.keys())
+    gpio0_o = top.jtag.boundary_scan_pads['gpio_0__gpio0__o']['o']
+    gpio1_o = top.jtag.boundary_scan_pads['gpio_0__gpio1__o']['o']
     
     # Have the sim run through a for-loop where the gpio_o_test is 
     # incremented like a counter (0000, 0001...)
@@ -528,11 +530,13 @@ def test_gpios():
         yield Settle()
         yield # Move to the next clk cycle
 
-        print(type(top.gpio.gpio0.o), type(gpios_pad.gpio0.o))
-        print(top.gpio.gpio0.o, gpios_pad.gpio0.o)
-        pad_out = yield gpios_pad.gpio0.o
-        print (gpio_o_val, pad_out)
-        assert (gpio_o_val & 0b0001) == pad_out
+        # yield the pad output
+        pad0_out = yield gpio0_o
+        pad1_out = yield gpio1_o
+        print("gpio0", gpio0_o, bin(gpio_o_val), pad0_out, pad1_out)
+        # gpio_o_val is a 4-bit binary number setting each pad (single-bit)
+        assert ((gpio_o_val & 0b0001) != 0) == pad0_out
+        assert ((gpio_o_val & 0b0010) != 0) == pad1_out
 
     # Another for loop to run through gpio_oe_test. Assert:
     # + oe set at core matches oe seen at pad.