From 78f18ad59382dcc061c32f9d63fb75c069c9b18e Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 8 Dec 2011 21:15:02 +0100 Subject: [PATCH] corelogic: round-robin module --- migen/corelogic/__init__.py | 0 migen/corelogic/roundrobin.py | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 migen/corelogic/__init__.py create mode 100644 migen/corelogic/roundrobin.py diff --git a/migen/corelogic/__init__.py b/migen/corelogic/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/migen/corelogic/roundrobin.py b/migen/corelogic/roundrobin.py new file mode 100644 index 00000000..834cfae5 --- /dev/null +++ b/migen/corelogic/roundrobin.py @@ -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 -- 2.30.2