Verilog 循环仲裁员

Verilog 循环仲裁员,verilog,Verilog,我通过数到3来编写代码,给每个请求4个时钟时间。下面是运行代码 module arbiter(input clk, input rst_n, input wire [3:0] req, // 4 requestor output reg [3:0] grant ); // 4 grant reg [3:0] en ; // enable : priority token d

我通过数到3来编写代码,给每个请求4个时钟时间。下面是运行代码

module arbiter(input clk,
        input rst_n,
        input wire [3:0] req,           // 4 requestor
        output reg [3:0] grant );       // 4 grant

reg [3:0] en ;                      // enable : priority token distributor
wire [3:0]en_d;                     // enable dummy
reg [1:0] count ;                   //for counting up to 3 everytime request is available 
wire [1:0] count_d;                 //count dummy

reg  temp;                      //differentiate between reset condition and normal clock edge               
wire [1:0] pos_one;                 // finding position of one in enable
//wire [3:0] grant_c;                   


always @( posedge clk, negedge rst_n )
begin
     if(!rst_n)
    begin
        en <= 4'b0000;
        count <= 2'b00;
        temp <= 1'b0;
        grant <= 4'd0 ;
    end
    else
    begin
        temp <= 1'b1;
        count <= count_d ;
        en <= en_d;
        //grant <= grant_c;
    end

end

// when reset load 1000 (msb priority) and when clock comes rotate or load the
// priority data as per the condition

assign en_d =(temp == 0)? 4'b1000 : ((count == 2'b11 | req[pos_one] == 0)? {en[0],en[3:1]} : en);

 //when reset assign 0 and increase count as soon as request data is available
 //on pos_one of enable
assign count_d = (temp == 0)? 2'd0 : ((req[pos_one] == 1)? count + 1 :2'b00 );

//find every time new position of one as enable becomes available
assign pos_one = (en[0] == 1)? 2'd0 : (en[1] == 1)? 2'd1 : (en[2] == 1)? 2'd2 : 2'd3 ;   

//if request available on pos_one assign enable data else if no request assign 0
always @(en)
begin
    grant <= (req[pos_one] == 1)? en  : 4'b0000;
end

endmodule
模块仲裁器(输入时钟,
输入rst\n,
输入线[3:0]请求,//4请求者
输出注册[3:0]授权);//4赠款
注册号[3:0]en;//启用:优先级令牌分发服务器
电线[3:0]en_d;//启用虚拟
reg[1:0]计数//每次请求可用时最多可计数3
导线[1:0]计数//计数假人
注册温度//区分复位条件和正常时钟边缘
电线[1:0]位置1;//在enable中查找一个的位置
//电报[3:0]授权书;
始终@(posedge clk,negedge rst_n)
开始
如果(!rst_n)
开始

en您可以在组合逻辑块中使用for循环来计算下一个时钟周期的grant索引和值。for循环必须能够静态展开才能进行合成

下面的代码是计算值的框架。我省略了一些计算供您计算,另外它们取决于您的设计要求

always @* begin // comb logic
  if (/* condition */) begin
    // keep previous
    next_grant = grant;
    next_index = index; // 'index' is the position of the last know granted request
  end
  else begin
    // determine next
    next_grant = 'b0;
    next_index = ... ; // initial priority
    for (i=0; i<4; i=i+1) begin
      if (next_grant=='b0) begin // prevent updates once grant is decided
        if (req[next_index]) begin
          // Set next_grant
        end
        else begin
          // set next_index to next priority
        end
      end
    end
  end
end

always @(posedge clk, negedge rst_n) begin
  if (!rst_n) begin
    grant <= 'b0;
    index <= 'b0;
  end
  else begin
    grant <= next_grant;
    index <= next_index;
  end
end
始终@*begin//comb逻辑
如果(/*条件*/)开始
//保持先前
下一次赠款=赠款;
下一个索引=索引;/'“索引”是最后一个已知已授予请求的位置
结束
否则开始
//下一步决定
下一次授予='b0;
下一个索引=…;//初始优先级

for(i=0;i您可以在组合逻辑块中使用for循环来计算下一个时钟周期的grant索引和值。for循环必须能够静态展开才能进行合成

下面的代码是计算这些值的框架。我省略了一些计算供您计算,另外它们取决于您的设计要求

always @* begin // comb logic
  if (/* condition */) begin
    // keep previous
    next_grant = grant;
    next_index = index; // 'index' is the position of the last know granted request
  end
  else begin
    // determine next
    next_grant = 'b0;
    next_index = ... ; // initial priority
    for (i=0; i<4; i=i+1) begin
      if (next_grant=='b0) begin // prevent updates once grant is decided
        if (req[next_index]) begin
          // Set next_grant
        end
        else begin
          // set next_index to next priority
        end
      end
    end
  end
end

always @(posedge clk, negedge rst_n) begin
  if (!rst_n) begin
    grant <= 'b0;
    index <= 'b0;
  end
  else begin
    grant <= next_grant;
    index <= next_index;
  end
end
始终@*begin//comb逻辑
如果(/*条件*/)开始
//保持先前
下一次赠款=赠款;
next_index=index;//“index”是最后一个已知已授予请求的位置
结束
否则开始
//下一步决定
下一次授予='b0;
下一个索引=…;//初始优先级

对于(i=0;iI注意,在论文中,他们为任意大小的仲裁器构建了一个生成可合成Verilog的工具。为什么不从作者那里获取该工具并使用它生成RRA?我注意到,在论文中,他们为任意大小的仲裁器构建了一个生成可合成Verilog的工具。为什么不从作者和使用它来生成您的RRA?