litex/examples/basic/simple_gpio.py

29 lines
835 B
Python
Raw Normal View History

from migen.fhdl.std import *
2011-12-05 11:43:56 -05:00
from migen.fhdl import verilog
2013-03-12 11:45:28 -04:00
from migen.genlib.cdc import MultiReg
2011-12-05 11:43:56 -05:00
from migen.bank import description, csrgen
2013-03-12 11:45:28 -04:00
class Example(Module):
def __init__(self, ninputs=32, noutputs=32):
r_o = description.CSRStorage(noutputs, atomic_write=True)
r_i = description.CSRStatus(ninputs)
2011-12-05 11:43:56 -05:00
self.submodules.bank = csrgen.Bank([r_o, r_i])
self.gpio_in = Signal(ninputs)
self.gpio_out = Signal(ninputs)
2011-12-05 11:43:56 -05:00
###
2011-12-05 11:43:56 -05:00
gpio_in_s = Signal(ninputs)
self.specials += MultiReg(self.gpio_in, gpio_in_s)
self.comb += [
self.gpio_out.eq(r_o.storage),
r_i.status.eq(gpio_in_s)
]
2013-03-12 11:45:28 -04:00
example = Example()
i = example.bank.bus
v = verilog.convert(example, {i.dat_r, i.adr, i.we, i.dat_w,
example.gpio_in, example.gpio_out})
2011-12-16 10:02:55 -05:00
print(v)