网站开发 打标签静态网站开发
轮询仲裁器规则
轮询仲裁的规则是当0、1、2、、、N-1个source信号源同时向仲裁器发出请求时,初始情况下source 0的优先级最高,当仲裁器响应了source0后,source1的优先级最高,依次类推。
轮询仲裁器实现
轮询仲裁器的实现分为检测仲裁器输入口source信号源的request,根据当前仲裁器的优先级响应相应的request,仲裁器grant输出source端的请求,更新仲裁器的优先级。
按排序0、1、2、3、4、5…优先级一个个排下来
优先级排序ABC
根据输出信号来作为状态机的转移条件的
总线上挂3个信号A,B,C,仲裁信号grant[1:0]。
grant[1:0]=2’b00 A获得总线
grant[1:0]=2’b01 B获得总线
grant[1:0]=2’b10 C获得总线
总线轮询算法:
a.如果当前只有一个信号请求,则不用仲裁,谁申请就可以占用总线。.
b.如果没有请求,那么A获得总线.
c.如果同时有多个信号请求,考虑上一个请求信号,
如果上一个请求信号是A,那么轮询的是BCA,
如果上一个请求信号是B,那么轮询的是CAB,
如果上一个请求信号是C,那么轮询的是ABC.
module bus_arbiter(clk,rst_n,arequest,brequest, crequest, grant);// I/O definition
input clk;
input rst_n;
input arequest;
input brequest;
input crequest;
output [1:0] grant;// register definition
wire[1:0] grant;
reg[1:0] nx_state,current_state;
// wire definition
wire[2:0] request_abc = {arequest, brequest, crequest};parameter mastera=2'b00,masterb=2'b01,masterc=2'b10,rstate=2'b11;//module part
always @(posedge clk or negedge rst_n)beginif(!rst_n) current_state <= rstate;else current_state <= nx_state;endalways@(*)begincurrent_state <= mastera;case(current_state)mastera: //acase(request_abc)3'b000: nx_state <= mastera;3'b001: nx_state <= masterc;3'b010: nx_state <= masterb;3'b100: nx_state <= mastera;3'b011: nx_state <= masterb;3'b101: nx_state <= masterc;3'b110: nx_state <= masterb;3'b111: nx_state <= masterb;default: nx_state <= mastera;endcasemasterb: //bcase(request_abc)3'b000: nx_state <= mastera;3'b001: nx_state <= masterc;3'b010: nx_state <= masterb;3'b100: nx_state <= mastera;3'b011: nx_state <= masterc;3'b101: nx_state <= masterc;3'b110: nx_state <= mastera;3'b111: nx_state <= masterc;default: nx_state <= mastera;endcasemasterc: //ccase(request_abc)3'b000: nx_state <= mastera;3'b001: nx_state <= masterc;3'b010: nx_state <= masterb;3'b100: nx_state <= mastera;3'b011: nx_state <= masterb;3'b101: nx_state <= mastera;3'b110: nx_state <= mastera;3'b111: nx_state <= mastera;default: nx_state <= mastera;endcasedefault:nx_state <= mastera;endcaseend
assign grant = current_state;endmodule
固定优先级仲裁器规则
Fixed-priority Arbiter顾名思义当0、1、2、、、N-1个source同时发起request,Source 0的优先级最高,即便source0被响应完后,仍为最高优先级,其中优先级按照序号逐渐降低。
固定优先级仲裁实现
固定优先级仲裁器在FPGA实现与轮询仲裁器类似,唯一不同的是轮询仲裁在每次响应完request后会对优先级进行更新,而固定优先级则不需要此步骤。
//固定优先级不变,保持A--B--C
// 总线上挂3个信号A,B,C,仲裁信号grant[1:0]。
// grant[1:0]=2’b00 A获得总线
// grant[1:0]=2’b01 B获得总线
// grant[1:0]=2’b10 C获得总线`timescale 1ns/1ps
module bus_arbiter2(clk, rst_n, signal_a, signal_b, signal_c, grant);// I/O definition
input clk;
input rst_n;
input signal_a;
input signal_b;
input signal_c;
output [1:0] grant;
// register definition
reg [1:0] grant;// parameter definition
parameter s_null = 3'b000,s_a = 3'b100,s_b = 3'b010,s_c = 3'b001,s_ab = 3'b110,s_bc = 3'b001,s_ac = 3'b101,s_abc = 3'b111;//module part and FSM
always @(posedge clk or negedge rst_n)
if(!rst_n) // bus disable when negtive rst_nbegingrant <= 2'b11;//cs <= s_null;end
elsebegincase({signal_a, signal_b, signal_c})// bus enable with FSMs_null:grant <= 2'b00;s_a: grant <= 2'b00; s_b: grant <= 2'b01; s_c: grant <= 2'b10; s_ab: grant <= 2'b00; s_bc: grant <= 2'b01;s_ac: grant <= 2'b00;s_abc: grant <= 2'b00;default: grant <= 2'b00; endcase
end
endmodule
总线仲裁器的简单verilog实现_橙子的博客-CSDN博客_仲裁器verilog代码