轮询总线仲裁器代码

  1 //
2 // Verilog Module demo1_lib.bus_arbitor.arch_name
3 //
4 // Created:
5 // by - Newhand
6 // in - Shanghai ZhangJiang
7 // at - 20:39:41 2003-12-03
8 // using Mentor Graphics HDL Designer(TM)
9 //
10 ///////////////////////////////////////////////////////////
11 // Discription:
12 // Bus Polling Arbitor (BPA)
13 // 总线上挂3个信号A,B,C,仲裁信号grant[1:0]。
14 // grant[1:0]=2’b00 A获得总线
15 // grant[1:0]=2’b01 B获得总线
16 // grant[1:0]=2’b10 C获得总线
17 // 总线轮询算法a.如果当前只有一个信号请求,则处理.
18 // b.如果没有请求,那么A获得总线.
19 // c.如果同时有多个信号请求,考虑上一个请求信号,
20 // 如果上一个请求信号是A,那么轮询的是BCA,
21 // 如果上一个请求信号是B,那么轮询的是CAB,
22 // 如果上一个请求信号是C,那么轮询的是ABC
23 //////////////////////////////////////////////////////////
24
25 `resetall
26 `timescale 1ns/10ps
27 module bus_arbitor(clk_i, en_i, sig_a_i, sig_b_i, sig_c_i, grant_o);
28
29 // I/O definition
30 input clk_i;
31 input en_i;
32 input sig_a_i;
33 input sig_b_i;
34 input sig_c_i;
35 output [1:0] grant_o;
36
37 // register definition
38 reg [1:0] grant_o;
39 reg [1:0] ls;
40
41 // parameter definition
42 parameter s_null = 'd0,
43 s_a = 'd1,
44 s_b = 'd2,
45 s_c = 'd3,
46 s_ab = 'd4,
47 s_bc = 'd5,
48 s_ac = 'd6,
49 s_abc = 'd7;
50
51 //module part and FSM
52 always @(posedge clk_i or negedge en_i)
53 if(!en_i)// bus disable when negtive en_i
54 begin
55 grant_o <= 2'b11;
56 //cs <= s_null;
57 ls <= s_null;
58 end
59 else
60 begin
61 case({sig_a_i, sig_b_i, sig_c_i})// bus enable with FSM
62 s_null:
63 begin
64 grant_o <= 2'b00;
65 ls <= s_a;
66 end
67 s_a:
68 begin
69 grant_o <= 2'b00;
70 ls <= s_a;
71 end
72 s_b:
73 begin
74 grant_o <= 2'b01;
75 ls <= s_b;
76 end
77 s_c:
78 begin
79 grant_o <= 2'b10;
80 ls <= s_c;
81 end
82 s_ab:
83 case(ls)// feedback MUX configured
84 s_a: begin grant_o <= 2'b01; ls <= s_b; end
85 s_b: begin grant_o <= 2'b00; ls <= s_a; end
86 s_c: begin grant_o <= 2'b00; ls <= s_a; end
87 endcase
88 s_bc:
89 case(ls)
90 s_a: begin grant_o <= 2'b01; ls <= s_b; end
91 s_b: begin grant_o <= 2'b10; ls <= s_c; end
92 s_c: begin grant_o <= 2'b01; ls <= s_b; end
93 endcase
94 s_ac:
95 case(ls)
96 s_a: begin grant_o <= 2'b10; ls <= s_c; end
97 s_b: begin grant_o <= 2'b10; ls <= s_c; end
98 s_c: begin grant_o <= 2'b00; ls <= s_a; end
99 endcase
100 s_abc:
101 case(ls)
102 s_a: begin grant_o <= 2'b01; ls <= s_b; end
103 s_b: begin grant_o <= 2'b10; ls <= s_c; end
104 s_c: begin grant_o <= 2'b00; ls <= s_a; end
105 endcase
106 default:
107 begin grant_o <= 2'b00; ls <= s_a; end
108
109 endcase
110 end
111 endmodule
112 下面这个是根据输出信号来作为状态机的转移条件的,综合后发现面积更小,但由于没验证,怀疑后仿真可能会出现毛刺。
113
114 //
115 // Verilog Module demo1_lib.bus_arbitor.arch_name
116 //
117 // Created:
118 // by - Newhand
119 // in - Shanghai
120 // at - 20:39:41 2003-12-03
121 // using Mentor Graphics HDL Designer(TM)
122 //
123 ///////////////////////////////////////////////////////////
124 // Discription:
125 // Bus Polling Arbitor (BPA)
126 // 总线上挂3个信号A,B,C,仲裁信号grant[1:0]。
127 // grant[1:0]=2’b00 A获得总线
128 // grant[1:0]=2’b01 B获得总线
129 // grant[1:0]=2’b10 C获得总线
130 // 总线轮询算法:
131 // a.如果当前只有一个信号请求,则处理.
132 // b.如果没有请求,那么A获得总线.
133 // c.如果同时有多个信号请求,考虑上一个请求信号,
134 // 如果上一个请求信号是A,那么轮询的是BCA,
135 // 如果上一个请求信号是B,那么轮询的是CAB,
136 // 如果上一个请求信号是C,那么轮询的是ABC.
137 //////////////////////////////////////////////////////////
138
139 `resetall
140 `timescale 1ns/10ps
141 module bus_arbitor1(clk_i, en_i, sig_a_i, sig_b_i, sig_c_i, grant_o);
142
143 // I/O definition
144 input clk_i;
145 input en_i;
146 input sig_a_i;
147 input sig_b_i;
148 input sig_c_i;
149 output [1:0] grant_o;
150
151 // register definition
152 reg[1:0] grant_o;
153
154 // wire definition
155 wire[2:0] sig_abc = {sig_c_i, sig_b_i, sig_a_i};
156
157 //module part
158 always @(posedge clk_i or negedge en_i)
159 if(!en_i)
160 grant_o <= 2'b11;
161 else
162 begin
163 grant_o <= 2'b00;
164 case(grant_o)
165 2'b00: //a
166 case(sig_abc)
167 3'b000: grant_o <= 2'b00;
168 3'b001: grant_o <= 2'b00;
169 3'b010: grant_o <= 2'b01;
170 3'b100: grant_o <= 2'b10;
171 3'b011: grant_o <= 2'b01;
172 3'b101: grant_o <= 2'b10;
173 3'b110: grant_o <= 2'b01;
174 3'b111: grant_o <= 2'b01;
175 default: grant_o <= 2'b00;
176 endcase
177 2'b01: //b
178 case(sig_abc)
179 3'b000: grant_o <= 2'b00;
180 3'b001: grant_o <= 2'b00;
181 3'b010: grant_o <= 2'b01;
182 3'b100: grant_o <= 2'b10;
183 3'b011: grant_o <= 2'b00;
184 3'b101: grant_o <= 2'b10;
185 3'b110: grant_o <= 2'b10;
186 3'b111: grant_o <= 2'b10;
187 default: grant_o <= 2'b01;
188 endcase
189 2'b10: //c
190 case(sig_abc)
191 3'b000: grant_o <= 2'b00;
192 3'b001: grant_o <= 2'b00;
193 3'b010: grant_o <= 2'b01;
194 3'b100: grant_o <= 2'b10;
195 3'b011: grant_o <= 2'b00;
196 3'b101: grant_o <= 2'b00;
197 3'b110: grant_o <= 2'b01;
198 3'b111: grant_o <= 2'b00;
199 default: grant_o <= 2'b10;
200 endcase
201 default:
202 grant_o <= 2'b00;
203 endcase
204 end
205
206 endmodule

 

posted @ 2012-01-16 14:55  宫藏嘉辈  阅读(5175)  评论(1编辑  收藏  举报