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 from the i-th device.
19 grant : Signal(range(n))
20 Signal that equals to the index of the device which is currently granted access.
22 Strobe signal to enable granting access to the next device requesting. Externally driven.
24 def __init__(self
, n
):
26 self
.request
= Signal(n
)
27 self
.grant
= Signal(range(n
))
30 def elaborate(self
, platform
):
34 with m
.Switch(self
.grant
):
35 for i
in range(self
.n
):
37 with m
.If(~self
.request
[i
]):
38 for j
in reversed(range(i
+1, i
+self
.n
)):
39 # If i+1 <= j < n, then t == j; (after i)
40 # If n <= j < i+n, then t == j - n (before i)
42 with m
.If(self
.request
[t
]):
43 m
.d
.sync
+= self
.grant
.eq(t
)