litex/examples/simple_gpio.py

26 lines
762 B
Python
Raw Normal View History

from migen.fhdl.structure import *
2011-12-05 11:43:56 -05:00
from migen.fhdl import verilog
from migen.bank import description, csrgen
ninputs = 4
noutputs = 4
oreg = description.Register("o")
ofield = description.Field(oreg, "val", noutputs)
ireg = description.Register("i")
ifield = description.Field(ireg, "val", ninputs, description.READ_ONLY, description.WRITE_ONLY)
# input path
gpio_in = Signal(BV(ninputs))
gpio_in_s = Signal(BV(ninputs)) # synchronizer
incomb = [ifield.dev_we.eq(1)]
insync = [gpio_in_s.eq(gpio_in), ifield.dev_w.eq(gpio_in_s)]
inf = Fragment(incomb, insync)
2011-12-05 11:43:56 -05:00
bank = csrgen.Bank([oreg, ireg])
2011-12-16 10:02:55 -05:00
f = bank.get_fragment() + inf
2011-12-05 11:43:56 -05:00
i = bank.interface
ofield.dev_r.name = "gpio_out"
2011-12-08 10:35:32 -05:00
v = verilog.Convert(f, {i.d_o, ofield.dev_r, i.a_i, i.we_i, i.d_i, gpio_in})
2011-12-16 10:02:55 -05:00
print(v)