litex/migen/bus/csr.py

34 lines
771 B
Python
Raw Normal View History

2011-12-16 15:30:14 -05:00
from migen.fhdl.structure import *
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 = [
2011-12-11 14:16:50 -05:00
(True, "a", 14),
2011-12-08 12:47:32 -05:00
(True, "we", 1),
(True, "d", 32),
(False, "d", 32)
]
class Master(Simple):
2011-12-08 13:16:08 -05:00
def __init__(self, name=""):
Simple.__init__(self, _desc, False, name)
2011-12-04 18:16:44 -05:00
2011-12-08 12:47:32 -05:00
class Slave(Simple):
2011-12-08 13:16:08 -05:00
def __init__(self, name=""):
Simple.__init__(self, _desc, True, name)
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 = []
2011-12-16 15:30:14 -05:00
rb = Constant(0, BV(32))
2011-12-04 18:16:44 -05:00
for slave in self.slaves:
2011-12-16 15:30:14 -05:00
comb.append(slave.a_i.eq(self.master.a_o))
comb.append(slave.we_i.eq(self.master.we_o))
comb.append(slave.d_i.eq(self.master.d_o))
2011-12-04 18:16:44 -05:00
rb = rb | slave.d_o
2011-12-16 15:30:14 -05:00
comb.append(self.master.d_i.eq(rb))
return Fragment(comb)