wishbone: arbiter
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 8 Dec 2011 22:21:25 +0000 (23:21 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 8 Dec 2011 22:21:25 +0000 (23:21 +0100)
migen/bus/wishbone.py

index b92d5c59983c52b67a4d040a21d5bfb3eaa916a1..1e7f1e8e608b2c2996f288168e99d1283756c576 100644 (file)
@@ -1,5 +1,7 @@
 from migen.fhdl import structure as f
-from .simple import Simple
+from migen.corelogic import roundrobin, multimux
+from .simple import Simple, GetSigName
+from functools import partial
 
 _desc = [
        (True,  "adr",  32),
@@ -22,3 +24,33 @@ class Master(Simple):
 class Slave(Simple):
        def __init__(self, name=""):
                Simple.__init__(self, _desc, True, name)
+
+class Arbiter:
+       def __init__(self, masters, target):
+               self.masters = masters
+               self.target = target
+               self.rr = roundrobin.Inst(len(self.masters))
+
+       def GetFragment(self):
+               comb = []
+               
+               # mux master->slave signals
+               m2s_names = [GetSigName(x, False) for x in _desc if x[0]]
+               m2s_masters = [[getattr(m, name) for name in m2s_names] for m in self.masters]
+               m2s_target = [getattr(self.target, name) for name in m2s_names]
+               comb += multimux.MultiMux(self.rr.grant, m2s_masters, m2s_target)
+               
+               # connect slave->master signals
+               s2m_names = [GetSigName(x, False) for x in _desc if not x[0]]
+               for name in s2m_names:
+                       source = getattr(self.target, name)
+                       for m in self.masters:
+                               dest = getattr(m, name)
+                               comb.append(f.Assign(dest, source))
+               
+               # connect bus requests to round-robin selector
+               reqs = [m.cyc_o for m in self.masters]
+               comb.append(f.Assign(self.rr.request, f.Cat(*reqs)))
+               
+               return f.Fragment(comb) + self.rr.GetFragment()
+