2011-12-16 15:30:14 -05:00
|
|
|
from migen.fhdl.structure import *
|
2012-02-15 10:30:16 -05:00
|
|
|
from migen.corelogic.misc import optree
|
2011-12-08 12:47:32 -05:00
|
|
|
|
2012-02-15 10:30:16 -05:00
|
|
|
(S_TO_M, M_TO_S) = range(2)
|
2011-12-08 17:06:04 -05:00
|
|
|
|
2011-12-08 12:47:32 -05:00
|
|
|
# desc is a list of tuples, each made up of:
|
2012-02-15 10:30:16 -05:00
|
|
|
# 0) S_TO_M/M_TO_S: data direction
|
2011-12-08 12:47:32 -05:00
|
|
|
# 1) string: name
|
|
|
|
# 2) int: width
|
2012-02-15 10:30:16 -05:00
|
|
|
|
|
|
|
class Description:
|
|
|
|
def __init__(self, *desc):
|
|
|
|
self.desc = desc
|
|
|
|
|
|
|
|
def get_names(self, direction, *exclude_list):
|
|
|
|
exclude = set(exclude_list)
|
|
|
|
return [signal[1]
|
|
|
|
for signal in self.desc
|
|
|
|
if signal[0] == direction and signal[1] not in exclude]
|
|
|
|
|
|
|
|
class SimpleInterface:
|
|
|
|
def __init__(self, desc):
|
|
|
|
self.desc = desc
|
|
|
|
modules = self.__module__.split(".")
|
|
|
|
busname = modules[len(modules)-1]
|
|
|
|
for signal in self.desc.desc:
|
|
|
|
signame = signal[1]
|
2011-12-16 15:30:14 -05:00
|
|
|
setattr(self, signame, Signal(BV(signal[2]), busname + "_" + signame))
|
2012-02-15 10:30:16 -05:00
|
|
|
|
|
|
|
class SimpleInterconnect:
|
|
|
|
def __init__(self, master, slaves):
|
|
|
|
self.master = master
|
|
|
|
self.slaves = slaves
|
2012-01-15 09:48:51 -05:00
|
|
|
|
2012-02-15 10:30:16 -05:00
|
|
|
def get_fragment(self):
|
2012-02-15 10:42:05 -05:00
|
|
|
desc = self.master.desc
|
|
|
|
s2m = desc.get_names(S_TO_M)
|
|
|
|
m2s = desc.get_names(M_TO_S)
|
|
|
|
comb = [getattr(slave, name).eq(getattr(self.master, name))
|
|
|
|
for name in m2s for slave in self.slaves]
|
|
|
|
comb += [getattr(self.master, name).eq(
|
2012-02-15 10:30:16 -05:00
|
|
|
optree("|", [getattr(slave, name) for slave in self.slaves])
|
|
|
|
)
|
|
|
|
for name in s2m]
|
|
|
|
return Fragment(comb)
|