allow i2c to be routed via JTAG
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 3 Oct 2020 19:46:44 +0000 (20:46 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 3 Oct 2020 19:46:44 +0000 (20:46 +0100)
src/soc/debug/jtag.py
src/soc/litex/florent/libresoc/core.py
src/soc/litex/florent/ls180soc.py

index 5aa0bf536fee317ef34b319821467f4f8d8d4e43..45d4ee30f3eb26b52c65faa9e71d74a26cbd2d48 100644 (file)
@@ -26,7 +26,9 @@ def dummy_pinset():
     gpios = []
     for i in range(16):
         gpios.append("gpio%d*" % i)
-    return {'uart': ['tx+', 'rx-'], 'gpio': gpios}
+    return {'uart': ['tx+', 'rx-'],
+             'gpio': gpios,
+             'i2c': ['sda*', 'scl+']}
 
 # TODO: move to suitable location
 class Pins:
index f74b5f47d0159ddec0b4cbd909f174b8d9ab5bd1..44202b3b6d89aa3c2fe9f1177e053d4e7bca96a4 100644 (file)
@@ -8,6 +8,7 @@ from litex.soc.cores.cpu import CPU
 from soc.debug.jtag import Pins, dummy_pinset # TODO move to suitable location
 from c4m.nmigen.jtag.tap import IOType
 
+from libresoc.ls180 import io
 from libresoc.ls180io import make_uart, make_gpio
 from litex.build.generic_platform import ConstraintManager
 
@@ -39,6 +40,12 @@ def make_pad(res, dirn, name, suffix, cpup, iop):
     res['%s_%s__core__%s' % (cpud, name, suffix)] = cpup
     res['%s_%s__pad__%s' % (iod, name, suffix)] = iop
 
+def get_field(rec, name):
+    for f in rec.layout:
+        f = f[0]
+        if f.endswith(name):
+            return getattr(rec, f)
+
 
 def make_jtag_ioconn(res, pin, cpupads, iopads):
     (fn, pin, iotype, pin_name, scan_idx) = pin
@@ -48,6 +55,8 @@ def make_jtag_ioconn(res, pin, cpupads, iopads):
     print ("pin", fn, pin, iotype, pin_name)
     cpu = cpupads[fn]
     io = iopads[fn]
+    print ("cpu fn", cpu)
+    print ("io fn", io)
     sigs = []
 
     name = "%s_%s" % (fn, pin)
@@ -69,11 +78,13 @@ def make_jtag_ioconn(res, pin, cpupads, iopads):
     elif iotype == IOType.InTriOut:
         if fn == 'gpio': # sigh decode GPIO special-case
             idx = int(pin[4:])
-        cpup, iop = cpu.i[idx], io.i[idx]
+        else:
+            idx = 0
+        cpup, iop = get_field(cpu, "i")[idx], get_field(io, "i")[idx]
         make_pad(res, False, name, "i", cpup, iop)
-        cpup, iop = cpu.o[idx], io.o[idx]
+        cpup, iop = get_field(cpu, "o")[idx], get_field(io, "o")[idx]
         make_pad(res, True, name, "o", cpup, iop)
-        cpup, iop = cpu.oe[idx], io.oe[idx]
+        cpup, iop = get_field(cpu, "oe")[idx], get_field(io, "oe")[idx]
         make_pad(res, True, name, "oe", cpup, iop)
 
     if iotype in (IOType.In, IOType.InTriOut):
@@ -214,13 +225,13 @@ class LibreSoC(CPU):
         if variant == 'ls180':
             # urr yuk.  have to expose iopads / pins from core to litex
             # then back again.  cut _some_ of that out by connecting
-            self.padresources = (make_uart('uart', 0),
-                                 make_gpio('gpio', 0, 16))
+            self.padresources = io()
             self.pad_cm = ConstraintManager(self.padresources, [])
-            self.cpupads = {'uart': platform.request('uart', 0),
-                            'gpio': platform.request('gpio', 0)}
-            iopads = {'uart': self.pad_cm.request('uart', 0),
-                            'gpio': self.pad_cm.request('gpio', 0)}
+            self.cpupads = {}
+            iopads = {}
+            for (periph, num) in [('uart', 0), ('gpio', 0), ('i2c', 0)]:
+                self.cpupads[periph] = platform.request(periph, num)
+                iopads[periph] = self.pad_cm.request(periph, num)
 
             p = Pins(dummy_pinset())
             for pin in list(p):
index 50d2a95f9ff1bc781c112eb3ea0e78885c813693..4a14b2442817bad04fc9355d533227bce2a101eb 100755 (executable)
@@ -468,7 +468,8 @@ class LibreSoCSim(SoCCore):
             self.add_csr(name)
 
         # I2C Master
-        self.submodules.i2c = I2CMaster(platform.request("i2c"))
+        i2c_core_pads = self.cpu.cpupads['i2c']
+        self.submodules.i2c = I2CMaster(i2c_core_pads)
         self.add_csr("i2c")
 
         # SDCard -----------------------------------------------------