2011-12-16 15:30:14 -05:00
|
|
|
from migen.fhdl.structure import *
|
2011-12-08 15:15:02 -05:00
|
|
|
|
|
|
|
class Inst:
|
|
|
|
def __init__(self, n):
|
|
|
|
self.n = n
|
2011-12-16 15:30:14 -05:00
|
|
|
self.bn = bits_for(self.n-1)
|
2011-12-18 15:54:28 -05:00
|
|
|
self.request = Signal(BV(self.n))
|
|
|
|
self.grant = Signal(BV(self.bn))
|
2011-12-08 15:15:02 -05:00
|
|
|
|
2011-12-16 10:02:55 -05:00
|
|
|
def get_fragment(self):
|
2011-12-08 15:15:02 -05:00
|
|
|
cases = []
|
|
|
|
for i in range(self.n):
|
|
|
|
switch = []
|
|
|
|
for j in reversed(range(i+1,i+self.n)):
|
|
|
|
t = j % self.n
|
2011-12-16 15:30:14 -05:00
|
|
|
switch = [
|
|
|
|
If(self.request[t],
|
|
|
|
self.grant.eq(Constant(t, BV(self.bn)))
|
|
|
|
).Else(
|
|
|
|
*switch
|
|
|
|
)
|
|
|
|
]
|
|
|
|
case = If(~self.request[i], *switch)
|
|
|
|
cases.append([Constant(i, BV(self.bn)), case])
|
|
|
|
statement = Case(self.grant, *cases)
|
|
|
|
return Fragment(sync=[statement])
|