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

Subversion Repositories pcie_sg_dma

[/] [pcie_sg_dma/] [trunk/] [rtl/] [Tx_Output_Arbitor.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 weng_ziti
----------------------------------------------------------------------------------
2
-- Company:  ziti, Uni. HD
3
-- Engineer:  wgao
4
-- 
5
-- Create Date:    11:47:02 07 Dec 2006 
6
-- Design Name: 
7
-- Module Name:    Tx_Output_Arbitor - Behavioral 
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool versions: 
11
-- Description: 
12
--
13
-- Dependencies:
14
--
15
-- Revision 1.00 - first release.  14.12.2006
16
-- 
17
-- Additional Comments:
18
--                      Dimension can be easily expanded.
19
-- 
20
----------------------------------------------------------------------------------
21
 
22
LIBRARY IEEE;
23
USE IEEE.STD_LOGIC_1164.ALL;
24
USE IEEE.STD_LOGIC_ARITH.ALL;
25
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
26
 
27
library work;
28
use work.abb64Package.all;
29
 
30
 
31
-----------  Top entity   ---------------
32
entity Tx_Output_Arbitor is
33
        port (
34
              rst_n     : IN  std_logic;
35
              clk       : IN  std_logic;
36
 
37
              arbtake   : IN  std_logic;                                       -- take a valid arbitration by the user
38
              Req       : IN  std_logic_vector(C_ARBITRATE_WIDTH-1 downto 0);  -- similar to FIFO not-empty
39
 
40
              bufread   : OUT std_logic_vector(C_ARBITRATE_WIDTH-1 downto 0);  -- Read FIFO
41
              Ack       : OUT std_logic_vector(C_ARBITRATE_WIDTH-1 downto 0)   -- tells who is the winner
42
        );
43
end Tx_Output_Arbitor;
44
 
45
 
46
architecture Behavioral of Tx_Output_Arbitor is
47
 
48
  TYPE ArbStates is         (
49
                               aSt_Reset
50
                             , aSt_Idle
51
                             , aSt_ReadOne
52
                             , aSt_Ready
53
                             );
54
 
55
  signal Arb_FSM             : ArbStates;
56
  signal Arb_FSM_NS          : ArbStates;
57
 
58
 
59
  TYPE PriorMatrix is ARRAY (C_ARBITRATE_WIDTH-1 downto 0)
60
                               of std_logic_vector (C_ARBITRATE_WIDTH-1 downto 0);
61
 
62
  signal ChPriority          : PriorMatrix;
63
 
64
  signal Prior_Init_Value    : PriorMatrix;
65
 
66
  signal Wide_Req            : PriorMatrix;
67
 
68
  signal Wide_Req_turned     : PriorMatrix;
69
 
70
 
71
  signal  take_i             :  std_logic;
72
  signal  Req_i              :  std_logic_vector(C_ARBITRATE_WIDTH-1 downto 0);
73
 
74
  signal  Req_r1             :  std_logic_vector(C_ARBITRATE_WIDTH-1 downto 0);
75
 
76
  signal  read_prep          :  std_logic_vector(C_ARBITRATE_WIDTH-1 downto 0);
77
  signal  read_i             :  std_logic_vector(C_ARBITRATE_WIDTH-1 downto 0);
78
  signal  Indice_prep        :  std_logic_vector(C_ARBITRATE_WIDTH-1 downto 0);
79
  signal  Indice_i           :  std_logic_vector(C_ARBITRATE_WIDTH-1 downto 0);
80
 
81
  signal  Champion_Vector    :  std_logic_vector (C_ARBITRATE_WIDTH-1 downto 0);
82
 
83
 
84
begin
85
 
86
   bufread   <= read_i;
87
   Ack       <= Indice_i;
88
 
89
   take_i    <= arbtake;
90
   Req_i     <= Req;
91
 
92
  -- ------------------------------------------------------------
93
  Prior_Init_Value(0) <= C_LOWEST_PRIORITY;
94
  Gen_Prior_Init_Values:
95
    FOR i IN 1 TO C_ARBITRATE_WIDTH-1 generate
96
      Prior_Init_Value(i) <= Prior_Init_Value(i-1)(C_ARBITRATE_WIDTH-2 downto 0) & '1';
97
    end generate;
98
 
99
 
100
  -- ------------------------------------------------------------
101
  --  Mask the requests
102
  -- 
103
  Gen_Wide_Requests:
104
    FOR i IN 0 TO C_ARBITRATE_WIDTH-1 generate
105
      Wide_Req(i) <= ChPriority(i) when Req_i(i)='1'
106
                     else C_ALL_ZEROS(C_ARBITRATE_WIDTH-1 downto 0);
107
    end generate;
108
 
109
 
110
-- ------------------------------------
111
-- Synchronous Delay: Req
112
--
113
   Synch_Delay_Req:
114
   process(clk)
115
   begin
116
     if clk'event and clk = '1' then
117
       Req_r1  <= Req_i;
118
     end if;
119
   end process;
120
 
121
 
122
-- ------------------------------------
123
-- Synchronous: States
124
--
125
   Seq_FSM_NextState:
126
   process(clk, rst_n)
127
   begin
128
     if (rst_n = '0') then
129
       Arb_FSM <= aSt_Reset;
130
     elsif clk'event and clk = '1' then
131
       Arb_FSM <= Arb_FSM_NS;
132
     end if;
133
   end process;
134
 
135
 
136
-- ------------------------------------
137
-- Combinatorial: Next States
138
--
139
   Comb_FSM_NextState:
140
   process (
141
             Arb_FSM
142
           , take_i
143
           , Req_r1
144
           )
145
   begin
146
     case Arb_FSM  is
147
 
148
       when aSt_Reset  =>
149
          Arb_FSM_NS <= aSt_Idle;
150
 
151
       when aSt_Idle  =>
152
          if Req_r1 = C_ALL_ZEROS(C_ARBITRATE_WIDTH-1 downto 0) then
153
             Arb_FSM_NS <= aSt_Idle;
154
          else
155
             Arb_FSM_NS <= aSt_ReadOne;
156
          end if;
157
 
158
       when aSt_ReadOne  =>
159
          if Req_r1 = C_ALL_ZEROS(C_ARBITRATE_WIDTH-1 downto 0) then  -- Ghost Request !!!
160
             Arb_FSM_NS <= aSt_Idle;
161
          else
162
             Arb_FSM_NS <= aSt_Ready;
163
          end if;
164
 
165
       when aSt_Ready  =>
166
          if take_i = '0' then
167
             Arb_FSM_NS <= aSt_Ready;
168
          elsif Req_r1 = C_ALL_ZEROS(C_ARBITRATE_WIDTH-1 downto 0) then
169
             Arb_FSM_NS <= aSt_Idle;
170
          else
171
             Arb_FSM_NS <= aSt_ReadOne;
172
          end if;
173
 
174
       when Others  =>
175
          Arb_FSM_NS <= aSt_Reset;
176
 
177
     end case;
178
 
179
   end process;
180
 
181
 
182
-- --------------------------------------------------
183
-- Turn the Request-Array Around
184
--
185
   Turn_the_Request_Array_Around:
186
       FOR i IN 0 TO C_ARBITRATE_WIDTH-1 generate
187
         Dimension_2nd:
188
         FOR j IN 0 TO C_ARBITRATE_WIDTH-1 generate
189
            Wide_Req_turned(i)(j) <= Wide_Req(j)(i);
190
         END generate;
191
       END generate;
192
 
193
 
194
-- --------------------------------------------------
195
-- Synchronous Calculation: Champion_Vector
196
--
197
   Sync_Champion_Vector:
198
   process(clk)
199
   begin
200
     if clk'event and clk = '1' then
201
 
202
       FOR i IN 0 TO C_ARBITRATE_WIDTH-1 LOOP
203
         if Wide_Req_turned(i)=C_ALL_ZEROS(C_ARBITRATE_WIDTH-1 downto 0) then
204
            Champion_Vector(i) <= '0';
205
         else
206
            Champion_Vector(i) <= '1';
207
         end if;
208
       END LOOP;
209
 
210
     end if;
211
   end process;
212
 
213
 
214
-- --------------------------------------------------
215
--  Prepare the buffer read signal: read_i
216
-- 
217
   Gen_Read_Signals:
218
     FOR i IN 0 TO C_ARBITRATE_WIDTH-1 generate
219
       read_prep(i) <= '1' when Champion_Vector=ChPriority(i) else '0';
220
     end generate;
221
 
222
 
223
-- --------------------------------------------------
224
-- FSM Output :  Buffer read_i and Indice_i
225
--
226
   FSM_Output_read_Indice:
227
   process (clk, rst_n)
228
   begin
229
     if (rst_n = '0') then
230
       read_i      <= C_ALL_ZEROS(C_ARBITRATE_WIDTH-1 downto 0);
231
       Indice_prep <= C_ALL_ZEROS(C_ARBITRATE_WIDTH-1 downto 0);
232
       Indice_i    <= C_ALL_ZEROS(C_ARBITRATE_WIDTH-1 downto 0);
233
     elsif clk'event and clk = '1' then
234
 
235
       case Arb_FSM is
236
 
237
         when aSt_ReadOne =>
238
           read_i      <= read_prep;
239
           Indice_prep <= read_prep;
240
           Indice_i    <= C_ALL_ZEROS(C_ARBITRATE_WIDTH-1 downto 0);
241
 
242
         when aSt_Ready =>
243
           read_i      <= C_ALL_ZEROS(C_ARBITRATE_WIDTH-1 downto 0);
244
           Indice_prep <= Indice_prep;
245
           if take_i ='1' then
246
            Indice_i    <= C_ALL_ZEROS(C_ARBITRATE_WIDTH-1 downto 0);
247
           else
248
            Indice_i    <= Indice_prep;
249
           end if;
250
 
251
         when Others =>
252
           read_i      <= C_ALL_ZEROS(C_ARBITRATE_WIDTH-1 downto 0);
253
           Indice_prep <= Indice_prep;
254
           Indice_i    <= C_ALL_ZEROS(C_ARBITRATE_WIDTH-1 downto 0);
255
 
256
       end case;
257
 
258
     end if;
259
   end process;
260
 
261
 
262
-- --------------------------------------------------
263
--
264
 Gen_Modify_Priorities:
265
 
266
   FOR i IN 0 TO C_ARBITRATE_WIDTH-1 generate
267
 
268
      Proc_Priority_Cycling:
269
      process (clk, rst_n)
270
      begin
271
        if (rst_n = '0') then
272
          ChPriority(i) <= Prior_Init_Value(i);
273
        elsif clk'event and clk = '1' then
274
 
275
          case Arb_FSM is
276
 
277
            when aSt_ReadOne =>
278
              if ChPriority(i) = Champion_Vector then
279
                 ChPriority(i) <= C_LOWEST_PRIORITY;
280
              elsif (ChPriority(i) and Champion_Vector) = Champion_Vector then
281
                 ChPriority(i) <= ChPriority(i);
282
              else
283
                 ChPriority(i) <= ChPriority(i)(C_ARBITRATE_WIDTH-2 downto 0) & '1';
284
              end if;
285
 
286
            when Others =>
287
                 ChPriority(i) <= ChPriority(i);
288
 
289
          end case;
290
 
291
        end if;
292
      end process;
293
 
294
  end generate;
295
 
296
 
297
end architecture Behavioral;

powered by: WebSVN 2.1.0

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