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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- Title      : Mesh configuration package
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : ase_noc_pkg.vhd
6
-- Author     : Lasse Lehtonen
7
-- Company    : 
8
-- Created    : 2011-01-18
9
-- Last update: 2011-11-08
10
-- Platform   : 
11
-- Standard   : VHDL'93
12
-------------------------------------------------------------------------------
13
-- Description: 
14
-------------------------------------------------------------------------------
15
-- Copyright (c) 2011 
16
-------------------------------------------------------------------------------
17
-- Revisions  :
18
-- Date        Version  Author  Description
19
-- 2011-01-18  1.0      lehton87        Created
20
-------------------------------------------------------------------------------
21
 
22
 
23
library ieee;
24
use ieee.std_logic_1164.all;
25
use ieee.numeric_std.all;
26
use work.log2_pkg.all;
27
 
28
package ase_noc_pkg is
29
 
30
  -- Commands
31
  constant mesh_cmd_idle_c  : std_logic_vector(1 downto 0) := "00";
32
  constant mesh_cmd_addr_c  : std_logic_vector(1 downto 0) := "01";
33
  constant mesh_cmd_data_c  : std_logic_vector(1 downto 0) := "10";
34
  constant mesh_cmd_empty_c : std_logic_vector(1 downto 0) := "11";
35
 
36
  -- Helper functions
37
  function ase_noc_address (
38
    constant own_id             : in natural;
39
    constant target_id          : in natural;
40
    constant mesh_cols_c        : in positive;
41
    constant mesh_rows_c        : in positive;
42
    constant mesh_agent_ports_c : in positive;
43
    constant mesh_data_width_c  : in positive)
44
    return std_logic_vector;
45
 
46
  function ase_noc_address_s (
47
    constant own_id             : in natural;
48
    signal   target_id          : in integer;
49
    constant mesh_cols_c        : in positive;
50
    constant mesh_rows_c        : in positive;
51
    constant mesh_agent_ports_c : in positive;
52
    constant mesh_data_width_c  : in positive)
53
    return std_logic_vector;
54
 
55
end package ase_noc_pkg;
56
 
57
 
58
 
59
 
60
package body ase_noc_pkg is
61
 
62
 
63
  function ase_noc_address (
64
    constant own_id             : in natural;
65
    constant target_id          : in natural;
66
    constant mesh_cols_c        : in positive;
67
    constant mesh_rows_c        : in positive;
68
    constant mesh_agent_ports_c : in positive;
69
    constant mesh_data_width_c  : in positive)
70
    return std_logic_vector is
71
    variable ret               : std_logic_vector(mesh_data_width_c-1 downto 0);
72
    variable src_row           : natural range 0 to mesh_rows_c-1;
73
    variable src_col           : natural range 0 to mesh_cols_c-1;
74
    variable dst_row           : natural range 0 to mesh_rows_c-1;
75
    variable dst_col           : natural range 0 to mesh_cols_c-1;
76
    variable col_dif           : integer range -mesh_cols_c/2-1 to mesh_cols_c/2+1;
77
    variable row_dif           : integer range -mesh_rows_c/2-1 to mesh_rows_c/2+1;
78
    variable dst_port          : natural range 4 to 4+mesh_agent_ports_c-1;
79
    constant mesh_port_width_c : natural := log2_ceil(4+mesh_agent_ports_c);
80
    constant mesh_ids_c        : natural :=
81
      mesh_rows_c*mesh_cols_c*mesh_agent_ports_c;
82
    constant mesh_col_add_c : natural := log2_ceil(mesh_cols_c-1);
83
    constant mesh_row_add_c : natural := log2_ceil(mesh_rows_c-1);
84
  begin  -- function mesh_address    
85
 
86
    ret      := (others => '0');
87
    src_row  := (own_id / (mesh_cols_c * mesh_agent_ports_c));
88
    src_col  := own_id - (src_row * (mesh_cols_c * mesh_agent_ports_c));
89
    dst_row  := (target_id / (mesh_cols_c * mesh_agent_ports_c));
90
    dst_col  := target_id - (dst_row * (mesh_cols_c * mesh_agent_ports_c));
91
    col_dif  := dst_col - src_col;
92
    row_dif  := dst_row - src_row;
93
    dst_port := target_id - (dst_row*mesh_cols_c+dst_col)*mesh_agent_ports_c+4;
94
 
95
    if src_row = dst_row then
96
 
97
      if src_col = dst_col then
98
 
99
        ret(mesh_port_width_c-1 downto 0) :=
100
          std_logic_vector(to_unsigned(dst_port, mesh_port_width_c));
101
 
102
      elsif src_col < dst_col then
103
 
104
        ret(mesh_port_width_c-1 downto 0) :=
105
          std_logic_vector(to_unsigned(1, mesh_port_width_c));
106
        ret(mesh_col_add_c+mesh_port_width_c-1 downto mesh_port_width_c) :=
107
          std_logic_vector(to_unsigned(2**mesh_col_add_c-col_dif,
108
                                       mesh_col_add_c));
109
        ret(mesh_port_width_c+mesh_col_add_c+mesh_port_width_c-1 downto
110
            mesh_col_add_c+mesh_port_width_c) :=
111
          std_logic_vector(to_unsigned(dst_port, mesh_port_width_c));
112
 
113
      else
114
 
115
        ret(mesh_port_width_c-1 downto 0) :=
116
          std_logic_vector(to_unsigned(3, mesh_port_width_c));
117
        ret(mesh_col_add_c+mesh_port_width_c-1 downto mesh_port_width_c) :=
118
          std_logic_vector(to_unsigned(2**mesh_col_add_c+col_dif,
119
                                       mesh_col_add_c));
120
        ret(mesh_port_width_c+mesh_col_add_c+mesh_port_width_c-1 downto
121
            mesh_col_add_c+mesh_port_width_c) :=
122
          std_logic_vector(to_unsigned(dst_port, mesh_port_width_c));
123
 
124
      end if;
125
 
126
    elsif src_row < dst_row then
127
 
128
      if src_col = dst_col then
129
 
130
        ret(mesh_port_width_c-1 downto 0) :=
131
          std_logic_vector(to_unsigned(2, mesh_port_width_c));
132
        ret(mesh_col_add_c+mesh_port_width_c-1 downto mesh_port_width_c) :=
133
          std_logic_vector(to_unsigned(2**mesh_row_add_c-row_dif,
134
                                       mesh_row_add_c));
135
        ret(mesh_port_width_c+mesh_row_add_c+mesh_port_width_c-1 downto
136
            mesh_row_add_c+mesh_port_width_c) :=
137
          std_logic_vector(to_unsigned(dst_port, mesh_port_width_c));
138
 
139
      elsif src_col < dst_col then
140
 
141
        ret(mesh_port_width_c-1 downto 0) :=
142
          std_logic_vector(to_unsigned(2, mesh_port_width_c));
143
        ret(mesh_row_add_c+mesh_port_width_c-1 downto mesh_port_width_c) :=
144
          std_logic_vector(to_unsigned(2**mesh_row_add_c-row_dif,
145
                                       mesh_row_add_c));
146
        ret(mesh_row_add_c+mesh_port_width_c*2-1 downto
147
            mesh_row_add_c+mesh_port_width_c) :=
148
          std_logic_vector(to_unsigned(1, mesh_port_width_c));
149
        ret(mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*2-1 downto
150
            mesh_port_width_c*2+mesh_row_add_c) :=
151
          std_logic_vector(to_unsigned(2**mesh_col_add_c-col_dif,
152
                                       mesh_col_add_c));
153
        ret(mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*3-1 downto
154
            mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*2) :=
155
          std_logic_vector(to_unsigned(dst_port, mesh_port_width_c));
156
 
157
      else
158
 
159
        ret(mesh_port_width_c-1 downto 0) :=
160
          std_logic_vector(to_unsigned(2, mesh_port_width_c));
161
        ret(mesh_row_add_c+mesh_port_width_c-1 downto mesh_port_width_c) :=
162
          std_logic_vector(to_unsigned(2**mesh_row_add_c-row_dif,
163
                                       mesh_row_add_c));
164
        ret(mesh_row_add_c+mesh_port_width_c*2-1 downto
165
            mesh_row_add_c+mesh_port_width_c) :=
166
          std_logic_vector(to_unsigned(3, mesh_port_width_c));
167
        ret(mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*2-1 downto
168
            mesh_port_width_c*2+mesh_row_add_c) :=
169
          std_logic_vector(to_unsigned(2**mesh_col_add_c+col_dif,
170
                                       mesh_col_add_c));
171
        ret(mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*3-1 downto
172
            mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*2) :=
173
          std_logic_vector(to_unsigned(dst_port, mesh_port_width_c));
174
 
175
      end if;
176
 
177
    else
178
 
179
      if src_col = dst_col then
180
 
181
        ret(mesh_port_width_c-1 downto 0) :=
182
          std_logic_vector(to_unsigned(0, mesh_port_width_c));
183
        ret(mesh_col_add_c+mesh_port_width_c-1 downto mesh_port_width_c) :=
184
          std_logic_vector(to_unsigned(2**mesh_row_add_c+row_dif,
185
                                       mesh_row_add_c));
186
        ret(mesh_port_width_c+mesh_row_add_c+mesh_port_width_c-1 downto
187
            mesh_row_add_c+mesh_port_width_c) :=
188
          std_logic_vector(to_unsigned(dst_port, mesh_port_width_c));
189
 
190
      elsif src_col < dst_col then
191
 
192
        ret(mesh_port_width_c-1 downto 0) :=
193
          std_logic_vector(to_unsigned(0, mesh_port_width_c));
194
        ret(mesh_row_add_c+mesh_port_width_c-1 downto mesh_port_width_c) :=
195
          std_logic_vector(to_unsigned(2**mesh_row_add_c+row_dif,
196
                                       mesh_row_add_c));
197
        ret(mesh_row_add_c+mesh_port_width_c*2-1 downto
198
            mesh_row_add_c+mesh_port_width_c) :=
199
          std_logic_vector(to_unsigned(1, mesh_port_width_c));
200
        ret(mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*2-1 downto
201
            mesh_port_width_c*2+mesh_row_add_c) :=
202
          std_logic_vector(to_unsigned(2**mesh_col_add_c-col_dif,
203
                                       mesh_col_add_c));
204
        ret(mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*3-1 downto
205
            mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*2) :=
206
          std_logic_vector(to_unsigned(dst_port, mesh_port_width_c));
207
 
208
      else
209
 
210
        ret(mesh_port_width_c-1 downto 0) :=
211
          std_logic_vector(to_unsigned(0, mesh_port_width_c));
212
        ret(mesh_row_add_c+mesh_port_width_c-1 downto mesh_port_width_c) :=
213
          std_logic_vector(to_unsigned(2**mesh_row_add_c+row_dif,
214
                                       mesh_row_add_c));
215
        ret(mesh_row_add_c+mesh_port_width_c*2-1 downto
216
            mesh_row_add_c+mesh_port_width_c) :=
217
          std_logic_vector(to_unsigned(3, mesh_port_width_c));
218
        ret(mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*2-1 downto
219
            mesh_port_width_c*2+mesh_row_add_c) :=
220
          std_logic_vector(to_unsigned(2**mesh_col_add_c+col_dif,
221
                                       mesh_col_add_c));
222
        ret(mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*3-1 downto
223
            mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*2) :=
224
          std_logic_vector(to_unsigned(dst_port, mesh_port_width_c));
225
 
226
      end if;
227
 
228
    end if;
229
 
230
    report "From " & integer'image(own_id) & " to " & integer'image(target_id)
231
      & " gives " & integer'image(to_integer(unsigned(ret))) severity note;
232
    report "col_add " & integer'image(mesh_col_add_c)
233
      & ", row_add " & integer'image(mesh_row_add_c)
234
      & ", port_w " & integer'image(mesh_port_width_c) severity note;
235
 
236
    return ret;
237
 
238
  end function ase_noc_address;
239
 
240
 
241
  function ase_noc_address_s (
242
    constant own_id             : in natural;
243
    signal   target_id          : in integer;
244
    constant mesh_cols_c        : in positive;
245
    constant mesh_rows_c        : in positive;
246
    constant mesh_agent_ports_c : in positive;
247
    constant mesh_data_width_c  : in positive)
248
    return std_logic_vector is
249
    variable ret               : std_logic_vector(mesh_data_width_c-1 downto 0);
250
    variable src_row           : natural range 0 to mesh_rows_c-1;
251
    variable src_col           : natural range 0 to mesh_cols_c-1;
252
    variable dst_row           : natural range 0 to mesh_rows_c-1;
253
    variable dst_col           : natural range 0 to mesh_cols_c-1;
254
    variable col_dif           : integer range -mesh_cols_c/2-1 to mesh_cols_c/2+1;
255
    variable row_dif           : integer range -mesh_rows_c/2-1 to mesh_rows_c/2+1;
256
    variable dst_port          : natural range 4 to 4+mesh_agent_ports_c-1;
257
    constant mesh_port_width_c : natural := log2_ceil(4+mesh_agent_ports_c);
258
    constant mesh_ids_c        : natural :=
259
      mesh_rows_c*mesh_cols_c*mesh_agent_ports_c;
260
    constant mesh_col_add_c : natural := log2_ceil(mesh_cols_c-1);
261
    constant mesh_row_add_c : natural := log2_ceil(mesh_rows_c-1);
262
  begin  -- function mesh_address
263
 
264
    ret      := (others => '0');
265
    src_row  := (own_id / (mesh_cols_c * mesh_agent_ports_c));
266
    src_col  := own_id - (src_row * (mesh_cols_c * mesh_agent_ports_c));
267
    dst_row  := (target_id / (mesh_cols_c * mesh_agent_ports_c));
268
    dst_col  := target_id - (dst_row * (mesh_cols_c * mesh_agent_ports_c));
269
    col_dif  := dst_col - src_col;
270
    row_dif  := dst_row - src_row;
271
    dst_port := target_id - (dst_row*mesh_cols_c+dst_col)*mesh_agent_ports_c+4;
272
 
273
    if src_row = dst_row then
274
 
275
      if src_col = dst_col then
276
 
277
        ret(mesh_port_width_c-1 downto 0) :=
278
          std_logic_vector(to_unsigned(dst_port, mesh_port_width_c));
279
 
280
      elsif src_col < dst_col then
281
 
282
        ret(mesh_port_width_c-1 downto 0) :=
283
          std_logic_vector(to_unsigned(1, mesh_port_width_c));
284
        ret(mesh_col_add_c+mesh_port_width_c-1 downto mesh_port_width_c) :=
285
          std_logic_vector(to_unsigned(2**mesh_col_add_c-col_dif,
286
                                       mesh_col_add_c));
287
        ret(mesh_port_width_c+mesh_col_add_c+mesh_port_width_c-1 downto
288
            mesh_col_add_c+mesh_port_width_c) :=
289
          std_logic_vector(to_unsigned(dst_port, mesh_port_width_c));
290
 
291
      else
292
 
293
        ret(mesh_port_width_c-1 downto 0) :=
294
          std_logic_vector(to_unsigned(3, mesh_port_width_c));
295
        ret(mesh_col_add_c+mesh_port_width_c-1 downto mesh_port_width_c) :=
296
          std_logic_vector(to_unsigned(2**mesh_col_add_c+col_dif,
297
                                       mesh_col_add_c));
298
        ret(mesh_port_width_c+mesh_col_add_c+mesh_port_width_c-1 downto
299
            mesh_col_add_c+mesh_port_width_c) :=
300
          std_logic_vector(to_unsigned(dst_port, mesh_port_width_c));
301
 
302
      end if;
303
 
304
    elsif src_row < dst_row then
305
 
306
      if src_col = dst_col then
307
 
308
        ret(mesh_port_width_c-1 downto 0) :=
309
          std_logic_vector(to_unsigned(2, mesh_port_width_c));
310
        ret(mesh_col_add_c+mesh_port_width_c-1 downto mesh_port_width_c) :=
311
          std_logic_vector(to_unsigned(2**mesh_row_add_c-row_dif,
312
                                       mesh_row_add_c));
313
        ret(mesh_port_width_c+mesh_row_add_c+mesh_port_width_c-1 downto
314
            mesh_row_add_c+mesh_port_width_c) :=
315
          std_logic_vector(to_unsigned(dst_port, mesh_port_width_c));
316
 
317
      elsif src_col < dst_col then
318
 
319
        ret(mesh_port_width_c-1 downto 0) :=
320
          std_logic_vector(to_unsigned(2, mesh_port_width_c));
321
        ret(mesh_row_add_c+mesh_port_width_c-1 downto mesh_port_width_c) :=
322
          std_logic_vector(to_unsigned(2**mesh_row_add_c-row_dif,
323
                                       mesh_row_add_c));
324
        ret(mesh_row_add_c+mesh_port_width_c*2-1 downto
325
            mesh_row_add_c+mesh_port_width_c) :=
326
          std_logic_vector(to_unsigned(1, mesh_port_width_c));
327
        ret(mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*2-1 downto
328
            mesh_port_width_c*2+mesh_row_add_c) :=
329
          std_logic_vector(to_unsigned(2**mesh_col_add_c-col_dif,
330
                                       mesh_col_add_c));
331
        ret(mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*3-1 downto
332
            mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*2) :=
333
          std_logic_vector(to_unsigned(dst_port, mesh_port_width_c));
334
 
335
      else
336
 
337
        ret(mesh_port_width_c-1 downto 0) :=
338
          std_logic_vector(to_unsigned(2, mesh_port_width_c));
339
        ret(mesh_row_add_c+mesh_port_width_c-1 downto mesh_port_width_c) :=
340
          std_logic_vector(to_unsigned(2**mesh_row_add_c-row_dif,
341
                                       mesh_row_add_c));
342
        ret(mesh_row_add_c+mesh_port_width_c*2-1 downto
343
            mesh_row_add_c+mesh_port_width_c) :=
344
          std_logic_vector(to_unsigned(3, mesh_port_width_c));
345
        ret(mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*2-1 downto
346
            mesh_port_width_c*2+mesh_row_add_c) :=
347
          std_logic_vector(to_unsigned(2**mesh_col_add_c+col_dif,
348
                                       mesh_col_add_c));
349
        ret(mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*3-1 downto
350
            mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*2) :=
351
          std_logic_vector(to_unsigned(dst_port, mesh_port_width_c));
352
 
353
      end if;
354
 
355
    else
356
 
357
      if src_col = dst_col then
358
 
359
        ret(mesh_port_width_c-1 downto 0) :=
360
          std_logic_vector(to_unsigned(0, mesh_port_width_c));
361
        ret(mesh_col_add_c+mesh_port_width_c-1 downto mesh_port_width_c) :=
362
          std_logic_vector(to_unsigned(2**mesh_row_add_c+row_dif,
363
                                       mesh_row_add_c));
364
        ret(mesh_port_width_c+mesh_row_add_c+mesh_port_width_c-1 downto
365
            mesh_row_add_c+mesh_port_width_c) :=
366
          std_logic_vector(to_unsigned(dst_port, mesh_port_width_c));
367
 
368
      elsif src_col < dst_col then
369
 
370
        ret(mesh_port_width_c-1 downto 0) :=
371
          std_logic_vector(to_unsigned(0, mesh_port_width_c));
372
        ret(mesh_row_add_c+mesh_port_width_c-1 downto mesh_port_width_c) :=
373
          std_logic_vector(to_unsigned(2**mesh_row_add_c+row_dif,
374
                                       mesh_row_add_c));
375
        ret(mesh_row_add_c+mesh_port_width_c*2-1 downto
376
            mesh_row_add_c+mesh_port_width_c) :=
377
          std_logic_vector(to_unsigned(1, mesh_port_width_c));
378
        ret(mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*2-1 downto
379
            mesh_port_width_c*2+mesh_row_add_c) :=
380
          std_logic_vector(to_unsigned(2**mesh_col_add_c-col_dif,
381
                                       mesh_col_add_c));
382
        ret(mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*3-1 downto
383
            mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*2) :=
384
          std_logic_vector(to_unsigned(dst_port, mesh_port_width_c));
385
 
386
      else
387
 
388
        ret(mesh_port_width_c-1 downto 0) :=
389
          std_logic_vector(to_unsigned(0, mesh_port_width_c));
390
        ret(mesh_row_add_c+mesh_port_width_c-1 downto mesh_port_width_c) :=
391
          std_logic_vector(to_unsigned(2**mesh_row_add_c+row_dif,
392
                                       mesh_row_add_c));
393
        ret(mesh_row_add_c+mesh_port_width_c*2-1 downto
394
            mesh_row_add_c+mesh_port_width_c) :=
395
          std_logic_vector(to_unsigned(3, mesh_port_width_c));
396
        ret(mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*2-1 downto
397
            mesh_port_width_c*2+mesh_row_add_c) :=
398
          std_logic_vector(to_unsigned(2**mesh_col_add_c+col_dif,
399
                                       mesh_col_add_c));
400
        ret(mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*3-1 downto
401
            mesh_col_add_c+mesh_row_add_c+mesh_port_width_c*2) :=
402
          std_logic_vector(to_unsigned(dst_port, mesh_port_width_c));
403
 
404
      end if;
405
 
406
    end if;
407
 
408
    return ret;
409
 
410
  end function ase_noc_address_s;
411
 
412
 
413
 
414
end package body ase_noc_pkg;

powered by: WebSVN 2.1.0

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