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

Subversion Repositories dp_repack_data

[/] [dp_repack_data/] [trunk/] [tb_dp_repack_data.vhd] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 danv
-------------------------------------------------------------------------------
2
--
3
-- Copyright (C) 2015
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
-- Purpose:
23
-- . Test bench for dp_repack_data
24
-- Description:
25
--                                                       c_no_unpack
26
--                                                          .
27
--             g_in_dat_w             g_pack_dat_w          .   g_in_dat_w
28
--             g_in_nof_words         g_pack_nof_words      .   g_in_nof_words
29
--                 .                       .                .       .
30
--                 .   u_pack              .       u_unpack .       .
31
--                 .   ______________      .       ______________   .
32
--                 .  |dp_repack_data|     .      |dp_repack_data|  .
33
--   stimuli_src ---->|              |----------->|              |----> verify_snk
34
--                    | in       out |  pack_src  | in       out |
35
--                    |______________|            |______________|
36
--
37
-- Usage:                                  
38
-- > as 10
39
-- > run -all
40
--
41
 
42
LIBRARY IEEE, common_pkg_lib, dp_pkg_lib;
43
USE IEEE.std_logic_1164.ALL;
44
USE IEEE.numeric_std.ALL;
45
USE common_pkg_lib.common_pkg.ALL;
46
USE common_pkg_lib.common_lfsr_sequences_pkg.ALL;
47
USE common_pkg_lib.tb_common_pkg.ALL;
48
USE dp_pkg_lib.dp_stream_pkg.ALL;
49
USE dp_pkg_lib.tb_dp_pkg.ALL;
50
 
51
 
52
ENTITY tb_dp_repack_data IS
53
  GENERIC (
54
    -- general
55
    g_flow_control_stimuli   : t_dp_flow_control_enum := e_active;  -- always e_active, e_random or e_pulse flow control
56
    g_flow_control_verify    : t_dp_flow_control_enum := e_active;  -- always e_active, e_random or e_pulse flow control
57
    -- specific
58
    g_in_dat_w               : NATURAL := 8 * 42;
59
    g_in_nof_words           : NATURAL := 1;
60
    g_pack_dat_w             : NATURAL := 32;
61
    g_pack_nof_words         : NATURAL := 11;
62
    g_in_bypass              : BOOLEAN := TRUE;   -- can use TRUE when g_in_nof_words=1  or g_in_nof_words=g_out_nof_words
63
    g_pack_bypass            : BOOLEAN := FALSE;  -- can use TRUE when g_out_nof_words=1 or g_in_nof_words=g_out_nof_words
64
    g_in_symbol_w            : NATURAL := 8;      -- default 1 for snk_in.empty  in nof bits, else use power of 2
65
    g_pack_symbol_w          : NATURAL := 8;      -- default 1 for src_out.empty in nof bits, else use power of 2
66
    g_nof_repeat             : NATURAL := 10;
67
    g_pkt_len                : NATURAL := 1;     -- if not a multiple of g_in_nof_words then the input stage flush creates gap between blocks
68
    g_pkt_gap                : NATURAL := 0
69
  );
70
END tb_dp_repack_data;
71
 
72
 
73
ARCHITECTURE tb OF tb_dp_repack_data IS
74
 
75
  CONSTANT c_no_unpack                : BOOLEAN := FALSE;
76
  CONSTANT c_enable_repack_in         : BOOLEAN := TRUE;
77
  CONSTANT c_enable_repack_out        : BOOLEAN := TRUE;
78
 
79
  -- dp_stream_stimuli
80
  CONSTANT c_stimuli_pulse_active     : NATURAL := 3;  --g_in_nof_words;
81
  CONSTANT c_stimuli_pulse_period     : NATURAL := 7;
82
 
83
  CONSTANT c_data_init                : NATURAL := 0;
84
  CONSTANT c_bsn_init                 : STD_LOGIC_VECTOR(c_dp_stream_bsn_w-1 DOWNTO 0) := X"0000000000000000";  -- X"0877665544332211"
85
  CONSTANT c_err_init                 : NATURAL := 247;
86
  CONSTANT c_channel_init             : NATURAL := 5;  -- fixed
87
 
88
  -- dp_stream_verify
89
  CONSTANT c_verify_pulse_active      : NATURAL := 1;
90
  CONSTANT c_verify_pulse_period      : NATURAL := 5;
91
 
92
  CONSTANT c_data_max                 : UNSIGNED(g_in_dat_w-1 DOWNTO 0) := (OTHERS=>'1');
93
  CONSTANT c_dsp_max                  : UNSIGNED(g_in_dat_w-1 DOWNTO 0) := (OTHERS=>'1');
94
 
95
  --CONSTANT c_verify_snk_in_cnt_max    : t_dp_sosi_unsigned := c_dp_sosi_unsigned_rst;  -- default 0 is no wrap
96
  CONSTANT c_verify_snk_in_cnt_max    : t_dp_sosi_unsigned := TO_DP_SOSI_UNSIGNED('0', '0', '0', '0', c_data_max, c_dsp_max, c_dsp_max, c_unsigned_0, c_unsigned_0, c_unsigned_0, c_unsigned_0);
97
  CONSTANT c_verify_snk_in_cnt_gap    : t_dp_sosi_unsigned := c_dp_sosi_unsigned_ones; -- default only accept increment +1
98
 
99
  CONSTANT c_expected_pkt_len         : NATURAL := sel_a_b(c_no_unpack, g_pkt_len * g_pack_nof_words / g_in_nof_words, g_pkt_len);
100
  -- both
101
  CONSTANT c_sync_period              : NATURAL := 10;
102
  CONSTANT c_sync_offset              : NATURAL := 7;
103
 
104
  SIGNAL clk                        : STD_LOGIC := '1';
105
  SIGNAL rst                        : STD_LOGIC := '1';
106
  SIGNAL tb_end                     : STD_LOGIC := '0';
107
 
108
  SIGNAL stimuli_src_in             : t_dp_siso := c_dp_siso_rdy;
109
  SIGNAL stimuli_src_out            : t_dp_sosi;
110
  SIGNAL stimuli_src_out_data       : STD_LOGIC_VECTOR(g_in_dat_w-1 DOWNTO 0);
111
 
112
  SIGNAL verify_snk_in_enable       : t_dp_sosi_sl := c_dp_sosi_sl_rst;
113
  SIGNAL last_snk_in                : t_dp_sosi;
114
  SIGNAL last_snk_in_evt            : STD_LOGIC;
115
  SIGNAL verify_last_snk_in_evt     : t_dp_sosi_sl := c_dp_sosi_sl_rst;
116
 
117
  SIGNAL verify_snk_out             : t_dp_siso := c_dp_siso_rdy;
118
  SIGNAL verify_snk_in              : t_dp_sosi;
119
  SIGNAL verify_snk_in_data         : STD_LOGIC_VECTOR(g_in_dat_w-1 DOWNTO 0);
120
 
121
  -- specific
122
  SIGNAL pack_src_in                : t_dp_siso;
123
  SIGNAL pack_src_out               : t_dp_sosi;
124
  SIGNAL pack_src_out_data          : STD_LOGIC_VECTOR(g_pack_dat_w-1 DOWNTO 0);
125
 
126
  SIGNAL unpack_src_in              : t_dp_siso;
127
  SIGNAL unpack_src_out             : t_dp_sosi;
128
  SIGNAL unpack_src_out_data        : STD_LOGIC_VECTOR(g_in_dat_w-1 DOWNTO 0);
129
 
130
BEGIN
131
 
132
  clk <= (NOT clk) OR tb_end AFTER clk_period/2;
133
  rst <= '1', '0' AFTER clk_period*7;
134
 
135
  ------------------------------------------------------------------------------
136
  -- DATA GENERATION
137
  ------------------------------------------------------------------------------
138
 
139
  u_dp_stream_stimuli : ENTITY dp_pkg_lib.dp_stream_stimuli
140
  GENERIC MAP (
141
    g_instance_nr    => 0,                        -- only one stream so choose index 0
142
    -- flow control
143
    g_random_w       => 15,                       -- use different random width for stimuli and for verify to have different random sequences
144
    g_pulse_active   => c_stimuli_pulse_active,
145
    g_pulse_period   => c_stimuli_pulse_period,
146
    g_flow_control   => g_flow_control_stimuli,   -- always active, random or pulse flow control
147
    -- initializations
148
    g_sync_period    => c_sync_period,
149
    g_sync_offset    => c_sync_offset,
150
    g_data_init      => c_data_init,
151
    g_bsn_init       => c_bsn_init,
152
    g_err_init       => c_err_init,
153
    g_channel_init   => c_channel_init,
154
    -- specific
155
    g_in_dat_w       => g_in_dat_w,
156
    g_nof_repeat     => g_nof_repeat,
157
    g_pkt_len        => g_pkt_len,
158
    g_pkt_gap        => g_pkt_gap
159
  )
160
  PORT MAP (
161
    rst                 => rst,
162
    clk                 => clk,
163
 
164
    -- Generate stimuli
165
    src_in              => stimuli_src_in,
166
    src_out             => stimuli_src_out,
167
 
168
    -- End of stimuli
169
    last_snk_in         => last_snk_in,      -- expected verify_snk_in after end of stimuli
170
    last_snk_in_evt     => last_snk_in_evt,  -- trigger verify to verify the last_snk_in
171
    tb_end              => tb_end            -- signal end of tb as far as this dp_stream_stimuli is concerned
172
  );
173
 
174
 
175
  ------------------------------------------------------------------------------
176
  -- DATA VERIFICATION
177
  ------------------------------------------------------------------------------
178
 
179
  -- Select fields that need to be verified
180
  -- . during the test
181
  verify_snk_in_enable.sync    <= '1';
182
  verify_snk_in_enable.bsn     <= '1';
183
  verify_snk_in_enable.data    <= '1' WHEN c_no_unpack=FALSE ELSE '0';
184
  verify_snk_in_enable.re      <= '0';
185
  verify_snk_in_enable.im      <= '0';
186
  verify_snk_in_enable.valid   <= '1';
187
  verify_snk_in_enable.sop     <= '1';
188
  verify_snk_in_enable.eop     <= '1';
189
  verify_snk_in_enable.empty   <= '0';
190
  verify_snk_in_enable.channel <= '1';
191
  verify_snk_in_enable.err     <= '1';
192
 
193
  -- . after the test
194
  verify_last_snk_in_evt.sync    <= last_snk_in_evt;
195
  verify_last_snk_in_evt.bsn     <= last_snk_in_evt;
196
  verify_last_snk_in_evt.data    <= last_snk_in_evt WHEN c_no_unpack=FALSE ELSE '0';
197
  verify_last_snk_in_evt.re      <= '0';
198
  verify_last_snk_in_evt.im      <= '0';
199
  verify_last_snk_in_evt.valid   <= last_snk_in_evt;
200
  verify_last_snk_in_evt.sop     <= last_snk_in_evt;
201
  verify_last_snk_in_evt.eop     <= last_snk_in_evt;
202
  verify_last_snk_in_evt.empty   <= '0';
203
  verify_last_snk_in_evt.channel <= last_snk_in_evt;
204
  verify_last_snk_in_evt.err     <= last_snk_in_evt;
205
 
206
  u_dp_stream_verify : ENTITY dp_pkg_lib.dp_stream_verify
207
  GENERIC MAP (
208
    g_instance_nr    => 0,                        -- only one stream so choose index 0
209
    -- flow control
210
    g_random_w       => 14,                       -- use different random width for stimuli and for verify to have different random sequences
211
    g_pulse_active   => c_verify_pulse_active,
212
    g_pulse_period   => c_verify_pulse_period,
213
    g_flow_control   => g_flow_control_verify,    -- always active, random or pulse flow control
214
    -- initializations
215
    g_sync_period    => c_sync_period,
216
    g_sync_offset    => c_sync_offset,
217
    g_snk_in_cnt_max => c_verify_snk_in_cnt_max,
218
    g_snk_in_cnt_gap => c_verify_snk_in_cnt_gap,
219
    -- specific
220
    g_in_dat_w       => g_in_dat_w,
221
    g_pkt_len        => c_expected_pkt_len
222
  )
223
  PORT MAP (
224
    rst                        => rst,
225
    clk                        => clk,
226
 
227
    -- Verify data
228
    snk_out                    => verify_snk_out,
229
    snk_in                     => verify_snk_in,
230
 
231
    -- During stimuli
232
    verify_snk_in_enable       => verify_snk_in_enable,  -- enable verify to verify that the verify_snk_in fields are incrementing
233
 
234
    -- End of stimuli
235
    expected_snk_in            => last_snk_in,            -- expected verify_snk_in after end of stimuli
236
    verify_expected_snk_in_evt => verify_last_snk_in_evt  -- trigger verify to verify the last_snk_in
237
  );
238
 
239
  ------------------------------------------------------------------------------
240
  -- DUT Pack
241
  ------------------------------------------------------------------------------
242
 
243
  u_pack : ENTITY work.dp_repack_data
244
  GENERIC MAP (
245
    g_enable_repack_in  => c_enable_repack_in,
246
    g_enable_repack_out => c_enable_repack_out,
247
    g_in_bypass         => g_in_bypass,
248
    g_in_dat_w          => g_in_dat_w,
249
    g_in_nof_words      => g_in_nof_words,
250
    g_in_symbol_w       => g_in_symbol_w,
251
    g_out_bypass        => g_pack_bypass,
252
    g_out_dat_w         => g_pack_dat_w,
253
    g_out_nof_words     => g_pack_nof_words,
254
    g_out_symbol_w      => g_pack_symbol_w
255
  )
256
  PORT MAP (
257
    rst              => rst,
258
    clk              => clk,
259
 
260
    snk_out          => stimuli_src_in,
261
    snk_in           => stimuli_src_out,
262
 
263
    src_in           => pack_src_in,
264
    src_out          => pack_src_out
265
  );
266
 
267
  pack_src_out_data <= pack_src_out.data(g_pack_dat_w-1 DOWNTO 0);
268
 
269
  ------------------------------------------------------------------------------
270
  -- DUT Unpack
271
  ------------------------------------------------------------------------------
272
 
273
  no_unpack : IF c_no_unpack=TRUE GENERATE
274
    pack_src_in    <= unpack_src_in;
275
    unpack_src_out <= pack_src_out;
276
  END GENERATE;
277
 
278
  gen_unpack : IF c_no_unpack=FALSE GENERATE
279
    u_unpack : ENTITY work.dp_repack_data
280
    GENERIC MAP (
281
      g_enable_repack_in  => c_enable_repack_out,
282
      g_enable_repack_out => c_enable_repack_in,
283
      g_in_bypass         => g_pack_bypass,
284
      g_in_dat_w          => g_pack_dat_w,
285
      g_in_nof_words      => g_pack_nof_words,
286
      g_in_symbol_w       => g_pack_symbol_w,
287
      g_out_bypass        => g_in_bypass,
288
      g_out_dat_w         => g_in_dat_w,
289
      g_out_nof_words     => g_in_nof_words,
290
      g_out_symbol_w      => g_in_symbol_w
291
    )
292
    PORT MAP (
293
      rst              => rst,
294
      clk              => clk,
295
 
296
      snk_out          => pack_src_in,
297
      snk_in           => pack_src_out,
298
 
299
      src_in           => unpack_src_in,
300
      src_out          => unpack_src_out
301
    );
302
  END GENERATE;
303
 
304
  unpack_src_out_data <= unpack_src_out.data(g_in_dat_w-1 DOWNTO 0);
305
 
306
  unpack_src_in <= verify_snk_out;
307
  verify_snk_in <= unpack_src_out;
308
 
309
  ------------------------------------------------------------------------------
310
  -- Auxiliary
311
  ------------------------------------------------------------------------------
312
 
313
  -- Map to slv to ease monitoring in wave window
314
  stimuli_src_out_data <= stimuli_src_out.data(g_in_dat_w-1 DOWNTO 0);
315
  verify_snk_in_data   <= verify_snk_in.data(g_in_dat_w-1 DOWNTO 0);
316
 
317
END tb;

powered by: WebSVN 2.1.0

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