OpenCores
URL https://opencores.org/ocsvn/nocem/nocem/trunk

Subversion Repositories nocem

[/] [nocem/] [trunk/] [VHDL/] [Xto1_arbiter.vhd] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 schelleg
 
2
-----------------------------------------------------------------------------
3
-- NoCem -- Network on Chip Emulation Tool for System on Chip Research 
4
-- and Implementations
5
-- 
6
-- Copyright (C) 2006  Graham Schelle, Dirk Grunwald
7
-- 
8
-- This program is free software; you can redistribute it and/or
9
-- modify it under the terms of the GNU General Public License
10
-- as published by the Free Software Foundation; either version 2
11
-- of the License, or (at your option) any later version.
12
-- 
13
-- This program is distributed in the hope that it will be useful,
14
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
15
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
-- GNU General Public License for more details.
17
-- 
18
-- You should have received a copy of the GNU General Public License
19
-- along with this program; if not, write to the Free Software
20
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
21
-- 02110-1301, USA.
22
-- 
23
-- The authors can be contacted by email: <schelleg,grunwald>@cs.colorado.edu 
24
-- 
25
-- or by mail: Campus Box 430, Department of Computer Science,
26
-- University of Colorado at Boulder, Boulder, Colorado 80309
27
-------------------------------------------------------------------------------- 
28
 
29
 
30
-- 
31 2 schelleg
-- Filename: Xto1_arbiter.vhd
32 4 schelleg
-- 
33 2 schelleg
-- Description: a simple arbiter
34 4 schelleg
-- 
35
 
36
 
37
--a X to 1 arbiter takes in X arbitration requests and puts 
38
--out 1 grant signal.  This is done by:
39
--
40
--1. barrelshift inputs every cycle in a loop
41
--2. take results of that output and take highest reqs 
42
--   (where req priorities change every cycle)
43
--3. determine which input really won and in parallel, 
44
--   barrelshift back out the masked result
45
--
46
 
47
 
48
 
49
library IEEE;
50
use IEEE.STD_LOGIC_1164.ALL;
51
use IEEE.STD_LOGIC_ARITH.ALL;
52
use IEEE.STD_LOGIC_UNSIGNED.ALL;
53
 
54
 
55
entity Xto1_arbiter is
56
        Generic (
57
                NUM_REQS   : integer := 2;       -- 2,4 supported.  
58
                REG_OUTPUT : integer := 0
59
        );
60
    Port (
61
                          arb_req : in std_logic_vector(NUM_REQS-1 downto 0);
62
                          arb_grant : out std_logic_vector(NUM_REQS-1 downto 0);
63
                          clk : in std_logic;
64
           rst : in std_logic);
65
end Xto1_arbiter;
66
 
67
architecture Behavioral of Xto1_arbiter is
68
 
69
 
70
        -- specifically for a 4 input arbiter -----------------------------
71
        constant constant4      : std_logic_vector(2 downto 0) := "100";
72
        signal shift_reqs4   : std_logic_vector(1 downto 0);
73
        signal shift_grants4 : std_logic_vector(2 downto 0);
74
        -------------------------------------------------------------------
75
 
76
        -- specifically for a 2 input arbiter -----------------------------
77
        signal arb2_order     : std_logic;
78
        -------------------------------------------------------------------
79
 
80
 
81
 
82
 
83
        signal reqs_shifted        : std_logic_vector(NUM_REQS-1 downto 0);
84
        signal reqs_shifted_masked : std_logic_vector(NUM_REQS-1 downto 0);
85
 
86
        signal arb_grant_i                      : std_logic_vector(NUM_REQS-1 downto 0);
87
 
88
 
89
        -- wrapped up primitive, since not sure how to "infer" this element
90
        -- in VHDL...
91
   COMPONENT barrelshift4_wrapper
92
   PORT( I0     :       IN      STD_LOGIC;
93
          I1    :       IN      STD_LOGIC;
94
          I2    :       IN      STD_LOGIC;
95
          I3    :       IN      STD_LOGIC;
96
          S0    :       IN      STD_LOGIC;
97
          S1    :       IN      STD_LOGIC;
98
          O3    :       OUT     STD_LOGIC;
99
          O2    :       OUT     STD_LOGIC;
100
          O1    :       OUT     STD_LOGIC;
101
          O0    :       OUT     STD_LOGIC);
102
   END COMPONENT;
103
 
104
 
105
   COMPONENT barrelshift8_wrapper
106
   PORT( I0     :       IN      STD_LOGIC;
107
          I1    :       IN      STD_LOGIC;
108
          I2    :       IN      STD_LOGIC;
109
          I3    :       IN      STD_LOGIC;
110
          I4    :       IN      STD_LOGIC;
111
          I5    :       IN      STD_LOGIC;
112
          I6    :       IN      STD_LOGIC;
113
          I7    :       IN      STD_LOGIC;
114
          O7    :       OUT     STD_LOGIC;
115
          O6    :       OUT     STD_LOGIC;
116
          O5    :       OUT     STD_LOGIC;
117
          O4    :       OUT     STD_LOGIC;
118
          O3    :       OUT     STD_LOGIC;
119
          O2    :       OUT     STD_LOGIC;
120
          O1    :       OUT     STD_LOGIC;
121
          O0    :       OUT     STD_LOGIC;
122
          S2    :       IN      STD_LOGIC;
123
          S1    :       IN      STD_LOGIC;
124
          S0    :       IN      STD_LOGIC);
125
   END COMPONENT;
126
 
127
--   UUT: barrelshift8_wrapper PORT MAP(
128
--              I0 => , 
129
--              I1 => , 
130
--              I2 => , 
131
--              I3 => , 
132
--              I4 => , 
133
--              I5 => , 
134
--              I6 => , 
135
--              I7 => , 
136
--              O7 => , 
137
--              O6 => , 
138
--              O5 => , 
139
--              O4 => , 
140
--              O3 => , 
141
--              O2 => , 
142
--              O1 => , 
143
--              O0 => , 
144
--              S2 => , 
145
--              S1 => , 
146
--              S0 => 
147
--   );
148
 
149
 
150
 
151
 
152
 
153
begin
154
 
155
 
156
        arb4_gen : if NUM_REQS = 4 generate
157
 
158
           bshift_req4 : barrelshift4_wrapper PORT MAP(
159
                        I0 => arb_req(0),
160
                        I1 => arb_req(1),
161
                        I2 => arb_req(2),
162
                        I3 => arb_req(3),
163
                        S0 => shift_reqs4(0),
164
                        S1 => shift_reqs4(1),
165
                        O3 => reqs_shifted(3),
166
                        O2 => reqs_shifted(2),
167
                        O1 => reqs_shifted(1),
168
                        O0 => reqs_shifted(0)
169
           );
170
 
171
 
172
                bshift_grant4 : barrelshift4_wrapper PORT MAP(
173
                        I0 => reqs_shifted_masked(0),
174
                        I1 => reqs_shifted_masked(1),
175
                        I2 => reqs_shifted_masked(2),
176
                        I3 => reqs_shifted_masked(3),
177
                        S0 => shift_grants4(0),
178
                        S1 => shift_grants4(1),
179
                        O3 => arb_grant_i(3),
180
                        O2 => arb_grant_i(2),
181
                        O1 => arb_grant_i(1),
182
                        O0 => arb_grant_i(0)
183
           );
184
 
185
 
186
 
187
 
188
                gen_grant_mask : process (reqs_shifted,rst)
189
                begin
190
 
191
                        reqs_shifted_masked <= (others => '0');
192
 
193
                        if rst = '1' then
194
                                reqs_shifted_masked <= (others => '0');
195
                        else
196
                                if reqs_shifted(3) = '1' then
197
                                        reqs_shifted_masked(3) <= '1';
198
                                elsif   reqs_shifted(2) = '1' then
199
                                        reqs_shifted_masked(2) <= '1';
200
                                elsif   reqs_shifted(1) = '1' then
201
                                        reqs_shifted_masked(1) <= '1';
202
                                elsif reqs_shifted(0) = '1' then
203
                                        reqs_shifted_masked(0) <= '1';
204
                                else
205
                                        null;
206
                                end if;
207
                        end if;
208
 
209
                end process;
210
 
211
 
212
                gen_shift_value_clkd : process (clk,rst)
213
                begin
214
                        if rst = '1' then
215
                                shift_reqs4     <= (others => '0');
216
                        elsif clk'event and clk='1' then
217
                                shift_reqs4     <= shift_reqs4+1;
218
                        end if;
219
                end process;
220
 
221
                gen_shift_value_uclkd : process (shift_reqs4,rst)
222
                begin
223
                        if rst = '1' then
224
                                shift_grants4   <= (others => '0');
225
                        else
226
                                shift_grants4   <= (constant4 - ("0" & shift_reqs4) );
227
                        end if;
228
                end process;
229
 
230
 
231
end generate;
232
 
233
 
234
 
235
arb2_gen: if NUM_REQS = 2 generate
236
 
237
        gen_arb2_order_clkd : process (clk,rst)
238
        begin
239
                if rst='1' then
240
                        arb2_order <= '0';
241
                elsif clk='1' and clk'event then
242
                        arb2_order <= not arb2_order;
243
                end if;
244
        end process;
245
 
246
 
247
        gen_arb2_grant  : process (arb2_order,arb_req)
248
        begin
249
 
250
                arb_grant_i <= (others => '0');
251
 
252
                if arb2_order = '0' then
253
                        if arb_req(0) = '1' then
254
                                arb_grant_i(0) <= '1';
255
                        elsif arb_req(1) = '1' then
256
                                arb_grant_i(1) <= '1';
257
                        end if;
258
                end if;
259
 
260
                if arb2_order = '1' then
261
                        if arb_req(1) = '1' then
262
                                arb_grant_i(1) <= '1';
263
                        elsif arb_req(0) = '1' then
264
                                arb_grant_i(0) <= '1';
265
                        end if;
266
                end if;
267
 
268
        end process;
269
 
270
 
271
 
272
end generate;
273
 
274
 
275
 
276
----------------------------------------
277
--  REGISTERING OUTPUTS IF NEEDED     --
278
----------------------------------------
279
 
280
g_reg: if REG_OUTPUT = 1 generate
281
        gen_regd_output : process (clk,rst)
282
        begin
283
        if rst='1' then
284
                arb_grant <= (others => '0');
285
        elsif clk='1' and clk'event then
286
                arb_grant <= arb_grant_i;
287
        end if;
288
 
289
        end process;
290
end generate;
291
 
292
g_ureg: if REG_OUTPUT = 0 generate
293
        gen_uregd_output : process (arb_grant_i)
294
        begin
295
                arb_grant <= arb_grant_i;
296
        end process;
297
end generate;
298
 
299
 
300
 
301
 
302
end Behavioral;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.