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 7

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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