corelogic/roundrobin: handle correctly special case with 1 request source
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Sat, 31 Mar 2012 16:01:40 +0000 (18:01 +0200)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Sat, 31 Mar 2012 16:01:40 +0000 (18:01 +0200)
migen/corelogic/roundrobin.py

index 6b0ca5312b67db93e34667d7f9d0894508715a1a..aa310204e2641c82377f7b6f0d62ed940066794d 100644 (file)
@@ -13,24 +13,27 @@ class RoundRobin:
                        self.ce = Signal()
        
        def get_fragment(self):
-               cases = []
-               for i in range(self.n):
-                       switch = []
-                       for j in reversed(range(i+1,i+self.n)):
-                               t = j % self.n
-                               switch = [
-                                       If(self.request[t],
-                                               self.grant.eq(Constant(t, BV(self.bn)))
-                                       ).Else(
-                                               *switch
-                                       )
-                               ]
-                       if self.switch_policy == SP_WITHDRAW:
-                               case = [If(~self.request[i], *switch)]
-                       else:
-                               case = switch
-                       cases.append([Constant(i, BV(self.bn))] + case)
-               statement = Case(self.grant, *cases)
-               if self.switch_policy == SP_CE:
-                       statement = If(self.ce, statement)
-               return Fragment(sync=[statement])
+               if self.n > 1:
+                       cases = []
+                       for i in range(self.n):
+                               switch = []
+                               for j in reversed(range(i+1,i+self.n)):
+                                       t = j % self.n
+                                       switch = [
+                                               If(self.request[t],
+                                                       self.grant.eq(Constant(t, BV(self.bn)))
+                                               ).Else(
+                                                       *switch
+                                               )
+                                       ]
+                               if self.switch_policy == SP_WITHDRAW:
+                                       case = [If(~self.request[i], *switch)]
+                               else:
+                                       case = switch
+                               cases.append([Constant(i, BV(self.bn))] + case)
+                       statement = Case(self.grant, *cases)
+                       if self.switch_policy == SP_CE:
+                               statement = If(self.ce, statement)
+                       return Fragment(sync=[statement])
+               else:
+                       return Fragment([self.grant.eq(0)])