网站公告列表

  没有公告

加入收藏
设为首页
联系站长
您现在的位置: 61EDA中国电子网 >> 技术文库 >> HDL语言 >> 正文
  一个简单的总线轮询仲裁器Verilog代码           ★★★ 【字体:
一个简单的总线轮询仲裁器Verilog代码
作者:Free    文章来源:本站原创    点击数:    更新时间:2008-2-4    

下面这个是以输入信号作为状态机的转移条件,写得比较冗余:
//
// Verilog Module demo1_lib.bus_arbitor.arch_name
//
// Created:
//          by - Newhand
//          in - Shanghai ZhangJiang
//          at - 20:39:41 2003-12-03
// using Mentor Graphics HDL Designer(TM)
//
///////////////////////////////////////////////////////////
// Discription:
// Bus Polling Arbitor (BPA)
// 总线上挂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
//////////////////////////////////////////////////////////

`resetall
`timescale 1ns/10ps
module bus_arbitor(clk_i, en_i, sig_a_i, sig_b_i, sig_c_i, grant_o);

// I/O definition
input      clk_i;
input      en_i;
input      sig_a_i;
input      sig_b_i;
input      sig_c_i;
output   [1:0] grant_o;

// register definition
reg   [1:0] grant_o;
reg  [1:0] ls;

// parameter definition
parameter   s_null = 'd0,
           s_a    = 'd1,
           s_b    = 'd2,
           s_c    = 'd3,
           s_ab   = 'd4,
           s_bc   = 'd5,
           s_ac   = 'd6,
           s_abc  = 'd7;

//module part and FSM
always @(posedge clk_i or negedge en_i)
if(!en_i)// bus disable when negtive en_i
begin
grant_o <= 2'b11;
//cs <= s_null;
ls <= s_null;
end
else
begin
case({sig_a_i, sig_b_i, sig_c_i})// bus enable with FSM
  s_null:
     begin
        grant_o <= 2'b00;
        ls <= s_a;
     end
  s_a:
     begin
        grant_o <= 2'b00;
        ls <= s_a;
     end
  s_b:
     begin
        grant_o <= 2'b01;
        ls <= s_b;
     end
  s_c:
     begin
        grant_o <= 2'b10;
        ls <= s_c;
     end
  s_ab:
     case(ls)// feedback MUX configured
        s_a: begin grant_o <= 2'b01; ls <= s_b; end
        s_b: begin grant_o <= 2'b00; ls <= s_a; end
        s_c: begin grant_o <= 2'b00; ls <= s_a; end
     endcase
  s_bc:
     case(ls)
        s_a: begin grant_o <= 2'b01; ls <= s_b; end
        s_b: begin grant_o <= 2'b10; ls <= s_c; end
        s_c: begin grant_o <= 2'b01; ls <= s_b; end
     endcase
  s_ac:
     case(ls)
        s_a: begin grant_o <= 2'b10; ls <= s_c; end
        s_b: begin grant_o <= 2'b10; ls <= s_c; end
        s_c: begin grant_o <= 2'b00; ls <= s_a; end
     endcase
  s_abc:
     case(ls)
        s_a: begin grant_o <= 2'b01; ls <= s_b; end
        s_b: begin grant_o <= 2'b10; ls <= s_c; end
        s_c: begin grant_o <= 2'b00; ls <= s_a; end
     endcase
  default:
  begin grant_o <= 2'b00; ls <= s_a; end
           
endcase
end
endmodule
下面这个是根据输出信号来作为状态机的转移条件的,综合后发现面积更小,但由于没验证,怀疑后仿真可能会出现毛刺。

//
// Verilog Module demo1_lib.bus_arbitor.arch_name
//
// Created:
//          by - Newhand
//          in - Shanghai
//          at - 20:39:41 2003-12-03
// using Mentor Graphics HDL Designer(TM)
//
///////////////////////////////////////////////////////////
// Discription:
// Bus Polling Arbitor (BPA)
// 总线上挂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.
//////////////////////////////////////////////////////////

`resetall
`timescale 1ns/10ps
module bus_arbitor1(clk_i, en_i, sig_a_i, sig_b_i, sig_c_i, grant_o);

// I/O definition
input      clk_i;
input      en_i;
input      sig_a_i;
input      sig_b_i;
input      sig_c_i;
output   [1:0] grant_o;

// register definition
reg[1:0] grant_o;

// wire definition
wire[2:0] sig_abc = {sig_c_i, sig_b_i, sig_a_i};

//module part
always @(posedge clk_i or negedge en_i)
if(!en_i)
grant_o <= 2'b11;
else
begin
grant_o <= 2'b00;
case(grant_o)
2'b00: //a
case(sig_abc)
3'b000: grant_o <= 2'b00;
3'b001: grant_o <= 2'b00;
3'b010: grant_o <= 2'b01;
3'b100: grant_o <= 2'b10;
3'b011: grant_o <= 2'b01;
3'b101: grant_o <= 2'b10;
3'b110: grant_o <= 2'b01;
3'b111: grant_o <= 2'b01;
default: grant_o <= 2'b00;
endcase
2'b01: //b
case(sig_abc)
3'b000: grant_o <= 2'b00;
3'b001: grant_o <= 2'b00;
3'b010: grant_o <= 2'b01;
3'b100: grant_o <= 2'b10;
3'b011: grant_o <= 2'b00;
3'b101: grant_o <= 2'b10;
3'b110: grant_o <= 2'b10;
3'b111: grant_o <= 2'b10;
default: grant_o <= 2'b01;
endcase
2'b10: //c
case(sig_abc)
3'b000: grant_o <= 2'b00;
3'b001: grant_o <= 2'b00;
3'b010: grant_o <= 2'b01;
3'b100: grant_o <= 2'b10;
3'b011: grant_o <= 2'b00;
3'b101: grant_o <= 2'b00;
3'b110: grant_o <= 2'b01;
3'b111: grant_o <= 2'b00;
default: grant_o <= 2'b10;
endcase
default:
grant_o <= 2'b00;
endcase
end

endmodule

文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
    基于SOPC的多功能车辆息线控…
    基于VHDL状态机设计的智能交…
    基于梯形图-VHDL的CPLD开发方…
    半整数分频的VHDL程序
    学写Testbench-结构篇
    TESTBENCH语法参考
    编写高效的测试设计(testben…
    测试向量(Test Bench)和波…
    Verilog 编码原则…
    VHDL秒表计时器
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    湘ICP备08001332号 站长:61EDA