2012-09-12 16:19:42 -04:00
|
|
|
from migen.fhdl.structure import *
|
|
|
|
from migen.bus import csr
|
|
|
|
from migen.bank import description, csrgen
|
|
|
|
from migen.bank.description import *
|
|
|
|
|
|
|
|
|
|
|
|
class MigIo:
|
2012-09-13 07:14:27 -04:00
|
|
|
def __init__(self,address, width, mode = "IO"):
|
|
|
|
self.address = address
|
2012-09-12 16:19:42 -04:00
|
|
|
self.width = width
|
|
|
|
self.mode = mode
|
|
|
|
if "I" in self.mode:
|
|
|
|
self.i = Signal(BV(self.width))
|
|
|
|
self.ireg = description.RegisterField("i", self.width, READ_ONLY, WRITE_ONLY)
|
|
|
|
self.ireg.field.w.name_override = "inputs"
|
|
|
|
if "O" in self.mode:
|
|
|
|
self.o = Signal(BV(self.width))
|
|
|
|
self.oreg = description.RegisterField("o", self.width)
|
|
|
|
self.oreg.field.r.name_override = "ouptuts"
|
2012-09-13 07:14:27 -04:00
|
|
|
self.bank = csrgen.Bank([self.oreg, self.ireg], address=self.address)
|
2012-09-12 16:19:42 -04:00
|
|
|
|
|
|
|
def get_fragment(self):
|
|
|
|
comb = []
|
2012-09-13 07:14:27 -04:00
|
|
|
if "I" in self.mode:
|
|
|
|
comb += [self.ireg.field.w.eq(self.i)]
|
|
|
|
if "O" in self.mode:
|
|
|
|
comb += [self.o.eq(self.oreg.field.r)]
|
2012-09-12 16:19:42 -04:00
|
|
|
return Fragment(comb=comb) + self.bank.get_fragment()
|