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

Subversion Repositories dp_pkg

[/] [dp_pkg/] [trunk/] [dp_stream_stimuli.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
-- Purpose:
22
-- . The dp_stream_stimuli generates as stream of packets with counter data.
23
-- Description:
24
--
25
-- Remark:
26
-- . The stimuli empty = 0 because the data in proc_dp_gen_block_data() is
27
--   generated with one symbol per data (because symbol_w = data_w).
28
--
29
-- Usage:
30
-- . See tb_dp_example_no_dut for usage example
31
--
32
 
33
LIBRARY IEEE, common_pkg_lib;
34
USE IEEE.std_logic_1164.ALL;
35
USE IEEE.numeric_std.ALL;
36
USE common_pkg_lib.common_pkg.ALL;
37
USE common_pkg_lib.common_lfsr_sequences_pkg.ALL;
38
USE common_pkg_lib.tb_common_pkg.ALL;
39
USE work.dp_stream_pkg.ALL;
40
USE work.tb_dp_pkg.ALL;
41
 
42
 
43
ENTITY dp_stream_stimuli IS
44
  GENERIC (
45
    g_instance_nr    : NATURAL := 0;
46
    -- flow control
47
    g_random_w       : NATURAL := 15;                       -- use different random width for stimuli and for verify to have different random sequences
48
    g_pulse_active   : NATURAL := 1;
49
    g_pulse_period   : NATURAL := 2;
50
    g_flow_control   : t_dp_flow_control_enum := e_active;  -- always active, random or pulse flow control
51
    -- initializations
52
    g_sync_period    : NATURAL := 10;
53
    g_sync_offset    : NATURAL := 0;
54
    g_data_init      : NATURAL := 0;    -- choose some easy to recognize and unique value, data will increment at every valid
55
    g_bsn_init       : STD_LOGIC_VECTOR(c_dp_stream_bsn_w-1 DOWNTO 0) := TO_DP_BSN(0);  -- X"0877665544332211", bsn will increment at every sop
56
    g_err_init       : NATURAL := 247;  -- choose some easy to recognize and unique value
57
    g_err_incr       : NATURAL := 1;    -- when 0 keep fixed at init value, when 1 increment at every sop
58
    g_channel_init   : NATURAL := 5;    -- choose some easy to recognize and unique value
59
    g_channel_incr   : NATURAL := 1;    -- when 0 keep fixed at init value, when 1 increment at every sop
60
    -- specific
61
    g_in_dat_w       : NATURAL := 32;
62
    g_nof_repeat     : NATURAL := 5;
63
    g_pkt_len        : NATURAL := 16;
64 5 danv
    g_pkt_gap        : NATURAL := 4;
65
    g_wait_last_evt  : NATURAL := 100   -- number of clk cycles to wait with last_snk_in_evt after finishing the stimuli
66 2 danv
  );
67
  PORT (
68
    rst               : IN  STD_LOGIC;
69
    clk               : IN  STD_LOGIC;
70
 
71
    -- Generate stimuli
72
    src_in            : IN  t_dp_siso := c_dp_siso_rdy;
73
    src_out           : OUT t_dp_sosi;
74
 
75
    -- End of stimuli
76
    last_snk_in       : OUT t_dp_sosi;   -- expected verify_snk_in after end of stimuli 
77
    last_snk_in_evt   : OUT STD_LOGIC;   -- trigger verify to verify the last_snk_in 
78
    tb_end            : OUT STD_LOGIC    -- signal end of tb as far as this dp_stream_stimuli is concerned
79
  );
80
END dp_stream_stimuli;
81
 
82
 
83
ARCHITECTURE str OF dp_stream_stimuli IS
84
 
85
  SIGNAL random          : STD_LOGIC_VECTOR(g_random_w-1 DOWNTO 0) := TO_UVEC(g_instance_nr, g_random_w);  -- use different initialization to have different random sequences per stream
86
  SIGNAL pulse           : STD_LOGIC;
87
  SIGNAL pulse_en        : STD_LOGIC := '1';
88
 
89
  SIGNAL stimuli_en      : STD_LOGIC := '1';
90
  SIGNAL src_out_data    : STD_LOGIC_VECTOR(g_in_dat_w-1 DOWNTO 0);
91
  SIGNAL i_src_out       : t_dp_sosi;
92
 
93
BEGIN
94
 
95
  src_out <= i_src_out;
96
 
97
  ------------------------------------------------------------------------------
98
  -- STREAM CONTROL
99
  ------------------------------------------------------------------------------
100
 
101
  random <= func_common_random(random) WHEN rising_edge(clk);
102
 
103
  proc_common_gen_duty_pulse(g_pulse_active, g_pulse_period, '1', rst, clk, pulse_en, pulse);
104
 
105
  stimuli_en <= '1'                 WHEN g_flow_control=e_active ELSE
106
                random(random'HIGH) WHEN g_flow_control=e_random ELSE
107
                pulse               WHEN g_flow_control=e_pulse;
108
 
109
  ------------------------------------------------------------------------------
110
  -- DATA GENERATION
111
  ------------------------------------------------------------------------------
112
 
113
  -- Generate data path input data
114
  p_stimuli_st : PROCESS
115
    VARIABLE v_sosi : t_dp_sosi := c_dp_sosi_rst;
116
    VARIABLE v_last : t_dp_sosi := c_dp_sosi_rst;
117
  BEGIN
118
    -- Initialisations
119
    last_snk_in <= c_dp_sosi_rst;
120
    last_snk_in_evt <= '0';
121
    tb_end <= '0';
122
 
123
    -- Adjust initial sosi field values by -1 to compensate for auto increment
124
    v_sosi.bsn     := INCR_UVEC(g_bsn_init,                    -1);
125
    v_sosi.channel := INCR_UVEC(TO_DP_CHANNEL(g_channel_init), -g_channel_incr);
126
    v_sosi.data    := INCR_UVEC(TO_DP_DATA(g_data_init),       -g_pkt_len);
127
    v_sosi.err     := INCR_UVEC(TO_DP_ERROR(g_err_init),       -g_err_incr);
128
 
129
    i_src_out <= c_dp_sosi_rst;
130
    proc_common_wait_until_low(clk, rst);
131
    proc_common_wait_some_cycles(clk, 5);
132
 
133
    -- Generate g_nof_repeat packets
134
    FOR I IN 0 TO g_nof_repeat-1 LOOP
135
      -- Auto increment v_sosi field values for this packet
136
      v_sosi.bsn     := INCR_UVEC(v_sosi.bsn, 1);
137
      v_sosi.sync    := sel_a_b((UNSIGNED(v_sosi.bsn) MOD g_sync_period) = g_sync_offset, '1', '0');  -- insert sync starting at BSN=g_sync_offset and with period g_sync_period
138
      v_sosi.channel := INCR_UVEC(v_sosi.channel, g_channel_incr);
139
      v_sosi.data    := INCR_UVEC(v_sosi.data, g_pkt_len);
140
      v_sosi.data    := RESIZE_DP_DATA(v_sosi.data(g_in_dat_w-1 DOWNTO 0));  -- wrap when >= 2**g_in_dat_w
141
      v_sosi.err     := INCR_UVEC(v_sosi.err, g_err_incr);
142
 
143
      -- Send packet
144
      proc_dp_gen_block_data(g_in_dat_w, TO_UINT(v_sosi.data), g_pkt_len, TO_UINT(v_sosi.channel), TO_UINT(v_sosi.err), v_sosi.sync, v_sosi.bsn, clk, stimuli_en, src_in, i_src_out);
145
 
146
      -- Insert optional gap between the packets
147
      proc_common_wait_some_cycles(clk, g_pkt_gap);
148
 
149
      -- Update v_last.sync
150
      IF v_sosi.sync='1' THEN v_last.sync := '1'; END IF;
151
    END LOOP;
152
 
153
    -- Update v_last control
154
    IF g_nof_repeat>0 THEN
155
      v_last.sop := '1';
156
      v_last.eop := '1';
157
      v_last.valid := '1';
158
    END IF;
159
 
160
    -- Determine and keep last expected sosi field values after end of stimuli
161
    -- . e_qual
162
    v_last.bsn     := STD_LOGIC_VECTOR( UNSIGNED(g_bsn_init) + g_nof_repeat-1);
163
    v_last.channel := TO_DP_CHANNEL(g_channel_init           + (g_nof_repeat-1)*g_channel_incr);
164
    v_last.err     := TO_DP_ERROR(g_err_init                 + (g_nof_repeat-1)*g_err_incr);
165
    -- . account for g_pkt_len
166
    v_last.data    := INCR_UVEC(v_sosi.data, g_pkt_len-1);
167
    v_last.data    := RESIZE_DP_DATA(v_last.data(g_in_dat_w-1 DOWNTO 0));  -- wrap when >= 2**g_in_dat_w
168
    last_snk_in <= v_last;
169
 
170
    -- Signal end of stimuli
171 5 danv
    proc_common_wait_some_cycles(clk, g_wait_last_evt);  -- latency from stimuli to verify depends on the flow control, so wait sufficiently long for last packet to have passed through
172 2 danv
    proc_common_gen_pulse(clk, last_snk_in_evt);
173
    proc_common_wait_some_cycles(clk, 50);
174
    tb_end <= '1';
175
    WAIT;
176
  END PROCESS;
177
 
178
  ------------------------------------------------------------------------------
179
  -- Auxiliary
180
  ------------------------------------------------------------------------------
181
 
182
  -- Map to slv to ease monitoring in wave window
183
  src_out_data <= i_src_out.data(g_in_dat_w-1 DOWNTO 0);
184
 
185
END str;

powered by: WebSVN 2.1.0

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