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

Subversion Repositories dp_components

[/] [dp_components/] [trunk/] [tb_dp_latency_adapter.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
-------------------------------------------------------------------------------
2
--
3 4 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 4 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, dp_pkg_lib;
22
USE IEEE.std_logic_1164.ALL;
23
USE IEEE.numeric_std.ALL;
24
USE common_pkg_lib.common_pkg.ALL;
25
USE dp_pkg_lib.dp_stream_pkg.ALL;
26
USE dp_pkg_lib.tb_dp_pkg.ALL;
27
 
28
ENTITY tb_dp_latency_adapter IS
29
END tb_dp_latency_adapter;
30
 
31
 
32
ARCHITECTURE tb OF tb_dp_latency_adapter IS
33
 
34
  -- See tb_dp_pkg.vhd for explanation and run time
35
 
36
  SUBTYPE t_dut_range  IS INTEGER RANGE -1 to INTEGER'HIGH;
37
 
38
  TYPE t_dut_natural_arr  IS ARRAY (t_dut_range RANGE <>) OF NATURAL;
39
  TYPE t_dut_data_arr     IS ARRAY (t_dut_range RANGE <>) OF STD_LOGIC_VECTOR(c_dp_data_w-1 DOWNTO 0);
40
  TYPE t_dut_logic_arr    IS ARRAY (t_dut_range RANGE <>) OF STD_LOGIC;  -- can not use STD_LOGIC_VECTOR because of integer range 
41
 
42
  -- TX ready latency to DUT chain
43
  CONSTANT c_tx_latency     : NATURAL := 3;
44
  CONSTANT c_tx_void        : NATURAL := sel_a_b(c_tx_latency, 1, 0);  -- used to avoid empty range VHDL warnings when c_tx_latency=0
45
 
46
  CONSTANT c_tx_offset_sop  : NATURAL := 3;
47
  CONSTANT c_tx_period_sop  : NATURAL := 7;              -- sop in data valid cycle 3,  10,  17, ...
48
  CONSTANT c_tx_offset_eop  : NATURAL := 5;              -- eop in data valid cycle   5,  12,  19, ...
49
  CONSTANT c_tx_period_eop  : NATURAL := c_tx_period_sop;
50
  CONSTANT c_tx_offset_sync : NATURAL := 3;                  -- sync in data valid cycle 3, 20, 37, ...
51
  CONSTANT c_tx_period_sync : NATURAL := 17;
52
 
53
  -- The TB supports using 1 or more dp_latency_adapter Devices Under Test in a chain. DUT 0 is the first DUT and it
54
  -- gets the tx_data from this test bench, which has index -1. Each next DUT gets its input from the previous DUT,
55
  -- hence the ready latency between DUTs should be the same.
56
  -- The output latency of the previous must equal the input latency of the next DUT, hence it is sufficient to define
57
  -- only the DUT output latencies.
58
  --CONSTANT c_dut_latency    : t_dut_natural_arr := (c_tx_latency, 3);  -- verify single dp_latency_adapter with only wires
59
  --CONSTANT c_dut_latency    : t_dut_natural_arr := (c_tx_latency, 4);  -- verify single dp_latency_adapter with latency increase
60
  --CONSTANT c_dut_latency    : t_dut_natural_arr := (c_tx_latency, 1);  -- verify single dp_latency_adapter with latency decrease
61
  CONSTANT c_dut_latency    : t_dut_natural_arr := (c_tx_latency, 1, 2, 0, 5, 5, 2, 1, 0, 7);
62
 
63
  -- The nof dut latencies in the c_dut_latency array automatically also defines the nof DUTs c_nof_dut.
64
  CONSTANT c_nof_dut        : NATURAL := c_dut_latency'HIGH+1;
65
 
66
  -- RX ready latency from DUT chain
67
  CONSTANT c_rx_latency     : NATURAL := c_dut_latency(c_nof_dut-1);
68
 
69
  CONSTANT c_verify_en_wait : NATURAL := 10+c_nof_dut*2;  -- wait some cycles before asserting verify enable
70
 
71
  CONSTANT c_empty_offset   : NATURAL := 1;
72
  CONSTANT c_channel_offset : NATURAL := 2;
73
 
74
  CONSTANT c_random_w       : NATURAL := 19;
75
 
76
  SIGNAL tb_end         : STD_LOGIC := '0';
77
  SIGNAL clk            : STD_LOGIC := '0';
78
  SIGNAL rst            : STD_LOGIC;
79
  SIGNAL sync           : STD_LOGIC;
80
  SIGNAL lfsr1          : STD_LOGIC_VECTOR(c_random_w-1 DOWNTO 0) := (OTHERS=>'0');
81
  SIGNAL lfsr2          : STD_LOGIC_VECTOR(c_random_w   DOWNTO 0) := (OTHERS=>'0');
82
 
83
  SIGNAL cnt_dat        : STD_LOGIC_VECTOR(c_dp_data_w-1 DOWNTO 0);
84
  SIGNAL cnt_val        : STD_LOGIC;
85
  SIGNAL cnt_en         : STD_LOGIC;
86
 
87
  SIGNAL tx_data        : t_dp_data_arr(0 TO c_tx_latency + c_tx_void);
88
  SIGNAL tx_val         : STD_LOGIC_VECTOR(0 TO c_tx_latency + c_tx_void);
89
 
90
  SIGNAL in_ready       : STD_LOGIC;
91
  SIGNAL in_data        : STD_LOGIC_VECTOR(c_dp_data_w-1 DOWNTO 0);
92
  SIGNAL in_sync        : STD_LOGIC;
93
  SIGNAL in_val         : STD_LOGIC;
94
  SIGNAL in_sop         : STD_LOGIC;
95
  SIGNAL in_eop         : STD_LOGIC;
96
 
97
  -- DUT index -1 = in_data
98
  SIGNAL dut_ready      : t_dut_logic_arr(-1 TO c_nof_dut-1);  -- SISO
99
  SIGNAL dut_data       : t_dut_data_arr(-1 TO c_nof_dut-1);   -- SOSI
100
  SIGNAL dut_empty      : t_dut_data_arr(-1 TO c_nof_dut-1) := (OTHERS=>(OTHERS=>'0'));
101
  SIGNAL dut_channel    : t_dut_data_arr(-1 TO c_nof_dut-1) := (OTHERS=>(OTHERS=>'0'));
102
  SIGNAL dut_sync       : t_dut_logic_arr(-1 TO c_nof_dut-1);
103
  SIGNAL dut_val        : t_dut_logic_arr(-1 TO c_nof_dut-1);
104
  SIGNAL dut_sop        : t_dut_logic_arr(-1 TO c_nof_dut-1);
105
  SIGNAL dut_eop        : t_dut_logic_arr(-1 TO c_nof_dut-1);
106
  -- DUT index c_nof_dut-1 = out_data
107
  SIGNAL dut_siso       : t_dp_siso_arr(-1 TO c_nof_dut-1);
108
  SIGNAL dut_sosi       : t_dp_sosi_arr(-1 TO c_nof_dut-1) := (OTHERS=>c_dp_sosi_rst);
109
 
110
  SIGNAL out_ready      : STD_LOGIC;
111
  SIGNAL prev_out_ready : STD_LOGIC_VECTOR(0 TO c_rx_latency);
112
  SIGNAL out_data       : STD_LOGIC_VECTOR(c_dp_data_w-1 DOWNTO 0);
113
  SIGNAL out_empty      : STD_LOGIC_VECTOR(c_dp_data_w-1 DOWNTO 0);
114
  SIGNAL out_channel    : STD_LOGIC_VECTOR(c_dp_data_w-1 DOWNTO 0);
115
  SIGNAL out_sync       : STD_LOGIC;
116
  SIGNAL out_val        : STD_LOGIC;
117
  SIGNAL out_sop        : STD_LOGIC;
118
  SIGNAL out_eop        : STD_LOGIC;
119
  SIGNAL hold_out_sop   : STD_LOGIC;
120
  SIGNAL prev_out_data  : STD_LOGIC_VECTOR(out_data'RANGE);
121
 
122
  SIGNAL state          : t_dp_state_enum;
123
 
124
  SIGNAL verify_en      : STD_LOGIC;
125
  SIGNAL verify_done    : STD_LOGIC;
126
 
127
  SIGNAL exp_data       : STD_LOGIC_VECTOR(c_dp_data_w-1 DOWNTO 0) := TO_UVEC(19555, c_dp_data_w);
128
 
129
BEGIN
130
 
131
  -- Use intervals marked by sync to start a new test named by state.
132
  --
133
  -- Under all circumstances the out_data should not mis or duplicate a count
134
  -- while out_val is asserted as checked by p_verify.
135
  -- The throughput must remain 100%, with only some increase in latency. This
136
  -- can be checked manually by checking that cnt_val does not toggle when the
137
  -- out_ready is asserted continuously. E.g. check that the out_data value 
138
  -- is sufficiently high given the number of sync intervals that have passed.
139
  --
140
  -- Stimuli to verify the dp_latency_adapter DUT:
141
  --
142
  -- * Use various ready latency combinations in c_dut_latency:
143
  --   .     c_in_latency > c_out_latency = 0
144
  --   .     c_in_latency > c_out_latency > 0
145
  --   .     c_in_latency = c_out_latency = 0
146
  --   .     c_in_latency = c_out_latency > 0
147
  --   . 0 = c_in_latency < c_out_latency
148
  --   . 0 < c_in_latency < c_out_latency
149
  --
150
  -- * Manipulate the stimuli in:
151
  --   . p_cnt_en    : cnt_en not always active when in_ready is asserted
152
  --   . p_out_ready : out_ready not always active
153
 
154
  clk <= NOT clk OR tb_end AFTER clk_period/2;
155
  rst <= '1', '0' AFTER clk_period*7;
156
 
157
  -- Sync interval
158
  proc_dp_sync_interval(clk, sync);
159
 
160
  -- Input data
161
  cnt_val <= in_ready AND cnt_en;
162
 
163
  proc_dp_cnt_dat(rst, clk, cnt_val, cnt_dat);
164
  proc_dp_tx_data(c_tx_latency, rst, clk, cnt_val, cnt_dat, tx_data, tx_val, in_data, in_val);
165
  proc_dp_tx_ctrl(c_tx_offset_sync, c_tx_period_sync, in_data, in_val, in_sync);
166
  proc_dp_tx_ctrl(c_tx_offset_sop, c_tx_period_sop, in_data, in_val, in_sop);
167
  proc_dp_tx_ctrl(c_tx_offset_eop, c_tx_period_eop, in_data, in_val, in_eop);
168
 
169
  -- Stimuli control
170
  proc_dp_count_en(rst, clk, sync, lfsr1, state, verify_done, tb_end, cnt_en);
171
  proc_dp_out_ready(rst, clk, sync, lfsr2, out_ready);
172
 
173
  -- Output verify
174
  proc_dp_verify_en(c_verify_en_wait, rst, clk, sync, verify_en);
175
  proc_dp_verify_data("out_data", c_rx_latency, clk, verify_en, out_ready, out_val, out_data, prev_out_data);
176
  proc_dp_verify_valid(c_rx_latency, clk, verify_en, out_ready, prev_out_ready, out_val);
177
  proc_dp_verify_ctrl(c_tx_offset_sync, c_tx_period_sync, "sync", clk, verify_en, out_data, out_val, out_sync);
178
  proc_dp_verify_ctrl(c_tx_offset_sop, c_tx_period_sop, "sop", clk, verify_en, out_data, out_val, out_sop);
179
  proc_dp_verify_ctrl(c_tx_offset_eop, c_tx_period_eop, "eop", clk, verify_en, out_data, out_val, out_eop);
180
  proc_dp_verify_sop_and_eop(c_rx_latency, FALSE, clk, out_val, out_val, out_sop, out_eop, hold_out_sop);  -- Verify that sop and eop come in pairs, no check on valid between eop and sop
181
  proc_dp_verify_other_sosi("empty", INCR_UVEC(out_data, c_empty_offset), clk, verify_en, out_empty);
182
  proc_dp_verify_other_sosi("channel", INCR_UVEC(out_data, c_channel_offset), clk, verify_en, out_channel);
183
 
184
  -- Check that the test has ran at all
185
  proc_dp_verify_value(e_equal, clk, verify_done, exp_data, out_data);
186
 
187
  ------------------------------------------------------------------------------
188
  -- Chain of 1 or more dp_latency_adapter DUTs
189
  --
190
  -- . Note this also models a series of streaming modules in a data path
191
  --
192
  ------------------------------------------------------------------------------
193
 
194
  -- Map the test bench tx counter data to the input of the chain
195
  in_ready        <= dut_ready(-1);
196
  dut_data(-1)    <=           in_data;
197
  dut_empty(-1)   <= INCR_UVEC(in_data, c_empty_offset);
198
  dut_channel(-1) <= INCR_UVEC(in_data, c_channel_offset);
199
  dut_sync(-1)    <= in_sync;
200
  dut_val(-1)     <= in_val;
201
  dut_sop(-1)     <= in_sop;
202
  dut_eop(-1)     <= in_eop;
203
 
204
  -- map sl, slv to record
205
  dut_ready(-1) <= dut_siso(-1).ready;                           -- SISO
206
  dut_sosi(-1).data(c_dp_data_w-1 DOWNTO 0) <= dut_data(-1);     -- SOSI
207
  dut_sosi(-1).empty                        <= dut_empty(-1)(c_dp_empty_w-1 DOWNTO 0);
208
  dut_sosi(-1).channel                      <= dut_channel(-1)(c_dp_channel_w-1 DOWNTO 0);
209
  dut_sosi(-1).sync                         <= dut_sync(-1);
210
  dut_sosi(-1).valid                        <= dut_val(-1);
211
  dut_sosi(-1).sop                          <= dut_sop(-1);
212
  dut_sosi(-1).eop                          <= dut_eop(-1);
213
 
214
  gen_chain : FOR I IN 0 TO c_nof_dut-1 GENERATE
215
    dut : ENTITY work.dp_latency_adapter
216
    GENERIC MAP (
217
      g_in_latency  => c_dut_latency(I-1),
218
      g_out_latency => c_dut_latency(I)
219
    )
220
    PORT MAP (
221
      rst       => rst,
222
      clk       => clk,
223
      -- ST sink
224
      snk_out   => dut_siso(I-1),
225
      snk_in    => dut_sosi(I-1),
226
      -- ST source
227
      src_in    => dut_siso(I),
228
      src_out   => dut_sosi(I)
229
    );
230
  END GENERATE;
231
 
232
  -- map record to sl, slv
233
  dut_siso(c_nof_dut-1).ready <= dut_ready(c_nof_dut-1);                                                      -- SISO
234
  dut_data(c_nof_dut-1)                               <= dut_sosi(c_nof_dut-1).data(c_dp_data_w-1 DOWNTO 0);  -- SOSI
235
  dut_empty(c_nof_dut-1)(c_dp_empty_w-1 DOWNTO 0)     <= dut_sosi(c_nof_dut-1).empty;
236
  dut_channel(c_nof_dut-1)(c_dp_channel_w-1 DOWNTO 0) <= dut_sosi(c_nof_dut-1).channel;
237
  dut_sync(c_nof_dut-1)                               <= dut_sosi(c_nof_dut-1).sync;
238
  dut_val(c_nof_dut-1)                                <= dut_sosi(c_nof_dut-1).valid;
239
  dut_sop(c_nof_dut-1)                                <= dut_sosi(c_nof_dut-1).sop;
240
  dut_eop(c_nof_dut-1)                                <= dut_sosi(c_nof_dut-1).eop;
241
 
242
  -- Map the output of the DUT chain to the test bench output data
243
  dut_ready(c_nof_dut-1) <= out_ready;
244
  out_data               <= dut_data(c_nof_dut-1);
245
  out_empty              <= dut_empty(c_nof_dut-1);
246
  out_channel            <= dut_channel(c_nof_dut-1);
247
  out_sync               <= dut_sync(c_nof_dut-1);
248
  out_val                <= dut_val(c_nof_dut-1);
249
  out_sop                <= dut_sop(c_nof_dut-1);
250
  out_eop                <= dut_eop(c_nof_dut-1);
251
 
252
END tb;

powered by: WebSVN 2.1.0

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