litex/examples/simple_gpio.py

23 lines
615 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 = 31
2011-12-05 11:43:56 -05:00
2012-02-06 07:55:50 -05:00
oreg = description.RegisterField("o", noutputs)
ireg = description.RegisterRaw("i", ninputs)
2011-12-05 11:43:56 -05:00
# input path
gpio_in = Signal(BV(ninputs))
gpio_in_s = Signal(BV(ninputs)) # synchronizer
2012-02-06 07:55:50 -05:00
insync = [gpio_in_s.eq(gpio_in), ireg.w.eq(gpio_in_s)]
inf = Fragment(sync=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
2012-02-06 07:55:50 -05:00
oreg.field.r.name_override = "gpio_out"
2011-12-05 11:43:56 -05:00
i = bank.interface
2012-02-15 10:42:17 -05:00
v = verilog.convert(f, {i.dat_r, oreg.field.r, i.adr, i.we, i.dat_w, gpio_in})
2011-12-16 10:02:55 -05:00
print(v)