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

Subversion Repositories dp_pkg

[/] [dp_pkg/] [trunk/] [dp_stream_pkg.vhd] - Blame information for rev 5

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
--------------------------------------------------------------------------------
2
--
3
-- Copyright (C) 2010
4
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
5
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
6
--
7
-- This program is free software: you can redistribute it and/or modify
8
-- it under the terms of the GNU General Public License as published by
9
-- the Free Software Foundation, either version 3 of the License, or
10
-- (at your option) any later version.
11
--
12
-- This program is distributed in the hope that it will be useful,
13
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
-- GNU General Public License for more details.
16
--
17
-- You should have received a copy of the GNU General Public License
18
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
--
20
--------------------------------------------------------------------------------
21
 
22
LIBRARY IEEE, common_pkg_lib;
23
USE IEEE.STD_LOGIC_1164.ALL;
24
USE IEEE.numeric_std.ALL;
25
USE common_pkg_lib.common_pkg.ALL;
26
 
27
PACKAGE dp_stream_pkg Is
28
 
29
  ------------------------------------------------------------------------------
30
  -- General DP stream record defintion
31
  ------------------------------------------------------------------------------
32
 
33
  -- Remarks:
34
  -- * Choose smallest maximum SOSI slv lengths that fit all use cases, because unconstrained record fields slv is not allowed
35
  -- * The large SOSI data field width of 256b has some disadvantages:
36
  --   . about 10% extra simulation time and PC memory usage compared to 72b (measured using tb_unb_tse_board)
37
  --   . a 256b number has 64 hex digits in the Wave window which is awkward because of the leading zeros when typically
38
  --     only 32b are used, fortunately integer representation still works OK (except 0 which is shown as blank).
39
  --   However the alternatives are not attractive, because they affect the implementation of the streaming
40
  --   components that use the SOSI record. Alternatives are e.g.:
41
  --   . define an extra long SOSI data field ldata[255:0] in addition to the existing data[71:0] field
42
  --   . use the array of SOSI records to contain wider data, all with the same SOSI control field values
43
  --   . define another similar SOSI record with data[255:0].
44
  --   Therefore define data width as 256b, because the disadvantages are acceptable and the benefit is great, because all
45
  --   streaming components can remain as they are.
46
  -- * Added sync and bsn to SOSI to have timestamp information with the data
47
  -- * Added re and im to SOSI to support complex data for DSP
48
  -- * The sosi fields can be labeled in diffent groups: ctrl, info and data as shown in comment at the t_dp_sosi definition.
49
  --   This grouping is useful for functions that operate on a t_dp_sosi signal.
50
  -- * The info fields are valid at the sop or at the eop, but typically they hold their last active value to avoid unnessary
51
  --   toggling and to ease viewing in the wave window.
52
  CONSTANT c_dp_stream_bsn_w      : NATURAL :=  64;  -- 64 is sufficient to count blocks of data for years
53
  CONSTANT c_dp_stream_data_w     : NATURAL := 768;  -- 72 is sufficient for max word 8 * 9-bit. 576 supports half rate DDR4 bus data width. The current 768 is enough for wide single clock SLVs (e.g. headers)
54
  CONSTANT c_dp_stream_dsp_data_w : NATURAL :=  64;  -- 64 is sufficient for DSP data, including complex power accumulates
55
  CONSTANT c_dp_stream_empty_w    : NATURAL :=  16;  --  8 is sufficient for max 256 symbols per data word, still use 16 bit to be able to count c_dp_stream_data_w in bits
56
  CONSTANT c_dp_stream_channel_w  : NATURAL :=  32;  -- 32 is sufficient for several levels of hierarchy in mapping types of streams on to channels 
57
  CONSTANT c_dp_stream_error_w    : NATURAL :=  32;  -- 32 is sufficient for several levels of hierarchy in mapping error numbers, e.g. 32 different one-hot encoded errors, bit [0] = 0 = OK
58
 
59
  CONSTANT c_dp_stream_ok         : NATURAL := 0;  -- SOSI err field OK value
60
  CONSTANT c_dp_stream_err        : NATURAL := 1;  -- SOSI err field error value /= OK
61
 
62
  CONSTANT c_dp_stream_rl         : NATURAL := 1;  -- SISO default data path stream ready latency RL = 1
63
 
64
  TYPE t_dp_siso IS RECORD  -- Source In or Sink Out
65
    ready    : STD_LOGIC;   -- fine cycle based flow control using ready latency RL >= 0
66
    xon      : STD_LOGIC;   -- coarse typically block based flow control using xon/xoff
67
  END RECORD;
68
 
69
  TYPE t_dp_sosi IS RECORD  -- Source Out or Sink In
70
    sync     : STD_LOGIC;                                           -- ctrl
71
    bsn      : STD_LOGIC_VECTOR(c_dp_stream_bsn_w-1 DOWNTO 0);      -- info at sop      (block sequence number)
72
    data     : STD_LOGIC_VECTOR(c_dp_stream_data_w-1 DOWNTO 0);     -- data
73
    re       : STD_LOGIC_VECTOR(c_dp_stream_dsp_data_w-1 DOWNTO 0); -- data
74
    im       : STD_LOGIC_VECTOR(c_dp_stream_dsp_data_w-1 DOWNTO 0); -- data
75
    valid    : STD_LOGIC;                                           -- ctrl
76
    sop      : STD_LOGIC;                                           -- ctrl
77
    eop      : STD_LOGIC;                                           -- ctrl
78
    empty    : STD_LOGIC_VECTOR(c_dp_stream_empty_w-1 DOWNTO 0);    -- info at eop
79
    channel  : STD_LOGIC_VECTOR(c_dp_stream_channel_w-1 DOWNTO 0);  -- info at sop
80
    err      : STD_LOGIC_VECTOR(c_dp_stream_error_w-1 DOWNTO 0);    -- info at eop (name field 'err' to avoid the 'error' keyword)
81
  END RECORD;
82
 
83
  -- Initialise signal declarations with c_dp_stream_rst/rdy to ease the interpretation of slv fields with unused bits
84
  CONSTANT c_dp_siso_rst   : t_dp_siso := ('0', '0');
85
  CONSTANT c_dp_siso_x     : t_dp_siso := ('X', 'X');
86
  CONSTANT c_dp_siso_hold  : t_dp_siso := ('0', '1');
87
  CONSTANT c_dp_siso_rdy   : t_dp_siso := ('1', '1');
88
  CONSTANT c_dp_siso_flush : t_dp_siso := ('1', '0');
89
  CONSTANT c_dp_sosi_rst   : t_dp_sosi := ('0', (OTHERS=>'0'), (OTHERS=>'0'), (OTHERS=>'0'), (OTHERS=>'0'), '0', '0', '0', (OTHERS=>'0'), (OTHERS=>'0'), (OTHERS=>'0'));
90
  CONSTANT c_dp_sosi_x     : t_dp_sosi := ('X', (OTHERS=>'X'), (OTHERS=>'X'), (OTHERS=>'X'), (OTHERS=>'X'), 'X', 'X', 'X', (OTHERS=>'X'), (OTHERS=>'X'), (OTHERS=>'X'));
91
 
92
  -- Use integers instead of slv for monitoring purposes (integer range limited to 31 bit plus sign bit)
93
  TYPE t_dp_sosi_integer IS RECORD
94
    sync     : STD_LOGIC;
95
    bsn      : NATURAL;
96
    data     : INTEGER;
97
    re       : INTEGER;
98
    im       : INTEGER;
99
    valid    : STD_LOGIC;
100
    sop      : STD_LOGIC;
101
    eop      : STD_LOGIC;
102
    empty    : NATURAL;
103
    channel  : NATURAL;
104
    err      : NATURAL;
105
  END RECORD;
106
 
107
  -- Use unsigned instead of slv for monitoring purposes beyond the integer range of t_dp_sosi_integer
108
  TYPE t_dp_sosi_unsigned IS RECORD
109
    sync     : STD_LOGIC;
110
    bsn      : UNSIGNED(c_dp_stream_bsn_w-1 DOWNTO 0);
111
    data     : UNSIGNED(c_dp_stream_data_w-1 DOWNTO 0);
112
    re       : UNSIGNED(c_dp_stream_dsp_data_w-1 DOWNTO 0);
113
    im       : UNSIGNED(c_dp_stream_dsp_data_w-1 DOWNTO 0);
114
    valid    : STD_LOGIC;
115
    sop      : STD_LOGIC;
116
    eop      : STD_LOGIC;
117
    empty    : UNSIGNED(c_dp_stream_empty_w-1 DOWNTO 0);
118
    channel  : UNSIGNED(c_dp_stream_channel_w-1 DOWNTO 0);
119
    err      : UNSIGNED(c_dp_stream_error_w-1 DOWNTO 0);
120
  END RECORD;
121
 
122
  CONSTANT c_dp_sosi_unsigned_rst  : t_dp_sosi_unsigned := ('0', (OTHERS=>'0'), (OTHERS=>'0'), (OTHERS=>'0'), (OTHERS=>'0'), '0', '0', '0', (OTHERS=>'0'), (OTHERS=>'0'), (OTHERS=>'0'));
123
  CONSTANT c_dp_sosi_unsigned_ones : t_dp_sosi_unsigned := ('1',
124
                                                            TO_UNSIGNED(1, c_dp_stream_bsn_w),
125
                                                            TO_UNSIGNED(1, c_dp_stream_data_w),
126
                                                            TO_UNSIGNED(1, c_dp_stream_dsp_data_w),
127
                                                            TO_UNSIGNED(1, c_dp_stream_dsp_data_w),
128
                                                            '1', '1', '1',
129
                                                            TO_UNSIGNED(1, c_dp_stream_empty_w),
130
                                                            TO_UNSIGNED(1, c_dp_stream_channel_w),
131
                                                            TO_UNSIGNED(1, c_dp_stream_error_w));
132
 
133
  -- Use boolean to define whether a t_dp_siso, t_dp_sosi field is used ('1') or not ('0')
134
  TYPE t_dp_siso_sl IS RECORD
135
    ready    : STD_LOGIC;
136
    xon      : STD_LOGIC;
137
  END RECORD;
138
 
139
  TYPE t_dp_sosi_sl IS RECORD
140
    sync     : STD_LOGIC;
141
    bsn      : STD_LOGIC;
142
    data     : STD_LOGIC;
143
    re       : STD_LOGIC;
144
    im       : STD_LOGIC;
145
    valid    : STD_LOGIC;
146
    sop      : STD_LOGIC;
147
    eop      : STD_LOGIC;
148
    empty    : STD_LOGIC;
149
    channel  : STD_LOGIC;
150
    err      : STD_LOGIC;
151
  END RECORD;
152
 
153
  CONSTANT c_dp_siso_sl_rst  : t_dp_siso_sl := ('0', '0');
154
  CONSTANT c_dp_siso_sl_ones : t_dp_siso_sl := ('1', '1');
155
  CONSTANT c_dp_sosi_sl_rst  : t_dp_sosi_sl := ('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0');
156
  CONSTANT c_dp_sosi_sl_ones : t_dp_sosi_sl := ('1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1');
157
 
158
  -- Multi port or multi register array for DP stream records
159
  TYPE t_dp_siso_arr IS ARRAY (INTEGER RANGE <>) OF t_dp_siso;
160
  TYPE t_dp_sosi_arr IS ARRAY (INTEGER RANGE <>) OF t_dp_sosi;
161
 
162
  TYPE t_dp_sosi_integer_arr  IS ARRAY (INTEGER RANGE <>) OF t_dp_sosi_integer;
163
  TYPE t_dp_sosi_unsigned_arr IS ARRAY (INTEGER RANGE <>) OF t_dp_sosi_unsigned;
164
 
165
  TYPE t_dp_siso_sl_arr IS ARRAY (INTEGER RANGE <>) OF t_dp_siso_sl;
166
  TYPE t_dp_sosi_sl_arr IS ARRAY (INTEGER RANGE <>) OF t_dp_sosi_sl;
167
 
168
  -- Multi port or multi register slv arrays for DP stream records fields
169
  TYPE t_dp_bsn_slv_arr      IS ARRAY (INTEGER RANGE <>) OF STD_LOGIC_VECTOR(c_dp_stream_bsn_w-1 DOWNTO 0);
170
  TYPE t_dp_data_slv_arr     IS ARRAY (INTEGER RANGE <>) OF STD_LOGIC_VECTOR(c_dp_stream_data_w-1 DOWNTO 0);
171
  TYPE t_dp_dsp_data_slv_arr IS ARRAY (INTEGER RANGE <>) OF STD_LOGIC_VECTOR(c_dp_stream_dsp_data_w-1 DOWNTO 0);
172
  TYPE t_dp_empty_slv_arr    IS ARRAY (INTEGER RANGE <>) OF STD_LOGIC_VECTOR(c_dp_stream_empty_w-1 DOWNTO 0);
173
  TYPE t_dp_channel_slv_arr  IS ARRAY (INTEGER RANGE <>) OF STD_LOGIC_VECTOR(c_dp_stream_channel_w-1 DOWNTO 0);
174
  TYPE t_dp_error_slv_arr    IS ARRAY (INTEGER RANGE <>) OF STD_LOGIC_VECTOR(c_dp_stream_error_w-1 DOWNTO 0);
175
 
176
  -- Multi-dimemsion array types with fixed LS-dimension
177
  TYPE t_dp_siso_2arr_1 IS ARRAY (INTEGER RANGE <>) OF t_dp_siso_arr(0 DOWNTO 0);
178
  TYPE t_dp_sosi_2arr_1 IS ARRAY (INTEGER RANGE <>) OF t_dp_sosi_arr(0 DOWNTO 0);
179
 
180
  -- . 2 dimensional array with 2 fixed LS sosi/siso interfaces (dp_split, dp_concat)
181
  TYPE t_dp_siso_2arr_2 IS ARRAY (INTEGER RANGE <>) OF t_dp_siso_arr(1 DOWNTO 0);
182
  TYPE t_dp_sosi_2arr_2 IS ARRAY (INTEGER RANGE <>) OF t_dp_sosi_arr(1 DOWNTO 0);
183
 
184
  TYPE t_dp_siso_2arr_3 IS ARRAY (INTEGER RANGE <>) OF t_dp_siso_arr(2 DOWNTO 0);
185
  TYPE t_dp_sosi_2arr_3 IS ARRAY (INTEGER RANGE <>) OF t_dp_sosi_arr(2 DOWNTO 0);
186
 
187
  TYPE t_dp_siso_2arr_4 IS ARRAY (INTEGER RANGE <>) OF t_dp_siso_arr(3 DOWNTO 0);
188
  TYPE t_dp_sosi_2arr_4 IS ARRAY (INTEGER RANGE <>) OF t_dp_sosi_arr(3 DOWNTO 0);
189
 
190
  TYPE t_dp_siso_2arr_8 IS ARRAY (INTEGER RANGE <>) OF t_dp_siso_arr(7 DOWNTO 0);
191
  TYPE t_dp_sosi_2arr_8 IS ARRAY (INTEGER RANGE <>) OF t_dp_sosi_arr(7 DOWNTO 0);
192
 
193
  TYPE t_dp_siso_2arr_9 IS ARRAY (INTEGER RANGE <>) OF t_dp_siso_arr(8 DOWNTO 0);
194
  TYPE t_dp_sosi_2arr_9 IS ARRAY (INTEGER RANGE <>) OF t_dp_sosi_arr(8 DOWNTO 0);
195
 
196
  TYPE t_dp_siso_2arr_12 IS ARRAY (INTEGER RANGE <>) OF t_dp_siso_arr(11 DOWNTO 0);
197
  TYPE t_dp_sosi_2arr_12 IS ARRAY (INTEGER RANGE <>) OF t_dp_sosi_arr(11 DOWNTO 0);
198
 
199
  TYPE t_dp_siso_3arr_4_2 IS ARRAY (INTEGER RANGE <>) OF t_dp_siso_2arr_2(3 DOWNTO 0);
200
  TYPE t_dp_sosi_3arr_4_2 IS ARRAY (INTEGER RANGE <>) OF t_dp_sosi_2arr_2(3 DOWNTO 0);
201
 
202
  -- 2-dimensional streaming array type:
203
  -- Note:
204
  --   This t_*_mat is less useful then a t_*_2arr array of arrays, because assignments can only be done per element (i.e. not per row). However for t_*_2arr
205
  --   the arrays dimension must be fixed, so these t_*_2arr types are application dependent and need to be defined where used. 
206
  TYPE t_dp_siso_mat IS ARRAY (INTEGER RANGE <>, INTEGER RANGE <>) OF t_dp_siso;
207
  TYPE t_dp_sosi_mat IS ARRAY (INTEGER RANGE <>, INTEGER RANGE <>) OF t_dp_sosi;
208
 
209
  -- Check sosi.valid against siso.ready
210
  PROCEDURE proc_dp_siso_alert(CONSTANT c_ready_latency : IN    NATURAL;
211
                               SIGNAL   clk             : IN    STD_LOGIC;
212
                               SIGNAL   sosi            : IN    t_dp_sosi;
213
                               SIGNAL   siso            : IN    t_dp_siso;
214
                               SIGNAL   ready_reg       : INOUT STD_LOGIC_VECTOR);
215
 
216
  -- Default RL=1
217
  PROCEDURE proc_dp_siso_alert(SIGNAL   clk             : IN    STD_LOGIC;
218
                               SIGNAL   sosi            : IN    t_dp_sosi;
219
                               SIGNAL   siso            : IN    t_dp_siso;
220
                               SIGNAL   ready_reg       : INOUT STD_LOGIC_VECTOR);
221
 
222
  -- SOSI/SISO array version
223
  PROCEDURE proc_dp_siso_alert(CONSTANT c_ready_latency : IN    NATURAL;
224
                               SIGNAL   clk             : IN    STD_LOGIC;
225
                               SIGNAL   sosi_arr        : IN    t_dp_sosi_arr;
226
                               SIGNAL   siso_arr        : IN    t_dp_siso_arr;
227
                               SIGNAL   ready_reg       : INOUT STD_LOGIC_VECTOR);
228
 
229
  -- SOSI/SISO array version with RL=1
230
  PROCEDURE proc_dp_siso_alert(SIGNAL   clk             : IN    STD_LOGIC;
231
                               SIGNAL   sosi_arr        : IN    t_dp_sosi_arr;
232
                               SIGNAL   siso_arr        : IN    t_dp_siso_arr;
233
                               SIGNAL   ready_reg       : INOUT STD_LOGIC_VECTOR);
234
 
235
  -- Resize functions to fit an integer or an SLV in the corresponding t_dp_sosi field width
236
  -- . Use these functions to assign sosi data TO a record field
237
  -- . Use the range selection [n-1 DOWNTO 0] to assign sosi data FROM a record field to an slv
238
  -- . The unused sosi data field bits could remain undefined 'X', because the unused bits in the fields are not used at all. 
239
  --   Typically the sosi data are treated as unsigned in the record field, so extended with '0'. However for interpretating
240
  --   signed data in the simulation wave window it is easier to use sign extension in the record field. Therefore TO_DP_SDATA
241
  --   and RESIZE_DP_SDATA are defined as well.
242
  FUNCTION TO_DP_BSN(     n : NATURAL) RETURN STD_LOGIC_VECTOR;
243
  FUNCTION TO_DP_DATA(    n : INTEGER) RETURN STD_LOGIC_VECTOR;  -- use integer to support 32 bit range, so -1 = 0xFFFFFFFF = +2**32-1
244
  FUNCTION TO_DP_SDATA(   n : INTEGER) RETURN STD_LOGIC_VECTOR;  -- use integer to support 32 bit range and signed
245
  FUNCTION TO_DP_UDATA(   n : INTEGER) RETURN STD_LOGIC_VECTOR;  -- alias of TO_DP_DATA()
246
  FUNCTION TO_DP_DSP_DATA(n : INTEGER) RETURN STD_LOGIC_VECTOR;  -- for re and im fields, signed data
247
  FUNCTION TO_DP_DSP_UDATA(n: INTEGER) RETURN STD_LOGIC_VECTOR;  -- for re and im fields, unsigned data (useful to carry indices)
248
  FUNCTION TO_DP_EMPTY(   n : NATURAL) RETURN STD_LOGIC_VECTOR;
249
  FUNCTION TO_DP_CHANNEL( n : NATURAL) RETURN STD_LOGIC_VECTOR;
250
  FUNCTION TO_DP_ERROR(   n : NATURAL) RETURN STD_LOGIC_VECTOR;
251
  FUNCTION RESIZE_DP_BSN(     vec : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR;
252
  FUNCTION RESIZE_DP_DATA(    vec : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR;  -- set unused MSBits to '0'
253
  FUNCTION RESIZE_DP_SDATA(   vec : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR;  -- sign extend unused MSBits
254
  FUNCTION RESIZE_DP_XDATA(   vec : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR;  -- set unused MSBits to 'X'
255
  FUNCTION RESIZE_DP_DSP_DATA(vec : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR;  -- sign extend unused MSBits of re and im fields
256
  FUNCTION RESIZE_DP_EMPTY(   vec : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR;
257
  FUNCTION RESIZE_DP_CHANNEL( vec : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR;
258
  FUNCTION RESIZE_DP_ERROR(   vec : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR;
259
 
260
  FUNCTION INCR_DP_DATA(    vec : STD_LOGIC_VECTOR; dec : INTEGER; w : NATURAL) RETURN STD_LOGIC_VECTOR;  -- unsigned vec(w-1:0) + dec
261
  FUNCTION INCR_DP_SDATA(   vec : STD_LOGIC_VECTOR; dec : INTEGER; w : NATURAL) RETURN STD_LOGIC_VECTOR;  --   signed vec(w-1:0) + dec
262
  FUNCTION INCR_DP_DSP_DATA(vec : STD_LOGIC_VECTOR; dec : INTEGER; w : NATURAL) RETURN STD_LOGIC_VECTOR;  --   signed vec(w-1:0) + dec
263
 
264
  FUNCTION REPLICATE_DP_DATA(  seq  : STD_LOGIC_VECTOR                 ) RETURN STD_LOGIC_VECTOR;  -- replicate seq as often as fits in c_dp_stream_data_w
265
  FUNCTION UNREPLICATE_DP_DATA(data : STD_LOGIC_VECTOR; seq_w : NATURAL) RETURN STD_LOGIC_VECTOR;  -- unreplicate data to width seq_w, return low seq_w bits and set mismatch MSbits bits to '1'
266
 
267
  FUNCTION TO_DP_SOSI_UNSIGNED(sync, valid, sop, eop : STD_LOGIC; bsn, data, re, im, empty, channel, err : UNSIGNED) RETURN t_dp_sosi_unsigned;
268
 
269
  -- Keep part of head data and combine part of tail data, use the other sosi from head_sosi
270
  FUNCTION func_dp_data_shift_first(head_sosi, tail_sosi : t_dp_sosi; symbol_w, nof_symbols_per_data, nof_symbols_from_tail              : NATURAL) RETURN t_dp_sosi;
271
  -- Shift and combine part of previous data and this data, use the other sosi from prev_sosi
272
  FUNCTION func_dp_data_shift(      prev_sosi, this_sosi : t_dp_sosi; symbol_w, nof_symbols_per_data, nof_symbols_from_this              : NATURAL) RETURN t_dp_sosi;
273
  -- Shift part of tail data and account for input empty
274
  FUNCTION func_dp_data_shift_last(            tail_sosi : t_dp_sosi; symbol_w, nof_symbols_per_data, nof_symbols_from_tail, input_empty : NATURAL) RETURN t_dp_sosi;
275
 
276
  -- Determine resulting empty if two streams are concatenated or split
277
  FUNCTION func_dp_empty_concat(head_empty, tail_empty : STD_LOGIC_VECTOR; nof_symbols_per_data : NATURAL) RETURN STD_LOGIC_VECTOR;
278
  FUNCTION func_dp_empty_split(input_empty, head_empty : STD_LOGIC_VECTOR; nof_symbols_per_data : NATURAL) RETURN STD_LOGIC_VECTOR;
279
 
280
  -- Multiplex the t_dp_sosi_arr based on the valid, assuming that at most one input is active valid.
281
  FUNCTION func_dp_sosi_arr_mux(dp : t_dp_sosi_arr) RETURN t_dp_sosi;
282
 
283
  -- Determine the combined logical value of corresponding STD_LOGIC fields in t_dp_*_arr (for all elements or only for the mask[]='1' elements)
284
  FUNCTION func_dp_stream_arr_and(dp : t_dp_siso_arr; mask : STD_LOGIC_VECTOR; str : STRING) RETURN STD_LOGIC;
285
  FUNCTION func_dp_stream_arr_and(dp : t_dp_sosi_arr; mask : STD_LOGIC_VECTOR; str : STRING) RETURN STD_LOGIC;
286
  FUNCTION func_dp_stream_arr_and(dp : t_dp_siso_arr;                          str : STRING) RETURN STD_LOGIC;
287
  FUNCTION func_dp_stream_arr_and(dp : t_dp_sosi_arr;                          str : STRING) RETURN STD_LOGIC;
288
  FUNCTION func_dp_stream_arr_or( dp : t_dp_siso_arr; mask : STD_LOGIC_VECTOR; str : STRING) RETURN STD_LOGIC;
289
  FUNCTION func_dp_stream_arr_or( dp : t_dp_sosi_arr; mask : STD_LOGIC_VECTOR; str : STRING) RETURN STD_LOGIC;
290
  FUNCTION func_dp_stream_arr_or( dp : t_dp_siso_arr;                          str : STRING) RETURN STD_LOGIC;
291
  FUNCTION func_dp_stream_arr_or( dp : t_dp_sosi_arr;                          str : STRING) RETURN STD_LOGIC;
292
 
293
  -- Functions to set or get a STD_LOGIC field as a STD_LOGIC_VECTOR to or from an siso or an sosi array
294
  FUNCTION func_dp_stream_arr_set(dp : t_dp_siso_arr; slv : STD_LOGIC_VECTOR; str : STRING) RETURN t_dp_siso_arr;
295
  FUNCTION func_dp_stream_arr_set(dp : t_dp_sosi_arr; slv : STD_LOGIC_VECTOR; str : STRING) RETURN t_dp_sosi_arr;
296
  FUNCTION func_dp_stream_arr_set(dp : t_dp_siso_arr; sl  : STD_LOGIC;        str : STRING) RETURN t_dp_siso_arr;
297
  FUNCTION func_dp_stream_arr_set(dp : t_dp_sosi_arr; sl  : STD_LOGIC;        str : STRING) RETURN t_dp_sosi_arr;
298
  FUNCTION func_dp_stream_arr_get(dp : t_dp_siso_arr;                         str : STRING) RETURN STD_LOGIC_VECTOR;
299
  FUNCTION func_dp_stream_arr_get(dp : t_dp_sosi_arr;                         str : STRING) RETURN STD_LOGIC_VECTOR;
300
 
301
  -- Functions to select elements from two siso or two sosi arrays (sel[] = '1' selects a, sel[] = '0' selects b)
302
  FUNCTION func_dp_stream_arr_select(sel : STD_LOGIC_VECTOR; a,                 b : t_dp_siso)     RETURN t_dp_siso_arr;
303
  FUNCTION func_dp_stream_arr_select(sel : STD_LOGIC_VECTOR; a,                 b : t_dp_sosi)     RETURN t_dp_sosi_arr;
304
  FUNCTION func_dp_stream_arr_select(sel : STD_LOGIC_VECTOR; a : t_dp_siso_arr; b : t_dp_siso)     RETURN t_dp_siso_arr;
305
  FUNCTION func_dp_stream_arr_select(sel : STD_LOGIC_VECTOR; a : t_dp_sosi_arr; b : t_dp_sosi)     RETURN t_dp_sosi_arr;
306
  FUNCTION func_dp_stream_arr_select(sel : STD_LOGIC_VECTOR; a : t_dp_siso;     b : t_dp_siso_arr) RETURN t_dp_siso_arr;
307
  FUNCTION func_dp_stream_arr_select(sel : STD_LOGIC_VECTOR; a : t_dp_sosi;     b : t_dp_sosi_arr) RETURN t_dp_sosi_arr;
308
  FUNCTION func_dp_stream_arr_select(sel : STD_LOGIC_VECTOR; a,                 b : t_dp_siso_arr) RETURN t_dp_siso_arr;
309
  FUNCTION func_dp_stream_arr_select(sel : STD_LOGIC_VECTOR; a,                 b : t_dp_sosi_arr) RETURN t_dp_sosi_arr;
310
 
311
  -- Fix reversed buses due to connecting TO to DOWNTO range arrays. 
312
  FUNCTION func_dp_stream_arr_reverse_range(in_arr : t_dp_sosi_arr) RETURN t_dp_sosi_arr;
313
  FUNCTION func_dp_stream_arr_reverse_range(in_arr : t_dp_siso_arr) RETURN t_dp_siso_arr;
314
 
315
  -- Functions to combinatorially hold the data fields and to set or reset the control fields in an sosi array
316
  FUNCTION func_dp_stream_arr_combine_data_info_ctrl(dp : t_dp_sosi_arr; info, ctrl : t_dp_sosi) RETURN t_dp_sosi_arr;
317
  FUNCTION func_dp_stream_arr_set_info(              dp : t_dp_sosi_arr; info       : t_dp_sosi) RETURN t_dp_sosi_arr;
318
  FUNCTION func_dp_stream_arr_set_control(           dp : t_dp_sosi_arr;       ctrl : t_dp_sosi) RETURN t_dp_sosi_arr;
319
  FUNCTION func_dp_stream_arr_reset_control(         dp : t_dp_sosi_arr                        ) RETURN t_dp_sosi_arr;
320
 
321
  -- Reset sosi ctrl and preserve the sosi data (to avoid unnecessary data toggling and to ease data view in Wave window)
322
  FUNCTION func_dp_stream_reset_control(dp : t_dp_sosi) RETURN t_dp_sosi;
323
 
324
  -- Functions to combinatorially determine the maximum and minimum sosi bsn[w-1:0] value in the sosi array (for all elements or only for the mask[]='1' elements)
325
  FUNCTION func_dp_stream_arr_bsn_max(dp : t_dp_sosi_arr; mask : STD_LOGIC_VECTOR; w : NATURAL) RETURN STD_LOGIC_VECTOR;
326
  FUNCTION func_dp_stream_arr_bsn_max(dp : t_dp_sosi_arr;                          w : NATURAL) RETURN STD_LOGIC_VECTOR;
327
  FUNCTION func_dp_stream_arr_bsn_min(dp : t_dp_sosi_arr; mask : STD_LOGIC_VECTOR; w : NATURAL) RETURN STD_LOGIC_VECTOR;
328
  FUNCTION func_dp_stream_arr_bsn_min(dp : t_dp_sosi_arr;                          w : NATURAL) RETURN STD_LOGIC_VECTOR;
329
 
330
  -- Function to copy the BSN of one valid stream to all output streams. 
331
  FUNCTION func_dp_stream_arr_copy_valid_bsn(dp : t_dp_sosi_arr; mask : STD_LOGIC_VECTOR) RETURN t_dp_sosi_arr;
332
 
333
  -- Functions to combinatorially handle channels
334
  -- Note that the *_select and *_remove function are equivalent to dp_demux with g_combined=TRUE
335
  FUNCTION func_dp_stream_channel_set   (st_sosi : t_dp_sosi; ch : NATURAL) RETURN t_dp_sosi;  -- select channel nr, add the channel field
336
  FUNCTION func_dp_stream_channel_select(st_sosi : t_dp_sosi; ch : NATURAL) RETURN t_dp_sosi;  -- select channel nr, skip the channel field
337
  FUNCTION func_dp_stream_channel_remove(st_sosi : t_dp_sosi; ch : NATURAL) RETURN t_dp_sosi;  -- skip channel nr
338
 
339
  -- Functions to combinatorially handle the error field
340
  FUNCTION func_dp_stream_error_set(st_sosi : t_dp_sosi; n : NATURAL) RETURN t_dp_sosi;  -- force err = 0, is OK
341
 
342
  -- Functions to combinatorially handle the BSN field
343
  FUNCTION func_dp_stream_bsn_set(st_sosi : t_dp_sosi; bsn : STD_LOGIC_VECTOR) RETURN t_dp_sosi;
344
 
345
  -- Functions to combine sosi fields
346
  FUNCTION func_dp_stream_combine_info_and_data(info, data : t_dp_sosi) RETURN t_dp_sosi;
347
 
348
  -- Functions to convert sosi fields
349
  FUNCTION func_dp_stream_slv_to_integer(slv_sosi : t_dp_sosi; w : NATURAL) RETURN t_dp_sosi_integer;
350
 
351
  -- Functions to set the DATA, RE and IM field in a stream.
352
  FUNCTION func_dp_stream_set_data(dp : t_dp_sosi;     slv : STD_LOGIC_VECTOR; str : STRING                         ) RETURN t_dp_sosi;
353
  FUNCTION func_dp_stream_set_data(dp : t_dp_sosi_arr; slv : STD_LOGIC_VECTOR; str : STRING                         ) RETURN t_dp_sosi_arr;
354
  FUNCTION func_dp_stream_set_data(dp : t_dp_sosi_arr; slv : STD_LOGIC_VECTOR; str : STRING; mask : STD_LOGIC_VECTOR) RETURN t_dp_sosi_arr;
355
 
356 5 danv
   -- Functions to rewire between concatenated sosi.data and concatenated sosi.re,im
357
   -- . data_order_im_re defines the concatenation order data = im&re or re&im
358
   -- . nof_data defines the number of concatenated streams that are concatenated in the sosi.data or sosi.re,im
359
   -- . rewire nof_data streams from data  to re,im and force data = X  to show that sosi data    is used
360
   -- . rewire nof_data streams from re,im to data  and force re,im = X to show that sosi complex is used
361
  FUNCTION func_dp_stream_complex_to_data(dp : t_dp_sosi; data_w : NATURAL; nof_data : NATURAL; data_order_im_re : BOOLEAN) RETURN t_dp_sosi;
362
  FUNCTION func_dp_stream_complex_to_data(dp : t_dp_sosi; data_w : NATURAL; nof_data : NATURAL                            ) RETURN t_dp_sosi;  -- data_order_im_re = TRUE
363
  FUNCTION func_dp_stream_complex_to_data(dp : t_dp_sosi; data_w : NATURAL                                                ) RETURN t_dp_sosi;  -- data_order_im_re = TRUE, nof_data = 1
364
  FUNCTION func_dp_stream_data_to_complex(dp : t_dp_sosi; data_w : NATURAL; nof_data : NATURAL; data_order_im_re : BOOLEAN) RETURN t_dp_sosi;
365
  FUNCTION func_dp_stream_data_to_complex(dp : t_dp_sosi; data_w : NATURAL; nof_data : NATURAL                            ) RETURN t_dp_sosi;  -- data_order_im_re = TRUE
366
  FUNCTION func_dp_stream_data_to_complex(dp : t_dp_sosi; data_w : NATURAL                                                ) RETURN t_dp_sosi;  -- data_order_im_re = TRUE, nof_data = 1
367
 
368
  FUNCTION func_dp_stream_complex_to_data(dp_arr : t_dp_sosi_arr; data_w : NATURAL; nof_data : NATURAL; data_order_im_re : BOOLEAN) RETURN t_dp_sosi_arr;
369
  FUNCTION func_dp_stream_complex_to_data(dp_arr : t_dp_sosi_arr; data_w : NATURAL; nof_data : NATURAL                            ) RETURN t_dp_sosi_arr;
370
  FUNCTION func_dp_stream_complex_to_data(dp_arr : t_dp_sosi_arr; data_w : NATURAL                                                ) RETURN t_dp_sosi_arr;
371
  FUNCTION func_dp_stream_data_to_complex(dp_arr : t_dp_sosi_arr; data_w : NATURAL; nof_data : NATURAL; data_order_im_re : BOOLEAN) RETURN t_dp_sosi_arr;
372
  FUNCTION func_dp_stream_data_to_complex(dp_arr : t_dp_sosi_arr; data_w : NATURAL; nof_data : NATURAL                            ) RETURN t_dp_sosi_arr;
373
  FUNCTION func_dp_stream_data_to_complex(dp_arr : t_dp_sosi_arr; data_w : NATURAL                                                ) RETURN t_dp_sosi_arr;
374
 
375
  -- Concatenate the data and complex re,im fields from a SOSI array into a single SOSI stream (assumes streams are in sync)
376 2 danv
  FUNCTION func_dp_stream_concat(snk_in_arr : t_dp_sosi_arr; data_w : NATURAL) RETURN t_dp_sosi; -- Concat SOSI_ARR data into single SOSI
377
  FUNCTION func_dp_stream_concat(src_in     : t_dp_siso; nof_streams : NATURAL) RETURN t_dp_siso_arr; -- Wire single SISO to SISO_ARR
378 5 danv
 
379
  -- Reconcatenate the data and complex re,im fields from a SOSI array from nof_data*in_w to nof_data*out_w
380
  -- . data_representation = "SIGNED"   treat sosi.data field as signed
381
  --                         "UNSIGNED" treat sosi.data field as unsigned
382
  --                         "COMPLEX"  treat sosi.data field as complex concatenated
383
  -- . data_order_im_re = TRUE  then "COMPLEX" data = im&re
384
  --                      FALSE then "COMPLEX" data = re&im
385
  --                      ignore when data_representation /= "COMPLEX"
386
  FUNCTION func_dp_stream_reconcat(snk_in     : t_dp_sosi;     in_w, out_w, nof_data : NATURAL; data_representation : STRING; data_order_im_re : BOOLEAN) RETURN t_dp_sosi;
387
  FUNCTION func_dp_stream_reconcat(snk_in     : t_dp_sosi;     in_w, out_w, nof_data : NATURAL; data_representation : STRING                            ) RETURN t_dp_sosi;
388
  FUNCTION func_dp_stream_reconcat(snk_in_arr : t_dp_sosi_arr; in_w, out_w, nof_data : NATURAL; data_representation : STRING; data_order_im_re : BOOLEAN) RETURN t_dp_sosi_arr;
389
  FUNCTION func_dp_stream_reconcat(snk_in_arr : t_dp_sosi_arr; in_w, out_w, nof_data : NATURAL; data_representation : STRING                            ) RETURN t_dp_sosi_arr;
390
 
391
  -- Deconcatenate data and complex re,im fields from SOSI into SOSI array
392 2 danv
  FUNCTION func_dp_stream_deconcat(snk_in      : t_dp_sosi; nof_streams, data_w : NATURAL) RETURN t_dp_sosi_arr; -- Deconcat SOSI data
393
  FUNCTION func_dp_stream_deconcat(src_out_arr : t_dp_siso_arr) RETURN t_dp_siso; -- Wire SISO_ARR(0) to single SISO 
394
 
395
END dp_stream_pkg;
396
 
397
 
398
PACKAGE BODY dp_stream_pkg IS
399
 
400
  -- Check sosi.valid against siso.ready
401
  PROCEDURE proc_dp_siso_alert(CONSTANT c_ready_latency : IN    NATURAL;
402
                               SIGNAL   clk             : IN    STD_LOGIC;
403
                               SIGNAL   sosi            : IN    t_dp_sosi;
404
                               SIGNAL   siso            : IN    t_dp_siso;
405
                               SIGNAL   ready_reg       : INOUT STD_LOGIC_VECTOR) IS
406
  BEGIN
407
    ready_reg(0) <= siso.ready;
408
    -- Register siso.ready in c_ready_latency registers
409
    IF rising_edge(clk) THEN
410
      -- Check DP sink
411
      IF sosi.valid = '1' AND ready_reg(c_ready_latency) = '0' THEN
412
        REPORT "RL ERROR" SEVERITY FAILURE;
413
      END IF;
414
      ready_reg( 1 TO c_ready_latency) <= ready_reg( 0 TO c_ready_latency-1);
415
    END IF;
416
  END proc_dp_siso_alert;
417
 
418
  -- Default RL=1
419
  PROCEDURE proc_dp_siso_alert(SIGNAL   clk             : IN    STD_LOGIC;
420
                               SIGNAL   sosi            : IN    t_dp_sosi;
421
                               SIGNAL   siso            : IN    t_dp_siso;
422
                               SIGNAL   ready_reg       : INOUT STD_LOGIC_VECTOR) IS
423
  BEGIN
424
    proc_dp_siso_alert(1, clk, sosi, siso, ready_reg);
425
  END proc_dp_siso_alert;
426
 
427
  -- SOSI/SISO array version
428
  PROCEDURE proc_dp_siso_alert(CONSTANT c_ready_latency : IN    NATURAL;
429
                               SIGNAL   clk             : IN    STD_LOGIC;
430
                               SIGNAL   sosi_arr        : IN    t_dp_sosi_arr;
431
                               SIGNAL   siso_arr        : IN    t_dp_siso_arr;
432
                               SIGNAL   ready_reg       : INOUT STD_LOGIC_VECTOR) IS
433
  BEGIN
434
    FOR i IN 0 TO sosi_arr'LENGTH-1 LOOP
435
      ready_reg(i*(c_ready_latency+1)) <= siso_arr(i).ready; -- SLV is used as an array: nof_streams*(0..c_ready_latency)
436
    END LOOP;
437
    -- Register siso.ready in c_ready_latency registers
438
    IF rising_edge(clk) THEN
439
      FOR i IN 0 TO sosi_arr'LENGTH-1 LOOP
440
        -- Check DP sink
441
        IF sosi_arr(i).valid = '1' AND ready_reg(i*(c_ready_latency+1)+1) = '0' THEN
442
          REPORT "RL ERROR" SEVERITY FAILURE;
443
        END IF;
444
        ready_reg(i*(c_ready_latency+1)+1 TO i*(c_ready_latency+1)+c_ready_latency) <=  ready_reg(i*(c_ready_latency+1) TO i*(c_ready_latency+1)+c_ready_latency-1);
445
      END LOOP;
446
    END IF;
447
  END proc_dp_siso_alert;
448
 
449
  -- SOSI/SISO array version with RL=1
450
  PROCEDURE proc_dp_siso_alert(SIGNAL   clk             : IN    STD_LOGIC;
451
                               SIGNAL   sosi_arr        : IN    t_dp_sosi_arr;
452
                               SIGNAL   siso_arr        : IN    t_dp_siso_arr;
453
                               SIGNAL   ready_reg       : INOUT STD_LOGIC_VECTOR) IS
454
  BEGIN
455
    proc_dp_siso_alert(1, clk, sosi_arr, siso_arr, ready_reg);
456
  END proc_dp_siso_alert;
457
 
458
  -- Resize functions to fit an integer or an SLV in the corresponding t_dp_sosi field width
459
  FUNCTION TO_DP_BSN(n : NATURAL) RETURN STD_LOGIC_VECTOR IS
460
  BEGIN
461
    RETURN RESIZE_UVEC(TO_SVEC(n, 32), c_dp_stream_bsn_w);
462
  END TO_DP_BSN;
463
 
464
  FUNCTION TO_DP_DATA(n : INTEGER) RETURN STD_LOGIC_VECTOR IS
465
  BEGIN
466
    RETURN RESIZE_UVEC(TO_SVEC(n, 32), c_dp_stream_data_w);
467
  END TO_DP_DATA;
468
 
469
  FUNCTION TO_DP_SDATA(n : INTEGER) RETURN STD_LOGIC_VECTOR IS
470
  BEGIN
471
    RETURN RESIZE_SVEC(TO_SVEC(n, 32), c_dp_stream_data_w);
472
  END TO_DP_SDATA;
473
 
474
  FUNCTION TO_DP_UDATA(n : INTEGER) RETURN STD_LOGIC_VECTOR IS
475
  BEGIN
476
    RETURN TO_DP_DATA(n);
477
  END TO_DP_UDATA;
478
 
479
  FUNCTION TO_DP_DSP_DATA(n : INTEGER) RETURN STD_LOGIC_VECTOR IS
480
  BEGIN
481
    RETURN RESIZE_SVEC(TO_SVEC(n, 32), c_dp_stream_dsp_data_w);
482
  END TO_DP_DSP_DATA;
483
 
484
  FUNCTION TO_DP_DSP_UDATA(n : INTEGER) RETURN STD_LOGIC_VECTOR IS
485
  BEGIN
486
    RETURN RESIZE_UVEC(TO_SVEC(n, 32), c_dp_stream_dsp_data_w);
487
  END TO_DP_DSP_UDATA;
488
 
489
  FUNCTION TO_DP_EMPTY(n : NATURAL) RETURN STD_LOGIC_VECTOR IS
490
  BEGIN
491
    RETURN TO_UVEC(n, c_dp_stream_empty_w);
492
  END TO_DP_EMPTY;
493
 
494
  FUNCTION TO_DP_CHANNEL(n : NATURAL) RETURN STD_LOGIC_VECTOR IS
495
  BEGIN
496
    RETURN TO_UVEC(n, c_dp_stream_channel_w);
497
  END TO_DP_CHANNEL;
498
 
499
  FUNCTION TO_DP_ERROR(n : NATURAL) RETURN STD_LOGIC_VECTOR IS
500
  BEGIN
501
    RETURN TO_UVEC(n, c_dp_stream_error_w);
502
  END TO_DP_ERROR;
503
 
504
  FUNCTION RESIZE_DP_BSN(vec : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR IS
505
  BEGIN
506
    RETURN RESIZE_UVEC(vec, c_dp_stream_bsn_w);
507
  END RESIZE_DP_BSN;
508
 
509
  FUNCTION RESIZE_DP_DATA(vec : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR IS
510
  BEGIN
511
    RETURN RESIZE_UVEC(vec, c_dp_stream_data_w);
512
  END RESIZE_DP_DATA;
513
 
514
  FUNCTION RESIZE_DP_SDATA(vec : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR IS
515
  BEGIN
516
    RETURN RESIZE_SVEC(vec, c_dp_stream_data_w);
517
  END RESIZE_DP_SDATA;
518
 
519
  FUNCTION RESIZE_DP_XDATA(vec : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR IS
520
    VARIABLE v_vec : STD_LOGIC_VECTOR(c_dp_stream_data_w-1 DOWNTO 0) := (OTHERS=>'X');
521
  BEGIN
522
    v_vec(vec'LENGTH-1 DOWNTO 0) := vec;
523
    RETURN v_vec;
524
  END RESIZE_DP_XDATA;
525
 
526
  FUNCTION RESIZE_DP_DSP_DATA(vec : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR IS
527
  BEGIN
528
    RETURN RESIZE_SVEC(vec, c_dp_stream_dsp_data_w);
529
  END RESIZE_DP_DSP_DATA;
530
 
531
  FUNCTION RESIZE_DP_EMPTY(vec : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR IS
532
  BEGIN
533
    RETURN RESIZE_UVEC(vec, c_dp_stream_empty_w);
534
  END RESIZE_DP_EMPTY;
535
 
536
  FUNCTION RESIZE_DP_CHANNEL(vec : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR IS
537
  BEGIN
538
    RETURN RESIZE_UVEC(vec, c_dp_stream_channel_w);
539
  END RESIZE_DP_CHANNEL;
540
 
541
  FUNCTION RESIZE_DP_ERROR(vec : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR IS
542
  BEGIN
543
    RETURN RESIZE_UVEC(vec, c_dp_stream_error_w);
544
  END RESIZE_DP_ERROR;
545
 
546
  FUNCTION INCR_DP_DATA(vec : STD_LOGIC_VECTOR; dec : INTEGER; w : NATURAL) RETURN STD_LOGIC_VECTOR IS
547
  BEGIN
548
    RETURN RESIZE_DP_DATA(STD_LOGIC_VECTOR(UNSIGNED(vec(w-1 DOWNTO 0)) + dec));
549
  END INCR_DP_DATA;
550
 
551
  FUNCTION INCR_DP_SDATA(vec : STD_LOGIC_VECTOR; dec : INTEGER; w : NATURAL) RETURN STD_LOGIC_VECTOR IS
552
  BEGIN
553
    RETURN RESIZE_DP_SDATA(STD_LOGIC_VECTOR(SIGNED(vec(w-1 DOWNTO 0)) + dec));
554
  END INCR_DP_SDATA;
555
 
556
  FUNCTION INCR_DP_DSP_DATA(vec : STD_LOGIC_VECTOR; dec : INTEGER; w : NATURAL) RETURN STD_LOGIC_VECTOR IS
557
  BEGIN
558
    RETURN RESIZE_DP_DSP_DATA(STD_LOGIC_VECTOR(SIGNED(vec(w-1 DOWNTO 0)) + dec));
559
  END INCR_DP_DSP_DATA;
560
 
561
  FUNCTION REPLICATE_DP_DATA(seq : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR IS
562
    CONSTANT c_seq_w            : NATURAL := seq'LENGTH;
563
    CONSTANT c_nof_replications : NATURAL := ceil_div(c_dp_stream_data_w, c_seq_w);
564
    CONSTANT c_vec_w            : NATURAL := ceil_value(c_dp_stream_data_w, c_seq_w);
565
    VARIABLE v_vec              : STD_LOGIC_VECTOR(c_vec_w-1 DOWNTO 0);
566
  BEGIN
567
    FOR I IN 0 TO c_nof_replications-1 LOOP
568
      v_vec((I+1)*c_seq_w-1 DOWNTO I*c_seq_w) := seq;
569
    END LOOP;
570
    RETURN v_vec(c_dp_stream_data_w-1 DOWNTO 0);
571
  END REPLICATE_DP_DATA;
572
 
573
  FUNCTION UNREPLICATE_DP_DATA(data : STD_LOGIC_VECTOR; seq_w :NATURAL) RETURN STD_LOGIC_VECTOR IS
574
    CONSTANT c_data_w           : NATURAL := data'LENGTH;
575
    CONSTANT c_nof_replications : NATURAL := ceil_div(c_data_w, seq_w);
576
    CONSTANT c_vec_w            : NATURAL := ceil_value(c_data_w, seq_w);
577
    VARIABLE v_seq              : STD_LOGIC_VECTOR(seq_w-1 DOWNTO 0);
578
    VARIABLE v_data             : STD_LOGIC_VECTOR(c_vec_w-1 DOWNTO 0);
579
    VARIABLE v_vec              : STD_LOGIC_VECTOR(c_vec_w-1 DOWNTO 0);
580
  BEGIN
581
    v_data := RESIZE_UVEC(data, c_vec_w);
582
    v_seq := v_data(seq_w-1 DOWNTO 0);                                                          -- low data part is the v_seq
583
    v_vec(seq_w-1 DOWNTO 0) := v_seq;                                                           -- keep v_seq at low part of return value
584
    IF c_nof_replications>1 THEN
585
      FOR I IN 1 TO c_nof_replications-1 LOOP
586
        v_vec((I+1)*seq_w-1 DOWNTO I*seq_w) := v_data((I+1)*seq_w-1 DOWNTO I*seq_w) XOR v_seq;  -- set return bit to '1' for high part data bits that do not match low part v_seq
587
      END LOOP;
588
    END IF;
589
    RETURN v_vec(c_data_w-1 DOWNTO 0);
590
  END UNREPLICATE_DP_DATA;
591
 
592
  FUNCTION TO_DP_SOSI_UNSIGNED(sync, valid, sop, eop : STD_LOGIC; bsn, data, re, im, empty, channel, err : UNSIGNED) RETURN t_dp_sosi_unsigned IS
593
    VARIABLE v_sosi_unsigned : t_dp_sosi_unsigned;
594
  BEGIN
595
    v_sosi_unsigned.sync    := sync;
596
    v_sosi_unsigned.valid   := valid;
597
    v_sosi_unsigned.sop     := sop;
598
    v_sosi_unsigned.eop     := eop;
599
    v_sosi_unsigned.bsn     := RESIZE(bsn,     c_dp_stream_bsn_w);
600
    v_sosi_unsigned.data    := RESIZE(data,    c_dp_stream_data_w);
601
    v_sosi_unsigned.re      := RESIZE(re,      c_dp_stream_dsp_data_w);
602
    v_sosi_unsigned.im      := RESIZE(im,      c_dp_stream_dsp_data_w);
603
    v_sosi_unsigned.empty   := RESIZE(empty,   c_dp_stream_empty_w);
604
    v_sosi_unsigned.channel := RESIZE(channel, c_dp_stream_channel_w);
605
    v_sosi_unsigned.err     := RESIZE(err,     c_dp_stream_error_w);
606
    RETURN v_sosi_unsigned;
607
  END TO_DP_SOSI_UNSIGNED;
608
 
609
  -- Keep part of head data and combine part of tail data
610
  FUNCTION func_dp_data_shift_first(head_sosi, tail_sosi : t_dp_sosi; symbol_w, nof_symbols_per_data, nof_symbols_from_tail : NATURAL) RETURN t_dp_sosi IS
611
    VARIABLE vN     : NATURAL := nof_symbols_per_data;
612
    VARIABLE v_sosi : t_dp_sosi;
613
  BEGIN
614
    ASSERT nof_symbols_from_tail<vN REPORT "func_dp_data_shift_first : no symbols from head" SEVERITY FAILURE;
615
    -- use the other sosi from head_sosi
616
    v_sosi := head_sosi;     -- I = nof_symbols_from_tail = 0
617
    FOR I IN 1 TO vN-1 LOOP  -- I > 0
618
      IF nof_symbols_from_tail = I THEN
619
        v_sosi.data(I*symbol_w-1 DOWNTO 0) := tail_sosi.data(vN*symbol_w-1 DOWNTO (vN-I)*symbol_w);
620
      END IF;
621
    END LOOP;
622
    RETURN v_sosi;
623
  END func_dp_data_shift_first;
624
 
625
 
626
  -- Shift and combine part of previous data and this data,
627
  FUNCTION func_dp_data_shift(prev_sosi, this_sosi : t_dp_sosi; symbol_w, nof_symbols_per_data, nof_symbols_from_this : NATURAL) RETURN t_dp_sosi IS
628
    VARIABLE vK     : NATURAL := nof_symbols_from_this;
629
    VARIABLE vN     : NATURAL := nof_symbols_per_data;
630
    VARIABLE v_sosi : t_dp_sosi;
631
  BEGIN
632
    -- use the other sosi from this_sosi if nof_symbols_from_this > 0 else use other sosi from prev_sosi
633
    IF vK>0 THEN
634
      v_sosi := this_sosi;
635
    ELSE
636
      v_sosi := prev_sosi;
637
    END IF;
638
 
639
    -- use sosi data from both if 0 < nof_symbols_from_this < nof_symbols_per_data (i.e. 0 < I < vN)
640
    IF vK<nof_symbols_per_data THEN   -- I = vK = nof_symbols_from_this < vN
641
      -- Implementation using variable vK directly instead of via I in a LOOP
642
      -- IF vK > 0 THEN
643
      --   v_sosi.data(vN*symbol_w-1 DOWNTO vK*symbol_w)            := prev_sosi.data((vN-vK)*symbol_w-1 DOWNTO                0);
644
      --   v_sosi.data(                     vK*symbol_w-1 DOWNTO 0) := this_sosi.data( vN    *symbol_w-1 DOWNTO (vN-vK)*symbol_w);
645
      -- END IF;
646
      -- Implementaion using LOOP vK rather than VARIABLE vK directly as index to help synthesis and avoid potential multiplier
647
      v_sosi.data := prev_sosi.data;  -- I = vK = nof_symbols_from_this = 0
648
      FOR I IN 1 TO vN-1 LOOP         -- I = vK = nof_symbols_from_this > 0
649
        IF vK = I THEN
650
          v_sosi.data(vN*symbol_w-1 DOWNTO I*symbol_w)            := prev_sosi.data((vN-I)*symbol_w-1 DOWNTO               0);
651
          v_sosi.data(                     I*symbol_w-1 DOWNTO 0) := this_sosi.data( vN   *symbol_w-1 DOWNTO (vN-I)*symbol_w);
652
        END IF;
653
      END LOOP;
654
    END IF;
655
    RETURN v_sosi;
656
  END func_dp_data_shift;
657
 
658
 
659
  -- Shift part of tail data and account for input empty
660
  FUNCTION func_dp_data_shift_last(tail_sosi : t_dp_sosi; symbol_w, nof_symbols_per_data, nof_symbols_from_tail, input_empty : NATURAL) RETURN t_dp_sosi IS
661
    VARIABLE vK     : NATURAL := nof_symbols_from_tail;
662
    VARIABLE vL     : NATURAL := input_empty;
663
    VARIABLE vN     : NATURAL := nof_symbols_per_data;
664
    VARIABLE v_sosi : t_dp_sosi;
665
  BEGIN
666
    ASSERT vK   > 0  REPORT "func_dp_data_shift_last : no symbols from tail" SEVERITY FAILURE;
667
    ASSERT vK+vL<=vN REPORT "func_dp_data_shift_last : impossible shift" SEVERITY FAILURE;
668
    v_sosi := tail_sosi;
669
    -- Implementation using variable vK directly instead of via I in a LOOP
670
    -- IF vK > 0 THEN
671
    --   v_sosi.data(vN*symbol_w-1 DOWNTO (vN-vK)*symbol_w) <= tail_sosi.data((vK+vL)*symbol_w-1 DOWNTO vL*symbol_w);
672
    -- END IF;  
673
    -- Implementation using LOOP vK rather than VARIABLE vK directly as index to help synthesis and avoid potential multiplier
674
    -- Implementation using LOOP vL rather than VARIABLE vL directly as index to help synthesis and avoid potential multiplier
675
    FOR I IN 1 TO vN-1 LOOP
676
      IF vK = I THEN
677
        FOR J IN 0 TO vN-1 LOOP
678
          IF vL = J THEN
679
            v_sosi.data(vN*symbol_w-1 DOWNTO (vN-I)*symbol_w) := tail_sosi.data((I+J)*symbol_w-1 DOWNTO J*symbol_w);
680
          END IF;
681
        END LOOP;
682
      END IF;
683
    END LOOP;
684
    RETURN v_sosi;
685
  END func_dp_data_shift_last;
686
 
687
 
688
  -- Determine resulting empty if two streams are concatenated
689
  -- . both empty must use the same nof symbols per data
690
  FUNCTION func_dp_empty_concat(head_empty, tail_empty : STD_LOGIC_VECTOR; nof_symbols_per_data : NATURAL) RETURN STD_LOGIC_VECTOR IS
691
    VARIABLE v_a, v_b, v_empty : NATURAL;
692
  BEGIN
693
    v_a := TO_UINT(head_empty);
694
    v_b := TO_UINT(tail_empty);
695
    v_empty := v_a + v_b;
696
    IF v_empty >= nof_symbols_per_data THEN
697
      v_empty := v_empty - nof_symbols_per_data;
698
    END IF;
699
    RETURN TO_UVEC(v_empty, head_empty'LENGTH);
700
  END func_dp_empty_concat;
701
 
702
  FUNCTION func_dp_empty_split(input_empty, head_empty : STD_LOGIC_VECTOR; nof_symbols_per_data : NATURAL) RETURN STD_LOGIC_VECTOR IS
703
    VARIABLE v_a, v_b, v_empty : NATURAL;
704
  BEGIN
705
    v_a   := TO_UINT(input_empty);
706
    v_b   := TO_UINT(head_empty);
707
    IF v_a >= v_b THEN
708
      v_empty := v_a - v_b;
709
    ELSE
710
      v_empty := (nof_symbols_per_data + v_a) - v_b;
711
    END IF;
712
    RETURN TO_UVEC(v_empty, head_empty'LENGTH);
713
  END func_dp_empty_split;
714
 
715
 
716
  -- Multiplex the t_dp_sosi_arr based on the valid, assuming that at most one input is active valid.
717
  FUNCTION func_dp_sosi_arr_mux(dp : t_dp_sosi_arr) RETURN t_dp_sosi IS
718
    VARIABLE v_sosi : t_dp_sosi := c_dp_sosi_rst;
719
  BEGIN
720
    FOR I IN dp'RANGE LOOP
721
      IF dp(I).valid='1' THEN
722
        v_sosi := dp(I);
723
        EXIT;
724
      END IF;
725
    END LOOP;
726
    RETURN v_sosi;
727
  END func_dp_sosi_arr_mux;
728
 
729
 
730
  -- Determine the combined logical value of corresponding STD_LOGIC fields in t_dp_*_arr (for all elements or only for the mask[]='1' elements)
731
  FUNCTION func_dp_stream_arr_and(dp : t_dp_siso_arr; mask : STD_LOGIC_VECTOR; str : STRING) RETURN STD_LOGIC IS
732
    VARIABLE v_vec : STD_LOGIC_VECTOR(dp'RANGE) := (OTHERS=>'1');  -- set default v_vec such that unmasked input have no influence on operation result
733
    VARIABLE v_any : STD_LOGIC := '0';
734
  BEGIN
735
    -- map siso field to v_vec
736
    FOR I IN dp'RANGE LOOP
737
      IF mask(I)='1' THEN
738
        v_any := '1';
739
        IF    str="READY" THEN v_vec(I) := dp(I).ready;
740
        ELSIF str="XON"   THEN v_vec(I) := dp(I).xon;
741
        ELSE  REPORT "Error in func_dp_stream_arr_and for t_dp_siso_arr";
742
        END IF;
743
      END IF;
744
    END LOOP;
745
    -- do operation on the selected record field
746
    IF v_any='1' THEN
747
      RETURN vector_and(v_vec);   -- return AND of the masked input fields
748
    ELSE
749
      RETURN '0';                 -- return '0' if no input was masked
750
    END IF;
751
  END func_dp_stream_arr_and;
752
 
753
  FUNCTION func_dp_stream_arr_and(dp : t_dp_sosi_arr; mask : STD_LOGIC_VECTOR; str : STRING) RETURN STD_LOGIC IS
754
    VARIABLE v_vec : STD_LOGIC_VECTOR(dp'RANGE) := (OTHERS=>'1');  -- set default v_vec such that unmasked input have no influence on operation result
755
    VARIABLE v_any : STD_LOGIC := '0';
756
  BEGIN
757
    -- map siso field to v_vec
758
    FOR I IN dp'RANGE LOOP
759
      IF mask(I)='1' THEN
760
        v_any := '1';
761
        IF    str="VALID" THEN v_vec(I) := dp(I).valid;
762
        ELSIF str="SOP"   THEN v_vec(I) := dp(I).sop;
763
        ELSIF str="EOP"   THEN v_vec(I) := dp(I).eop;
764
        ELSIF str="SYNC"  THEN v_vec(I) := dp(I).sync;
765
        ELSE  REPORT "Error in func_dp_stream_arr_and for t_dp_sosi_arr";
766
        END IF;
767
      END IF;
768
    END LOOP;
769
    -- do operation on the selected record field
770
    IF v_any='1' THEN
771
      RETURN vector_and(v_vec);   -- return AND of the masked input fields
772
    ELSE
773
      RETURN '0';                 -- return '0' if no input was masked
774
    END IF;
775
  END func_dp_stream_arr_and;
776
 
777
  FUNCTION func_dp_stream_arr_and(dp : t_dp_siso_arr; str : STRING) RETURN STD_LOGIC IS
778
    CONSTANT c_mask : STD_LOGIC_VECTOR(dp'RANGE) := (OTHERS=>'1');
779
  BEGIN
780
    RETURN func_dp_stream_arr_and(dp, c_mask, str);
781
  END func_dp_stream_arr_and;
782
 
783
  FUNCTION func_dp_stream_arr_and(dp : t_dp_sosi_arr; str : STRING) RETURN STD_LOGIC IS
784
    CONSTANT c_mask : STD_LOGIC_VECTOR(dp'RANGE) := (OTHERS=>'1');
785
  BEGIN
786
    RETURN func_dp_stream_arr_and(dp, c_mask, str);
787
  END func_dp_stream_arr_and;
788
 
789
  FUNCTION func_dp_stream_arr_or(dp : t_dp_siso_arr; mask : STD_LOGIC_VECTOR; str : STRING) RETURN STD_LOGIC IS
790
    VARIABLE v_vec : STD_LOGIC_VECTOR(dp'RANGE) := (OTHERS=>'0');  -- set default v_vec such that unmasked input have no influence on operation result
791
    VARIABLE v_any : STD_LOGIC := '0';
792
  BEGIN
793
    -- map siso field to v_vec
794
    FOR I IN dp'RANGE LOOP
795
      IF mask(I)='1' THEN
796
        v_any := '1';
797
        IF    str="READY" THEN v_vec(I) := dp(I).ready;
798
        ELSIF str="XON"   THEN v_vec(I) := dp(I).xon;
799
        ELSE  REPORT "Error in func_dp_stream_arr_or for t_dp_siso_arr";
800
        END IF;
801
      END IF;
802
    END LOOP;
803
    -- do operation on the selected record field
804
    IF v_any='1' THEN
805
      RETURN vector_or(v_vec);   -- return OR of the masked input fields
806
    ELSE
807
      RETURN '0';                -- return '0' if no input was masked
808
    END IF;
809
  END func_dp_stream_arr_or;
810
 
811
  FUNCTION func_dp_stream_arr_or(dp : t_dp_sosi_arr; mask : STD_LOGIC_VECTOR; str : STRING) RETURN STD_LOGIC IS
812
    VARIABLE v_vec : STD_LOGIC_VECTOR(dp'RANGE) := (OTHERS=>'0');  -- set default v_vec such that unmasked input have no influence on operation result
813
    VARIABLE v_any : STD_LOGIC := '0';
814
  BEGIN
815
    -- map siso field to v_vec
816
    FOR I IN dp'RANGE LOOP
817
      IF mask(I)='1' THEN
818
        v_any := '1';
819
        IF    str="VALID" THEN v_vec(I) := dp(I).valid;
820
        ELSIF str="SOP"   THEN v_vec(I) := dp(I).sop;
821
        ELSIF str="EOP"   THEN v_vec(I) := dp(I).eop;
822
        ELSIF str="SYNC"  THEN v_vec(I) := dp(I).sync;
823
        ELSE  REPORT "Error in func_dp_stream_arr_or for t_dp_sosi_arr";
824
        END IF;
825
      END IF;
826
    END LOOP;
827
    -- do operation on the selected record field
828
    IF v_any='1' THEN
829
      RETURN vector_or(v_vec);   -- return OR of the masked input fields
830
    ELSE
831
      RETURN '0';                -- return '0' if no input was masked
832
    END IF;
833
  END func_dp_stream_arr_or;
834
 
835
  FUNCTION func_dp_stream_arr_or(dp : t_dp_siso_arr; str : STRING) RETURN STD_LOGIC IS
836
    CONSTANT c_mask : STD_LOGIC_VECTOR(dp'RANGE) := (OTHERS=>'1');
837
  BEGIN
838
    RETURN func_dp_stream_arr_or(dp, c_mask, str);
839
  END func_dp_stream_arr_or;
840
 
841
  FUNCTION func_dp_stream_arr_or(dp : t_dp_sosi_arr; str : STRING) RETURN STD_LOGIC IS
842
    CONSTANT c_mask : STD_LOGIC_VECTOR(dp'RANGE) := (OTHERS=>'1');
843
  BEGIN
844
    RETURN func_dp_stream_arr_or(dp, c_mask, str);
845
  END func_dp_stream_arr_or;
846
 
847
 
848
  -- Functions to set or get a STD_LOGIC field as a STD_LOGIC_VECTOR to or from an siso or an sosi array
849
  FUNCTION func_dp_stream_arr_set(dp : t_dp_siso_arr; slv : STD_LOGIC_VECTOR; str : STRING) RETURN t_dp_siso_arr IS
850
    VARIABLE v_dp  : t_dp_siso_arr(dp'RANGE)    := dp;   -- default
851
    VARIABLE v_slv : STD_LOGIC_VECTOR(dp'RANGE) := slv;  -- map to ensure same range as for dp
852
  BEGIN
853
    FOR I IN dp'RANGE LOOP
854
      IF    str="READY" THEN v_dp(I).ready := v_slv(I);
855
      ELSIF str="XON"   THEN v_dp(I).xon   := v_slv(I);
856
      ELSE  REPORT "Error in func_dp_stream_arr_set for t_dp_siso_arr";
857
      END IF;
858
    END LOOP;
859
    RETURN v_dp;
860
  END func_dp_stream_arr_set;
861
 
862
  FUNCTION func_dp_stream_arr_set(dp : t_dp_sosi_arr; slv : STD_LOGIC_VECTOR; str : STRING) RETURN t_dp_sosi_arr IS
863
    VARIABLE v_dp  : t_dp_sosi_arr(dp'RANGE)    := dp;   -- default
864
    VARIABLE v_slv : STD_LOGIC_VECTOR(dp'RANGE) := slv;  -- map to ensure same range as for dp
865
  BEGIN
866
    FOR I IN dp'RANGE LOOP
867
      IF    str="VALID" THEN v_dp(I).valid := v_slv(I);
868
      ELSIF str="SOP"   THEN v_dp(I).sop   := v_slv(I);
869
      ELSIF str="EOP"   THEN v_dp(I).eop   := v_slv(I);
870
      ELSIF str="SYNC"  THEN v_dp(I).sync  := v_slv(I);
871
      ELSE  REPORT "Error in func_dp_stream_arr_set for t_dp_sosi_arr";
872
      END IF;
873
    END LOOP;
874
    RETURN v_dp;
875
  END func_dp_stream_arr_set;
876
 
877
  FUNCTION func_dp_stream_arr_set(dp : t_dp_siso_arr; sl : STD_LOGIC; str : STRING) RETURN t_dp_siso_arr IS
878
    VARIABLE v_slv : STD_LOGIC_VECTOR(dp'RANGE) := (OTHERS=>sl);
879
  BEGIN
880
    RETURN func_dp_stream_arr_set(dp, v_slv, str);
881
  END func_dp_stream_arr_set;
882
 
883
  FUNCTION func_dp_stream_arr_set(dp : t_dp_sosi_arr; sl : STD_LOGIC; str : STRING) RETURN t_dp_sosi_arr IS
884
    VARIABLE v_slv : STD_LOGIC_VECTOR(dp'RANGE) := (OTHERS=>sl);
885
  BEGIN
886
    RETURN func_dp_stream_arr_set(dp, v_slv, str);
887
  END func_dp_stream_arr_set;
888
 
889
  FUNCTION func_dp_stream_arr_get(dp : t_dp_siso_arr; str : STRING) RETURN STD_LOGIC_VECTOR IS
890
    VARIABLE v_ctrl : STD_LOGIC_VECTOR(dp'RANGE);
891
  BEGIN
892
    FOR I IN dp'RANGE LOOP
893
      IF    str="READY" THEN v_ctrl(I) := dp(I).ready;
894
      ELSIF str="XON"   THEN v_ctrl(I) := dp(I).xon;
895
      ELSE  REPORT "Error in func_dp_stream_arr_get for t_dp_siso_arr";
896
      END IF;
897
    END LOOP;
898
    RETURN v_ctrl;
899
  END func_dp_stream_arr_get;
900
 
901
  FUNCTION func_dp_stream_arr_get(dp : t_dp_sosi_arr; str : STRING) RETURN STD_LOGIC_VECTOR IS
902
    VARIABLE v_ctrl : STD_LOGIC_VECTOR(dp'RANGE);
903
  BEGIN
904
    FOR I IN dp'RANGE LOOP
905
      IF    str="VALID" THEN v_ctrl(I) := dp(I).valid;
906
      ELSIF str="SOP"   THEN v_ctrl(I) := dp(I).sop;
907
      ELSIF str="EOP"   THEN v_ctrl(I) := dp(I).eop;
908
      ELSIF str="SYNC"  THEN v_ctrl(I) := dp(I).sync;
909
      ELSE  REPORT "Error in func_dp_stream_arr_get for t_dp_sosi_arr";
910
      END IF;
911
    END LOOP;
912
    RETURN v_ctrl;
913
  END func_dp_stream_arr_get;
914
 
915
 
916
  -- Functions to select elements from two siso or two sosi arrays (sel[] = '1' selects a, sel[] = '0' selects b)
917
  FUNCTION func_dp_stream_arr_select(sel : STD_LOGIC_VECTOR; a, b : t_dp_siso) RETURN t_dp_siso_arr IS
918
    VARIABLE v_dp : t_dp_siso_arr(sel'RANGE);
919
  BEGIN
920
    FOR I IN sel'RANGE LOOP
921
      IF sel(I)='1' THEN
922
        v_dp(I) := a;
923
      ELSE
924
        v_dp(I) := b;
925
      END IF;
926
    END LOOP;
927
    RETURN v_dp;
928
  END func_dp_stream_arr_select;
929
 
930
  FUNCTION func_dp_stream_arr_select(sel : STD_LOGIC_VECTOR; a : t_dp_siso_arr; b : t_dp_siso) RETURN t_dp_siso_arr IS
931
    VARIABLE v_dp : t_dp_siso_arr(sel'RANGE);
932
  BEGIN
933
    FOR I IN sel'RANGE LOOP
934
      IF sel(I)='1' THEN
935
        v_dp(I) := a(I);
936
      ELSE
937
        v_dp(I) := b;
938
      END IF;
939
    END LOOP;
940
    RETURN v_dp;
941
  END func_dp_stream_arr_select;
942
 
943
  FUNCTION func_dp_stream_arr_select(sel : STD_LOGIC_VECTOR; a : t_dp_siso; b : t_dp_siso_arr) RETURN t_dp_siso_arr IS
944
    VARIABLE v_dp : t_dp_siso_arr(sel'RANGE);
945
  BEGIN
946
    FOR I IN sel'RANGE LOOP
947
      IF sel(I)='1' THEN
948
        v_dp(I) := a;
949
      ELSE
950
        v_dp(I) := b(I);
951
      END IF;
952
    END LOOP;
953
    RETURN v_dp;
954
  END func_dp_stream_arr_select;
955
 
956
  FUNCTION func_dp_stream_arr_select(sel : STD_LOGIC_VECTOR; a, b : t_dp_siso_arr) RETURN t_dp_siso_arr IS
957
    VARIABLE v_dp : t_dp_siso_arr(sel'RANGE);
958
  BEGIN
959
    FOR I IN sel'RANGE LOOP
960
      IF sel(I)='1' THEN
961
        v_dp(I) := a(I);
962
      ELSE
963
        v_dp(I) := b(I);
964
      END IF;
965
    END LOOP;
966
    RETURN v_dp;
967
  END func_dp_stream_arr_select;
968
 
969
  FUNCTION func_dp_stream_arr_select(sel : STD_LOGIC_VECTOR; a, b : t_dp_sosi) RETURN t_dp_sosi_arr IS
970
    VARIABLE v_dp : t_dp_sosi_arr(sel'RANGE);
971
  BEGIN
972
    FOR I IN sel'RANGE LOOP
973
      IF sel(I)='1' THEN
974
        v_dp(I) := a;
975
      ELSE
976
        v_dp(I) := b;
977
      END IF;
978
    END LOOP;
979
    RETURN v_dp;
980
  END func_dp_stream_arr_select;
981
 
982
  FUNCTION func_dp_stream_arr_select(sel : STD_LOGIC_VECTOR; a : t_dp_sosi_arr; b : t_dp_sosi) RETURN t_dp_sosi_arr IS
983
    VARIABLE v_dp : t_dp_sosi_arr(sel'RANGE);
984
  BEGIN
985
    FOR I IN sel'RANGE LOOP
986
      IF sel(I)='1' THEN
987
        v_dp(I) := a(I);
988
      ELSE
989
        v_dp(I) := b;
990
      END IF;
991
    END LOOP;
992
    RETURN v_dp;
993
  END func_dp_stream_arr_select;
994
 
995
  FUNCTION func_dp_stream_arr_select(sel : STD_LOGIC_VECTOR; a : t_dp_sosi; b : t_dp_sosi_arr) RETURN t_dp_sosi_arr IS
996
    VARIABLE v_dp : t_dp_sosi_arr(sel'RANGE);
997
  BEGIN
998
    FOR I IN sel'RANGE LOOP
999
      IF sel(I)='1' THEN
1000
        v_dp(I) := a;
1001
      ELSE
1002
        v_dp(I) := b(I);
1003
      END IF;
1004
    END LOOP;
1005
    RETURN v_dp;
1006
  END func_dp_stream_arr_select;
1007
 
1008
  FUNCTION func_dp_stream_arr_select(sel : STD_LOGIC_VECTOR; a, b : t_dp_sosi_arr) RETURN t_dp_sosi_arr IS
1009
    VARIABLE v_dp : t_dp_sosi_arr(sel'RANGE);
1010
  BEGIN
1011
    FOR I IN sel'RANGE LOOP
1012
      IF sel(I)='1' THEN
1013
        v_dp(I) := a(I);
1014
      ELSE
1015
        v_dp(I) := b(I);
1016
      END IF;
1017
    END LOOP;
1018
    RETURN v_dp;
1019
  END func_dp_stream_arr_select;
1020
 
1021
  FUNCTION func_dp_stream_arr_reverse_range(in_arr : t_dp_siso_arr) RETURN t_dp_siso_arr IS
1022
    VARIABLE v_to_range : t_dp_siso_arr(0 TO in_arr'HIGH);
1023
    VARIABLE v_downto_range : t_dp_siso_arr(in_arr'HIGH DOWNTO 0);
1024
  BEGIN
1025
    FOR i IN in_arr'RANGE LOOP
1026
      v_to_range(i)     := in_arr(in_arr'HIGH-i);
1027
      v_downto_range(i) := in_arr(in_arr'HIGH-i);
1028
    END LOOP;
1029
    IF in_arr'LEFT>in_arr'RIGHT THEN
1030
      RETURN v_downto_range;
1031
    ELSIF in_arr'LEFT<in_arr'RIGHT THEN
1032
      RETURN v_to_range;
1033
    ELSE
1034
      RETURN in_arr;
1035
    END IF;
1036
  END func_dp_stream_arr_reverse_range;
1037
 
1038
  FUNCTION func_dp_stream_arr_reverse_range(in_arr : t_dp_sosi_arr) RETURN t_dp_sosi_arr IS
1039
    VARIABLE v_to_range : t_dp_sosi_arr(0 TO in_arr'HIGH);
1040
    VARIABLE v_downto_range : t_dp_sosi_arr(in_arr'HIGH DOWNTO 0);
1041
  BEGIN
1042
    FOR i IN in_arr'RANGE LOOP
1043
      v_to_range(i)     := in_arr(in_arr'HIGH-i);
1044
      v_downto_range(i) := in_arr(in_arr'HIGH-i);
1045
    END LOOP;
1046
    IF in_arr'LEFT>in_arr'RIGHT THEN
1047
      RETURN v_downto_range;
1048
    ELSIF in_arr'LEFT<in_arr'RIGHT THEN
1049
      RETURN v_to_range;
1050
    ELSE
1051
      RETURN in_arr;
1052
    END IF;
1053
  END func_dp_stream_arr_reverse_range;
1054
 
1055
  -- Functions to combinatorially hold the data fields and to set or reset the info and control fields in an sosi array
1056
  FUNCTION func_dp_stream_arr_combine_data_info_ctrl(dp : t_dp_sosi_arr; info, ctrl : t_dp_sosi) RETURN t_dp_sosi_arr IS
1057
    VARIABLE v_dp : t_dp_sosi_arr(dp'RANGE) := dp;       -- hold sosi data
1058
  BEGIN
1059
    v_dp := func_dp_stream_arr_set_info(   v_dp, info);  -- set sosi info
1060
    v_dp := func_dp_stream_arr_set_control(v_dp, ctrl);  -- set sosi ctrl
1061
    RETURN v_dp;
1062
  END func_dp_stream_arr_combine_data_info_ctrl;
1063
 
1064
  FUNCTION func_dp_stream_arr_set_info(dp : t_dp_sosi_arr; info : t_dp_sosi) RETURN t_dp_sosi_arr IS
1065
    VARIABLE v_dp : t_dp_sosi_arr(dp'RANGE) := dp;  -- hold sosi data
1066
  BEGIN
1067
    FOR I IN dp'RANGE LOOP                          -- set sosi info
1068
      v_dp(I).bsn     := info.bsn;      -- sop
1069
      v_dp(I).channel := info.channel;  -- sop
1070
      v_dp(I).empty   := info.empty;    -- eop
1071
      v_dp(I).err     := info.err;      -- eop
1072
    END LOOP;
1073
    RETURN v_dp;
1074
  END func_dp_stream_arr_set_info;
1075
 
1076
  FUNCTION func_dp_stream_arr_set_control(dp : t_dp_sosi_arr; ctrl : t_dp_sosi) RETURN t_dp_sosi_arr IS
1077
    VARIABLE v_dp : t_dp_sosi_arr(dp'RANGE) := dp;  -- hold sosi data
1078
  BEGIN
1079
    FOR I IN dp'RANGE LOOP                          -- set sosi control
1080
      v_dp(I).valid := ctrl.valid;
1081
      v_dp(I).sop   := ctrl.sop;
1082
      v_dp(I).eop   := ctrl.eop;
1083
      v_dp(I).sync  := ctrl.sync;
1084
    END LOOP;
1085
    RETURN v_dp;
1086
  END func_dp_stream_arr_set_control;
1087
 
1088
  FUNCTION func_dp_stream_arr_reset_control(dp : t_dp_sosi_arr) RETURN t_dp_sosi_arr IS
1089
    VARIABLE v_dp : t_dp_sosi_arr(dp'RANGE) := dp;  -- hold sosi data
1090
  BEGIN
1091
    FOR I IN dp'RANGE LOOP                          -- reset sosi control
1092
      v_dp(I).valid := '0';
1093
      v_dp(I).sop   := '0';
1094
      v_dp(I).eop   := '0';
1095
      v_dp(I).sync  := '0';
1096
    END LOOP;
1097
    RETURN v_dp;
1098
  END func_dp_stream_arr_reset_control;
1099
 
1100
  FUNCTION func_dp_stream_reset_control(dp : t_dp_sosi) RETURN t_dp_sosi IS
1101
    VARIABLE v_dp : t_dp_sosi := dp;  -- hold sosi data
1102
  BEGIN
1103
    -- reset sosi control
1104
    v_dp.valid := '0';
1105
    v_dp.sop   := '0';
1106
    v_dp.eop   := '0';
1107
    v_dp.sync  := '0';
1108
    RETURN v_dp;
1109
  END func_dp_stream_reset_control;
1110
 
1111
  -- Functions to combinatorially determine the maximum and minimum sosi bsn[w-1:0] value in the sosi array (for all elements or only for the mask[]='1' elements)
1112
  FUNCTION func_dp_stream_arr_bsn_max(dp : t_dp_sosi_arr; mask : STD_LOGIC_VECTOR; w : NATURAL) RETURN STD_LOGIC_VECTOR IS
1113
    VARIABLE v_bsn : STD_LOGIC_VECTOR(w-1 DOWNTO 0) := (OTHERS=>'0');  -- init max v_bsn with minimum value
1114
  BEGIN
1115
    FOR I IN dp'RANGE LOOP
1116
      IF mask(I)='1' THEN
1117
        IF UNSIGNED(v_bsn) < UNSIGNED(dp(I).bsn(w-1 DOWNTO 0)) THEN
1118
          v_bsn := dp(I).bsn(w-1 DOWNTO 0);
1119
        END IF;
1120
      END IF;
1121
    END LOOP;
1122
    RETURN v_bsn;
1123
  END func_dp_stream_arr_bsn_max;
1124
 
1125
  FUNCTION func_dp_stream_arr_bsn_max(dp : t_dp_sosi_arr; w : NATURAL) RETURN STD_LOGIC_VECTOR IS
1126
    CONSTANT c_mask : STD_LOGIC_VECTOR(dp'RANGE) := (OTHERS=>'1');
1127
  BEGIN
1128
    RETURN func_dp_stream_arr_bsn_max(dp, c_mask, w);
1129
  END func_dp_stream_arr_bsn_max;
1130
 
1131
  FUNCTION func_dp_stream_arr_bsn_min(dp : t_dp_sosi_arr; mask : STD_LOGIC_VECTOR; w : NATURAL) RETURN STD_LOGIC_VECTOR IS
1132
    VARIABLE v_bsn : STD_LOGIC_VECTOR(w-1 DOWNTO 0) := (OTHERS=>'1');  -- init min v_bsn with maximum value
1133
  BEGIN
1134
    FOR I IN dp'RANGE LOOP
1135
      IF mask(I)='1' THEN
1136
        IF UNSIGNED(v_bsn) > UNSIGNED(dp(I).bsn(w-1 DOWNTO 0)) THEN
1137
          v_bsn := dp(I).bsn(w-1 DOWNTO 0);
1138
        END IF;
1139
      END IF;
1140
    END LOOP;
1141
    RETURN v_bsn;
1142
  END func_dp_stream_arr_bsn_min;
1143
 
1144
  FUNCTION func_dp_stream_arr_bsn_min(dp : t_dp_sosi_arr; w : NATURAL) RETURN STD_LOGIC_VECTOR IS
1145
    CONSTANT c_mask : STD_LOGIC_VECTOR(dp'RANGE) := (OTHERS=>'1');
1146
  BEGIN
1147
    RETURN func_dp_stream_arr_bsn_min(dp, c_mask, w);
1148
  END func_dp_stream_arr_bsn_min;
1149
 
1150
  -- Function to copy the BSN number of one valid stream to all other streams. 
1151
  FUNCTION func_dp_stream_arr_copy_valid_bsn(dp : t_dp_sosi_arr; mask : STD_LOGIC_VECTOR) RETURN t_dp_sosi_arr IS
1152
    VARIABLE v_bsn : STD_LOGIC_VECTOR(c_dp_stream_bsn_w-1 DOWNTO 0) := (OTHERS=>'0');
1153
    VARIABLE v_dp  : t_dp_sosi_arr(dp'RANGE) := dp;  -- hold sosi data
1154
  BEGIN
1155
    FOR I IN dp'RANGE LOOP
1156
      IF mask(I)='1' THEN
1157
        v_bsn := dp(I).bsn;
1158
      END IF;
1159
    END LOOP;
1160
    FOR I IN dp'RANGE LOOP
1161
      v_dp(I).bsn := v_bsn;
1162
    END LOOP;
1163
    RETURN v_dp;
1164
  END func_dp_stream_arr_copy_valid_bsn;
1165
 
1166
 
1167
  -- Functions to combinatorially handle channels
1168
  FUNCTION func_dp_stream_channel_set(st_sosi : t_dp_sosi; ch : NATURAL) RETURN t_dp_sosi IS
1169
    VARIABLE v_rec : t_dp_sosi := st_sosi;
1170
  BEGIN
1171
    v_rec.channel := TO_UVEC(ch, c_dp_stream_channel_w);
1172
    RETURN v_rec;
1173
  END func_dp_stream_channel_set;
1174
 
1175
  FUNCTION func_dp_stream_channel_select(st_sosi : t_dp_sosi; ch : NATURAL) RETURN t_dp_sosi IS
1176
    VARIABLE v_rec : t_dp_sosi := st_sosi;
1177
  BEGIN
1178
    IF UNSIGNED(st_sosi.channel)/=ch THEN
1179
      v_rec.valid := '0';
1180
      v_rec.sop   := '0';
1181
      v_rec.eop   := '0';
1182
    END IF;
1183
    RETURN v_rec;
1184
  END func_dp_stream_channel_select;
1185
 
1186
  FUNCTION func_dp_stream_channel_remove(st_sosi : t_dp_sosi; ch : NATURAL) RETURN t_dp_sosi IS
1187
    VARIABLE v_rec : t_dp_sosi := st_sosi;
1188
  BEGIN
1189
    IF UNSIGNED(st_sosi.channel)=ch THEN
1190
      v_rec.valid := '0';
1191
      v_rec.sop   := '0';
1192
      v_rec.eop   := '0';
1193
    END IF;
1194
    RETURN v_rec;
1195
  END func_dp_stream_channel_remove;
1196
 
1197
 
1198
  FUNCTION func_dp_stream_error_set(st_sosi : t_dp_sosi; n : NATURAL) RETURN t_dp_sosi IS
1199
    VARIABLE v_rec : t_dp_sosi := st_sosi;
1200
  BEGIN
1201
    v_rec.err := TO_UVEC(n, c_dp_stream_error_w);
1202
    RETURN v_rec;
1203
  END func_dp_stream_error_set;
1204
 
1205
 
1206
  FUNCTION func_dp_stream_bsn_set(st_sosi : t_dp_sosi; bsn : STD_LOGIC_VECTOR) RETURN t_dp_sosi IS
1207
    VARIABLE v_rec : t_dp_sosi := st_sosi;
1208
  BEGIN
1209
    v_rec.bsn := RESIZE_DP_BSN(bsn);
1210
    RETURN v_rec;
1211
  END func_dp_stream_bsn_set;
1212
 
1213
 
1214
  FUNCTION func_dp_stream_combine_info_and_data(info, data : t_dp_sosi) RETURN t_dp_sosi IS
1215
    VARIABLE v_rec : t_dp_sosi := data;  -- Sosi data fields
1216
  BEGIN
1217
    -- Combine sosi data with the sosi info fields
1218
    v_rec.sync    := info.sync AND data.sop;  -- force sync only active at data.sop
1219
    v_rec.bsn     := info.bsn;
1220
    v_rec.channel := info.channel;
1221
    v_rec.empty   := info.empty;
1222
    v_rec.err     := info.err;
1223
    RETURN v_rec;
1224
  END func_dp_stream_combine_info_and_data;
1225
 
1226
 
1227
  FUNCTION func_dp_stream_slv_to_integer(slv_sosi : t_dp_sosi; w : NATURAL) RETURN t_dp_sosi_integer IS
1228
    VARIABLE v_rec : t_dp_sosi_integer;
1229
  BEGIN
1230
    v_rec.sync     := slv_sosi.sync;
1231
    v_rec.bsn      := TO_UINT(slv_sosi.bsn(30 DOWNTO 0));         -- NATURAL'width = 31 bit
1232
    v_rec.data     := TO_SINT(slv_sosi.data(w-1 DOWNTO 0));
1233
    v_rec.re       := TO_SINT(slv_sosi.re(w-1 DOWNTO 0));
1234
    v_rec.im       := TO_SINT(slv_sosi.im(w-1 DOWNTO 0));
1235
    v_rec.valid    := slv_sosi.valid;
1236
    v_rec.sop      := slv_sosi.sop;
1237
    v_rec.eop      := slv_sosi.eop;
1238
    v_rec.empty    := TO_UINT(slv_sosi.empty);
1239
    v_rec.channel  := TO_UINT(slv_sosi.channel);
1240
    v_rec.err      := TO_UINT(slv_sosi.err);
1241
    RETURN v_rec;
1242
  END func_dp_stream_slv_to_integer;
1243
 
1244
  FUNCTION func_dp_stream_set_data(dp : t_dp_sosi; slv : STD_LOGIC_VECTOR; str : STRING) RETURN t_dp_sosi IS
1245
    VARIABLE v_dp : t_dp_sosi := dp;
1246
  BEGIN
1247
      IF    str="DATA" THEN v_dp.data := RESIZE_DP_DATA(slv);
1248
      ELSIF str="DSP"  THEN v_dp.re   := RESIZE_DP_DSP_DATA(slv);
1249
                            v_dp.im   := RESIZE_DP_DSP_DATA(slv);
1250
      ELSIF str="RE"  THEN  v_dp.re   := RESIZE_DP_DSP_DATA(slv);
1251
      ELSIF str="IM"  THEN  v_dp.im   := RESIZE_DP_DSP_DATA(slv);
1252
      ELSIF str="ALL" THEN  v_dp.data := RESIZE_DP_DATA(slv);
1253
                            v_dp.re   := RESIZE_DP_DSP_DATA(slv);
1254
                            v_dp.im   := RESIZE_DP_DSP_DATA(slv);
1255
      ELSE  REPORT "Error in func_dp_stream_set_data for t_dp_sosi";
1256
      END IF;
1257
    RETURN v_dp;
1258
  END;
1259
 
1260
  FUNCTION func_dp_stream_set_data(dp : t_dp_sosi_arr; slv : STD_LOGIC_VECTOR; str : STRING) RETURN t_dp_sosi_arr IS
1261
    VARIABLE v_dp : t_dp_sosi_arr(dp'RANGE) := dp;
1262
  BEGIN
1263
    FOR I IN dp'RANGE LOOP
1264
      v_dp(I) := func_dp_stream_set_data(dp(I), slv, str);
1265
    END LOOP;
1266
    RETURN v_dp;
1267
  END;
1268
 
1269
  FUNCTION func_dp_stream_set_data(dp : t_dp_sosi_arr; slv : STD_LOGIC_VECTOR; str : STRING; mask : STD_LOGIC_VECTOR) RETURN t_dp_sosi_arr IS
1270
    VARIABLE v_dp : t_dp_sosi_arr(dp'RANGE) := dp;
1271
  BEGIN
1272
    FOR I IN dp'RANGE LOOP
1273
      IF mask(I)='0' THEN
1274
        v_dp(I) := func_dp_stream_set_data(dp(I), slv, str);
1275
      END IF;
1276
    END LOOP;
1277
    RETURN v_dp;
1278
  END;
1279
 
1280 5 danv
   -- Functions to rewire between concatenated sosi.data and concatenated sosi.re,im
1281
  FUNCTION func_dp_stream_complex_to_data(dp : t_dp_sosi; data_w : NATURAL; nof_data : NATURAL; data_order_im_re : BOOLEAN) RETURN t_dp_sosi IS
1282
    CONSTANT c_compl_data_w : NATURAL := data_w/2;
1283
    VARIABLE v_dp           : t_dp_sosi := dp;
1284
    VARIABLE v_re           : STD_LOGIC_VECTOR(c_compl_data_w-1 DOWNTO 0);
1285
    VARIABLE v_im           : STD_LOGIC_VECTOR(c_compl_data_w-1 DOWNTO 0);
1286
  BEGIN
1287
    v_dp.data := (OTHERS=>'0');
1288
    v_dp.re := (OTHERS=>'X');
1289
    v_dp.im := (OTHERS=>'X');
1290
    FOR I IN 0 TO nof_data-1 LOOP
1291
      v_re := dp.re(c_compl_data_w-1 + I*c_compl_data_w DOWNTO I*c_compl_data_w);
1292
      v_im := dp.im(c_compl_data_w-1 + I*c_compl_data_w DOWNTO I*c_compl_data_w);
1293
      IF data_order_im_re=TRUE THEN
1294
        v_dp.data((I+1)*data_w-1 DOWNTO I*data_w) := v_im & v_re;
1295
      ELSE
1296
        v_dp.data((I+1)*data_w-1 DOWNTO I*data_w) := v_re & v_im;
1297
      END IF;
1298
    END LOOP;
1299
    RETURN v_dp;
1300
  END;
1301
 
1302
  FUNCTION func_dp_stream_complex_to_data(dp : t_dp_sosi; data_w : NATURAL; nof_data : NATURAL) RETURN t_dp_sosi IS
1303
  BEGIN
1304
    RETURN func_dp_stream_complex_to_data(dp, data_w, nof_data, TRUE);
1305
  END;
1306
 
1307
  FUNCTION func_dp_stream_complex_to_data(dp : t_dp_sosi; data_w : NATURAL) RETURN t_dp_sosi IS
1308
  BEGIN
1309
    RETURN func_dp_stream_complex_to_data(dp, data_w, 1, TRUE);
1310
  END;
1311
 
1312
  FUNCTION func_dp_stream_data_to_complex(dp : t_dp_sosi; data_w : NATURAL; nof_data : NATURAL; data_order_im_re : BOOLEAN) RETURN t_dp_sosi IS
1313
    CONSTANT c_compl_data_w : NATURAL := data_w/2;
1314
    VARIABLE v_dp           : t_dp_sosi := dp;
1315
    VARIABLE v_hi           : STD_LOGIC_VECTOR(c_compl_data_w-1 DOWNTO 0);
1316
    VARIABLE v_lo           : STD_LOGIC_VECTOR(c_compl_data_w-1 DOWNTO 0);
1317
  BEGIN
1318
    v_dp.data := (OTHERS=>'X');
1319
    v_dp.re := (OTHERS=>'0');
1320
    v_dp.im := (OTHERS=>'0');
1321
    FOR I IN 0 TO nof_data-1 LOOP
1322
      v_hi := dp.data(        data_w-1 + I*data_w DOWNTO c_compl_data_w + I*data_w);
1323
      v_lo := dp.data(c_compl_data_w-1 + I*data_w DOWNTO              0 + I*data_w);
1324
      IF data_order_im_re=TRUE THEN
1325
        v_dp.im((I+1)*c_compl_data_w-1 DOWNTO I*c_compl_data_w) := v_hi;
1326
        v_dp.re((I+1)*c_compl_data_w-1 DOWNTO I*c_compl_data_w) := v_lo;
1327
      ELSE
1328
        v_dp.re((I+1)*c_compl_data_w-1 DOWNTO I*c_compl_data_w) := v_hi;
1329
        v_dp.im((I+1)*c_compl_data_w-1 DOWNTO I*c_compl_data_w) := v_lo;
1330
      END IF;
1331
    END LOOP;
1332
    RETURN v_dp;
1333
  END;
1334
 
1335
  FUNCTION func_dp_stream_data_to_complex(dp : t_dp_sosi; data_w : NATURAL; nof_data : NATURAL) RETURN t_dp_sosi IS
1336
  BEGIN
1337
    RETURN func_dp_stream_data_to_complex(dp, data_w, nof_data, TRUE);
1338
  END;
1339
 
1340
  FUNCTION func_dp_stream_data_to_complex(dp : t_dp_sosi; data_w : NATURAL) RETURN t_dp_sosi IS
1341
  BEGIN
1342
    RETURN func_dp_stream_data_to_complex(dp, data_w, 1, TRUE);
1343
  END;
1344
 
1345
  FUNCTION func_dp_stream_complex_to_data(dp_arr : t_dp_sosi_arr; data_w : NATURAL; nof_data : NATURAL; data_order_im_re : BOOLEAN) RETURN t_dp_sosi_arr IS
1346
    VARIABLE v_dp_arr : t_dp_sosi_arr(dp_arr'RANGE);
1347
  BEGIN
1348
    FOR i IN dp_arr'RANGE LOOP
1349
      v_dp_arr(i) := func_dp_stream_complex_to_data(dp_arr(i), data_w, nof_data, data_order_im_re);  -- nof_data per stream is 1
1350
    END LOOP;
1351
    RETURN v_dp_arr;
1352
  END;
1353
 
1354
  FUNCTION func_dp_stream_complex_to_data(dp_arr : t_dp_sosi_arr; data_w : NATURAL; nof_data : NATURAL) RETURN t_dp_sosi_arr IS
1355
  BEGIN
1356
    RETURN func_dp_stream_complex_to_data(dp_arr, data_w, nof_data, TRUE);
1357
  END;
1358
 
1359
  FUNCTION func_dp_stream_complex_to_data(dp_arr : t_dp_sosi_arr; data_w : NATURAL) RETURN t_dp_sosi_arr IS
1360
  BEGIN
1361
    RETURN func_dp_stream_complex_to_data(dp_arr, data_w, 1, TRUE);
1362
  END;
1363
 
1364
  FUNCTION func_dp_stream_data_to_complex(dp_arr : t_dp_sosi_arr; data_w : NATURAL; nof_data : NATURAL; data_order_im_re : BOOLEAN) RETURN t_dp_sosi_arr IS
1365
    VARIABLE v_dp_arr : t_dp_sosi_arr(dp_arr'RANGE);
1366
  BEGIN
1367
    FOR i IN dp_arr'RANGE LOOP
1368
      v_dp_arr(i) := func_dp_stream_data_to_complex(dp_arr(i), data_w, nof_data, data_order_im_re);  -- nof_data per stream is 1
1369
    END LOOP;
1370
    RETURN v_dp_arr;
1371
  END;
1372
 
1373
  FUNCTION func_dp_stream_data_to_complex(dp_arr : t_dp_sosi_arr; data_w : NATURAL; nof_data : NATURAL) RETURN t_dp_sosi_arr IS
1374
  BEGIN
1375
    RETURN func_dp_stream_data_to_complex(dp_arr, data_w, nof_data, TRUE);
1376
  END;
1377
 
1378
  FUNCTION func_dp_stream_data_to_complex(dp_arr : t_dp_sosi_arr; data_w : NATURAL) RETURN t_dp_sosi_arr IS
1379
  BEGIN
1380
    RETURN func_dp_stream_data_to_complex(dp_arr, data_w, 1, TRUE);
1381
  END;
1382
 
1383 2 danv
  -- Concatenate the data (and complex fields) from a SOSI array into a single SOSI stream (assumes streams are in sync)
1384
  FUNCTION func_dp_stream_concat(snk_in_arr : t_dp_sosi_arr; data_w : NATURAL) RETURN t_dp_sosi IS
1385 5 danv
    CONSTANT c_compl_data_w : NATURAL   := data_w/2;
1386 2 danv
    VARIABLE v_src_out      : t_dp_sosi := snk_in_arr(0);
1387
  BEGIN
1388 5 danv
    v_src_out.data := (OTHERS=>'0');
1389
    v_src_out.re   := (OTHERS=>'0');
1390
    v_src_out.im   := (OTHERS=>'0');
1391 2 danv
    FOR i IN snk_in_arr'RANGE LOOP
1392
      v_src_out.data((i+1)*        data_w-1 DOWNTO i*        data_w) := snk_in_arr(i).data(      data_w-1 DOWNTO 0);
1393 5 danv
      v_src_out.re(  (i+1)*c_compl_data_w-1 DOWNTO i*c_compl_data_w) := snk_in_arr(i).re(c_compl_data_w-1 DOWNTO 0);
1394
      v_src_out.im(  (i+1)*c_compl_data_w-1 DOWNTO i*c_compl_data_w) := snk_in_arr(i).im(c_compl_data_w-1 DOWNTO 0);
1395 2 danv
    END LOOP;
1396
    RETURN v_src_out;
1397
  END;
1398
 
1399
  FUNCTION func_dp_stream_concat(src_in : t_dp_siso; nof_streams : NATURAL) RETURN t_dp_siso_arr IS -- Wire single SISO to SISO_ARR
1400
    VARIABLE v_snk_out_arr : t_dp_siso_arr(nof_streams-1 DOWNTO 0);
1401
  BEGIN
1402
    FOR i IN v_snk_out_arr'RANGE LOOP
1403
      v_snk_out_arr(i) := src_in;
1404
    END LOOP;
1405
    RETURN v_snk_out_arr;
1406
  END;
1407
 
1408 5 danv
  -- Reconcatenate the data and complex re,im fields from a SOSI array from nof_data*in_w to nof_data*out_w
1409
  FUNCTION func_dp_stream_reconcat(snk_in : t_dp_sosi; in_w, out_w, nof_data : NATURAL; data_representation : STRING; data_order_im_re : BOOLEAN) RETURN t_dp_sosi IS
1410
    CONSTANT c_compl_in_w  : NATURAL   := in_w/2;
1411
    CONSTANT c_compl_out_w : NATURAL   := out_w/2;
1412
    VARIABLE v_src_out     : t_dp_sosi := snk_in;
1413
    VARIABLE v_in_data     : STD_LOGIC_VECTOR(in_w-1 DOWNTO 0);
1414
    VARIABLE v_out_data    : STD_LOGIC_VECTOR(out_w-1 DOWNTO 0) := (OTHERS=>'0');   -- default set sosi.data to 0
1415
  BEGIN
1416
    v_src_out := snk_in;
1417
    v_src_out.data := (OTHERS=>'0');
1418
    v_src_out.re   := (OTHERS=>'0');
1419
    v_src_out.im   := (OTHERS=>'0');
1420
    FOR i IN 0 TO nof_data-1 LOOP
1421
      v_in_data := snk_in.data((i+1)*in_w-1 DOWNTO i*in_w);
1422
      IF data_representation="UNSIGNED" THEN  -- treat data as unsigned
1423
        v_out_data := RESIZE_UVEC(v_in_data, out_w);
1424
      ELSE
1425
        IF data_representation="SIGNED" THEN  -- treat data as signed
1426
          v_out_data := RESIZE_SVEC(v_in_data, out_w);
1427
        ELSE
1428
          -- treat data as complex
1429
          IF data_order_im_re=TRUE THEN
1430
            -- data = im&re
1431
            v_out_data := RESIZE_SVEC(v_in_data(2*c_compl_in_w-1 DOWNTO c_compl_in_w), c_compl_out_w) &
1432
                          RESIZE_SVEC(v_in_data(  c_compl_in_w-1 DOWNTO            0), c_compl_out_w);
1433
          ELSE
1434
            -- data = re&im
1435
            v_out_data := RESIZE_SVEC(v_in_data(  c_compl_in_w-1 DOWNTO            0), c_compl_out_w) &
1436
                          RESIZE_SVEC(v_in_data(2*c_compl_in_w-1 DOWNTO c_compl_in_w), c_compl_out_w);
1437
          END IF;
1438
        END IF;
1439
      END IF;
1440
      v_src_out.data((i+1)*        out_w-1 DOWNTO i*        out_w) := v_out_data;
1441
      v_src_out.re(  (i+1)*c_compl_out_w-1 DOWNTO i*c_compl_out_w) := RESIZE_SVEC(snk_in.re((i+1)*c_compl_in_w-1 DOWNTO i*c_compl_in_w), c_compl_out_w);
1442
      v_src_out.im(  (i+1)*c_compl_out_w-1 DOWNTO i*c_compl_out_w) := RESIZE_SVEC(snk_in.im((i+1)*c_compl_in_w-1 DOWNTO i*c_compl_in_w), c_compl_out_w);
1443
    END LOOP;
1444
    RETURN v_src_out;
1445
  END;
1446
 
1447
  FUNCTION func_dp_stream_reconcat(snk_in : t_dp_sosi; in_w, out_w, nof_data : NATURAL; data_representation : STRING) RETURN t_dp_sosi IS
1448
  BEGIN
1449
    RETURN func_dp_stream_reconcat(snk_in, in_w, out_w, nof_data, data_representation, TRUE);
1450
  END;
1451
 
1452
  FUNCTION func_dp_stream_reconcat(snk_in_arr : t_dp_sosi_arr; in_w, out_w, nof_data : NATURAL; data_representation : STRING; data_order_im_re : BOOLEAN) RETURN t_dp_sosi_arr IS
1453
    VARIABLE v_src_out_arr : t_dp_sosi_arr(snk_in_arr'RANGE) := snk_in_arr;
1454
  BEGIN
1455
    FOR i IN v_src_out_arr'RANGE LOOP
1456
      v_src_out_arr(i) := func_dp_stream_reconcat(snk_in_arr(i), in_w, out_w, nof_data, data_representation, data_order_im_re);
1457
    END LOOP;
1458
    RETURN v_src_out_arr;
1459
  END;
1460
 
1461
  FUNCTION func_dp_stream_reconcat(snk_in_arr : t_dp_sosi_arr; in_w, out_w, nof_data : NATURAL; data_representation : STRING) RETURN t_dp_sosi_arr IS
1462
  BEGIN
1463
    RETURN func_dp_stream_reconcat(snk_in_arr, in_w, out_w, nof_data, data_representation, TRUE);
1464
  END;
1465
 
1466 2 danv
  -- Deconcatenate data from SOSI into SOSI array
1467
  FUNCTION func_dp_stream_deconcat(snk_in : t_dp_sosi; nof_streams, data_w : NATURAL) RETURN t_dp_sosi_arr IS
1468 5 danv
    CONSTANT c_compl_data_w : NATURAL := data_w/2;
1469 2 danv
    VARIABLE v_src_out_arr  : t_dp_sosi_arr(nof_streams-1 DOWNTO 0);
1470
  BEGIN
1471
    FOR i IN v_src_out_arr'RANGE LOOP
1472
      v_src_out_arr(i) := snk_in;
1473
      v_src_out_arr(i).data := (OTHERS=>'0');
1474
      v_src_out_arr(i).re   := (OTHERS=>'0');
1475
      v_src_out_arr(i).im   := (OTHERS=>'0');
1476 5 danv
      v_src_out_arr(i).data := RESIZE_DP_DATA(    snk_in.data((i+1)*        data_w-1 DOWNTO i*        data_w));
1477
      v_src_out_arr(i).re   := RESIZE_DP_DSP_DATA(snk_in.re  ((i+1)*c_compl_data_w-1 DOWNTO i*c_compl_data_w));
1478
      v_src_out_arr(i).im   := RESIZE_DP_DSP_DATA(snk_in.im  ((i+1)*c_compl_data_w-1 DOWNTO i*c_compl_data_w));
1479 2 danv
    END LOOP;
1480
    RETURN v_src_out_arr;
1481
  END;
1482
 
1483
  FUNCTION func_dp_stream_deconcat(src_out_arr : t_dp_siso_arr) RETURN t_dp_siso IS -- Wire SISO_ARR(0) to single SISO
1484
  BEGIN
1485
    RETURN src_out_arr(0);
1486
  END;
1487
 
1488
END dp_stream_pkg;
1489
 

powered by: WebSVN 2.1.0

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