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

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.hwp.communication/] [ase_mesh1/] [1.0/] [vhd/] [ase_mesh1_router.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- Title      : Router for 2D mesh mk1 by ase
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : ase_mesh1_router.vhdl
6
-- Author     : Lasse Lehtonen (ase)
7
-- Company    : 
8
-- Created    : 2010-04-06
9
-- Last update: 2012-03-22
10
-- Platform   : 
11
-- Standard   : VHDL'93
12
-------------------------------------------------------------------------------
13
-- Description: Router has connections to 4 neighbors and to IP. Neighbors are
14
--              are named as compass points: north, east, south and west.
15
--              Routing is fixed to YX routing and arbitration has fixed prio-
16
--              rities among the input ports. Addresses are expressed as number
17
--              of hops, e.g. 2 up and then 3 to the right.
18
--              Flow control needs 2 bits downstream (da+av) and 1 upstream (stall)
19
-------------------------------------------------------------------------------
20
-- Copyright (c) 2010 
21
-------------------------------------------------------------------------------
22
-- Revisions  :
23
-- Date        Version  Author  Description
24
-- 2010-04-06  1.0      ase     Created
25
-------------------------------------------------------------------------------
26
 
27
library ieee;
28
use ieee.std_logic_1164.all;
29
use ieee.numeric_std.all;
30
 
31
use work.log2_pkg.all;
32
 
33
entity ase_mesh1_router is
34
  generic (
35
    n_rows_g    : positive;             -- Number of rows
36
    n_cols_g    : positive;             -- Number of columns
37
    bus_width_g : positive              -- Width of the data bus in bits
38
    );
39
  port (
40
    clk   : in std_logic;
41
    rst_n : in std_logic;
42
 
43
    -- Agent interface
44
    a_data_in   : in  std_logic_vector(bus_width_g-1 downto 0);
45
    a_da_in     : in  std_logic;        -- data available = not empty = either addr or data
46
    a_av_in     : in  std_logic;        -- addr valid
47
    a_stall_out : out std_logic;
48
 
49
    a_data_out  : out std_logic_vector(bus_width_g-1 downto 0);
50
    a_da_out    : out std_logic;
51
    a_av_out    : out std_logic;
52
    a_stall_in  : in  std_logic;
53
 
54
    -- North interface
55
    n_data_in   : in  std_logic_vector(bus_width_g-1 downto 0);
56
    n_da_in     : in  std_logic;
57
    n_av_in     : in  std_logic;
58
    n_stall_out : out std_logic;
59
    n_data_out  : out std_logic_vector(bus_width_g-1 downto 0);
60
    n_da_out    : out std_logic;
61
    n_av_out    : out std_logic;
62
    n_stall_in  : in  std_logic;
63
 
64
    -- East interface
65
    e_data_in   : in  std_logic_vector(bus_width_g-1 downto 0);
66
    e_da_in     : in  std_logic;
67
    e_av_in     : in  std_logic;
68
    e_stall_out : out std_logic;
69
    e_data_out  : out std_logic_vector(bus_width_g-1 downto 0);
70
    e_da_out    : out std_logic;
71
    e_av_out    : out std_logic;
72
    e_stall_in  : in  std_logic;
73
 
74
    -- South interface
75
    s_data_in   : in  std_logic_vector(bus_width_g-1 downto 0);
76
    s_da_in     : in  std_logic;
77
    s_av_in     : in  std_logic;
78
    s_stall_out : out std_logic;
79
    s_data_out  : out std_logic_vector(bus_width_g-1 downto 0);
80
    s_da_out    : out std_logic;
81
    s_av_out    : out std_logic;
82
    s_stall_in  : in  std_logic;
83
 
84
    -- West interface
85
    w_data_in   : in  std_logic_vector(bus_width_g-1 downto 0);
86
    w_da_in     : in  std_logic;
87
    w_av_in     : in  std_logic;
88
    w_stall_out : out std_logic;
89
    w_data_out  : out std_logic_vector(bus_width_g-1 downto 0);
90
    w_da_out    : out std_logic;
91
    w_av_out    : out std_logic;
92
    w_stall_in  : in  std_logic
93
    );
94
 
95
end entity ase_mesh1_router;
96
 
97
 
98
-------------------------------------------------------------------------------
99
-- ARCHITECTURE
100
-------------------------------------------------------------------------------
101
 
102
architecture rtl of ase_mesh1_router is
103
 
104
  -----------------------------------------------------------------------------
105
  -- CONSTANTS
106
  -----------------------------------------------------------------------------
107
 
108
  -- Num of hops are stored into the lowest bits of the flit
109
  constant r_addr_width_c  : positive := log2_ceil(n_rows_g-1);
110
  constant c_addr_width_c  : positive := log2_ceil(n_cols_g-1);
111
  -- 4 additional bits are used for routing.
112
  --  1b telling go to left or right?,
113
  --  1b already in the right column? (called "here"), 
114
  --  2b for where to go first when data comes from ip
115
  constant lr_index_c      : positive := r_addr_width_c + c_addr_width_c;
116
  constant here_index_c    : positive := r_addr_width_c + c_addr_width_c + 1;
117
  constant first_index_h_c : positive := r_addr_width_c + c_addr_width_c + 3;
118
  constant first_index_l_c : positive := r_addr_width_c + c_addr_width_c + 2;
119
 
120
  -----------------------------------------------------------------------------
121
  -- REGISTERS
122
  -----------------------------------------------------------------------------
123
 
124
  -- Output registers
125
  signal a_stall_out_r : std_logic;
126
  signal a_data_out_r  : std_logic_vector(bus_width_g-1 downto 0);
127
  signal a_da_out_r    : std_logic;
128
  signal a_av_out_r    : std_logic;
129
  signal n_stall_out_r : std_logic;
130
  signal n_data_out_r  : std_logic_vector(bus_width_g-1 downto 0);
131
  signal n_da_out_r    : std_logic;
132
  signal n_av_out_r    : std_logic;
133
  signal e_stall_out_r : std_logic;
134
  signal e_data_out_r  : std_logic_vector(bus_width_g-1 downto 0);
135
  signal e_da_out_r    : std_logic;
136
  signal e_av_out_r    : std_logic;
137
  signal s_stall_out_r : std_logic;
138
  signal s_data_out_r  : std_logic_vector(bus_width_g-1 downto 0);
139
  signal s_da_out_r    : std_logic;
140
  signal s_av_out_r    : std_logic;
141
  signal w_stall_out_r : std_logic;
142
  signal w_data_out_r  : std_logic_vector(bus_width_g-1 downto 0);
143
  signal w_da_out_r    : std_logic;
144
  signal w_av_out_r    : std_logic;
145
 
146
  -- Input registers
147
  signal a_data_in_r : std_logic_vector(bus_width_g-1 downto 0);
148
  signal a_av_in_r   : std_logic;
149
  signal a_da_in_r   : std_logic;
150
  signal n_data_in_r : std_logic_vector(bus_width_g-1 downto 0);
151
  signal n_av_in_r   : std_logic;
152
  signal n_da_in_r   : std_logic;
153
  signal e_data_in_r : std_logic_vector(bus_width_g-1 downto 0);
154
  signal e_av_in_r   : std_logic;
155
  signal e_da_in_r   : std_logic;
156
  signal s_data_in_r : std_logic_vector(bus_width_g-1 downto 0);
157
  signal s_av_in_r   : std_logic;
158
  signal s_da_in_r   : std_logic;
159
  signal w_data_in_r : std_logic_vector(bus_width_g-1 downto 0);
160
  signal w_av_in_r   : std_logic;
161
  signal w_da_in_r   : std_logic;
162
 
163
  -- Other registers
164
  signal reroute_n_r : std_logic;       -- Data from n(orht) makes a turn or not?
165
  signal reroute_e_r : std_logic;
166
  signal reroute_s_r : std_logic;
167
  signal reroute_w_r : std_logic;
168
 
169
  signal grant_s_n_r : std_logic;       -- Output n(orht) granted for data from s(outh)
170
  signal grant_a_n_r : std_logic;
171
 
172
  signal grant_n_e_r : std_logic;
173
  signal grant_s_e_r : std_logic;
174
  signal grant_w_e_r : std_logic;
175
  signal grant_a_e_r : std_logic;
176
 
177
  signal grant_n_s_r : std_logic;
178
  signal grant_a_s_r : std_logic;
179
 
180
  signal grant_n_w_r : std_logic;
181
  signal grant_e_w_r : std_logic;
182
  signal grant_s_w_r : std_logic;
183
  signal grant_a_w_r : std_logic;
184
 
185
  signal grant_n_a_r : std_logic;
186
  signal grant_e_a_r : std_logic;
187
  signal grant_s_a_r : std_logic;
188
  signal grant_w_a_r : std_logic;
189
 
190
  -- Address = num of hops is incremented on every router. When row or col bit
191
  -- overflow packet has reached the right row or column. Note that this
192
  -- addition performed also for data flits. Therefore, 
193
 
194
  signal add_ar_r : std_logic_vector(r_addr_width_c-1 downto 0);
195
  signal add_ac_r : std_logic_vector(c_addr_width_c-1 downto 0);
196
 
197
  -----------------------------------------------------------------------------
198
  -- COMBINATIORIAL SIGNALS
199
  -----------------------------------------------------------------------------
200
  signal add_n : std_logic_vector(r_addr_width_c downto 0);
201
  signal add_e : std_logic_vector(c_addr_width_c downto 0);
202
  signal add_s : std_logic_vector(r_addr_width_c downto 0);
203
  signal add_w : std_logic_vector(c_addr_width_c downto 0);
204
 
205
  signal data_n : std_logic_vector(bus_width_g-1 downto 0);
206
  signal data_e : std_logic_vector(bus_width_g-1 downto 0);
207
  signal data_s : std_logic_vector(bus_width_g-1 downto 0);
208
  signal data_w : std_logic_vector(bus_width_g-1 downto 0);
209
  signal data_a : std_logic_vector(bus_width_g-1 downto 0);
210
 
211
  signal reroute_n : std_logic;
212
  signal reroute_e : std_logic;
213
  signal reroute_s : std_logic;
214
  signal reroute_w : std_logic;
215
 
216
  signal here_n      : std_logic;
217
  signal here_s      : std_logic;
218
  signal here_n_prev : std_logic;
219
  signal here_s_prev : std_logic;
220
 
221
  signal lr_n      : std_logic;
222
  signal lr_s      : std_logic;
223
  signal lr_n_prev : std_logic;
224
  signal lr_s_prev : std_logic;
225
 
226
  signal a_first_hi      : std_logic;
227
  signal a_first_lo      : std_logic;
228
  signal a_first_hi_prev : std_logic;
229
  signal a_first_lo_prev : std_logic;
230
 
231
  signal req_n_e : std_logic;
232
  signal req_n_s : std_logic;
233
  signal req_n_w : std_logic;
234
  signal req_n_a : std_logic;
235
 
236
  signal req_e_w : std_logic;
237
  signal req_e_a : std_logic;
238
 
239
  signal req_s_n : std_logic;
240
  signal req_s_e : std_logic;
241
  signal req_s_w : std_logic;
242
  signal req_s_a : std_logic;
243
 
244
  signal req_w_e : std_logic;
245
  signal req_w_a : std_logic;
246
 
247
  signal req_a_n : std_logic;
248
  signal req_a_e : std_logic;
249
  signal req_a_s : std_logic;
250
  signal req_a_w : std_logic;
251
 
252
  signal grant_s_n : std_logic;
253
  signal grant_a_n : std_logic;
254
 
255
  signal grant_n_e : std_logic;
256
  signal grant_s_e : std_logic;
257
  signal grant_w_e : std_logic;
258
  signal grant_a_e : std_logic;
259
 
260
  signal grant_n_s : std_logic;
261
  signal grant_a_s : std_logic;
262
 
263
  signal grant_n_w : std_logic;
264
  signal grant_e_w : std_logic;
265
  signal grant_s_w : std_logic;
266
  signal grant_a_w : std_logic;
267
 
268
  signal grant_n_a : std_logic;
269
  signal grant_e_a : std_logic;
270
  signal grant_s_a : std_logic;
271
  signal grant_w_a : std_logic;
272
 
273
  signal stall_n : std_logic;
274
  signal stall_e : std_logic;
275
  signal stall_s : std_logic;
276
  signal stall_w : std_logic;
277
  signal stall_a : std_logic;
278
 
279
 
280
begin  -- architecture rtl
281
 
282
  -----------------------------------------------------------------------------
283
  -- CONNECT OUTPUT REGISTERS TO OUTPUT PORTS
284
  -----------------------------------------------------------------------------
285
  a_stall_out <= a_stall_out_r;
286
  a_data_out  <= a_data_out_r;
287
  a_da_out    <= a_da_out_r;
288
  a_av_out    <= a_av_out_r;
289
 
290
  n_stall_out <= n_stall_out_r;
291
  n_data_out  <= n_data_out_r;
292
  n_da_out    <= n_da_out_r;
293
  n_av_out    <= n_av_out_r;
294
 
295
  e_stall_out <= e_stall_out_r;
296
  e_data_out  <= e_data_out_r;
297
  e_da_out    <= e_da_out_r;
298
  e_av_out    <= e_av_out_r;
299
 
300
  s_stall_out <= s_stall_out_r;
301
  s_data_out  <= s_data_out_r;
302
  s_da_out    <= s_da_out_r;
303
  s_av_out    <= s_av_out_r;
304
 
305
  w_stall_out <= w_stall_out_r;
306
  w_data_out  <= w_data_out_r;
307
  w_da_out    <= w_da_out_r;
308
  w_av_out    <= w_av_out_r;
309
 
310
  -----------------------------------------------------------------------------
311
  -- COMINATORIAL SIGNALS
312
  -----------------------------------------------------------------------------
313
 
314
  -- Always increment the incoming flits
315
  add_n <=
316
    std_logic_vector(resize(unsigned(n_data_in(r_addr_width_c-1 downto 0)),
317
                            r_addr_width_c+1)
318
                     + to_unsigned(1, r_addr_width_c+1));
319
  add_e <=
320
    std_logic_vector(resize(unsigned(
321
      e_data_in(c_addr_width_c + r_addr_width_c-1 downto r_addr_width_c)),
322
                            c_addr_width_c+1)
323
                     + to_unsigned(1, c_addr_width_c+1));
324
  add_s <=
325
    std_logic_vector(resize(unsigned(s_data_in(r_addr_width_c-1 downto 0)),
326
                            r_addr_width_c+1)
327
                     + to_unsigned(1, r_addr_width_c+1));
328
  add_w <=
329
    std_logic_vector(resize(unsigned(
330
      w_data_in(c_addr_width_c + r_addr_width_c-1 downto r_addr_width_c)),
331
                            c_addr_width_c+1)
332
                     + to_unsigned(1, c_addr_width_c+1));
333
 
334
  -- Forward the data to the agent (=IP block) and other outputs
335
  with a_av_in select
336
    data_a <=
337
    a_data_in when '1',
338
    a_data_in(bus_width_g-1 downto c_addr_width_c+r_addr_width_c) &
339
    std_logic_vector(unsigned(a_data_in(c_addr_width_c+r_addr_width_c-1
340
                                        downto r_addr_width_c)) +
341
                     unsigned(add_ac_r)) &
342
    std_logic_vector(unsigned(a_data_in(r_addr_width_c-1 downto 0)) +
343
                     unsigned(add_ar_r)) when others;
344
 
345
  data_n <= n_data_in(bus_width_g-1 downto r_addr_width_c) &
346
            add_n(r_addr_width_c-1 downto 0);
347
  data_e <= e_data_in(bus_width_g-1 downto c_addr_width_c + r_addr_width_c) &
348
            add_e(c_addr_width_c-1 downto 0) &
349
            e_data_in(r_addr_width_c-1 downto 0);
350
  data_s <= s_data_in(bus_width_g-1 downto r_addr_width_c) &
351
            add_s(r_addr_width_c-1 downto 0);
352
  data_w <= w_data_in(bus_width_g-1 downto c_addr_width_c + r_addr_width_c) &
353
            add_w(c_addr_width_c-1 downto 0) &
354
            w_data_in(r_addr_width_c-1 downto 0);
355
 
356
 
357
 
358
  -- Short-hand notations: for detecting if a turn is needed (reroute),
359
  -- has the right column been reached, whether to go left or right, and where
360
  -- to go first when entering the network.
361
  reroute_n <= add_n(r_addr_width_c);
362
  reroute_e <= add_e(c_addr_width_c);
363
  reroute_s <= add_s(r_addr_width_c);
364
  reroute_w <= add_w(c_addr_width_c);
365
 
366
  here_n      <= n_data_in(here_index_c);
367
  here_s      <= s_data_in(here_index_c);
368
  here_n_prev <= n_data_in_r(here_index_c);
369
  here_s_prev <= s_data_in_r(here_index_c);
370
 
371
  lr_n      <= n_data_in(lr_index_c);
372
  lr_s      <= s_data_in(lr_index_c);
373
  lr_n_prev <= n_data_in_r(lr_index_c);
374
  lr_s_prev <= s_data_in_r(lr_index_c);
375
 
376
  a_first_hi      <= a_data_in(first_index_h_c);
377
  a_first_lo      <= a_data_in(first_index_l_c);
378
  a_first_hi_prev <= a_data_in_r(first_index_h_c);
379
  a_first_lo_prev <= a_data_in_r(first_index_l_c);
380
 
381
 
382
  -- Arbitrate for outputs. Routing algorithm decides with output to "request"
383
  -- and fixed-priority algorithm "grants" the output to one of the requestors
384
  req_n_e <= ((n_av_in and not n_stall_out_r) and reroute_n and (not here_n) and
385
              (not lr_n)) or
386
             (n_av_in_r and reroute_n_r and (not here_n_prev) and
387
              (not lr_n_prev));
388
  req_n_s <= ((n_av_in and not n_stall_out_r) and (not reroute_n)) or
389
             (n_av_in_r and (not reroute_n_r));
390
  req_n_w <= ((n_av_in and not n_stall_out_r) and reroute_n and (not here_n) and
391
              (lr_n)) or
392
             (n_av_in_r and reroute_n_r and (not here_n_prev) and
393
              (lr_n_prev));
394
  req_n_a <= ((n_av_in and not n_stall_out_r) and reroute_n and here_n) or
395
             (n_av_in_r and reroute_n_r and here_n_prev);
396
 
397
  req_e_w <= ((e_av_in and not e_stall_out_r) and (not reroute_e)) or
398
             (e_av_in_r and (not reroute_e_r));
399
  req_e_a <= ((e_av_in and not e_stall_out_r) and reroute_e) or
400
             (e_av_in_r and reroute_e_r);
401
 
402
  req_s_n <= ((s_av_in and not s_stall_out_r) and (not reroute_s)) or
403
             (s_av_in_r and (not reroute_s_r));
404
  req_s_e <= ((s_av_in and not s_stall_out_r) and reroute_s and (not here_s) and
405
              (not lr_s)) or
406
             (s_av_in_r and reroute_s_r and (not here_s_prev) and
407
              (not lr_s_prev));
408
  req_s_w <= ((s_av_in and not s_stall_out_r) and reroute_s and (not here_s) and
409
              (lr_s)) or
410
             (s_av_in_r and reroute_s_r and (not here_s_prev) and
411
              (lr_s_prev));
412
  req_s_a <= ((s_av_in and not s_stall_out_r) and reroute_s and here_s) or
413
             (s_av_in_r and reroute_s_r and here_s_prev);
414
 
415
  -- (was just w_av_in              )
416
  req_w_e <= ((w_av_in and not w_stall_out_r) and (not reroute_w)) or
417
             (w_av_in_r and (not reroute_w_r));
418
  req_w_a <= ((w_av_in and not w_stall_out_r) and reroute_w) or
419
             (w_av_in_r and reroute_w_r);
420
 
421
  -- ( was just a_av_in       )
422
  req_a_n <= ((a_av_in and not a_stall_out_r) and (not a_first_hi)
423
              and (not a_first_lo)) or
424
             (a_av_in_r and (not a_first_hi_prev)
425
              and (not a_first_lo_prev));
426
  req_a_e <= ((a_av_in and not a_stall_out_r) and (not a_first_hi)
427
              and a_first_lo) or
428
             (a_av_in_r and (not a_first_hi_prev)
429
              and a_first_lo_prev);
430
  req_a_s <= ((a_av_in and not a_stall_out_r) and a_first_hi
431
              and (not a_first_lo)) or
432
             (a_av_in_r and a_first_hi_prev
433
              and (not a_first_lo_prev));
434
  req_a_w <= ((a_av_in and not a_stall_out_r) and a_first_hi
435
              and a_first_lo) or
436
             (a_av_in_r and a_first_hi_prev
437
              and a_first_lo_prev);
438
 
439
  grant_s_n <= (req_s_n
440
                and (not (grant_a_n_r and a_da_in and (not a_av_in)))
441
                and (not (grant_a_n_r and a_da_in_r and (not a_av_in_r)))) or
442
               (s_da_in and (not s_av_in) and grant_s_n_r) or
443
               (s_da_in_r and (not s_av_in_r) and grant_s_n_r);
444
  grant_a_n <= (req_a_n
445
                and (not (grant_s_n))) or
446
               (a_da_in and (not a_av_in) and grant_a_n_r) or
447
               (a_da_in_r and (not a_av_in_r) and grant_a_n_r);
448
 
449
  grant_n_e <= (req_n_e
450
                and (not (s_da_in and (not s_av_in) and grant_s_e_r))
451
                and (not (s_da_in_r and (not s_av_in_r) and grant_s_e_r))
452
                and (not (w_da_in and (not w_av_in) and grant_w_e_r))
453
                and (not (w_da_in_r and (not w_av_in_r) and grant_w_e_r))
454
                and (not (a_da_in and (not a_av_in) and grant_a_e_r))
455
                and (not (a_da_in_r and (not a_av_in_r) and grant_a_e_r))) or
456
               (n_da_in and (not n_av_in) and grant_n_e_r) or
457
               (n_da_in_r and (not n_av_in_r) and grant_n_e_r);
458
  grant_s_e <= (req_s_e
459
                and (not (grant_n_e))
460
                and (not (w_da_in and (not w_av_in) and grant_w_e_r))
461
                and (not (w_da_in_r and (not w_av_in_r) and grant_w_e_r))
462
                and (not (a_da_in and (not a_av_in) and grant_a_e_r))
463
                and (not (a_da_in_r and (not a_av_in_r) and grant_a_e_r))) or
464
               (s_da_in and (not s_av_in) and grant_s_e_r) or
465
               (s_da_in_r and (not s_av_in_r) and grant_s_e_r);
466
  grant_w_e <= (req_w_e
467
                and (not (grant_n_e))
468
                and (not (grant_s_e))
469
                and (not (a_da_in and (not a_av_in) and grant_a_e_r))
470
                and (not (a_da_in_r and (not a_av_in_r) and grant_a_e_r))) or
471
               (w_da_in and (not w_av_in) and grant_w_e_r) or
472
               (w_da_in_r and (not w_av_in_r) and grant_w_e_r);
473
  grant_a_e <= (req_a_e
474
                and (not (grant_n_e))
475
                and (not (grant_s_e))
476
                and (not (grant_w_e))) or
477
               (a_da_in and (not a_av_in) and grant_a_e_r) or
478
               (a_da_in_r and (not a_av_in_r) and grant_a_e_r);
479
 
480
  grant_n_s <= (req_n_s
481
                and (not (a_da_in and (not a_av_in) and grant_a_s_r))
482
                and (not (a_da_in_r and (not a_av_in_r) and grant_a_s_r))) or
483
               (n_da_in and (not n_av_in) and grant_n_s_r) or
484
               (n_da_in_r and (not n_av_in_r) and grant_n_s_r);
485
  grant_a_s <= (req_a_s
486
                and (not (grant_n_s))) or
487
               (a_da_in and (not a_av_in) and grant_a_s_r) or
488
               (a_da_in_r and (not a_av_in_r) and grant_a_s_r);
489
 
490
  grant_n_w <= (req_n_w
491
                and (not (s_da_in and (not s_av_in) and grant_s_w_r))
492
                and (not (s_da_in_r and (not s_av_in_r) and grant_s_w_r))
493
                and (not (e_da_in and (not e_av_in) and grant_e_w_r))
494
                and (not (e_da_in_r and (not e_av_in_r) and grant_e_w_r))
495
                and (not (a_da_in and (not a_av_in) and grant_a_w_r))
496
                and (not (a_da_in_r and (not a_av_in_r) and grant_a_w_r))) or
497
               (n_da_in and (not n_av_in) and grant_n_w_r) or
498
               (n_da_in_r and (not n_av_in_r) and grant_n_w_r);
499
  grant_e_w <= (req_e_w
500
                and (not (grant_n_w))
501
                and (not (s_da_in and (not s_av_in) and grant_s_w_r))
502
                and (not (s_da_in_r and (not s_av_in_r) and grant_s_w_r))
503
                and (not (a_da_in and (not a_av_in) and grant_a_w_r))
504
                and (not (a_da_in_r and (not a_av_in_r) and grant_a_w_r))) or
505
               (e_da_in and (not e_av_in) and grant_e_w_r) or
506
               (e_da_in_r and (not e_av_in_r) and grant_e_w_r);
507
  grant_s_w <= (req_s_w
508
                and (not (grant_n_w))
509
                and (not (grant_e_w))
510
                and (not (a_da_in and (not a_av_in) and grant_a_w_r))
511
                and (not (a_da_in_r and (not a_av_in_r) and grant_a_w_r))) or
512
               (s_da_in and (not s_av_in) and grant_s_w_r) or
513
               (s_da_in_r and (not s_av_in_r) and grant_s_w_r);
514
  grant_a_w <= (req_a_w
515
                and (not (grant_n_w))
516
                and (not (grant_s_w))
517
                and (not (grant_e_w))) or
518
               (a_da_in and (not a_av_in) and grant_a_w_r) or
519
               (a_da_in_r and (not a_av_in_r) and grant_a_w_r);
520
 
521
  grant_n_a <= (req_n_a
522
                and (not (s_da_in and (not s_av_in) and grant_s_a_r))
523
                and (not (s_da_in_r and (not s_av_in_r) and grant_s_a_r))
524
                and (not (w_da_in and (not w_av_in) and grant_w_a_r))
525
                and (not (w_da_in_r and (not w_av_in_r) and grant_w_a_r))
526
                and (not (e_da_in and (not e_av_in) and grant_e_a_r))
527
                and (not (e_da_in_r and (not e_av_in_r) and grant_e_a_r))) or
528
               (n_da_in and (not n_av_in) and grant_n_a_r) or
529
               (n_da_in_r and (not n_av_in_r) and grant_n_a_r);
530
 
531
  grant_e_a <= (req_e_a
532
                and (not (grant_n_a))
533
                and (not (s_da_in and (not s_av_in) and grant_s_a_r))
534
                and (not (s_da_in_r and (not s_av_in_r) and grant_s_a_r))
535
                and (not (w_da_in and (not w_av_in) and grant_w_a_r))
536
                and (not (w_da_in_r and (not w_av_in_r) and grant_w_a_r))) or
537
               (e_da_in and (not e_av_in) and grant_e_a_r) or
538
               (e_da_in_r and (not e_av_in_r) and grant_e_a_r);
539
  grant_s_a <= (req_s_a
540
                and (not (grant_n_a))
541
                and (not (grant_e_a))
542
                and (not (w_da_in and (not w_av_in) and grant_w_a_r))
543
                and (not (w_da_in_r and (not w_av_in_r) and grant_w_a_r))) or
544
               (s_da_in and (not s_av_in) and grant_s_a_r) or
545
               (s_da_in_r and (not s_av_in_r) and grant_s_a_r);
546
  grant_w_a <= (req_w_a
547
                and (not (grant_n_a))
548
                and (not (grant_e_a))
549
                and (not (grant_s_a))) or
550
               (w_da_in and (not w_av_in) and grant_w_a_r) or
551
               (w_da_in_r and (not w_av_in_r) and grant_w_a_r);
552
 
553
  -- Flow control. Stall the incoming data if it cannot be forwarded.
554
  stall_n <= (req_n_e and (not grant_n_e or e_stall_in)) or
555
             (grant_n_e_r and e_stall_in and grant_n_e) or  -- last added
556
             (req_n_s and (not grant_n_s or s_stall_in)) or
557
             (grant_n_s_r and s_stall_in and grant_n_s) or
558
             (req_n_w and (not grant_n_w or w_stall_in)) or
559
             (grant_n_w_r and w_stall_in and grant_n_w) or
560
             (req_n_a and (not grant_n_a or a_stall_in)) or
561
             (grant_n_a_r and a_stall_in and grant_n_a);
562
  stall_e <= (req_e_w and (not grant_e_w or w_stall_in)) or
563
             (grant_e_w_r and w_stall_in and grant_e_w) or
564
             (req_e_a and (not grant_e_a or a_stall_in)) or
565
             (grant_e_a_r and a_stall_in and grant_e_a);
566
  stall_s <= (req_s_e and (not grant_s_e or e_stall_in)) or
567
             (grant_s_e_r and e_stall_in and grant_s_e) or
568
             (req_s_n and (not grant_s_n or n_stall_in)) or
569
             (grant_s_n_r and n_stall_in and grant_s_n) or
570
             (req_s_w and (not grant_s_w or w_stall_in)) or
571
             (grant_s_w_r and w_stall_in and grant_s_w) or
572
             (req_s_a and (not grant_s_a or a_stall_in)) or
573
             (grant_s_a_r and a_stall_in and grant_s_a);
574
  stall_w <= (req_w_e and (not grant_w_e or e_stall_in)) or
575
             (grant_w_e_r and e_stall_in and grant_w_e) or
576
             (req_w_a and (not grant_w_a or a_stall_in)) or
577
             (grant_w_a_r and a_stall_in and grant_w_a);
578
  stall_a <= (req_a_n and (not grant_a_n or n_stall_in)) or
579
             (grant_a_n_r and n_stall_in and grant_a_n) or
580
             (req_a_e and (not grant_a_e or e_stall_in)) or
581
             (grant_a_e_r and e_stall_in and grant_a_e) or
582
             (req_a_s and (not grant_a_s or s_stall_in)) or
583
             (grant_a_s_r and s_stall_in and grant_a_s) or
584
             (req_a_w and (not grant_a_w or w_stall_in)) or
585
             (grant_a_w_r and w_stall_in and grant_a_w);
586
 
587
 
588
 
589
  -----------------------------------------------------------------------------
590
  -- SYNCHRONOUS SIGNALS
591
  -----------------------------------------------------------------------------
592
 
593
  regs_p : process (clk, rst_n) is
594
  begin  -- process regs_p
595
    if rst_n = '0' then                 -- asynchronous reset (active low)
596
 
597
      n_stall_out_r <= '0';
598
      n_da_out_r    <= '0';
599
      n_av_out_r    <= '0';
600
      e_stall_out_r <= '0';
601
      e_da_out_r    <= '0';
602
      e_av_out_r    <= '0';
603
      s_stall_out_r <= '0';
604
      s_da_out_r    <= '0';
605
      s_av_out_r    <= '0';
606
      w_stall_out_r <= '0';
607
      w_da_out_r    <= '0';
608
      w_av_out_r    <= '0';
609
      a_stall_out_r <= '0';
610
      a_da_out_r    <= '0';
611
      a_av_out_r    <= '0';
612
 
613
      n_data_out_r <= (others => '0');
614
      e_data_out_r <= (others => '0');
615
      s_data_out_r <= (others => '0');
616
      w_data_out_r <= (others => '0');
617
      a_data_out_r <= (others => '0');
618
 
619
      n_data_in_r <= (others => '0');
620
      n_av_in_r   <= '0';
621
      n_da_in_r   <= '0';
622
      e_data_in_r <= (others => '0');
623
      e_av_in_r   <= '0';
624
      e_da_in_r   <= '0';
625
      s_data_in_r <= (others => '0');
626
      s_av_in_r   <= '0';
627
      s_da_in_r   <= '0';
628
      w_data_in_r <= (others => '0');
629
      w_av_in_r   <= '0';
630
      w_da_in_r   <= '0';
631
      a_data_in_r <= (others => '0');
632
      a_av_in_r   <= '0';
633
      a_da_in_r   <= '0';
634
 
635
      reroute_n_r <= '0';
636
      reroute_e_r <= '0';
637
      reroute_s_r <= '0';
638
      reroute_w_r <= '0';
639
 
640
      grant_s_n_r <= '0';
641
      grant_a_n_r <= '0';
642
      grant_n_e_r <= '0';
643
      grant_s_e_r <= '0';
644
      grant_w_e_r <= '0';
645
      grant_a_e_r <= '0';
646
      grant_n_s_r <= '0';
647
      grant_a_s_r <= '0';
648
      grant_n_w_r <= '0';
649
      grant_e_w_r <= '0';
650
      grant_s_w_r <= '0';
651
      grant_a_w_r <= '0';
652
      grant_n_a_r <= '0';
653
      grant_e_a_r <= '0';
654
      grant_s_a_r <= '0';
655
      grant_w_a_r <= '0';
656
 
657
      add_ar_r <= (others => '0');
658
      add_ac_r <= (others => '0');
659
 
660
    elsif clk'event and clk = '1' then  -- rising clock edge
661
 
662
      n_stall_out_r <= stall_n;
663
      e_stall_out_r <= stall_e;
664
      s_stall_out_r <= stall_s;
665
      w_stall_out_r <= stall_w;
666
      a_stall_out_r <= stall_a;
667
 
668
      grant_s_n_r <= grant_s_n;
669
      grant_a_n_r <= grant_a_n;
670
      grant_n_e_r <= grant_n_e;
671
      grant_s_e_r <= grant_s_e;
672
      grant_w_e_r <= grant_w_e;
673
      grant_a_e_r <= grant_a_e;
674
      grant_n_s_r <= grant_n_s;
675
      grant_a_s_r <= grant_a_s;
676
      grant_n_w_r <= grant_n_w;
677
      grant_e_w_r <= grant_e_w;
678
      grant_s_w_r <= grant_s_w;
679
      grant_a_w_r <= grant_a_w;
680
      grant_n_a_r <= grant_n_a;
681
      grant_e_a_r <= grant_e_a;
682
      grant_s_a_r <= grant_s_a;
683
      grant_w_a_r <= grant_w_a;
684
 
685
      if a_av_in = '1' then
686
        add_ar_r <= a_data_in(r_addr_width_c-1 downto 0);
687
        add_ac_r <= a_data_in(c_addr_width_c+r_addr_width_c-1 downto
688
                              r_addr_width_c);
689
      end if;
690
 
691
      if stall_n = '1' and n_stall_out_r = '0' then
692
        n_data_in_r <= data_n;
693
        n_da_in_r   <= n_da_in;
694
        n_av_in_r   <= n_av_in;
695
        reroute_n_r <= reroute_n;
696
      elsif stall_n = '0' and n_stall_out_r = '1' then
697
        n_data_in_r <= (others => '0');
698
        n_da_in_r   <= '0';
699
        n_av_in_r   <= '0';
700
        reroute_n_r <= '0';
701
      end if;
702
 
703
      if stall_e = '1' and e_stall_out_r = '0' then
704
        e_data_in_r <= data_e;
705
        e_da_in_r   <= e_da_in;
706
        e_av_in_r   <= e_av_in;
707
        reroute_e_r <= reroute_e;
708
      elsif stall_e = '0' and e_stall_out_r = '1' then
709
        e_data_in_r <= (others => '0');
710
        e_da_in_r   <= '0';
711
        e_av_in_r   <= '0';
712
        reroute_e_r <= '0';
713
      end if;
714
 
715
      if stall_s = '1' and s_stall_out_r = '0' then
716
        s_data_in_r <= data_s;
717
        s_da_in_r   <= s_da_in;
718
        s_av_in_r   <= s_av_in;
719
        reroute_s_r <= reroute_s;
720
      elsif stall_s = '0' and s_stall_out_r = '1' then
721
        s_data_in_r <= (others => '0');
722
        s_da_in_r   <= '0';
723
        s_av_in_r   <= '0';
724
        reroute_s_r <= '0';
725
      end if;
726
 
727
      if stall_w = '1' and w_stall_out_r = '0' then
728
        w_data_in_r <= data_w;
729
        w_da_in_r   <= w_da_in;
730
        w_av_in_r   <= w_av_in;
731
        reroute_w_r <= reroute_w;
732
      elsif stall_w = '0' and w_stall_out_r = '1' then
733
        w_data_in_r <= (others => '0');
734
        w_da_in_r   <= '0';
735
        w_av_in_r   <= '0';
736
        reroute_w_r <= '0';
737
      end if;
738
 
739
      if stall_a = '1' and a_stall_out_r = '0' then
740
        a_data_in_r <= data_a;
741
        a_da_in_r   <= a_da_in;
742
        a_av_in_r   <= a_av_in;
743
      elsif stall_a = '0' and a_stall_out_r = '1' then
744
        a_data_in_r <= (others => '0');
745
        a_da_in_r   <= '0';
746
        a_av_in_r   <= '0';
747
      end if;
748
 
749
      if e_stall_in = '1' then
750
 
751
      elsif grant_n_e = '1' and e_stall_in = '0' and n_stall_out_r = '0' then
752
        e_data_out_r <= data_n;
753
        e_da_out_r   <= n_da_in;
754
        e_av_out_r   <= n_av_in;
755
      elsif grant_n_e = '1' and e_stall_in = '0' and n_stall_out_r = '1' then
756
        e_data_out_r <= n_data_in_r;
757
        e_da_out_r   <= n_da_in_r;
758
        e_av_out_r   <= n_av_in_r;
759
      elsif grant_s_e = '1' and e_stall_in = '0' and s_stall_out_r = '0' then
760
        e_data_out_r <= data_s;
761
        e_da_out_r   <= s_da_in;
762
        e_av_out_r   <= s_av_in;
763
      elsif grant_s_e = '1' and e_stall_in = '0' and s_stall_out_r = '1' then
764
        e_data_out_r <= s_data_in_r;
765
        e_da_out_r   <= s_da_in_r;
766
        e_av_out_r   <= s_av_in_r;
767
      elsif grant_w_e = '1' and e_stall_in = '0' and w_stall_out_r = '0' then
768
        e_data_out_r <= data_w;
769
        e_da_out_r   <= w_da_in;
770
        e_av_out_r   <= w_av_in;
771
      elsif grant_w_e = '1' and e_stall_in = '0' and w_stall_out_r = '1' then
772
        e_data_out_r <= w_data_in_r;
773
        e_da_out_r   <= w_da_in_r;
774
        e_av_out_r   <= w_av_in_r;
775
      elsif grant_a_e = '1' and e_stall_in = '0' and a_stall_out_r = '0' then
776
        e_data_out_r <= data_a;
777
        e_da_out_r   <= a_da_in;
778
        e_av_out_r   <= a_av_in;
779
      elsif grant_a_e = '1' and e_stall_in = '0' and a_stall_out_r = '1' then
780
        e_data_out_r <= a_data_in_r;
781
        e_da_out_r   <= a_da_in_r;
782
        e_av_out_r   <= a_av_in_r;
783
      elsif grant_n_e = '0' and grant_s_e = '0'
784
        and grant_w_e = '0' and grant_a_e = '0' then
785
        e_data_out_r <= (others => '0');
786
        e_da_out_r   <= '0';
787
        e_av_out_r   <= '0';
788
      end if;
789
 
790
      if s_stall_in = '1' then
791
 
792
      elsif grant_n_s = '1' and s_stall_in = '0' and n_stall_out_r = '0' then
793
        s_data_out_r <= data_n;
794
        s_da_out_r   <= n_da_in;
795
        s_av_out_r   <= n_av_in;
796
      elsif grant_n_s = '1' and s_stall_in = '0' and n_stall_out_r = '1' then
797
        s_data_out_r <= n_data_in_r;
798
        s_da_out_r   <= n_da_in_r;
799
        s_av_out_r   <= n_av_in_r;
800
      elsif grant_a_s = '1' and s_stall_in = '0' and a_stall_out_r = '0' then
801
        s_data_out_r <= data_a;
802
        s_da_out_r   <= a_da_in;
803
        s_av_out_r   <= a_av_in;
804
      elsif grant_a_s = '1' and s_stall_in = '0' and a_stall_out_r = '1' then
805
        s_data_out_r <= a_data_in_r;
806
        s_da_out_r   <= a_da_in_r;
807
        s_av_out_r   <= a_av_in_r;
808
      elsif grant_n_s = '0' and grant_a_s = '0' then
809
        s_data_out_r <= (others => '0');
810
        s_da_out_r   <= '0';
811
        s_av_out_r   <= '0';
812
      end if;
813
 
814
      if w_stall_in = '1' then
815
 
816
      elsif grant_n_w = '1' and w_stall_in = '0' and n_stall_out_r = '0' then
817
        w_data_out_r <= data_n;
818
        w_da_out_r   <= n_da_in;
819
        w_av_out_r   <= n_av_in;
820
      elsif grant_n_w = '1' and w_stall_in = '0' and n_stall_out_r = '1' then
821
        w_data_out_r <= n_data_in_r;
822
        w_da_out_r   <= n_da_in_r;
823
        w_av_out_r   <= n_av_in_r;
824
      elsif grant_s_w = '1' and w_stall_in = '0' and s_stall_out_r = '0' then
825
        w_data_out_r <= data_s;
826
        w_da_out_r   <= s_da_in;
827
        w_av_out_r   <= s_av_in;
828
      elsif grant_s_w = '1' and w_stall_in = '0' and s_stall_out_r = '1' then
829
        w_data_out_r <= s_data_in_r;
830
        w_da_out_r   <= s_da_in_r;
831
        w_av_out_r   <= s_av_in_r;
832
      elsif grant_e_w = '1' and w_stall_in = '0' and e_stall_out_r = '0' then
833
        w_data_out_r <= data_e;
834
        w_da_out_r   <= e_da_in;
835
        w_av_out_r   <= e_av_in;
836
      elsif grant_e_w = '1' and w_stall_in = '0' and e_stall_out_r = '1' then
837
        w_data_out_r <= e_data_in_r;
838
        w_da_out_r   <= e_da_in_r;
839
        w_av_out_r   <= e_av_in_r;
840
      elsif grant_a_w = '1' and w_stall_in = '0' and a_stall_out_r = '0' then
841
        w_data_out_r <= data_a;
842
        w_da_out_r   <= a_da_in;
843
        w_av_out_r   <= a_av_in;
844
      elsif grant_a_w = '1' and w_stall_in = '0' and a_stall_out_r = '1' then
845
        w_data_out_r <= a_data_in_r;
846
        w_da_out_r   <= a_da_in_r;
847
        w_av_out_r   <= a_av_in_r;
848
      elsif grant_n_w = '0' and grant_e_w = '0'
849
        and grant_s_w = '0' and grant_a_w = '0' then
850
        w_data_out_r <= (others => '0');
851
        w_da_out_r   <= '0';
852
        w_av_out_r   <= '0';
853
      end if;
854
 
855
 
856
      if n_stall_in = '1' then
857
 
858
      elsif grant_s_n = '1' and n_stall_in = '0' and s_stall_out_r = '0' then
859
        n_data_out_r <= data_s;
860
        n_da_out_r   <= s_da_in;
861
        n_av_out_r   <= s_av_in;
862
      elsif grant_s_n = '1' and n_stall_in = '0' and s_stall_out_r = '1' then
863
        n_data_out_r <= s_data_in_r;
864
        n_da_out_r   <= s_da_in_r;
865
        n_av_out_r   <= s_av_in_r;
866
      elsif grant_a_n = '1' and n_stall_in = '0' and a_stall_out_r = '0' then
867
        n_data_out_r <= data_a;
868
        n_da_out_r   <= a_da_in;
869
        n_av_out_r   <= a_av_in;
870
      elsif grant_a_n = '1' and n_stall_in = '0' and a_stall_out_r = '1' then
871
        n_data_out_r <= a_data_in_r;
872
        n_da_out_r   <= a_da_in_r;
873
        n_av_out_r   <= a_av_in_r;
874
      elsif grant_s_n = '0' and grant_a_n = '0' then
875
        n_data_out_r <= (others => '0');
876
        n_da_out_r   <= '0';
877
        n_av_out_r   <= '0';
878
      end if;
879
 
880
      if a_stall_in = '1' then
881
 
882
      elsif grant_n_a = '1' and a_stall_in = '0' and n_stall_out_r = '0' then
883
        a_data_out_r <= data_n;
884
        a_da_out_r   <= n_da_in;
885
        a_av_out_r   <= n_av_in;
886
      elsif grant_n_a = '1' and a_stall_in = '0' and n_stall_out_r = '1' then
887
        a_data_out_r <= n_data_in_r;
888
        a_da_out_r   <= n_da_in_r;
889
        a_av_out_r   <= n_av_in_r;
890
      elsif grant_s_a = '1' and a_stall_in = '0' and s_stall_out_r = '0' then
891
        a_data_out_r <= data_s;
892
        a_da_out_r   <= s_da_in;
893
        a_av_out_r   <= s_av_in;
894
      elsif grant_s_a = '1' and a_stall_in = '0' and s_stall_out_r = '1' then
895
        a_data_out_r <= s_data_in_r;
896
        a_da_out_r   <= s_da_in_r;
897
        a_av_out_r   <= s_av_in_r;
898
      elsif grant_e_a = '1' and a_stall_in = '0' and e_stall_out_r = '0' then
899
        a_data_out_r <= data_e;
900
        a_da_out_r   <= e_da_in;
901
        a_av_out_r   <= e_av_in;
902
      elsif grant_e_a = '1' and a_stall_in = '0' and e_stall_out_r = '1' then
903
        a_data_out_r <= e_data_in_r;
904
        a_da_out_r   <= e_da_in_r;
905
        a_av_out_r   <= e_av_in_r;
906
      elsif grant_w_a = '1' and a_stall_in = '0' and w_stall_out_r = '0' then
907
        a_data_out_r <= data_w;
908
        a_da_out_r   <= w_da_in;
909
        a_av_out_r   <= w_av_in;
910
      elsif grant_w_a = '1' and a_stall_in = '0' and w_stall_out_r = '1' then
911
        a_data_out_r <= w_data_in_r;
912
        a_da_out_r   <= w_da_in_r;
913
        a_av_out_r   <= w_av_in_r;
914
      elsif grant_n_a = '0' and grant_e_a = '0'
915
        and grant_s_a = '0' and grant_w_a = '0' then
916
        a_data_out_r <= (others => '0');
917
        a_da_out_r   <= '0';
918
        a_av_out_r   <= '0';
919
      end if;
920
 
921
    end if;
922
  end process regs_p;
923
 
924
 
925
end architecture rtl;

powered by: WebSVN 2.1.0

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