yuedx的个人空间 https://blog.eetop.cn/317611 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

一个简单的总线轮询仲裁器Verilog代码

已有 4888 次阅读| 2009-3-17 12:40

下面这个是以输入信号作为状态机的转移条件,写得比较冗余:
//
// 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


点赞

发表评论 评论 (1 个评论)

回复 jerry_gzy 2009-11-30 15:09
03年就有HDL Designer了。。。。

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 13

    粉丝
  • 1

    好友
  • 35

    获赞
  • 156

    评论
  • 4698

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-4-26 15:12 , Processed in 0.011065 second(s), 7 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部