From d193ca5905c1293d3b8be3a1014dacc634ffef75 Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Sun, 16 Nov 2014 01:58:17 -0800 Subject: [PATCH] Add LSB_PRIORITY parameter --- rtl/arbiter.v | 22 +++++++++++++++++----- rtl/priority_encoder.v | 22 +++++++++++++++++----- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/rtl/arbiter.v b/rtl/arbiter.v index 219b4661..d6e06303 100644 --- a/rtl/arbiter.v +++ b/rtl/arbiter.v @@ -35,7 +35,9 @@ module arbiter # // arbitration type: "PRIORITY" or "ROUND_ROBIN" parameter TYPE = "PRIORITY", // block type: "NONE", "REQUEST", "ACKNOWLEDGE" - parameter BLOCK = "NONE" + parameter BLOCK = "NONE", + // LSB priority: "LOW", "HIGH" + parameter LSB_PRIORITY = "LOW" ) ( input wire clk, @@ -62,7 +64,8 @@ wire [$clog2(PORTS)-1:0] request_index; wire [PORTS-1:0] request_mask; priority_encoder #( - .WIDTH(PORTS) + .WIDTH(PORTS), + .LSB_PRIORITY(LSB_PRIORITY) ) priority_encoder_inst ( .input_unencoded(request), @@ -78,7 +81,8 @@ wire [$clog2(PORTS)-1:0] masked_request_index; wire [PORTS-1:0] masked_request_mask; priority_encoder #( - .WIDTH(PORTS) + .WIDTH(PORTS), + .LSB_PRIORITY(LSB_PRIORITY) ) priority_encoder_masked ( .input_unencoded(request & mask_reg), @@ -113,12 +117,20 @@ always @* begin grant_valid_next = 1; grant_next = masked_request_mask; grant_encoded_next = masked_request_index; - mask_next = {PORTS{1'b1}} >> (PORTS - masked_request_index); + if (LSB_PRIORITY == "LOW") begin + mask_next = {PORTS{1'b1}} >> (PORTS - masked_request_index); + end else begin + mask_next = {PORTS{1'b1}} << (masked_request_index + 1); + end end else begin grant_valid_next = 1; grant_next = request_mask; grant_encoded_next = request_index; - mask_next = {PORTS{1'b1}} >> (PORTS - request_index); + if (LSB_PRIORITY == "LOW") begin + mask_next = {PORTS{1'b1}} >> (PORTS - request_index); + end else begin + mask_next = {PORTS{1'b1}} << (request_index + 1); + end end end end diff --git a/rtl/priority_encoder.v b/rtl/priority_encoder.v index 03af53fe..cb380c76 100644 --- a/rtl/priority_encoder.v +++ b/rtl/priority_encoder.v @@ -31,7 +31,9 @@ THE SOFTWARE. */ module priority_encoder # ( - parameter WIDTH = 4 + parameter WIDTH = 4, + // LSB priority: "LOW", "HIGH" + parameter LSB_PRIORITY = "LOW" ) ( input wire [WIDTH-1:0] input_unencoded, @@ -48,14 +50,19 @@ generate if (WIDTH == 2) begin // two inputs - just an OR gate assign output_valid = |input_unencoded; - assign output_encoded = input_unencoded[1]; + if (LSB_PRIORITY == "LOW") begin + assign output_encoded = input_unencoded[1]; + end else begin + assign output_encoded = ~input_unencoded[0]; + end end else begin // more than two inputs - split into two parts and recurse // also pad input to correct power-of-two width wire [$clog2(W2)-1:0] out1, out2; wire valid1, valid2; priority_encoder #( - .WIDTH(W2) + .WIDTH(W2), + .LSB_PRIORITY(LSB_PRIORITY) ) priority_encoder_inst1 ( .input_unencoded(input_unencoded[W2-1:0]), @@ -63,7 +70,8 @@ generate .output_encoded(out1) ); priority_encoder #( - .WIDTH(W2) + .WIDTH(W2), + .LSB_PRIORITY(LSB_PRIORITY) ) priority_encoder_inst2 ( .input_unencoded({{W1-WIDTH{1'b0}}, input_unencoded[WIDTH-1:W2]}), @@ -72,7 +80,11 @@ generate ); // multiplexer to select part assign output_valid = valid1 | valid2; - assign output_encoded = valid2 ? {1'b1, out2} : {1'b0, out1}; + if (LSB_PRIORITY == "LOW") begin + assign output_encoded = valid2 ? {1'b1, out2} : {1'b0, out1}; + end else begin + assign output_encoded = valid1 ? {1'b0, out1} : {1'b1, out2}; + end end endgenerate