module thymesisflow_rr_arbiter
 #(parameter SIZE = 2) (

    input              clock                   // Clock - samples & launches data on rising edge
  , input              reset_n                //  Active Low

  // fifo_in AXI-STREAM 
   , input  [SIZE-1:0]  request_vector
   , input              request_nxt
   , output [SIZE-1:0]  selected

);

reg [SIZE-1:0] masked_req_vector;//snapshot of the request input.


//masked req vector
always @(posedge(clock))
begin
  if (reset_n == 1'b0) //Reset active 
     begin
       masked_req_vector <= 2'b0;
     end
  else if ((request_nxt == 1'b1) && (masked_req_vector == 2'b0)) //active
     begin
       masked_req_vector <= (request_vector ^ selected) & request_vector;  //empty mask means no history or rollover - so we just remove previous selection.
     end
  else if ((request_nxt == 1'b1))
     begin
       masked_req_vector <= (masked_req_vector ^ selected) & request_vector; //
     end
end

//Combinational to return selection immediately
assign selected = (masked_req_vector == 2'b0) ? request_vector & (~request_vector + 1) : masked_req_vector & (~masked_req_vector + 1); 

endmodule