2011-12-18 15:54:39 -05:00
|
|
|
from migen.fhdl.structure import *
|
2013-03-12 11:45:28 -04:00
|
|
|
from migen.fhdl.module import Module
|
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
|
2012-02-15 12:23:31 -05:00
|
|
|
from migen.bank.description import READ_ONLY, WRITE_ONLY
|
2011-12-05 11:43:56 -05:00
|
|
|
|
2013-03-12 11:45:28 -04:00
|
|
|
class Example(Module):
|
|
|
|
def __init__(self, ninputs=32, noutputs=32):
|
|
|
|
r_o = description.RegisterField(noutputs, atomic_write=True)
|
|
|
|
r_i = description.RegisterField(ninputs, READ_ONLY, WRITE_ONLY)
|
2011-12-05 11:43:56 -05:00
|
|
|
|
2013-03-12 11:45:28 -04: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
|
|
|
|
2013-03-12 11:45:28 -04:00
|
|
|
###
|
2011-12-05 11:43:56 -05:00
|
|
|
|
2013-03-12 11:45:28 -04:00
|
|
|
gpio_in_s = Signal(ninputs)
|
|
|
|
self.specials += MultiReg(self.gpio_in, "ext", gpio_in_s, "sys")
|
|
|
|
self.comb += [
|
|
|
|
r_i.field.w.eq(gpio_in_s),
|
|
|
|
self.gpio_out.eq(r_o.field.r)
|
|
|
|
]
|
|
|
|
|
|
|
|
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)
|