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

Subversion Repositories astron_multiplexer

[/] [astron_multiplexer/] [trunk/] [tb_common_multiplexer.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) 2013
4
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
5
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
6
--
7
-- This program is free software: you can redistribute it and/or modify
8
-- it under the terms of the GNU General Public License as published by
9
-- the Free Software Foundation, either version 3 of the License, or
10
-- (at your option) any later version.
11
--
12
-- This program is distributed in the hope that it will be useful,
13
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
-- GNU General Public License for more details.
16
--
17
-- You should have received a copy of the GNU General Public License
18
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
--
20
-------------------------------------------------------------------------------
21
 
22
LIBRARY IEEE, common_pkg_lib, common_components_lib;
23
USE IEEE.std_logic_1164.ALL;
24
USE IEEE.numeric_std.ALL;
25
USE common_pkg_lib.common_pkg.ALL;
26
USE common_pkg_lib.common_lfsr_sequences_pkg.ALL;
27
USE common_pkg_lib.tb_common_pkg.ALL;
28
 
29
-- Purpose: Test bench for common_multiplexer.vhd and common_demultiplexer.vhd
30
-- Usage:
31
-- > as 6
32
-- > run -all
33
--   The tb p_verify self-checks the output by using first a 1->g_nof_streams
34
--   demultiplexer and then a g_nof_streams->1 multiplexer. Both the use the
35
--   same output and input selection so that the expected output data is again
36
--   the same as the input stimuli data.
37
-- Remark:
38
 
39
ENTITY tb_common_multiplexer IS
40
  GENERIC (
41
    g_pipeline_demux_in  : NATURAL := 1;
42
    g_pipeline_demux_out : NATURAL := 1;
43
    g_nof_streams        : NATURAL := 3;
44
    g_pipeline_mux_in    : NATURAL := 1;
45
    g_pipeline_mux_out   : NATURAL := 1;
46
    g_dat_w              : NATURAL := 8;
47
    g_random_in_val      : BOOLEAN := FALSE;
48
    g_test_nof_cycles    : NATURAL := 500
49
  );
50
END tb_common_multiplexer;
51
 
52
ARCHITECTURE tb OF tb_common_multiplexer IS
53
 
54
  CONSTANT clk_period        : TIME := 10 ns;
55
 
56
  CONSTANT c_rl              : NATURAL := 1;
57
  CONSTANT c_init            : NATURAL := 0;
58
 
59
  -- DUT constants
60
  CONSTANT c_pipeline_demux  : NATURAL := g_pipeline_demux_in + g_pipeline_demux_out;
61
  CONSTANT c_pipeline_mux    : NATURAL := g_pipeline_mux_in   + g_pipeline_mux_out;
62
  CONSTANT c_pipeline_total  : NATURAL := c_pipeline_demux + c_pipeline_mux;
63
 
64
  CONSTANT c_sel_w           : NATURAL := ceil_log2(g_nof_streams);
65
 
66
  -- Stimuli
67
  SIGNAL tb_end             : STD_LOGIC := '0';
68
  SIGNAL rst                : STD_LOGIC;
69
  SIGNAL clk                : STD_LOGIC := '1';
70
  SIGNAL ready              : STD_LOGIC := '1';
71
  SIGNAL verify_en          : STD_LOGIC := '0';
72
  SIGNAL random_0           : STD_LOGIC_VECTOR(14 DOWNTO 0) := (OTHERS=>'0');  -- use different lengths to have different random sequences
73
  SIGNAL cnt_en             : STD_LOGIC := '1';
74
 
75
  -- DUT input
76
  SIGNAL in_dat             : STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0) := (OTHERS => '0');
77
  SIGNAL in_val             : STD_LOGIC;
78
  SIGNAL in_sel             : STD_LOGIC_VECTOR(c_sel_w-1 DOWNTO 0) := (OTHERS => '0');
79
 
80
  -- Demux-Mux interface
81
  SIGNAL demux_dat_vec      : STD_LOGIC_VECTOR(g_nof_streams*g_dat_w-1 DOWNTO 0);
82
  SIGNAL demux_val_vec      : STD_LOGIC_VECTOR(g_nof_streams        -1 DOWNTO 0);
83
  SIGNAL demux_val          : STD_LOGIC;
84
  SIGNAL demux_sel          : STD_LOGIC_VECTOR(c_sel_w-1 DOWNTO 0);
85
 
86
  -- DUT output
87
  SIGNAL out_dat            : STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);
88
  SIGNAL out_val            : STD_LOGIC;
89
 
90
  -- Verify
91
  SIGNAL prev_out_dat       : STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);
92
  SIGNAL pipe_dat_vec       : STD_LOGIC_VECTOR(0 TO (c_pipeline_total+1)*g_dat_w-1);
93
  SIGNAL pipe_val_vec       : STD_LOGIC_VECTOR(0 TO (c_pipeline_total+1)*1      -1);
94
 
95
BEGIN
96
 
97
  ------------------------------------------------------------------------------
98
  -- Stimuli
99
  ------------------------------------------------------------------------------
100
 
101
  -- . tb
102
  clk <= NOT clk OR tb_end AFTER clk_period/2;
103
  rst <= '1', '0' AFTER 3*clk_period;
104
  tb_end <= '0', '1' AFTER g_test_nof_cycles*clk_period;
105
 
106
  -- . data
107
  random_0 <= func_common_random(random_0) WHEN rising_edge(clk);
108
 
109
  cnt_en <= '1' WHEN g_random_in_val=FALSE ELSE random_0(random_0'HIGH);
110
 
111
  proc_common_gen_data(c_rl, c_init, rst, clk, cnt_en, ready, in_dat, in_val);
112
 
113
  -- . selection
114
  in_sel <= INCR_UVEC(in_sel, 1) WHEN rising_edge(clk) AND TO_UINT(in_sel)<g_nof_streams-1 ELSE
115
            TO_UVEC(0, c_sel_w)  WHEN rising_edge(clk);  -- periodic selection over all demultiplexer output and multiplexer input streams
116
 
117
  -- . verification
118
  p_verify_en : PROCESS
119
  BEGIN
120
    proc_common_wait_until_high(clk, in_val);
121
    proc_common_wait_some_cycles(clk, c_pipeline_total);
122
 
123
    verify_en <= '1';
124
    WAIT;
125
  END PROCESS;
126
 
127
  ------------------------------------------------------------------------------
128
  -- DUT : 1 --> g_nof_streams --> 1
129
  ------------------------------------------------------------------------------
130
 
131
  -- . Demultiplex single input to output[in_sel]
132
  u_demux : ENTITY work.common_demultiplexer
133
  GENERIC MAP (
134
    g_pipeline_in   => g_pipeline_demux_in,
135
    g_pipeline_out  => g_pipeline_demux_out,
136
    g_nof_out       => g_nof_streams,
137
    g_dat_w         => g_dat_w
138
  )
139
  PORT MAP(
140
    rst         => rst,
141
    clk         => clk,
142
 
143
    in_dat      => in_dat,
144
    in_val      => in_val,
145
 
146
    out_sel     => in_sel,
147
    out_dat     => demux_dat_vec,
148
    out_val     => demux_val_vec
149
  );
150
 
151
  -- . pipeline in_sel to align demux_sel to demux_*_vec
152
  u_pipe_sel : ENTITY common_components_lib.common_pipeline
153
  GENERIC MAP (
154
    g_pipeline  => c_pipeline_demux,
155
    g_in_dat_w  => c_sel_w,
156
    g_out_dat_w => c_sel_w
157
  )
158
  PORT MAP (
159
    rst     => rst,
160
    clk     => clk,
161
    in_dat  => in_sel,
162
    out_dat => demux_sel
163
  );
164
 
165
  demux_val <= demux_val_vec(TO_UINT(demux_sel));
166
 
167
  -- . Multiplex input[demux_sel] back to a single output
168
  u_mux : ENTITY work.common_multiplexer
169
  GENERIC MAP (
170
    g_pipeline_in   => g_pipeline_mux_in,
171
    g_pipeline_out  => g_pipeline_mux_out,
172
    g_nof_in        => g_nof_streams,
173
    g_dat_w         => g_dat_w
174
  )
175
  PORT MAP (
176
    rst         => rst,
177
    clk         => clk,
178
 
179
    in_sel      => demux_sel,
180
    in_dat      => demux_dat_vec,
181
    in_val      => demux_val,
182
 
183
    out_dat     => out_dat,
184
    out_val     => out_val
185
  );
186
 
187
 
188
  ------------------------------------------------------------------------------
189
  -- Verification
190
  ------------------------------------------------------------------------------
191
 
192
  proc_common_verify_data(c_rl, clk, verify_en, ready, out_val, out_dat, prev_out_dat);                   -- verify out_dat assuming incrementing data
193
  proc_common_verify_latency("data",  c_pipeline_total, clk, verify_en, in_dat, pipe_dat_vec, out_dat);   -- verify out_dat using delayed input
194
  proc_common_verify_latency("valid", c_pipeline_total, clk, verify_en, in_val, pipe_val_vec, out_val);   -- verify out_val using delayed input
195
 
196
END tb;

powered by: WebSVN 2.1.0

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