588238abecd547c2b01982a31726b137749cda85
4 __all__
= ["RoundRobin"]
7 class RoundRobin(Elaboratable
):
8 """A round-robin scheduler.
13 Maximum number of requests to handle.
18 Signal where a '1' on the i-th bit represents an incoming request
20 grant : Signal(range(n))
21 Signal that equals to the index of the device which is currently
24 Strobe signal to enable granting access to the next device
25 requesting. Externally driven.
27 def __init__(self
, n
):
29 self
.request
= Signal(n
)
30 self
.grant
= Signal(range(n
))
33 def elaborate(self
, platform
):
37 with m
.Switch(self
.grant
):
38 for i
in range(self
.n
):
40 for j
in reversed(range(i
+1, i
+self
.n
)):
41 # If i+1 <= j < n, then t == j; (after i)
42 # If n <= j < i+n, then t == j - n (before i)
44 with m
.If(self
.request
[t
]):
45 m
.d
.sync
+= self
.grant
.eq(t
)