corelogic/roundrobin: CE switching

This commit is contained in:
Sebastien Bourdeauducq 2012-03-16 16:54:47 +01:00
parent e969b9afc3
commit a4294762d0

View file

@ -1,11 +1,16 @@
from migen.fhdl.structure import * from migen.fhdl.structure import *
(SP_WITHDRAW, SP_CE) = range(2)
class RoundRobin: class RoundRobin:
def __init__(self, n): def __init__(self, n, switch_policy=SP_WITHDRAW):
self.n = n self.n = n
self.bn = bits_for(self.n-1) self.bn = bits_for(self.n-1)
self.request = Signal(BV(self.n)) self.request = Signal(BV(self.n))
self.grant = Signal(BV(self.bn)) self.grant = Signal(BV(self.bn))
self.switch_policy = switch_policy
if self.switch_policy == SP_CE:
self.ce = Signal()
def get_fragment(self): def get_fragment(self):
cases = [] cases = []
@ -20,7 +25,12 @@ class RoundRobin:
*switch *switch
) )
] ]
case = If(~self.request[i], *switch) if self.switch_policy == SP_WITHDRAW:
cases.append([Constant(i, BV(self.bn)), case]) case = [If(~self.request[i], *switch)]
else:
case = switch
cases.append([Constant(i, BV(self.bn))] + case)
statement = Case(self.grant, *cases) statement = Case(self.grant, *cases)
if self.switch_policy == SP_CE:
statement = If(self.ce, statement)
return Fragment(sync=[statement]) return Fragment(sync=[statement])