`timescale 1ns/1ps
|
`timescale 1ns/1ps
|
/**********************************************************************
|
/**********************************************************************
|
** File: arbiter.v
|
** File: arbiter.v
|
**
|
**
|
** Copyright (C) 2014-2017 Alireza Monemi
|
** Copyright (C) 2014-2017 Alireza Monemi
|
**
|
**
|
** This file is part of ProNoC
|
** This file is part of ProNoC
|
**
|
**
|
** ProNoC ( stands for Prototype Network-on-chip) is free software:
|
** ProNoC ( stands for Prototype Network-on-chip) is free software:
|
** you can redistribute it and/or modify it under the terms of the GNU
|
** you can redistribute it and/or modify it under the terms of the GNU
|
** Lesser General Public License as published by the Free Software Foundation,
|
** Lesser General Public License as published by the Free Software Foundation,
|
** either version 2 of the License, or (at your option) any later version.
|
** either version 2 of the License, or (at your option) any later version.
|
**
|
**
|
** ProNoC is distributed in the hope that it will be useful, but WITHOUT
|
** ProNoC is distributed in the hope that it will be useful, but WITHOUT
|
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
** or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
** or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
** Public License for more details.
|
** Public License for more details.
|
**
|
**
|
** You should have received a copy of the GNU Lesser General Public
|
** You should have received a copy of the GNU Lesser General Public
|
** License along with ProNoC. If not, see <http:**www.gnu.org/licenses/>.
|
** License along with ProNoC. If not, see <http:**www.gnu.org/licenses/>.
|
**
|
**
|
**
|
**
|
**
|
**
|
** Description:
|
** Description:
|
** This file contains several Fixed prority and round robin
|
** This file contains several Fixed prority and round robin
|
** arbiters
|
** arbiters
|
**
|
**
|
******************************************************************************/
|
******************************************************************************/
|
|
|
|
|
/*****************************************
|
/*****************************************
|
*
|
*
|
* general round robin arbiter
|
* general round robin arbiter
|
*
|
*
|
*
|
*
|
******************************************/
|
******************************************/
|
|
|
module arbiter #(
|
module arbiter #(
|
parameter ARBITER_WIDTH =8
|
parameter ARBITER_WIDTH =8
|
|
|
)
|
)
|
(
|
(
|
clk,
|
clk,
|
reset,
|
reset,
|
request,
|
request,
|
grant,
|
grant,
|
any_grant
|
any_grant
|
);
|
);
|
|
|
|
|
input [ARBITER_WIDTH-1 : 0] request;
|
input [ARBITER_WIDTH-1 : 0] request;
|
output [ARBITER_WIDTH-1 : 0] grant;
|
output [ARBITER_WIDTH-1 : 0] grant;
|
output any_grant;
|
output any_grant;
|
input clk;
|
input clk;
|
input reset;
|
input reset;
|
|
|
|
|
|
|
generate
|
generate
|
if(ARBITER_WIDTH==1) begin: w1
|
if(ARBITER_WIDTH==1) begin: w1
|
assign grant= request;
|
assign grant= request;
|
assign any_grant =request;
|
assign any_grant =request;
|
end else if(ARBITER_WIDTH<=4) begin: w4
|
end else if(ARBITER_WIDTH<=4) begin: w4
|
//my own arbiter
|
//my own arbiter
|
my_one_hot_arbiter #(
|
my_one_hot_arbiter #(
|
.ARBITER_WIDTH (ARBITER_WIDTH)
|
.ARBITER_WIDTH (ARBITER_WIDTH)
|
)
|
)
|
one_hot_arb
|
one_hot_arb
|
(
|
(
|
.clk (clk),
|
.clk (clk),
|
.reset (reset),
|
.reset (reset),
|
.request (request),
|
.request (request),
|
.grant (grant),
|
.grant (grant),
|
.any_grant (any_grant)
|
.any_grant (any_grant)
|
);
|
);
|
|
|
end else begin : wb4
|
end else begin : wb4
|
|
|
thermo_arbiter #(
|
thermo_arbiter #(
|
.ARBITER_WIDTH (ARBITER_WIDTH)
|
.ARBITER_WIDTH (ARBITER_WIDTH)
|
)
|
)
|
one_hot_arb
|
one_hot_arb
|
(
|
(
|
.clk (clk),
|
.clk (clk),
|
.reset (reset),
|
.reset (reset),
|
.request (request),
|
.request (request),
|
.grant (grant),
|
.grant (grant),
|
.any_grant (any_grant)
|
.any_grant (any_grant)
|
);
|
);
|
end
|
end
|
endgenerate
|
endgenerate
|
endmodule
|
endmodule
|
|
|
/*****************************************
|
/*****************************************
|
*
|
*
|
* arbiter_priority_en
|
* arbiter_priority_en
|
* RRA with external priority enable signal
|
* RRA with external priority enable signal
|
*
|
*
|
******************************************/
|
******************************************/
|
|
|
module arbiter_priority_en #(
|
module arbiter_priority_en #(
|
parameter ARBITER_WIDTH =8
|
parameter ARBITER_WIDTH =8
|
|
|
)
|
)
|
(
|
(
|
clk,
|
clk,
|
reset,
|
reset,
|
request,
|
request,
|
grant,
|
grant,
|
any_grant,
|
any_grant,
|
priority_en
|
priority_en
|
);
|
);
|
|
|
|
|
|
|
|
|
input [ARBITER_WIDTH-1 : 0] request;
|
input [ARBITER_WIDTH-1 : 0] request;
|
output [ARBITER_WIDTH-1 : 0] grant;
|
output [ARBITER_WIDTH-1 : 0] grant;
|
output any_grant;
|
output any_grant;
|
input clk;
|
input clk;
|
input reset;
|
input reset;
|
input priority_en;
|
input priority_en;
|
|
|
|
|
generate
|
generate
|
if(ARBITER_WIDTH==1) begin: w1
|
if(ARBITER_WIDTH==1) begin: w1
|
assign grant= request;
|
assign grant= request;
|
assign any_grant =request;
|
assign any_grant =request;
|
end else if(ARBITER_WIDTH<=4) begin: w4
|
end else if(ARBITER_WIDTH<=4) begin: w4
|
//my own arbiter
|
//my own arbiter
|
my_one_hot_arbiter_priority_en #(
|
my_one_hot_arbiter_priority_en #(
|
.ARBITER_WIDTH (ARBITER_WIDTH)
|
.ARBITER_WIDTH (ARBITER_WIDTH)
|
)
|
)
|
one_hot_arb
|
one_hot_arb
|
(
|
(
|
.clk (clk),
|
.clk (clk),
|
.reset (reset),
|
.reset (reset),
|
.request (request),
|
.request (request),
|
.grant (grant),
|
.grant (grant),
|
.any_grant (any_grant),
|
.any_grant (any_grant),
|
.priority_en (priority_en)
|
.priority_en (priority_en)
|
|
|
);
|
);
|
|
|
end else begin :wb4
|
end else begin :wb4
|
|
|
thermo_arbiter_priority_en #(
|
thermo_arbiter_priority_en #(
|
.ARBITER_WIDTH (ARBITER_WIDTH)
|
.ARBITER_WIDTH (ARBITER_WIDTH)
|
)
|
)
|
one_hot_arb
|
one_hot_arb
|
(
|
(
|
.clk (clk),
|
.clk (clk),
|
.reset (reset),
|
.reset (reset),
|
.request (request),
|
.request (request),
|
.grant (grant),
|
.grant (grant),
|
.any_grant (any_grant),
|
.any_grant (any_grant),
|
.priority_en (priority_en)
|
.priority_en (priority_en)
|
);
|
);
|
end
|
end
|
endgenerate
|
endgenerate
|
endmodule
|
endmodule
|
|
|
|
|
|
|
/******************************************************
|
/******************************************************
|
* my_one_hot_arbiter
|
* my_one_hot_arbiter
|
* RRA with binary-coded priority register. Binary-coded
|
* RRA with binary-coded priority register. Binary-coded
|
* Priority results in less area cost and CPD for arbire
|
* Priority results in less area cost and CPD for arbire
|
* width of 4 and smaller only.
|
* width of 4 and smaller only.
|
*
|
*
|
******************************************************/
|
******************************************************/
|
|
|
|
|
|
|
module my_one_hot_arbiter #(
|
module my_one_hot_arbiter #(
|
parameter ARBITER_WIDTH =4
|
parameter ARBITER_WIDTH =4
|
|
|
|
|
)
|
)
|
(
|
(
|
input [ARBITER_WIDTH-1 : 0] request,
|
input [ARBITER_WIDTH-1 : 0] request,
|
output [ARBITER_WIDTH-1 : 0] grant,
|
output [ARBITER_WIDTH-1 : 0] grant,
|
output any_grant,
|
output any_grant,
|
input clk,
|
input clk,
|
input reset
|
input reset
|
);
|
);
|
|
|
function integer log2;
|
function integer log2;
|
input integer number; begin
|
input integer number; begin
|
log2=(number <=1) ? 1: 0;
|
log2=(number <=1) ? 1: 0;
|
while(2**log2<number) begin
|
while(2**log2<number) begin
|
log2=log2+1;
|
log2=log2+1;
|
end
|
end
|
end
|
end
|
endfunction // log2
|
endfunction // log2
|
|
|
localparam ARBITER_BIN_WIDTH= log2(ARBITER_WIDTH);
|
localparam ARBITER_BIN_WIDTH= log2(ARBITER_WIDTH);
|
reg [ARBITER_BIN_WIDTH-1 : 0] low_pr;
|
reg [ARBITER_BIN_WIDTH-1 : 0] low_pr;
|
wire [ARBITER_BIN_WIDTH-1 : 0] grant_bcd;
|
wire [ARBITER_BIN_WIDTH-1 : 0] grant_bcd;
|
|
|
one_hot_to_bin #(
|
one_hot_to_bin #(
|
.ONE_HOT_WIDTH (ARBITER_WIDTH)
|
.ONE_HOT_WIDTH (ARBITER_WIDTH)
|
)conv
|
)conv
|
(
|
(
|
.one_hot_code(grant),
|
.one_hot_code(grant),
|
.bin_code(grant_bcd)
|
.bin_code(grant_bcd)
|
|
|
);
|
);
|
|
|
|
|
|
`ifdef SYNC_RESET_MODE
|
|
always @ (posedge clk )begin
|
|
`else
|
always@(posedge clk or posedge reset) begin
|
always@(posedge clk or posedge reset) begin
|
|
`endif
|
|
|
if(reset) begin
|
if(reset) begin
|
low_pr <= {ARBITER_BIN_WIDTH{1'b0}};
|
low_pr <= {ARBITER_BIN_WIDTH{1'b0}};
|
end else begin
|
end else begin
|
if(any_grant) low_pr <= grant_bcd;
|
if(any_grant) low_pr <= grant_bcd;
|
end
|
end
|
end
|
end
|
|
|
|
|
assign any_grant = | request;
|
assign any_grant = | request;
|
|
|
generate
|
generate
|
if(ARBITER_WIDTH ==2) begin: w2 arbiter_2_one_hot arb( .in(request) , .out(grant), .low_pr(low_pr)); end
|
if(ARBITER_WIDTH ==2) begin: w2 arbiter_2_one_hot arb( .in(request) , .out(grant), .low_pr(low_pr)); end
|
if(ARBITER_WIDTH ==3) begin: w3 arbiter_3_one_hot arb( .in(request) , .out(grant), .low_pr(low_pr)); end
|
if(ARBITER_WIDTH ==3) begin: w3 arbiter_3_one_hot arb( .in(request) , .out(grant), .low_pr(low_pr)); end
|
if(ARBITER_WIDTH ==4) begin: w4 arbiter_4_one_hot arb( .in(request) , .out(grant), .low_pr(low_pr)); end
|
if(ARBITER_WIDTH ==4) begin: w4 arbiter_4_one_hot arb( .in(request) , .out(grant), .low_pr(low_pr)); end
|
endgenerate
|
endgenerate
|
|
|
endmodule
|
endmodule
|
|
|
|
|
module arbiter_2_one_hot(
|
module arbiter_2_one_hot(
|
input [1 : 0] in,
|
input [1 : 0] in,
|
output reg[1 : 0] out,
|
output reg[1 : 0] out,
|
input low_pr
|
input low_pr
|
);
|
);
|
always @(*) begin
|
always @(*) begin
|
out=2'b00;
|
out=2'b00;
|
case(low_pr)
|
case(low_pr)
|
1'd0:
|
1'd0:
|
if(in[1]) out=2'b10;
|
if(in[1]) out=2'b10;
|
else if(in[0]) out=2'b01;
|
else if(in[0]) out=2'b01;
|
1'd1:
|
1'd1:
|
if(in[0]) out=2'b01;
|
if(in[0]) out=2'b01;
|
else if(in[1]) out=2'b10;
|
else if(in[1]) out=2'b10;
|
default: out=2'b00;
|
default: out=2'b00;
|
endcase
|
endcase
|
end
|
end
|
endmodule
|
endmodule
|
|
|
|
|
|
|
|
|
module arbiter_3_one_hot(
|
module arbiter_3_one_hot(
|
input [2 : 0] in,
|
input [2 : 0] in,
|
output reg[2 : 0] out,
|
output reg[2 : 0] out,
|
input [1 : 0] low_pr
|
input [1 : 0] low_pr
|
);
|
);
|
always @(*) begin
|
always @(*) begin
|
out=3'b000;
|
out=3'b000;
|
case(low_pr)
|
case(low_pr)
|
2'd0:
|
2'd0:
|
if(in[1]) out=3'b010;
|
if(in[1]) out=3'b010;
|
else if(in[2]) out=3'b100;
|
else if(in[2]) out=3'b100;
|
else if(in[0]) out=3'b001;
|
else if(in[0]) out=3'b001;
|
2'd1:
|
2'd1:
|
if(in[2]) out=3'b100;
|
if(in[2]) out=3'b100;
|
else if(in[0]) out=3'b001;
|
else if(in[0]) out=3'b001;
|
else if(in[1]) out=3'b010;
|
else if(in[1]) out=3'b010;
|
2'd2:
|
2'd2:
|
if(in[0]) out=3'b001;
|
if(in[0]) out=3'b001;
|
else if(in[1]) out=3'b010;
|
else if(in[1]) out=3'b010;
|
else if(in[2]) out=3'b100;
|
else if(in[2]) out=3'b100;
|
default: out=3'b000;
|
default: out=3'b000;
|
endcase
|
endcase
|
end
|
end
|
endmodule
|
endmodule
|
|
|
|
|
module arbiter_4_one_hot(
|
module arbiter_4_one_hot(
|
input [3 : 0] in,
|
input [3 : 0] in,
|
output reg[3 : 0] out,
|
output reg[3 : 0] out,
|
input [1 : 0] low_pr
|
input [1 : 0] low_pr
|
);
|
);
|
always @(*) begin
|
always @(*) begin
|
out=4'b0000;
|
out=4'b0000;
|
case(low_pr)
|
case(low_pr)
|
2'd0:
|
2'd0:
|
if(in[1]) out=4'b0010;
|
if(in[1]) out=4'b0010;
|
else if(in[2]) out=4'b0100;
|
else if(in[2]) out=4'b0100;
|
else if(in[3]) out=4'b1000;
|
else if(in[3]) out=4'b1000;
|
else if(in[0]) out=4'b0001;
|
else if(in[0]) out=4'b0001;
|
2'd1:
|
2'd1:
|
if(in[2]) out=4'b0100;
|
if(in[2]) out=4'b0100;
|
else if(in[3]) out=4'b1000;
|
else if(in[3]) out=4'b1000;
|
else if(in[0]) out=4'b0001;
|
else if(in[0]) out=4'b0001;
|
else if(in[1]) out=4'b0010;
|
else if(in[1]) out=4'b0010;
|
2'd2:
|
2'd2:
|
if(in[3]) out=4'b1000;
|
if(in[3]) out=4'b1000;
|
else if(in[0]) out=4'b0001;
|
else if(in[0]) out=4'b0001;
|
else if(in[1]) out=4'b0010;
|
else if(in[1]) out=4'b0010;
|
else if(in[2]) out=4'b0100;
|
else if(in[2]) out=4'b0100;
|
2'd3:
|
2'd3:
|
if(in[0]) out=4'b0001;
|
if(in[0]) out=4'b0001;
|
else if(in[1]) out=4'b0010;
|
else if(in[1]) out=4'b0010;
|
else if(in[2]) out=4'b0100;
|
else if(in[2]) out=4'b0100;
|
else if(in[3]) out=4'b1000;
|
else if(in[3]) out=4'b1000;
|
default: out=4'b0000;
|
default: out=4'b0000;
|
endcase
|
endcase
|
end
|
end
|
endmodule
|
endmodule
|
|
|
|
|
/******************************************************
|
/******************************************************
|
* my_one_hot_arbiter_priority_en
|
* my_one_hot_arbiter_priority_en
|
*
|
*
|
******************************************************/
|
******************************************************/
|
|
|
|
|
|
|
module my_one_hot_arbiter_priority_en #(
|
module my_one_hot_arbiter_priority_en #(
|
parameter ARBITER_WIDTH =4
|
parameter ARBITER_WIDTH =4
|
|
|
|
|
)
|
)
|
(
|
(
|
input [ARBITER_WIDTH-1 : 0] request,
|
input [ARBITER_WIDTH-1 : 0] request,
|
output [ARBITER_WIDTH-1 : 0] grant,
|
output [ARBITER_WIDTH-1 : 0] grant,
|
output any_grant,
|
output any_grant,
|
input clk,
|
input clk,
|
input reset,
|
input reset,
|
input priority_en
|
input priority_en
|
);
|
);
|
|
|
function integer log2;
|
function integer log2;
|
input integer number; begin
|
input integer number; begin
|
log2=(number <=1) ? 1: 0;
|
log2=(number <=1) ? 1: 0;
|
while(2**log2<number) begin
|
while(2**log2<number) begin
|
log2=log2+1;
|
log2=log2+1;
|
end
|
end
|
end
|
end
|
endfunction // log2
|
endfunction // log2
|
|
|
localparam ARBITER_BIN_WIDTH= log2(ARBITER_WIDTH);
|
localparam ARBITER_BIN_WIDTH= log2(ARBITER_WIDTH);
|
reg [ARBITER_BIN_WIDTH-1 : 0] low_pr;
|
reg [ARBITER_BIN_WIDTH-1 : 0] low_pr;
|
wire [ARBITER_BIN_WIDTH-1 : 0] grant_bcd;
|
wire [ARBITER_BIN_WIDTH-1 : 0] grant_bcd;
|
|
|
one_hot_to_bin #(
|
one_hot_to_bin #(
|
.ONE_HOT_WIDTH (ARBITER_WIDTH)
|
.ONE_HOT_WIDTH (ARBITER_WIDTH)
|
)conv
|
)conv
|
(
|
(
|
.one_hot_code(grant),
|
.one_hot_code(grant),
|
.bin_code(grant_bcd)
|
.bin_code(grant_bcd)
|
);
|
);
|
|
|
|
`ifdef SYNC_RESET_MODE
|
|
always @ (posedge clk )begin
|
|
`else
|
always@(posedge clk or posedge reset) begin
|
always@(posedge clk or posedge reset) begin
|
|
`endif
|
|
|
if(reset) begin
|
if(reset) begin
|
low_pr <= {ARBITER_BIN_WIDTH{1'b0}};
|
low_pr <= {ARBITER_BIN_WIDTH{1'b0}};
|
end else begin
|
end else begin
|
if(priority_en) low_pr <= grant_bcd;
|
if(priority_en) low_pr <= grant_bcd;
|
end
|
end
|
end
|
end
|
|
|
|
|
assign any_grant = | request;
|
assign any_grant = | request;
|
|
|
generate
|
generate
|
if(ARBITER_WIDTH ==2) begin :w2 arbiter_2_one_hot arb( .in(request) , .out(grant), .low_pr(low_pr)); end
|
if(ARBITER_WIDTH ==2) begin :w2 arbiter_2_one_hot arb( .in(request) , .out(grant), .low_pr(low_pr)); end
|
if(ARBITER_WIDTH ==3) begin :w3 arbiter_3_one_hot arb( .in(request) , .out(grant), .low_pr(low_pr)); end
|
if(ARBITER_WIDTH ==3) begin :w3 arbiter_3_one_hot arb( .in(request) , .out(grant), .low_pr(low_pr)); end
|
if(ARBITER_WIDTH ==4) begin :w4 arbiter_4_one_hot arb( .in(request) , .out(grant), .low_pr(low_pr)); end
|
if(ARBITER_WIDTH ==4) begin :w4 arbiter_4_one_hot arb( .in(request) , .out(grant), .low_pr(low_pr)); end
|
endgenerate
|
endgenerate
|
|
|
endmodule
|
endmodule
|
|
|
|
|
|
|
/*******************
|
/*******************
|
*
|
*
|
* thermo_arbiter RRA
|
* thermo_arbiter RRA
|
*
|
*
|
********************/
|
********************/
|
|
|
module thermo_gen #(
|
module thermo_gen #(
|
parameter WIDTH=16
|
parameter WIDTH=16
|
|
|
|
|
)(
|
)(
|
input [WIDTH-1 : 0]in,
|
input [WIDTH-1 : 0]in,
|
output [WIDTH-1 : 0]out
|
output [WIDTH-1 : 0]out
|
);
|
);
|
genvar i;
|
genvar i;
|
generate
|
generate
|
for(i=0;i<WIDTH;i=i+1)begin :lp
|
for(i=0;i<WIDTH;i=i+1)begin :lp
|
assign out[i]= | in[i :0];
|
assign out[i]= | in[i :0];
|
end
|
end
|
endgenerate
|
endgenerate
|
|
|
endmodule
|
endmodule
|
|
|
|
|
|
|
|
|
module thermo_arbiter #(
|
module thermo_arbiter #(
|
parameter ARBITER_WIDTH =4
|
parameter ARBITER_WIDTH =4
|
|
|
)
|
)
|
(
|
(
|
clk,
|
clk,
|
reset,
|
reset,
|
request,
|
request,
|
grant,
|
grant,
|
any_grant
|
any_grant
|
);
|
);
|
|
|
|
|
|
|
|
|
input [ARBITER_WIDTH-1 : 0] request;
|
input [ARBITER_WIDTH-1 : 0] request;
|
output [ARBITER_WIDTH-1 : 0] grant;
|
output [ARBITER_WIDTH-1 : 0] grant;
|
output any_grant;
|
output any_grant;
|
input reset,clk;
|
input reset,clk;
|
|
|
|
|
wire [ARBITER_WIDTH-1 : 0] termo1,termo2,mux_out,masked_request,edge_mask;
|
wire [ARBITER_WIDTH-1 : 0] termo1,termo2,mux_out,masked_request,edge_mask;
|
reg [ARBITER_WIDTH-1 : 0] pr;
|
reg [ARBITER_WIDTH-1 : 0] pr;
|
|
|
|
|
thermo_gen #(
|
thermo_gen #(
|
.WIDTH(ARBITER_WIDTH)
|
.WIDTH(ARBITER_WIDTH)
|
) tm1
|
) tm1
|
(
|
(
|
.in(request),
|
.in(request),
|
.out(termo1)
|
.out(termo1)
|
);
|
);
|
|
|
|
|
|
|
|
|
thermo_gen #(
|
thermo_gen #(
|
.WIDTH(ARBITER_WIDTH)
|
.WIDTH(ARBITER_WIDTH)
|
) tm2
|
) tm2
|
(
|
(
|
.in(masked_request),
|
.in(masked_request),
|
.out(termo2)
|
.out(termo2)
|
);
|
);
|
|
|
|
|
assign mux_out=(termo2[ARBITER_WIDTH-1])? termo2 : termo1;
|
assign mux_out=(termo2[ARBITER_WIDTH-1])? termo2 : termo1;
|
assign masked_request= request & pr;
|
assign masked_request= request & pr;
|
assign any_grant=termo1[ARBITER_WIDTH-1];
|
assign any_grant=termo1[ARBITER_WIDTH-1];
|
|
|
|
`ifdef SYNC_RESET_MODE
|
|
always @ (posedge clk )begin
|
|
`else
|
always @(posedge clk or posedge reset)begin
|
always @(posedge clk or posedge reset)begin
|
|
`endif
|
if(reset) pr<= {ARBITER_WIDTH{1'b1}};
|
if(reset) pr<= {ARBITER_WIDTH{1'b1}};
|
else begin
|
else begin
|
if(any_grant) pr<= edge_mask;
|
if(any_grant) pr<= edge_mask;
|
end
|
end
|
|
|
end
|
end
|
|
|
assign edge_mask= {mux_out[ARBITER_WIDTH-2:0],1'b0};
|
assign edge_mask= {mux_out[ARBITER_WIDTH-2:0],1'b0};
|
assign grant= mux_out ^ edge_mask;
|
assign grant= mux_out ^ edge_mask;
|
|
|
|
|
|
|
endmodule
|
endmodule
|
|
|
|
|
|
|
|
|
|
|
module thermo_arbiter_priority_en #(
|
module thermo_arbiter_priority_en #(
|
parameter ARBITER_WIDTH =4
|
parameter ARBITER_WIDTH =4
|
|
|
)
|
)
|
(
|
(
|
clk,
|
clk,
|
reset,
|
reset,
|
request,
|
request,
|
grant,
|
grant,
|
any_grant,
|
any_grant,
|
priority_en
|
priority_en
|
);
|
);
|
|
|
|
|
|
|
|
|
input [ARBITER_WIDTH-1 : 0] request;
|
input [ARBITER_WIDTH-1 : 0] request;
|
output [ARBITER_WIDTH-1 : 0] grant;
|
output [ARBITER_WIDTH-1 : 0] grant;
|
output any_grant;
|
output any_grant;
|
input reset,clk;
|
input reset,clk;
|
input priority_en;
|
input priority_en;
|
|
|
wire [ARBITER_WIDTH-1 : 0] termo1,termo2,mux_out,masked_request,edge_mask;
|
wire [ARBITER_WIDTH-1 : 0] termo1,termo2,mux_out,masked_request,edge_mask;
|
reg [ARBITER_WIDTH-1 : 0] pr;
|
reg [ARBITER_WIDTH-1 : 0] pr;
|
|
|
|
|
thermo_gen #(
|
thermo_gen #(
|
.WIDTH(ARBITER_WIDTH)
|
.WIDTH(ARBITER_WIDTH)
|
) tm1
|
) tm1
|
(
|
(
|
.in(request),
|
.in(request),
|
.out(termo1)
|
.out(termo1)
|
);
|
);
|
|
|
|
|
|
|
|
|
thermo_gen #(
|
thermo_gen #(
|
.WIDTH(ARBITER_WIDTH)
|
.WIDTH(ARBITER_WIDTH)
|
) tm2
|
) tm2
|
(
|
(
|
.in(masked_request),
|
.in(masked_request),
|
.out(termo2)
|
.out(termo2)
|
);
|
);
|
|
|
|
|
assign mux_out=(termo2[ARBITER_WIDTH-1])? termo2 : termo1;
|
assign mux_out=(termo2[ARBITER_WIDTH-1])? termo2 : termo1;
|
assign masked_request= request & pr;
|
assign masked_request= request & pr;
|
assign any_grant=termo1[ARBITER_WIDTH-1];
|
assign any_grant=termo1[ARBITER_WIDTH-1];
|
|
|
|
`ifdef SYNC_RESET_MODE
|
|
always @ (posedge clk )begin
|
|
`else
|
always @(posedge clk or posedge reset)begin
|
always @(posedge clk or posedge reset)begin
|
|
`endif
|
|
|
|
|
if(reset) pr<= {ARBITER_WIDTH{1'b1}};
|
if(reset) pr<= {ARBITER_WIDTH{1'b1}};
|
else begin
|
else begin
|
if(priority_en) pr<= edge_mask;
|
if(priority_en) pr<= edge_mask;
|
end
|
end
|
|
|
end
|
end
|
|
|
assign edge_mask= {mux_out[ARBITER_WIDTH-2:0],1'b0};
|
assign edge_mask= {mux_out[ARBITER_WIDTH-2:0],1'b0};
|
assign grant= mux_out ^ edge_mask;
|
assign grant= mux_out ^ edge_mask;
|
|
|
|
|
|
|
endmodule
|
endmodule
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module thermo_arbiter_ext_priority #(
|
module thermo_arbiter_ext_priority #(
|
parameter ARBITER_WIDTH =4
|
parameter ARBITER_WIDTH =4
|
|
|
)
|
)
|
(
|
(
|
|
|
request,
|
request,
|
grant,
|
grant,
|
any_grant,
|
any_grant,
|
priority_in
|
priority_in
|
|
|
);
|
);
|
|
|
|
|
|
|
|
|
input [ARBITER_WIDTH-1 : 0] request;
|
input [ARBITER_WIDTH-1 : 0] request;
|
output [ARBITER_WIDTH-1 : 0] grant;
|
output [ARBITER_WIDTH-1 : 0] grant;
|
output any_grant;
|
output any_grant;
|
input [ARBITER_WIDTH-1 : 0] priority_in;
|
input [ARBITER_WIDTH-1 : 0] priority_in;
|
|
|
wire [ARBITER_WIDTH-1 : 0] termo1,termo2,mux_out,masked_request,edge_mask;
|
wire [ARBITER_WIDTH-1 : 0] termo1,termo2,mux_out,masked_request,edge_mask;
|
wire [ARBITER_WIDTH-1 : 0] pr;
|
wire [ARBITER_WIDTH-1 : 0] pr;
|
|
|
|
|
thermo_gen #(
|
thermo_gen #(
|
.WIDTH(ARBITER_WIDTH)
|
.WIDTH(ARBITER_WIDTH)
|
) tm1
|
) tm1
|
(
|
(
|
.in(request),
|
.in(request),
|
.out(termo1)
|
.out(termo1)
|
);
|
);
|
|
|
|
|
|
|
|
|
thermo_gen #(
|
thermo_gen #(
|
.WIDTH(ARBITER_WIDTH)
|
.WIDTH(ARBITER_WIDTH)
|
) tm2
|
) tm2
|
(
|
(
|
.in(masked_request),
|
.in(masked_request),
|
.out(termo2)
|
.out(termo2)
|
);
|
);
|
|
|
|
|
thermo_gen #(
|
thermo_gen #(
|
.WIDTH(ARBITER_WIDTH)
|
.WIDTH(ARBITER_WIDTH)
|
) tm3
|
) tm3
|
(
|
(
|
.in(priority_in),
|
.in(priority_in),
|
.out(pr)
|
.out(pr)
|
);
|
);
|
|
|
|
|
assign mux_out=(termo2[ARBITER_WIDTH-1])? termo2 : termo1;
|
assign mux_out=(termo2[ARBITER_WIDTH-1])? termo2 : termo1;
|
assign masked_request= request & pr;
|
assign masked_request= request & pr;
|
assign any_grant=termo1[ARBITER_WIDTH-1];
|
assign any_grant=termo1[ARBITER_WIDTH-1];
|
|
|
|
|
assign edge_mask= {mux_out[ARBITER_WIDTH-2:0],1'b0};
|
assign edge_mask= {mux_out[ARBITER_WIDTH-2:0],1'b0};
|
assign grant= mux_out ^ edge_mask;
|
assign grant= mux_out ^ edge_mask;
|
|
|
|
|
|
|
endmodule
|
endmodule
|
|
|
|
|
|
|
/********************************
|
/********************************
|
*
|
*
|
* Tree arbiter
|
* Tree arbiter
|
*
|
*
|
*******************************/
|
*******************************/
|
|
|
module tree_arbiter #(
|
module tree_arbiter #(
|
parameter GROUP_NUM =4,
|
parameter GROUP_NUM =4,
|
parameter ARBITER_WIDTH =16
|
parameter ARBITER_WIDTH =16
|
)
|
)
|
(
|
(
|
clk,
|
clk,
|
reset,
|
reset,
|
request,
|
request,
|
grant,
|
grant,
|
any_grant
|
any_grant
|
);
|
);
|
|
|
|
|
function integer log2;
|
function integer log2;
|
input integer number; begin
|
input integer number; begin
|
log2=(number <=1) ? 1: 0;
|
log2=(number <=1) ? 1: 0;
|
while(2**log2<number) begin
|
while(2**log2<number) begin
|
log2=log2+1;
|
log2=log2+1;
|
end
|
end
|
end
|
end
|
endfunction // log2
|
endfunction // log2
|
|
|
localparam N = ARBITER_WIDTH;
|
localparam N = ARBITER_WIDTH;
|
localparam S = log2(ARBITER_WIDTH); // ceil of log_2 of N - put manually
|
localparam S = log2(ARBITER_WIDTH); // ceil of log_2 of N - put manually
|
|
|
|
|
// I/O interface
|
// I/O interface
|
input clk;
|
input clk;
|
input reset;
|
input reset;
|
input [N-1:0] request;
|
input [N-1:0] request;
|
output [N-1:0] grant;
|
output [N-1:0] grant;
|
output any_grant;
|
output any_grant;
|
|
|
|
|
localparam GROUP_WIDTH = ARBITER_WIDTH/GROUP_NUM;
|
localparam GROUP_WIDTH = ARBITER_WIDTH/GROUP_NUM;
|
|
|
wire [GROUP_WIDTH-1 : 0] group_req [GROUP_NUM-1 : 0];
|
wire [GROUP_WIDTH-1 : 0] group_req [GROUP_NUM-1 : 0];
|
wire [GROUP_WIDTH-1 : 0] group_grant [GROUP_NUM-1 : 0];
|
wire [GROUP_WIDTH-1 : 0] group_grant [GROUP_NUM-1 : 0];
|
wire [GROUP_WIDTH-1 : 0] grant_masked[GROUP_NUM-1 : 0];
|
wire [GROUP_WIDTH-1 : 0] grant_masked[GROUP_NUM-1 : 0];
|
|
|
wire [GROUP_NUM-1 : 0] any_group_member_req;
|
wire [GROUP_NUM-1 : 0] any_group_member_req;
|
wire [GROUP_NUM-1 : 0] any_group_member_grant;
|
wire [GROUP_NUM-1 : 0] any_group_member_grant;
|
|
|
|
|
genvar i;
|
genvar i;
|
generate
|
generate
|
for (i=0;i<GROUP_NUM;i=i+1) begin :group_lp
|
for (i=0;i<GROUP_NUM;i=i+1) begin :group_lp
|
|
|
//seprate inputs in group
|
//seprate inputs in group
|
assign group_req[i] = request[(i+1)*GROUP_WIDTH-1 : i*GROUP_WIDTH];
|
assign group_req[i] = request[(i+1)*GROUP_WIDTH-1 : i*GROUP_WIDTH];
|
|
|
//check if any member of qrup has request
|
//check if any member of qrup has request
|
assign any_group_member_req[i] = | group_req[i];
|
assign any_group_member_req[i] = | group_req[i];
|
|
|
//arbiterate one request from each group
|
//arbiterate one request from each group
|
arbiter #(
|
arbiter #(
|
.ARBITER_WIDTH (GROUP_WIDTH)
|
.ARBITER_WIDTH (GROUP_WIDTH)
|
)group_member_arbiter
|
)group_member_arbiter
|
(
|
(
|
.clk (clk),
|
.clk (clk),
|
.reset (reset),
|
.reset (reset),
|
.request (group_req[i]),
|
.request (group_req[i]),
|
.grant (group_grant[i]),
|
.grant (group_grant[i]),
|
.any_grant ()
|
.any_grant ()
|
);
|
);
|
|
|
// mask the non selected groups
|
// mask the non selected groups
|
assign grant_masked [i] = (any_group_member_grant[i])? group_grant[i]: {GROUP_WIDTH{1'b0}};
|
assign grant_masked [i] = (any_group_member_grant[i])? group_grant[i]: {GROUP_WIDTH{1'b0}};
|
|
|
//assemble the grants
|
//assemble the grants
|
assign grant [(i+1)*GROUP_WIDTH-1 : i*GROUP_WIDTH] = grant_masked [i];
|
assign grant [(i+1)*GROUP_WIDTH-1 : i*GROUP_WIDTH] = grant_masked [i];
|
|
|
|
|
end
|
end
|
endgenerate
|
endgenerate
|
|
|
//select one group which has atleast one active request
|
//select one group which has atleast one active request
|
|
|
//arbiterate one request from each group
|
//arbiterate one request from each group
|
arbiter #(
|
arbiter #(
|
.ARBITER_WIDTH (GROUP_NUM)
|
.ARBITER_WIDTH (GROUP_NUM)
|
)second_arbiter
|
)second_arbiter
|
(
|
(
|
.clk (clk),
|
.clk (clk),
|
.reset (reset),
|
.reset (reset),
|
.request (any_group_member_req),
|
.request (any_group_member_req),
|
.grant (any_group_member_grant),
|
.grant (any_group_member_grant),
|
.any_grant (any_grant)
|
.any_grant (any_grant)
|
);
|
);
|
|
|
|
|
|
|
endmodule
|
endmodule
|
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************
|
/*******************************
|
|
|
my_one_hot_arbiter_ext_priority
|
my_one_hot_arbiter_ext_priority
|
|
|
*******************************/
|
*******************************/
|
|
|
module my_one_hot_arbiter_ext_priority #(
|
module my_one_hot_arbiter_ext_priority #(
|
parameter ARBITER_WIDTH =4
|
parameter ARBITER_WIDTH =4
|
|
|
|
|
)
|
)
|
(
|
(
|
input [ARBITER_WIDTH-1 : 0] request,
|
input [ARBITER_WIDTH-1 : 0] request,
|
input [ARBITER_WIDTH-1 : 0] priority_in,
|
input [ARBITER_WIDTH-1 : 0] priority_in,
|
output [ARBITER_WIDTH-1 : 0] grant,
|
output [ARBITER_WIDTH-1 : 0] grant,
|
output any_grant
|
output any_grant
|
);
|
);
|
|
|
function integer log2;
|
function integer log2;
|
input integer number; begin
|
input integer number; begin
|
log2=(number <=1) ? 1: 0;
|
log2=(number <=1) ? 1: 0;
|
while(2**log2<number) begin
|
while(2**log2<number) begin
|
log2=log2+1;
|
log2=log2+1;
|
end
|
end
|
end
|
end
|
endfunction // log2
|
endfunction // log2
|
|
|
localparam ARBITER_BIN_WIDTH= log2(ARBITER_WIDTH);
|
localparam ARBITER_BIN_WIDTH= log2(ARBITER_WIDTH);
|
wire [ARBITER_BIN_WIDTH-1 : 0] low_pr;
|
wire [ARBITER_BIN_WIDTH-1 : 0] low_pr;
|
|
|
|
|
wire [ARBITER_WIDTH-1 : 0] low_pr_one_hot = {priority_in[0],priority_in[ARBITER_BIN_WIDTH-1:1]};
|
wire [ARBITER_WIDTH-1 : 0] low_pr_one_hot = {priority_in[0],priority_in[ARBITER_BIN_WIDTH-1:1]};
|
|
|
one_hot_to_bin #(
|
one_hot_to_bin #(
|
.ONE_HOT_WIDTH (ARBITER_WIDTH)
|
.ONE_HOT_WIDTH (ARBITER_WIDTH)
|
)conv
|
)conv
|
(
|
(
|
.one_hot_code(low_pr_one_hot),
|
.one_hot_code(low_pr_one_hot),
|
.bin_code(low_pr)
|
.bin_code(low_pr)
|
);
|
);
|
|
|
|
|
assign any_grant = | request;
|
assign any_grant = | request;
|
|
|
generate
|
generate
|
if(ARBITER_WIDTH ==2) begin: w2 arbiter_2_one_hot arb( .in(request) , .out(grant), .low_pr(low_pr)); end
|
if(ARBITER_WIDTH ==2) begin: w2 arbiter_2_one_hot arb( .in(request) , .out(grant), .low_pr(low_pr)); end
|
if(ARBITER_WIDTH ==3) begin: w3 arbiter_3_one_hot arb( .in(request) , .out(grant), .low_pr(low_pr)); end
|
if(ARBITER_WIDTH ==3) begin: w3 arbiter_3_one_hot arb( .in(request) , .out(grant), .low_pr(low_pr)); end
|
if(ARBITER_WIDTH ==4) begin: w4 arbiter_4_one_hot arb( .in(request) , .out(grant), .low_pr(low_pr)); end
|
if(ARBITER_WIDTH ==4) begin: w4 arbiter_4_one_hot arb( .in(request) , .out(grant), .low_pr(low_pr)); end
|
endgenerate
|
endgenerate
|
|
|
endmodule
|
endmodule
|
|
|
|
|
/*********************************
|
/*********************************
|
*
|
*
|
* arbiter_ext_priority
|
* arbiter_ext_priority
|
*
|
*
|
**********************************/
|
**********************************/
|
|
|
|
|
module arbiter_ext_priority #(
|
module arbiter_ext_priority #(
|
parameter ARBITER_WIDTH =8
|
parameter ARBITER_WIDTH =8
|
|
|
)
|
)
|
(
|
(
|
|
|
request,
|
request,
|
grant,
|
grant,
|
priority_in,
|
priority_in,
|
any_grant
|
any_grant
|
);
|
);
|
|
|
|
|
input [ARBITER_WIDTH-1 : 0] request;
|
input [ARBITER_WIDTH-1 : 0] request;
|
input [ARBITER_WIDTH-1 : 0] priority_in;
|
input [ARBITER_WIDTH-1 : 0] priority_in;
|
output [ARBITER_WIDTH-1 : 0] grant;
|
output [ARBITER_WIDTH-1 : 0] grant;
|
output any_grant;
|
output any_grant;
|
|
|
/*
|
/*
|
generate
|
generate
|
|
|
if(ARBITER_WIDTH<=4) begin :ws4
|
if(ARBITER_WIDTH<=4) begin :ws4
|
//my own arbiter
|
//my own arbiter
|
my_one_hot_arbiter_ext_priority #(
|
my_one_hot_arbiter_ext_priority #(
|
.ARBITER_WIDTH (ARBITER_WIDTH)
|
.ARBITER_WIDTH (ARBITER_WIDTH)
|
)
|
)
|
one_hot_arb
|
one_hot_arb
|
(
|
(
|
|
|
.request (request),
|
.request (request),
|
.priority_in(priority_in),
|
.priority_in(priority_in),
|
.grant (grant),
|
.grant (grant),
|
.any_grant (any_grant)
|
.any_grant (any_grant)
|
);
|
);
|
|
|
end else begin :wb4
|
end else begin :wb4
|
*/
|
*/
|
|
|
thermo_arbiter_ext_priority #(
|
thermo_arbiter_ext_priority #(
|
.ARBITER_WIDTH (ARBITER_WIDTH)
|
.ARBITER_WIDTH (ARBITER_WIDTH)
|
)
|
)
|
one_hot_arb
|
one_hot_arb
|
(
|
(
|
|
|
.request (request),
|
.request (request),
|
.priority_in(priority_in),
|
.priority_in(priority_in),
|
.grant (grant),
|
.grant (grant),
|
.any_grant (any_grant)
|
.any_grant (any_grant)
|
);
|
);
|
// end
|
// end
|
// endgenerate
|
// endgenerate
|
|
|
|
|
|
|
|
|
endmodule
|
endmodule
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
/*
|
module fixed_priority_arbiter #(
|
module fixed_priority_arbiter #(
|
parameter ARBITER_WIDTH =8,
|
parameter ARBITER_WIDTH =8,
|
parameter HIGH_PRORITY_BIT = "HSB"
|
parameter HIGH_PRORITY_BIT = "HSB"
|
)
|
)
|
(
|
(
|
|
|
request,
|
request,
|
grant,
|
grant,
|
any_grant
|
any_grant
|
);
|
);
|
|
|
|
|
input [ARBITER_WIDTH-1 : 0] request;
|
input [ARBITER_WIDTH-1 : 0] request;
|
output [ARBITER_WIDTH-1 : 0] grant;
|
output [ARBITER_WIDTH-1 : 0] grant;
|
output any_grant;
|
output any_grant;
|
|
|
wire [ARBITER_WIDTH-1 : 0] cout;
|
wire [ARBITER_WIDTH-1 : 0] cout;
|
reg [ARBITER_WIDTH-1 : 0] cin;
|
reg [ARBITER_WIDTH-1 : 0] cin;
|
|
|
|
|
assign any_grant= | request;
|
assign any_grant= | request;
|
|
|
assign grant = cin & request;
|
assign grant = cin & request;
|
assign cout = cin & ~request;
|
assign cout = cin & ~request;
|
|
|
always @(*) begin
|
always @(*) begin
|
if( HIGH_PRORITY_BIT == "HSB") cin = {1'b1, cout[ARBITER_WIDTH-1 :1]}; // hsb has highest priority
|
if( HIGH_PRORITY_BIT == "HSB") cin = {1'b1, cout[ARBITER_WIDTH-1 :1]}; // hsb has highest priority
|
else cin = {cout[ARBITER_WIDTH-2 :0] ,1'b1}; // lsb has highest priority
|
else cin = {cout[ARBITER_WIDTH-2 :0] ,1'b1}; // lsb has highest priority
|
end//always
|
end//always
|
endmodule
|
endmodule
|
|
|
*/
|
*/
|
|
|
|
|
|
|
|
|
|
|