文章目录
一、仲裁器Arbiter是什么?
仲裁器主要用于当多个source发出请求时,根据一定的规则,来选择响应哪一个source。
比如说source有6个,编号分别为0、1、2、3、4、5,优先级依次减小。那么当3号发出请求时,就无视4号、5号,响应3号的请求。同样的,当0号发出请求时,就响应0号,无视1-5号是否发出了请求。
二、固定优先级仲裁器Fixed Priority Arbiter
verilog设计:
i_priority为独热码,例如00100,则说明2号的请求优先级最高,向左依次降低
module FIXED_Arbiter#(
parameter P_CHANNEL_NUM = 8
)(
input i_clk ,
input i_rst ,
input [P_CHANNEL_NUM - 1 : 0] i_req ,
input [P_CHANNEL_NUM - 1 : 0] i_priority ,
input i_req_valid ,
output [P_CHANNEL_NUM - 1 : 0] o_grant ,
output o_grant_valid
);
/***************reg*******************/
reg [P_CHANNEL_NUM - 1 : 0] ro_grant ;
reg ro_grant_valid ;
/***************wire******************/
wire [2*P_CHANNEL_NUM - 1 : 0] req_sub_first_priority ;
wire [2*P_CHANNEL_NUM - 1 : 0] w_double_req ;
wire [2*P_CHANNEL_NUM - 1 : 0] w_double_grant ;
/***************component*************/
/***************assign****************/
assign o_grant = ro_grant ;
assign o_grant_valid = ro_grant_valid;
assign req_sub_first_priority = w_double_req - i_priority;
assign w_double_req = {i_req,i_req};
assign w_double_grant = w_double_req & (~req_sub_first_priority);
/***************always****************/
always @(posedge i_clk or posedge i_rst)begin
if(i_rst)
ro_grant <= 'd0;
else if(i_req_valid)
ro_grant <= w_double_grant[P_CHANNEL_NUM - 1 : 0] | w_double_grant[2*P_CHANNEL_NUM - 1 : P_CHANNEL_NUM];
else
ro_grant <= ro_grant;
end
always @(posedge i_clk or posedge i_rst)begin
if(i_rst)
ro_grant_valid <= 'd0;
else if(i_req_valid)
ro_grant_valid <= 1'b1;
else
ro_grant_valid <= 'd0;
end
endmodule
波形图:
输入请求为0110,第一次优先级为0001,授权为0010,第二次优先级为0010,授权依旧为0010,第三次优先级为0100授权变为0100,最后一次优先级为1000,授权变为0010;
三、轮询优先级仲裁器Round Robin Arbiter
当N个source同时发出请求时,默认source 0的优先级最高,当source 0 被响应后,它的优先级变为最低,source 1的优先级转为最高,以此类推。
verilog设计:
round_priority 初始值为0001,每次相应后最高优先级向左移位
module RR_arbiter#(
parameter P_CHANNEL_NUM = 8
)(
input i_clk ,
input i_rst ,
input [P_CHANNEL_NUM - 1 : 0] i_req ,
input i_req_valid ,
output [P_CHANNEL_NUM - 1 : 0] o_grant ,
output o_grant_valid ,
input reset_priority
);
/***************reg*******************/
reg [P_CHANNEL_NUM - 1 : 0] ro_grant ;
reg ro_grant_valid ;
reg [P_CHANNEL_NUM - 1 : 0] round_priority ;
/***************wire******************/
wire [2*P_CHANNEL_NUM - 1 : 0] req_sub_first_priority ;
wire [2*P_CHANNEL_NUM - 1 : 0] w_double_req ;
wire [2*P_CHANNEL_NUM - 1 : 0] w_double_grant ;
/***************component*************/
/***************assign****************/
assign o_grant = ro_grant ;
assign o_grant_valid = ro_grant_valid;
assign req_sub_first_priority = w_double_req - round_priority;
assign w_double_req = {i_req,i_req};
assign w_double_grant = w_double_req & (~req_sub_first_priority);
/***************always****************/
always @(posedge i_clk or posedge i_rst)begin
if(i_rst)
round_priority <= 'd1;
else if(reset_priority)
round_priority <= 'd1;
else if(ro_grant_valid)
round_priority <= {round_priority[P_CHANNEL_NUM - 2 : 0],round_priority[P_CHANNEL_NUM - 1]};
else
round_priority <= round_priority;
end
always @(posedge i_clk or posedge i_rst)begin
if(i_rst)
ro_grant <= 'd0;
else if(i_req_valid)
ro_grant <= w_double_grant[P_CHANNEL_NUM - 1 : 0] | w_double_grant[2*P_CHANNEL_NUM - 1 : P_CHANNEL_NUM];
else
ro_grant <= ro_grant;
end
always @(posedge i_clk or posedge i_rst)begin
if(i_rst)
ro_grant_valid <= 'd0;
else if(i_req_valid)
ro_grant_valid <= 1'b1;
else
ro_grant_valid <= 'd0;
end
endmodule
波形图:
可以看到每次授权后优先级都会发生改变
四、权重轮询优先级仲裁器Weighted Round Robin Arbiter
权重轮询仲裁器就是在轮询仲裁器的基础上,当grant次数等于weight时,再切换最高优先级。
我们在轮询的基础上加上一些权重,仲裁器虽然轮询的去serve requestor的 请求,但是完成一圈轮询后,requestor被serve的次数并不完全相同。
假设requestor有A、B、C、D三个,权值分别为4、3、2、1,假设它们的request一直为高,且从A开始轮询。则A被serve 4 次后B 才能被serve,依次类推。即weighted round robin则是要把weight计数器消耗光之后才轮换。如果A被serve的次数不够4次,此时request被拉低了呢?这个时候,我们不能等待A,而是要serve其他request为高的source,不然如果A后面不再发出有request,其他source的request就会永远不能被serve,就会挂死。 因此,当source的counter与weight相同(情况一),或者是正在被serve的source request被拉低(情况二),则重新load权值。