# When within the cycle, do not change of decision with m.If(bus_busy): m.d.comb += grant[interfaces[i]].eq(1) # Rotate the selection when a new decision is made # so that it stays stable for all the access # Start by the interfaces after it... for succ in range(i + 1, len(interfaces)): with m.Elif(requests[interfaces[succ]]): m.d.sync += grant_state.eq(succ) m.d.comb += grant[interfaces[succ]].eq(1) # ...then if none is requesting the ones before it... for pred in range(i): with m.Elif(requests[interfaces[pred]]): m.d.sync += grant_state.eq(pred) m.d.comb += grant[interfaces[pred]].eq(1) # ...then itself (at least one is active due to the grant_by_priority test) with m.Else(): m.d.comb += grant[interfaces[i]].eq(1)