litex/examples/simple_gpio.py

24 lines
704 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
from migen.bank.description import READ_ONLY, WRITE_ONLY
2011-12-05 11:43:56 -05:00
ninputs = 32
noutputs = 32
2011-12-05 11:43:56 -05:00
2012-02-06 07:55:50 -05:00
oreg = description.RegisterField("o", noutputs)
ireg = description.RegisterField("i", ninputs, READ_ONLY, WRITE_ONLY)
2011-12-05 11:43:56 -05:00
# input path
gpio_in = Signal(BV(ninputs))
gpio_in_s = Signal(BV(ninputs)) # synchronizer
insync = [gpio_in_s.eq(gpio_in), ireg.field.w.eq(gpio_in_s)]
2012-02-06 07:55:50 -05:00
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)