1f4e9e8c3698d62c4585f89bb448ff45b8f993e5
2 from nmigen
.build
.dsl
import Resource
, Subsignal
, Pins
3 from nmigen
.build
.plat
import TemplatedPlatform
4 from nmigen
import Elaboratable
, Signal
, Module
, Instance
5 from collections
import OrderedDict
8 # Was thinking of using these functions, but skipped for simplicity for now
9 # XXX nope. the output from JSON file.
10 #from pinfunctions import (i2s, lpc, emmc, sdmmc, mspi, mquadspi, spi,
11 # quadspi, i2c, mi2c, jtag, uart, uartfull, rgbttl, ulpi, rgmii, flexbus1,
12 # flexbus2, sdram1, sdram2, sdram3, vss, vdd, sys, eint, pwm, gpio)
14 # File for stage 1 pinmux tested proposed by Luke,
15 # https://bugs.libre-soc.org/show_bug.cgi?id=50#c10
19 # sigh this needs to come from pinmux.
22 gpios
.append("%d*" % i
)
23 return {'uart': ['tx+', 'rx-'],
25 'i2c': ['sda*', 'scl+']}
28 a function is needed which turns the results of dummy_pinset()
31 [UARTResource("uart", 0, tx=..., rx=..),
32 I2CResource("i2c", 0, scl=..., sda=...),
33 Resource("gpio", 0, Subsignal("i"...), Subsignal("o"...)
34 Resource("gpio", 1, Subsignal("i"...), Subsignal("o"...)
40 def create_resources(pinset
):
42 for periph
, pins
in pinset
.items():
45 #print("I2C required!")
46 resources
.append(I2CResource('i2c', 0, sda
='sda', scl
='scl'))
47 elif periph
== 'uart':
48 #print("UART required!")
49 resources
.append(UARTResource('uart', 0, tx
='tx', rx
='rx'))
50 elif periph
== 'gpio':
51 #print("GPIO required!")
52 print ("GPIO is defined as '*' type, meaning i, o and oe needed")
55 pname
= "gpio"+pin
[:-1] # strip "*" on end
57 # urrrr... tristsate and io assume a single pin which is
58 # of course exactly what we don't want in an ASIC: we want
59 # *all three* pins but the damn port is not outputted
60 # as a triplet, it's a single Record named "io". sigh.
61 # therefore the only way to get a triplet of i/o/oe
62 # is to *actually* create explicit triple pins
63 pads
.append(Subsignal("i",
64 Pins(pname
+"_i", dir="i", assert_width
=1)))
65 pads
.append(Subsignal("o",
66 Pins(pname
+"_o", dir="o", assert_width
=1)))
67 pads
.append(Subsignal("oe",
68 Pins(pname
+"_oe", dir="oe", assert_width
=1)))
69 ios
.append(Resource
.family(pname
, 0, default_name
=pname
,
71 resources
.append(Resource
.family(periph
, 0, default_name
="gpio",
75 clk
= Resource("clk", 0, Pins("sys_clk", dir="i"))
76 rst
= Resource("rst", 0, Pins("sys_rst", dir="i"))
82 def UARTResource(*args
, rx
, tx
):
84 io
.append(Subsignal("rx", Pins(rx
, dir="i", assert_width
=1)))
85 io
.append(Subsignal("tx", Pins(tx
, dir="o", assert_width
=1)))
86 return Resource
.family(*args
, default_name
="uart", ios
=io
)
89 def I2CResource(*args
, scl
, sda
):
91 io
.append(Subsignal("scl", Pins(scl
, dir="io", assert_width
=1)))
92 io
.append(Subsignal("sda", Pins(sda
, dir="io", assert_width
=1)))
93 return Resource
.family(*args
, default_name
="i2c", ios
=io
)
96 # ridiculously-simple top-level module. doesn't even have a sync domain
97 # and can't have one until a clock has been established by DummyPlatform.
98 class Blinker(Elaboratable
):
99 def __init__(self
, pinset
):
100 self
.jtag
= JTAG(pinset
, "sync")
102 def elaborate(self
, platform
):
104 m
.submodules
.jtag
= self
.jtag
106 m
.d
.sync
+= count
.eq(5)
107 print ("resources", platform
.resources
.items())
108 gpio
= platform
.request("gpio", 0)
109 print (gpio
, gpio
.layout
, gpio
.fields
)
110 # get the GPIO bank, mess about with some of the pins
111 m
.d
.comb
+= gpio
.gpio0
.o
.eq(1)
112 m
.d
.comb
+= gpio
.gpio1
.o
.eq(gpio
.gpio2
.i
)
113 m
.d
.comb
+= gpio
.gpio1
.oe
.eq(count
[4])
114 m
.d
.sync
+= count
[0].eq(gpio
.gpio1
.i
)
115 # get the UART resource, mess with the output tx
116 uart
= platform
.request("uart", 0)
117 print (uart
, uart
.fields
)
118 m
.d
.comb
+= uart
.tx
.eq(1)
123 _trellis_command_templates = [
125 {{invoke_tool("yosys")}}
127 {{get_override("yosys_opts")|options}}
134 # sigh, have to create a dummy platform for now.
135 # TODO: investigate how the heck to get it to output ilang. or verilog.
136 # or, anything, really. but at least it doesn't barf
137 class DummyPlatform(TemplatedPlatform
):
139 resources
= OrderedDict()
141 command_templates
= ['/bin/true']
143 **TemplatedPlatform
.build_script_templates
,
148 "{{name}}.debug.v": r
"""
149 /* {{autogenerated}} */
150 {{emit_debug_verilog()}}
154 default_clk
= "clk" # should be picked up / overridden by platform sys.clk
155 default_rst
= "rst" # should be picked up / overridden by platform sys.rst
156 def __init__(self
, resources
):
158 self
.add_resources(resources
)
160 # XXX these aren't strictly necessary right now but the next
161 # phase is to add JTAG Boundary Scan so it maaay be worth adding?
162 # at least for the print statements
163 def get_input(self
, pin
, port
, attrs
, invert
):
164 self
._check
_feature
("single-ended input", pin
, attrs
,
165 valid_xdrs
=(0,), valid_attrs
=None)
167 print (" get_input", pin
, "port", port
, port
.layout
)
169 m
.d
.comb
+= pin
.i
.eq(self
._invert
_if
(invert
, port
))
172 def get_output(self
, pin
, port
, attrs
, invert
):
173 self
._check
_feature
("single-ended output", pin
, attrs
,
174 valid_xdrs
=(0,), valid_attrs
=None)
176 print (" get_output", pin
, "port", port
, port
.layout
)
178 m
.d
.comb
+= port
.eq(self
._invert
_if
(invert
, pin
.o
))
181 def get_tristate(self
, pin
, port
, attrs
, invert
):
182 self
._check
_feature
("single-ended tristate", pin
, attrs
,
183 valid_xdrs
=(0,), valid_attrs
=None)
186 m
.submodules
+= Instance("$tribuf",
189 i_A
=self
._invert
_if
(invert
, pin
.o
),
194 def get_input_output(self
, pin
, port
, attrs
, invert
):
195 self
._check
_feature
("single-ended input/output", pin
, attrs
,
196 valid_xdrs
=(0,), valid_attrs
=None)
197 print (" get_input_output", pin
, "port", port
, port
.layout
)
199 m
.submodules
+= Instance("$tribuf",
202 i_A
=self
._invert
_if
(invert
, pin
.o
),
205 m
.d
.comb
+= pin
.i
.eq(self
._invert
_if
(invert
, port
))
210 and to create a Platform instance with that list, and build
214 p.resources=listofstuff
217 pinset
= dummy_pinset()
218 resources
= create_resources(pinset
)
221 p
= DummyPlatform (resources
)
222 p
.build(Blinker(pinset
))