|
| 1 | +// Copyright 2019 ETH Zurich and University of Bologna. |
| 2 | +// Copyright and related rights are licensed under the Solderpad Hardware |
| 3 | +// License, Version 0.51 (the "License"); you may not use this file except in |
| 4 | +// compliance with the License. You may obtain a copy of the License at |
| 5 | +// http://solderpad.org/licenses/SHL-0.51. Unless required by applicable law |
| 6 | +// or agreed to in writing, software, hardware and materials distributed under |
| 7 | +// this License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 8 | +// CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 9 | +// specific language governing permissions and limitations under the License. |
| 10 | +// |
| 11 | +// Author: Thomas Benz <[email protected]>, ETH Zurich |
| 12 | +// Date: 12.01.2021 |
| 13 | +// Description: round robin distributor |
| 14 | + |
| 15 | +module rr_distributor # ( |
| 16 | + parameter int unsigned NumOut = 1, |
| 17 | + parameter int unsigned Width = 1, |
| 18 | + parameter type payload_t = logic [Width-1:0], |
| 19 | + parameter int unsigned IdxWidth = (NumOut > 32'd1) ? unsigned'($clog2(NumOut)) : 32'd1, |
| 20 | + parameter type idx_t = logic [IdxWidth-1:0] |
| 21 | +) ( |
| 22 | + // input stream |
| 23 | + input logic clk_i, |
| 24 | + input logic rst_ni, |
| 25 | + input logic valid_i, |
| 26 | + output logic ready_o, |
| 27 | + input payload_t payload_i, |
| 28 | + // output stream |
| 29 | + output logic [NumOut-1:0] valid_o, |
| 30 | + input logic [NumOut-1:0] ready_i, |
| 31 | + output payload_t [NumOut-1:0] payload_o, |
| 32 | + output idx_t sel_o |
| 33 | +); |
| 34 | + |
| 35 | + if (NumOut == 1) begin : gen_bypass |
| 36 | + assign valid_o[0] = valid_i; |
| 37 | + assign ready_o = ready_i[0]; |
| 38 | + assign sel_o = 1'b0; |
| 39 | + end else begin : gen_arb |
| 40 | + |
| 41 | + idx_t rr_d, rr_q; |
| 42 | + logic one_ready; |
| 43 | + |
| 44 | + assign rr_d = (valid_i & one_ready) ? ((rr_q == idx_t'(NumOut-1)) ? '0 : rr_q + 1'b1) : rr_q; |
| 45 | + |
| 46 | + assign one_ready = |ready_i; |
| 47 | + |
| 48 | + always_comb begin : proc_arbitration |
| 49 | + valid_o = '0; |
| 50 | + ready_o = 1'b0; |
| 51 | + if (ready_i[rr_q]) begin |
| 52 | + valid_o[rr_q] = valid_i; |
| 53 | + ready_o = 1'b1; |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + always_ff @(posedge clk_i or negedge rst_ni) begin : proc_prio_regs |
| 58 | + if(~rst_ni) begin |
| 59 | + rr_q <= 0; |
| 60 | + end else begin |
| 61 | + rr_q <= rr_d; |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + assign sel_o = rr_q; |
| 66 | + end |
| 67 | + |
| 68 | + assign payload_o = {{NumOut}{payload_i}}; |
| 69 | + |
| 70 | +endmodule : rr_distributor |
0 commit comments