litex/migen/bus/csr.py

34 lines
804 B
Python
Raw Normal View History

2011-12-16 15:30:14 -05:00
from migen.fhdl.structure import *
2011-12-22 13:36:56 -05:00
from migen.corelogic.misc import optree
2011-12-16 10:02:55 -05:00
from migen.bus.simple import Simple
2011-12-04 18:16:44 -05:00
2011-12-08 12:47:32 -05:00
_desc = [
(True, "adr", 14),
2011-12-08 12:47:32 -05:00
(True, "we", 1),
(True, "dat", 8),
(False, "dat", 8)
2011-12-08 12:47:32 -05:00
]
class Master(Simple):
def __init__(self):
Simple.__init__(self, _desc, False)
2011-12-04 18:16:44 -05:00
2011-12-08 12:47:32 -05:00
class Slave(Simple):
def __init__(self):
Simple.__init__(self, _desc, True)
2011-12-04 18:16:44 -05:00
class Interconnect:
def __init__(self, master, slaves):
self.master = master
self.slaves = slaves
2011-12-16 10:02:55 -05:00
def get_fragment(self):
2011-12-04 18:16:44 -05:00
comb = []
for slave in self.slaves:
comb.append(slave.adr_i.eq(self.master.adr_o))
2011-12-16 15:30:14 -05:00
comb.append(slave.we_i.eq(self.master.we_o))
comb.append(slave.dat_i.eq(self.master.dat_o))
rb = optree("|", [slave.dat_o for slave in self.slaves])
comb.append(self.master.dat_i.eq(rb))
2011-12-16 15:30:14 -05:00
return Fragment(comb)