mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
corelogic: round-robin module
This commit is contained in:
parent
7c99e51b90
commit
78f18ad593
2 changed files with 22 additions and 0 deletions
0
migen/corelogic/__init__.py
Normal file
0
migen/corelogic/__init__.py
Normal file
22
migen/corelogic/roundrobin.py
Normal file
22
migen/corelogic/roundrobin.py
Normal file
|
@ -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])
|
Loading…
Reference in a new issue