-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwb_bridge.py
63 lines (46 loc) · 1.58 KB
/
wb_bridge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import itertools
import math
from nmigen import *
from nmigen_boards.resources import *
from nmigen.build import *
from nmigen_soc import wishbone
from pym.icesugar_nano import *
from pym.uartbridge import *
from pym.gpio import *
class UartTerm(Elaboratable):
def __init__(self, uart_divisor, uart_pins, gpio_pins):
self._wb_dec = wishbone.Decoder(addr_width=30, data_width=32, granularity=32)
# wishbone master
self._ub = UARTBridge(divisor=uart_divisor, pins=uart_pins)
# wishbone devices
self._gpio = GpioCtrl(pins=gpio_pins)
self._wb_dec.add(self._gpio.bus, addr=0x10000000)
def elaborate(self, p):
m = Module()
m.submodules.ub = self._ub
m.submodules.wb_dec = self._wb_dec
m.submodules.gpio = self._gpio
m.d.comb += [
self._ub.bus.connect(self._wb_dec.bus),
]
return m
if __name__ == "__main__":
# dummy uart port
pmod2_uart = [
UARTResource(1, rx="C5", tx="B6",
attrs=Attrs(IO_STANDARD="SB_LVTTL", PULLUP=1)),
]
p = iCESugarNanoPlatform()
p.add_resources(p.gpio)
p.add_resources(pmod2_uart)
uart_pins = p.request("uart", 0)
gpio_pins = []
for idx in itertools.count():
try:
gpio_pins.append(p.request("PMOD3", idx))
except ResourceError:
break
print("default_clk_frequency: {}".format(p.default_clk_frequency))
uart_divisor = int(p.default_clk_frequency // 115200)
demo = UartTerm(uart_divisor, uart_pins, gpio_pins)
p.build(demo, do_program=True)