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/] [fh_mesh_2d/] [1.0/] [vhd/] [mesh_2d.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- File        : mesh_2d.vhdl
3
-- Description : Connect several mesh_routers together to form a network.       
4
--               Routes packets in 2D mesh network.
5
--               Network parameters are defined in a mesh_2d_pkg.
6
--               Edit only the beginnning of the package.
7
--
8
-- Author      : Erno Salminen
9
-- Date        : 17.06.2003
10
-- Modified    : 
11
-- 24.07.2003   ES full signals added
12
-- 11.08.2003   ES fifo added to router, it stores data coming from ip
13
--              ports definitions modified at the same time
14
-- 21.08.2006  AK multiclk
15
-------------------------------------------------------------------------------
16
-------------------------------------------------------------------------------
17
--  This file is part of Transaction Generator.
18
--
19
--  Transaction Generator is free software: you can redistribute it and/or modify
20
--  it under the terms of the Lesser GNU General Public License as published by
21
--  the Free Software Foundation, either version 3 of the License, or
22
--  (at your option) any later version.
23
--
24
--  Transaction Generator is distributed in the hope that it will be useful,
25
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
--  Lesser GNU General Public License for more details.
28
--
29
--  You should have received a copy of the Lesser GNU General Public License
30
--  along with Transaction Generator.  If not, see <http://www.gnu.org/licenses/>.
31
-------------------------------------------------------------------------------
32
 
33
library ieee;
34
use ieee.std_logic_1164.all;
35
 
36
entity mesh_2d is
37
  generic (
38
    stfwd_en_g      : integer := 1;     --24.08.2006 es
39
    data_width_g    : integer := 16;
40
    addr_width_g    : integer := 16;
41
    fifo_depth_g    : integer;          -- := 5;
42
    pkt_len_g       : integer;          -- := 5;
43
    len_flit_en_g   : integer := 1;     -- 2007/08/03 where to place a pkt_len
44
    oaddr_flit_en_g : integer := 1;     -- 2007/08/03 whether to send the orig address
45
 
46
    mesh_freq_g   :    integer := 1;    -- relative mesh freq
47
    ip_freq_g     :    integer := 1;    --relative IP freq
48
    rows_g        :    integer := 4;
49
    cols_g        :    integer := 4;
50
    debug_ena_g   :    integer := 0;    --if debug_out is enabled, now 1=re and empty in
51
    -- debug_out
52
    debug_width_g :    integer := 0     -- for ena=1, rows*(cols-1)*2*2*2 (links,re+empty, bidir)
53
    );
54
  port (
55
    rst_n         : in std_logic;
56
    clk_mesh      : in std_logic;
57
    clk_ip        : in std_logic;
58
    tx_data_in    : in std_logic_vector(rows_g*cols_g*data_width_g-1 downto 0);
59
    tx_we_in      : in std_logic_vector(rows_g*cols_g-1 downto 0);
60
    rx_re_in      : in std_logic_vector(rows_g*cols_g-1 downto 0);
61
 
62
    rx_data_out  : out std_logic_vector(rows_g*cols_g*data_width_g-1 downto 0);  --data_array_type;
63
    rx_empty_out : out std_logic_vector(rows_g*cols_g-1 downto 0);
64
    rx_full_out  : out std_logic_vector(rows_g*cols_g-1 downto 0);
65
    tx_full_out  : out std_logic_vector(rows_g*cols_g-1 downto 0);
66
    tx_empty_out : out std_logic_vector(rows_g*cols_g-1 downto 0);
67
 
68
    debug_out : out std_logic_vector(debug_width_g-1 downto 0)  -- for debug
69
    -- signals (or monitor)
70
    );
71
 
72
end mesh_2d;
73
 
74
 
75
architecture structural of mesh_2d is
76
 
77
  -- Structure and indexing of the mesh. Signals coming from the outside are
78
  -- reset to zero.
79
  -- Note:(r,c)= (row,col)
80
  --
81
  --                             
82
  --            S(0, 0)  N(0,0)                 . . .    S(0, col-1)  N(0,col-1)
83
  --             =0                                         =0 
84
  --                  |  ^                                         |  ^
85
  --                  |  |                                         |  |            
86
  --                  V  |                                         V  |
87
  --             
88
  --  E(0, 0)=0  -->  ROUTER  --> E(0, 1) -->    . . .             ROUTER   --> E(0, col)     
89
  --  W(0, 0)   <--   (0,0)   <-- W(0, 1) <--                      (0,c-1)  <-- W(0, col)=0
90
  --
91
  --                  |  ^                                         |  ^
92
  --                  |  |                                         |  |
93
  --                  V  |                                         V  |
94
  --
95
  --             S(1,0)  N(1, 0)                . . .     S(1,col-1) N(1, col-1)       
96
  --
97
  --                  |  ^                                         |  ^     
98
  --                  |  |                                         |  |
99
  --                  V  |                                         V  |
100
  --
101
  --  E(1, 0)=0 -->  ROUTER   --> E(1, 1)-->     . . .            ROUTER  --> E(1, col)     
102
  --  W(1, 0)   <--   (1,0)  <--  W(1, 1)<--                   (1,col-1)  <-- W(1, col)=0
103
  --
104
  --                                            . . .             
105
  --                  . . .                                         . . . 
106
  --                    
107
  --                                            . . .
108
  -- E(row-1,0)=0 -->  ROUTER                                     ROUTER  --> E(row-1, col)     
109
  -- W(row-1,0)   <-- (row-1)(0)                               (r-1,c-1)  <-- W(row-1, col)=0     
110
  --
111
  --                   |   ^                                       |   ^
112
  --                   |   |                                       |   | 
113
  --                   V   |                                       V   |
114
  --
115
  --           S(row, 0)   N(row,0)=0                  S(row, col-1)   N(row, col-1)=0
116
  --                                        
117
 
118
  -- Top half of the addr is the row addr (vertical),
119
  -- and the lower half is the colums (horizontal) address 
120
  --  8b / 2 = 4b => max   4 rows ja   4 colums
121
  -- 16b / 2 = 8b => max 256 rows ja 256 colums => enough for most cases
122
 
123
  -- Number of routers = (rows-1)*(columns-1) 
124
  -- Indexing order (row_num, col_num)
125
  -- Smallest index (0,0) is the NorthWest corner (top-left)
126
  -- Biggest index is SouthEast corner (bottom-right)  
127
  -- constant num_of_agents : integer := mesh_rows * mesh_columns;
128
  -- 11.08.03 es: this constant is already set in system_package
129
 
130
  -- Own array types are needed for interface ports
131
  -- This is propably the only way to do it ?  
132
  -- Subtype needed for two-dimensional arrays
133
  subtype data_type is std_logic_vector (data_width_g-1 downto 0);
134
 
135
  -- Types for vertical (N <-> S) signals between router rows
136
  -- Note! Num_of_rows is (num_of_routers in vertical direction) +1 !
137
  type mesh_row_data_type is array (0 to cols_g-1) of data_type;
138
  type mesh_vert_data_type is array (0 to rows_g) of mesh_row_data_type;
139
 
140
  type mesh_row_one_bit_type is array (0 to cols_g-1) of std_logic;
141
  type mesh_vert_one_bit_type is array (0 to rows_g) of mesh_row_one_bit_type;
142
 
143
  -- Types for horizontal (W <-> E) signals between router columss
144
  -- Note! Num_of_colums is (num_of_routers in horizontal direction) +1 !
145
  type mesh_col_data_type is array (0 to cols_g) of data_type;
146
  type mesh_horiz_data_type is array (0 to rows_g-1) of mesh_col_data_type;
147
 
148
  type mesh_col_one_bit_type is array (0 to cols_g) of std_logic;
149
  type mesh_horiz_one_bit_type is array (0 to rows_g-1) of mesh_col_one_bit_type;
150
 
151
  -- Types for ip signals
152
  type data_array_type is array (0 to rows_g-1) of mesh_row_data_type;
153
  type one_bit_array_type is array (0 to rows_g-1) of mesh_row_one_bit_type;
154
 
155
 
156
 
157
  -- Top row is the row zero
158
  -- Left column is the colum zero
159
  signal Mesh_data_S_N        : mesh_vert_data_type;  -- south -> north
160
  signal Mesh_read_enable_S_N : mesh_vert_one_bit_type;
161
  signal Mesh_empty_S_N       : mesh_vert_one_bit_type;
162
  signal Mesh_full_S_N        : mesh_vert_one_bit_type;
163
 
164
  signal Mesh_data_N_S        : mesh_vert_data_type;  -- north -> south
165
  signal Mesh_read_enable_N_S : mesh_vert_one_bit_type;
166
  signal Mesh_empty_N_S       : mesh_vert_one_bit_type;
167
  signal Mesh_full_N_S        : mesh_vert_one_bit_type;
168
 
169
  signal Mesh_data_E_W        : mesh_horiz_data_type;  -- east -> west
170
  signal Mesh_read_enable_E_W : mesh_horiz_one_bit_type;
171
  signal Mesh_empty_E_W       : mesh_horiz_one_bit_type;
172
  signal Mesh_full_E_W        : mesh_horiz_one_bit_type;
173
 
174
  signal Mesh_data_W_E        : mesh_horiz_data_type;  -- west -> east
175
  signal Mesh_read_enable_W_E : mesh_horiz_one_bit_type;
176
  signal Mesh_empty_W_E       : mesh_horiz_one_bit_type;
177
  signal Mesh_full_W_E        : mesh_horiz_one_bit_type;
178
 
179
 
180
 
181
 
182
  component mesh_router
183
    generic (
184
      stfwd_en_g      : integer := 1;   -- 24.08.2006 es
185
      data_width_g    : integer := 0;
186
      addr_width_g    : integer := 0;   -- at least 2 bits,A = row & col
187
      fifo_depth_g    : integer := 0;
188
      pkt_len_g       : integer := 5;
189
      len_flit_en_g   : integer := 1;   -- 2007/08/03 where to place a pkt_len
190
      oaddr_flit_en_g : integer := 1;    -- 2007/08/03 whether to send the orig address
191
 
192
      ip_freq_g   : integer := 1;       -- relative IP frequency
193
      mesh_freq_g : integer := 1;       --relative router frequency      
194
      col_addr_g  : integer := 0;
195
      row_addr_g  : integer := 0;
196
 
197
      num_cols_g : integer;
198
      num_rows_g : integer
199
      );
200
    port (
201
 
202
      clk_ip   : in std_logic;
203
      clk_mesh : in std_logic;
204
      rst_n    : in std_logic;
205
 
206
      data_n_in  : in std_logic_vector (data_width_g-1 downto 0);
207
      empty_n_in : in std_logic;
208
      full_n_in  : in std_logic;
209
      re_n_in    : in std_logic;
210
      data_s_in  : in std_logic_vector (data_width_g-1 downto 0);
211
      empty_s_in : in std_logic;
212
      full_s_in  : in std_logic;
213
      re_s_in    : in std_logic;
214
      data_w_in  : in std_logic_vector (data_width_g-1 downto 0);
215
      empty_w_in : in std_logic;
216
      full_w_in  : in std_logic;
217
      re_w_in    : in std_logic;
218
      data_e_in  : in std_logic_vector (data_width_g-1 downto 0);
219
      empty_e_in : in std_logic;
220
      full_e_in  : in std_logic;
221
      re_e_in    : in std_logic;
222
 
223
      data_ip_tx_in : in std_logic_vector (data_width_g-1 downto 0);
224
      we_ip_tx_in   : in std_logic;
225
      re_ip_rx_in   : in std_logic;
226
 
227
      data_n_out  : out std_logic_vector (data_width_g-1 downto 0);
228
      empty_n_out : out std_logic;
229
      full_n_out  : out std_logic;
230
      re_n_out    : out std_logic;
231
      data_s_out  : out std_logic_vector (data_width_g-1 downto 0);
232
      empty_s_out : out std_logic;
233
      full_s_out  : out std_logic;
234
      re_s_out    : out std_logic;
235
      data_w_out  : out std_logic_vector (data_width_g-1 downto 0);
236
      empty_w_out : out std_logic;
237
      full_w_out  : out std_logic;
238
      re_w_out    : out std_logic;
239
      data_e_out  : out std_logic_vector (data_width_g-1 downto 0);
240
      empty_e_out : out std_logic;
241
      full_e_out  : out std_logic;
242
      re_e_out    : out std_logic;
243
 
244
      -- Ip signals modified 11.08.03
245
      data_ip_rx_out  : out std_logic_vector (data_width_g-1 downto 0);
246
      empty_ip_rx_out : out std_logic;
247
      full_ip_rx_out  : out std_logic;
248
      empty_ip_tx_out : out std_logic;
249
      full_ip_tx_out  : out std_logic
250
      -- re_ip_out : out std_logic
251
      );
252
  end component;  --router
253
 
254
begin  -- structural
255
 
256
 
257
 
258
 
259
  Map_router_rows : for r in 0 to rows_g-1 generate
260
    Map_router_colums : for c in 0 to cols_g-1 generate
261
 
262
      router_r_c : mesh_router
263
        generic map(
264
          stfwd_en_g      => stfwd_en_g,      --24.08.2006 es
265
          data_width_g    => data_width_g,
266
          addr_width_g    => addr_width_g,
267
          fifo_depth_g    => fifo_depth_g,
268
          pkt_len_g       => pkt_len_g,
269
          len_flit_en_g   => len_flit_en_g,   -- 2007/08/03
270
          oaddr_flit_en_g => oaddr_flit_en_g,  -- 2007/08/03
271
 
272
          ip_freq_g    => ip_freq_g,
273
          mesh_freq_g  => mesh_freq_g,
274
          col_addr_g   => c,
275
          row_addr_g   => r,
276
          num_cols_g   => cols_g,
277
          num_rows_g   => rows_g
278
          )
279
 
280
        port map(
281
          rst_n      => rst_n,
282
          clk_mesh   => clk_mesh,
283
          clk_ip     => clk_ip,
284
 
285
          data_n_in  => Mesh_data_N_S  (r) (c),
286
          empty_n_in => Mesh_empty_N_S (r) (c),
287
          full_n_in  => Mesh_full_N_S  (r) (c),
288
          re_n_in    => Mesh_read_enable_N_S (r) (c),
289
          data_s_in  => Mesh_data_S_N  (r+1)(c),
290
          empty_s_in => Mesh_empty_S_N (r+1)(c),
291
          full_s_in  => Mesh_full_S_N  (r+1)(c),
292
          re_s_in    => Mesh_read_enable_S_N (r+1)(c),
293
          data_w_in  => Mesh_data_W_E  (r) (c),
294
          empty_w_in => Mesh_empty_W_E (r) (c),
295
          full_w_in  => Mesh_full_W_E  (r) (c),
296
          re_w_in    => Mesh_read_enable_W_E (r) (c),
297
          data_e_in  => Mesh_data_E_W  (r) (c+1),
298
          empty_e_in => Mesh_empty_E_W (r) (c+1),
299
          full_e_in  => Mesh_full_E_W  (r) (c+1),
300
          re_e_in    => Mesh_read_enable_E_W (r) (c+1),
301
 
302
          -- Modified 11.08.03
303
          data_ip_tx_in => tx_data_in ((r*cols_g+c+1)*data_width_g-1 downto (r*cols_g+c)*data_width_g),  --(r) (c),
304
          we_ip_tx_in   => tx_we_in (r*cols_g+c),  --(r) (c),
305
          re_ip_rx_in   => rx_re_in (r*cols_g+c),  --(r) (c),
306
 
307
 
308
          data_n_out  => Mesh_data_S_N        (r) (c),
309
          empty_n_out => Mesh_empty_S_N       (r) (c),
310
          full_n_out  => Mesh_full_S_N        (r) (c),
311
          re_n_out    => Mesh_read_enable_S_N (r) (c),
312
          data_s_out  => Mesh_data_N_S        (r+1)(c),
313
          empty_s_out => Mesh_empty_N_S       (r+1)(c),
314
          full_s_out  => Mesh_full_N_S        (r+1)(c),
315
          re_s_out    => Mesh_read_enable_N_S (r+1)(c),
316
          data_w_out  => Mesh_data_E_W        (r) (c),
317
          empty_w_out => Mesh_empty_E_W       (r) (c),
318
          full_w_out  => Mesh_full_E_W        (r) (c),
319
          re_w_out    => Mesh_read_enable_E_W (r) (c),
320
          data_e_out  => Mesh_data_W_E        (r) (c+1),
321
          empty_e_out => Mesh_empty_W_E       (r) (c+1),
322
          full_e_out  => Mesh_full_W_E        (r) (c+1),
323
          re_e_out    => Mesh_read_enable_W_E (r) (c+1),
324
 
325
          data_ip_rx_out  => rx_data_out ((r*cols_g+c+1)*data_width_g-1 downto (r*cols_g+c)*data_width_g),  --(r) (c),
326
          empty_ip_rx_out => rx_empty_out (r*cols_g+c),
327
          full_ip_rx_out  => rx_full_out  (r*cols_g+c),   --(r) (c),
328
          empty_ip_tx_out => tx_empty_out (r*cols_g+c),  --(r) (c),
329
          full_ip_tx_out  => tx_full_out  (r*cols_g+c)    --(r) (c)
330
          );
331
 
332
    end generate Map_router_colums;
333
  end generate Map_router_rows;
334
 
335
 
336
 
337
  -- Reset values coming from the outside of the mesh
338
  -- For test purposes, data lines can be set corresponding to signals' index
339
 
340
  -- 1) vertical 
341
  Reset_values_from_north_and_south : for c in 0 to cols_g-1 generate
342
    -- Row 0 toward south comes from the outside
343
    Mesh_data_N_S (0)(c)        <= (others => 'Z');
344
    --<= conv_std_logic_vector (0, data_width/2) & conv_std_logic_vector (c, data_width/2);--test indexing 
345
    Mesh_empty_N_S (0)(c)       <= '1';
346
    Mesh_full_N_S (0)(c)        <= '0';  --24.07
347
    Mesh_read_enable_N_S (0)(c) <= '0';
348
 
349
    -- Bottom row toward north comes from the outside
350
    Mesh_data_S_N (rows_g)(c)        <= (others => 'Z');
351
    --<= conv_std_logic_vector (rows_g, data_width/2) & conv_std_logic_vector (c, data_width/2);--test indexing
352
    Mesh_empty_S_N (rows_g)(c)       <= '1';
353
    Mesh_full_S_N (rows_g)(c)        <= '0';  --24.07
354
    Mesh_read_enable_S_N (rows_g)(c) <= '0';
355
  end generate Reset_values_from_north_and_south;
356
 
357
 
358
  --2) horizontal
359
  Reset_values_from_west_and_east : for r in 0 to rows_g-1 generate
360
    -- Leftmost (west) colums toward east comes from the outside
361
    Mesh_data_W_E (r)(0)        <= (others => 'Z');
362
    --<= conv_std_logic_vector (r, data_width/2) & conv_std_logic_vector (0, data_width/2);--test indexing
363
    Mesh_empty_W_E (r)(0)       <= '1';
364
    Mesh_full_W_E (r)(0)        <= '0';  --24.07
365
    Mesh_read_enable_W_E (r)(0) <= '0';
366
 
367
    -- Rightmost (east) colums toward west comes from the outside
368
    Mesh_data_E_W (r)(cols_g)        <= (others => 'Z');
369
    --<= conv_std_logic_vector (r, data_width/2) & conv_std_logic_vector (cols_g, data_width/2);--test indexing
370
    Mesh_empty_E_W (r)(cols_g)       <= '1';
371
    Mesh_full_E_W (r)(cols_g)        <= '0';  --24.07
372
    Mesh_read_enable_E_W (r)(cols_g) <= '0';
373
  end generate Reset_values_from_west_and_east;
374
 
375
-------------------------------------------------------------------------------
376
  -- DEBUG OUT ASSIGNEMNTS
377
  -- do these only here!
378
 
379
  debug_ena : if debug_ena_g = 1 generate
380
    -- Top row is the row zero
381
    -- Left column is the colum zero
382
--  signal Mesh_data_S_N        : mesh_vert_data_type;  -- south -> north
383
--  signal Mesh_read_enable_S_N : mesh_vert_one_bit_type;
384
--  signal Mesh_empty_S_N       : mesh_vert_one_bit_type;
385
--  signal Mesh_full_S_N        : mesh_vert_one_bit_type;
386
 
387
--  signal Mesh_data_N_S        : mesh_vert_data_type;  -- north -> south
388
--  signal Mesh_read_enable_N_S : mesh_vert_one_bit_type;
389
--  signal Mesh_empty_N_S       : mesh_vert_one_bit_type;
390
--  signal Mesh_full_N_S        : mesh_vert_one_bit_type;
391
 
392
--  signal Mesh_data_E_W        : mesh_horiz_data_type;  -- east -> west
393
--  signal Mesh_read_enable_E_W : mesh_horiz_one_bit_type;
394
--  signal Mesh_empty_E_W       : mesh_horiz_one_bit_type;
395
--  signal Mesh_full_E_W        : mesh_horiz_one_bit_type;
396
 
397
--  signal Mesh_data_W_E        : mesh_horiz_data_type;  -- west -> east
398
--  signal Mesh_read_enable_W_E : mesh_horiz_one_bit_type;
399
--  signal Mesh_empty_W_E       : mesh_horiz_one_bit_type;
400
--  signal Mesh_full_W_E        : mesh_horiz_one_bit_type;
401
 
402
    debug0_r: for r in 0 to rows_g-1 generate
403
      debug0_c: for c in 0 to cols_g-1 generate
404
        debug_out (r * cols_g + c) <= not (Mesh_empty_N_S (r)(c));
405
      end generate debug0_c;
406
    end generate debug0_r;
407
 
408
     debug1_r: for r in 0 to rows_g-1 generate
409
       debug1_c: for c in 0 to cols_g-1 generate
410
         debug_out (r * cols_g + c + 1*rows_g*cols_g) <= not (Mesh_empty_S_N (r)(c));
411
       end generate debug1_c;
412
     end generate debug1_r;
413
 
414
     debug2_r: for r in 0 to rows_g-1 generate
415
       debug2_c: for c in 0 to cols_g-1 generate
416
         debug_out (r * cols_g + c + 2*rows_g*cols_g) <= not (Mesh_empty_W_E (r)(c));
417
       end generate debug2_c;
418
     end generate debug2_r;
419
 
420
     debug3_r: for r in 0 to rows_g-1 generate
421
       debug3_c: for c in 0 to cols_g-1 generate
422
         debug_out (r * cols_g + c + 3*rows_g*cols_g) <= not (Mesh_empty_E_W (r)(c));
423
       end generate debug3_c;
424
     end generate debug3_r;
425
 
426
 
427
 
428
--    debug_out <= Mesh_empty_W_E & Mesh_empty_E_W & Mesh_empty_N_S & Mesh_empty_S_N;
429
-- & Mesh_read_enable_W_E & Mesh_read_enable_E_W & Mesh_read_enable_N_S & Mesh_read_enable_S_N;
430
 
431
  end generate debug_ena;
432
 
433
 
434
end structural;

powered by: WebSVN 2.1.0

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