Adding stage2 file for auto-gen of the pinmux block test
[pinmux.git] / src / spec / stage2.py
1 #!/usr/bin/env python3
2 """
3 pinmux documented here https://libre-soc.org/docs/pinmux/
4 """
5 from nmigen.build.dsl import Resource, Subsignal, Pins
6 from nmigen.build.plat import TemplatedPlatform
7 from nmigen.build.res import ResourceManager, ResourceError
8 from nmigen.hdl.rec import Layout
9 from nmigen import Elaboratable, Signal, Module, Instance
10 from collections import OrderedDict
11 from jtag import JTAG, resiotypes, iotypes, scanlens
12 from copy import deepcopy
13 from nmigen.cli import rtlil
14 import sys
15
16 # extra dependencies for jtag testing (?)
17 #from soc.bus.sram import SRAM
18
19 #from nmigen import Memory
20 from nmigen.sim import Simulator, Delay, Settle, Tick, Passive
21
22 from nmutil.util import wrap
23
24 from nmutil.gtkw import write_gtkw
25
26 # from soc.debug.jtagutils import (jtag_read_write_reg,
27 # jtag_srv, jtag_set_reset,
28 # jtag_set_ir, jtag_set_get_dr)
29
30 from soc.debug.test.test_jtag_tap import (jtag_read_write_reg,
31 jtag_set_reset,
32 jtag_set_shift_ir,
33 jtag_set_shift_dr,
34 jtag_set_run,
35 jtag_set_idle,
36 tms_data_getset)
37
38 def dummy_pinset():
39 # sigh this needs to come from pinmux.
40 gpios = []
41 for i in range(4):
42 gpios.append("%d*0" % i) # gpios to mux 0
43 return {'uart': ['tx+1', 'rx-1'],
44 'gpio': gpios,
45 # 'jtag': ['tms-', 'tdi-', 'tdo+', 'tck+'],
46 'i2c': ['sda*2', 'scl+2']}
47
48
49 """
50 a function is needed which turns the results of dummy_pinset()
51 into:
52
53 [UARTResource("uart", 0, tx=..., rx=..),
54 I2CResource("i2c", 0, scl=..., sda=...),
55 Resource("gpio", 0, Subsignal("i"...), Subsignal("o"...)
56 Resource("gpio", 1, Subsignal("i"...), Subsignal("o"...)
57 ...
58 ]
59 """
60 # TODO: move to suitable location
61 class Pins:
62 """declare a list of pins, including name and direction. grouped by fn
63 the pin dictionary needs to be in a reliable order so that the JTAG
64 Boundary Scan is also in a reliable order
65 """
66 def __init__(self, pindict=None):
67 if pindict is None:
68 pindict = {}
69 self.io_names = OrderedDict()
70 if isinstance(pindict, OrderedDict):
71 self.io_names.update(pindict)
72 else:
73 keys = list(pindict.keys())
74 keys.sort()
75 for k in keys:
76 self.io_names[k] = pindict[k]
77
78 def __iter__(self):
79 # start parsing io_names and enumerate them to return pin specs
80 scan_idx = 0
81 for fn, pins in self.io_names.items():
82 for pin in pins:
83 # decode the pin name and determine the c4m jtag io type
84 name, pin_type, bank = pin[:-2], pin[-2], pin[-1]
85 iotype = iotypes[pin_type]
86 pin_name = "%s_%s" % (fn, name)
87 yield (fn, name, iotype, pin_name, scan_idx, bank)
88 scan_idx += scanlens[iotype] # inc boundary reg scan offset
89
90
91 if __name__ == '__main__':
92 #pname = "test"
93 pinset = dummy_pinset()
94 #print()
95 #pin_test = Pins(Pins(pname+"_oe", dir="o", assert_width=1))
96 pin_test = Pins(pinset)
97 print(dir(pin_test))
98 print(pin_test.io_names)
99 for fn, name, iotype, pin_name, scan_idx, bank in pin_test:
100 print(fn, name, iotype, pin_name, scan_idx, "Bank %s" % bank)