simple_gpio.py 613 Bytes
Newer Older
1
from migen.fhdl.structure import *
2 3 4 5
from migen.fhdl import verilog
from migen.bank import description, csrgen

ninputs = 4
6
noutputs = 31
7

Sebastien Bourdeauducq's avatar
Sebastien Bourdeauducq committed
8 9
oreg = description.RegisterField("o", noutputs)
ireg = description.RegisterRaw("i", ninputs)
10 11

# input path
12 13
gpio_in = Signal(BV(ninputs))
gpio_in_s = Signal(BV(ninputs)) # synchronizer
Sebastien Bourdeauducq's avatar
Sebastien Bourdeauducq committed
14 15
insync = [gpio_in_s.eq(gpio_in), ireg.w.eq(gpio_in_s)]
inf = Fragment(sync=insync)
16 17

bank = csrgen.Bank([oreg, ireg])
18
f = bank.get_fragment() + inf
Sebastien Bourdeauducq's avatar
Sebastien Bourdeauducq committed
19
oreg.field.r.name_override = "gpio_out"
20
i = bank.interface
Sebastien Bourdeauducq's avatar
Sebastien Bourdeauducq committed
21
v = verilog.convert(f, {i.d_o, oreg.field.r, i.a_i, i.we_i, i.d_i, gpio_in})
22
print(v)