21ic电子技术开发论坛 单片机与嵌入式系统 FPGA论坛 请高手来解答,跪求啊
发新帖我要提问
返回列表
打印

请高手来解答,跪求啊

[复制链接]
1376|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
小僧|  楼主 | 2013-12-2 16:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
AN, TE, IO, ST, rio
/*
***************************************************
* Round-robin arbiter with variable priority vector
* ---------------------
* G. Dimitrakopoulos
* Nov. 2008
***************************************************
*/
`timescale 1ns/1ps
module arbiter(clk,
               rst,
               req,
               grant,
               anyGrant);

  parameter N = 8;
  parameter S = 3; // ceil of log_2 of N - put manually
  parameter CHOISE = 0;  // 0 blind round-robin and 1 true round robin

  // I/O interface
  input           clk;
  input           rst;
  input  [N-1:0]  req;
  output [N-1:0]  grant;
  output          anyGrant;
  
  // internal pointers
  reg [N-1:0] priority; // one-hot priority vector
  
  
  // Outputs of combinational logic - real wires - declared as regs for use in a alway block
  // Better to change to wires and use generate statements in the future
  
  reg [N-1:0]  g[S:0]; // S levels of priority generate
  reg [N-1:0]  p[S-1:0]; // S-1 levels of priority propagate

  // internal synonym wires of true outputs anyGrant and grant
  wire anyGnt;
  wire [N-1:0] gnt;

  assign anyGrant = anyGnt;
  assign grant = gnt;
  
  


/////////////////////////////////////////////////
// Parallel prefix arbitration phase
/////////////////////////////////////////////////
  integer i,j;

  // arbitration phase
  always@(req or priority)
    begin
      // transfer request vector to the first propagate positions
      p[0] = {~req[N-2:0], ~req[N-1]};

      // transfer priority vector to the first generate positions
      g[0] = priority;
      
      // first log_2n - 1 prefix levels
      for (i=1; i < S; i = i + 1) begin
        for (j = 0; j < N ; j = j + 1) begin
          if (j-2**(i-1) < 0) begin
            g[i][j] = g[i-1][j] | (p[i-1][j] & g[i-1][N+j-2**(i-1)]);           
            p[i][j] = p[i-1][j] & p[i-1][N+j-2**(i-1)];
          end else begin
            g[i][j] = g[i-1][j] | (p[i-1][j] & g[i-1][j-2**(i-1)]);           
            p[i][j] = p[i-1][j] & p[i-1][j-2**(i-1)];
          end            
        end
      end  
      
      // last prefix level
      for (j = 0; j < N; j = j + 1) begin
        if (j-2**(S-1) < 0)
          g[S][j] = g[S-1][j] | (p[S-1][j] & g[S-1][N+j-2**(S-1)]);           
        else
          g[S][j] = g[S-1][j] | (p[S-1][j] & g[S-1][j-2**(S-1)]);           
      end
    end      
  
  // any grant generation at last prefix level
  assign anyGnt = ~(p[S-1][N-1] & p[S-1][N/2-1]);
  
  // output stage logic
  assign gnt  = req & g[S];  


/////////////////////////////////////////////////
// Pointer update logic
// ------------------------
// Version 1 - blind round robin CHOISE = 0
// Priority visits each input in a circural manner irrespective the granted output
// ------------------------
// Version 2 - true round robin CHOISE = 1
// Priority moves next to the granted output
// ------------------------
// Priority moves only when a grant was given, i.e., at least one active request
//////////////////////////////////////////////////

  always@(posedge clk)
    begin
      if (rst == 1'b1) begin
        priority <= 1;
      end else begin
        // update pointers only if at leas one match exists
        if (anyGnt == 1'b1) begin  
            if (CHOISE == 0) begin // blind circular round robin
                // shift left one-hot priority vector
                priority[N-1:1] <= priority[N-2:0];
                priority[0] <= priority[N-1];  
            end else begin // true round robin
                // shift left one-hot grant vector
                priority[N-1:1] <= grant[N-2:0];
                priority[0] <= grant[N-1];  
            end   
        end
      end
    end


endmodule

相关帖子

沙发
小僧|  楼主 | 2013-12-2 16:25 | 只看该作者
在 ise上跑,怎么出现两个错误。
ERROR:Xst:678 - "arbiter.v" line 60: Can not evaluate constant.
ERROR:Xst:2634 - "arbiter.v" line 67: For loop stop condition should depend on loop variable or be static.

使用特权

评论回复
板凳
小僧|  楼主 | 2013-12-2 16:27 | 只看该作者
求解答

使用特权

评论回复
地板
yuancwei| | 2013-12-3 22:35 | 只看该作者
代码没有问题,应该是综合工具的版本太低了。换个高级点的。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

16

帖子

0

粉丝
关闭 热门推荐
快速回复 在线客服 返回列表 返回顶部