corelogic: round-robin module
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 8 Dec 2011 20:15:02 +0000 (21:15 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 8 Dec 2011 20:15:02 +0000 (21:15 +0100)
migen/corelogic/__init__.py [new file with mode: 0644]
migen/corelogic/roundrobin.py [new file with mode: 0644]

diff --git a/migen/corelogic/__init__.py b/migen/corelogic/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/migen/corelogic/roundrobin.py b/migen/corelogic/roundrobin.py
new file mode 100644 (file)
index 0000000..834cfae
--- /dev/null
@@ -0,0 +1,22 @@
+from migen.fhdl import structure as f
+
+class Inst:
+       def __init__(self, n):
+               self.n = n
+               self.bn = f.BitsFor(self.n-1)
+               f.Declare(self, "request", f.BV(self.n))
+               f.Declare(self, "grant", f.BV(self.bn))
+       
+       def GetFragment(self):
+               cases = []
+               for i in range(self.n):
+                       switch = []
+                       for j in reversed(range(i+1,i+self.n)):
+                               t = j % self.n
+                               switch = [f.If(self.request[t],
+                                       [f.Assign(self.grant, f.Constant(t, f.BV(self.bn)))],
+                                       switch)]
+                       case = f.If(~self.request[i], switch)
+                       cases.append((f.Constant(i, f.BV(self.bn)), case))
+               statement = f.Case(self.grant, cases)
+               return f.Fragment(sync=[statement])
\ No newline at end of file