hooray got the output at least created in build/
[pinmux.git] / src / spec / testing_stage1.py
1 #!/usr/bin/env python3
2 from nmigen.build.dsl import Resource, Subsignal, Pins
3 from nmigen.build.plat import TemplatedPlatform
4 from nmigen import Elaboratable, Signal, Module
5
6 # Was thinking of using these functions, but skipped for simplicity for now
7 # XXX nope. the output from JSON file.
8 #from pinfunctions import (i2s, lpc, emmc, sdmmc, mspi, mquadspi, spi,
9 # quadspi, i2c, mi2c, jtag, uart, uartfull, rgbttl, ulpi, rgmii, flexbus1,
10 # flexbus2, sdram1, sdram2, sdram3, vss, vdd, sys, eint, pwm, gpio)
11
12 # File for stage 1 pinmux tested proposed by Luke,
13 # https://bugs.libre-soc.org/show_bug.cgi?id=50#c10
14
15
16 def dummy_pinset():
17 # sigh this needs to come from pinmux.
18 gpios = []
19 for i in range(16):
20 gpios.append("%d*" % i)
21 return {'uart': ['tx+', 'rx-'],
22 'gpio': gpios,
23 'i2c': ['sda*', 'scl+']}
24
25 """
26 a function is needed which turns the results of dummy_pinset()
27 into:
28
29 [UARTResource("uart", 0, tx=..., rx=..),
30 I2CResource("i2c", 0, scl=..., sda=...),
31 Resource("gpio", 0, Subsignal("i"...), Subsignal("o"...)
32 Resource("gpio", 1, Subsignal("i"...), Subsignal("o"...)
33 ...
34 ]
35 """
36
37
38 def create_resources(pinset):
39 resources = []
40 for periph, pins in pinset.items():
41 print(periph, pins)
42 if periph == 'i2c':
43 #print("I2C required!")
44 resources.append(I2CResource('i2c', 0, sda='sda', scl='scl'))
45 elif periph == 'uart':
46 #print("UART required!")
47 resources.append(UARTResource('uart', 0, tx='tx', rx='rx'))
48 elif periph == 'gpio':
49 #print("GPIO required!")
50 print ("GPIO is defined as '*' type, meaning i, o and oe needed")
51 resources.append(Resource('gpio', 0,
52 Subsignal("i", Pins('i0', dir="i", conn=None, assert_width=1)),
53 Subsignal("oe", Pins('oe0', dir="o", conn=None, assert_width=1)),
54 Subsignal("o", Pins('o0', dir="o", conn=None, assert_width=1))))
55 return resources
56
57
58 def UARTResource(*args, rx, tx):
59 io = []
60 io.append(Subsignal("rx", Pins(rx, dir="i", assert_width=1)))
61 io.append(Subsignal("tx", Pins(tx, dir="o", assert_width=1)))
62 return Resource.family(*args, default_name="uart", ios=io)
63
64
65 def I2CResource(*args, scl, sda):
66 io = []
67 io.append(Subsignal("scl", Pins(scl, dir="io", assert_width=1)))
68 io.append(Subsignal("sda", Pins(sda, dir="io", assert_width=1)))
69 return Resource.family(*args, default_name="i2c", ios=io)
70
71
72 # ridiculously-simple top-level module. doesn't even have a sync domain
73 # and can't have one until a clock has been established by DummyPlatform.
74 class Blinker(Elaboratable):
75 def __init__(self):
76 pass
77 def elaborate(self, platform):
78 m = Module()
79 count = Signal(5)
80 m.d.comb += count.eq(5)
81 return m
82
83
84 '''
85 _trellis_command_templates = [
86 r"""
87 {{invoke_tool("yosys")}}
88 {{quiet("-q")}}
89 {{get_override("yosys_opts")|options}}
90 -l {{name}}.rpt
91 {{name}}.ys
92 """,
93 ]
94 '''
95
96 # sigh, have to create a dummy platform for now.
97 # TODO: investigate how the heck to get it to output ilang. or verilog.
98 # or, anything, really. but at least it doesn't barf
99 class DummyPlatform(TemplatedPlatform):
100 resources = []
101 connectors = []
102 required_tools = []
103 command_templates = ['/bin/true']
104 file_templates = {
105 **TemplatedPlatform.build_script_templates,
106 "{{name}}.il": r"""
107 # {{autogenerated}}
108 {{emit_rtlil()}}
109 """,
110 "{{name}}.debug.v": r"""
111 /* {{autogenerated}} */
112 {{emit_debug_verilog()}}
113 """,
114 }
115 toolchain = None
116 def __init__(self, resources):
117 self.resources = resources
118 super().__init__()
119
120 """
121 and to create a Platform instance with that list, and build
122 something random
123
124 p=Platform()
125 p.resources=listofstuff
126 p.build(Blinker())
127 """
128 pinset = dummy_pinset()
129 resources = create_resources(pinset)
130 print(pinset)
131 print(resources)
132 p = DummyPlatform (resources)
133 p.resources = create_resources(pinset)
134 p.build(Blinker())
135