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

Subversion Repositories common_components

[/] [common_components/] [trunk/] [tb_common_switch.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 danv
-------------------------------------------------------------------------------
2
--
3 4 danv
-- Copyright 2020
4 3 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 3 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
USE common_pkg_lib.tb_common_pkg.ALL;
26
 
27
ENTITY tb_common_switch IS
28
END tb_common_switch;
29
 
30
-- Usage:
31
--   > as 10
32
--   > run -all
33
--   . expand out_level in the Wave window to check the behaviour of the 16 possible BOOLEAN generic setttings
34
--   . for expected Wave window see tb_common_switch.jpg
35
--
36
-- Description:
37
--   Runs 8 instances in parallel to try all combinations of:
38
--   . g_priority_lo
39
--   . g_or_high
40
--   . g_and_low
41
 
42
 
43
ARCHITECTURE tb OF tb_common_switch IS
44
 
45
  CONSTANT clk_period   : TIME := 10 ns;
46
 
47
  CONSTANT c_nof_generics : NATURAL := 3;
48
 
49
  CONSTANT c_nof_dut          : NATURAL := 2**c_nof_generics;
50
  CONSTANT c_generics_matrix  : t_boolean_matrix(0 TO c_nof_dut-1, 0 TO c_nof_generics-1) := ((FALSE, FALSE, FALSE),
51
                                                                                              (FALSE, FALSE,  TRUE),
52
                                                                                              (FALSE,  TRUE, FALSE),
53
                                                                                              (FALSE,  TRUE,  TRUE),
54
                                                                                              ( TRUE, FALSE, FALSE),
55
                                                                                              ( TRUE, FALSE,  TRUE),
56
                                                                                              ( TRUE,  TRUE, FALSE),
57
                                                                                              ( TRUE,  TRUE,  TRUE));
58
  -- View constants in Wave window
59
  SIGNAL dbg_c_generics_matrix  : t_boolean_matrix(0 TO c_nof_dut-1, 0 TO c_nof_generics-1) := c_generics_matrix;
60
  SIGNAL dbg_state              : NATURAL;
61
 
62
  SIGNAL rst                      : STD_LOGIC;
63
  SIGNAL clk                      : STD_LOGIC := '0';
64
  SIGNAL tb_end                   : STD_LOGIC := '0';
65
  SIGNAL in_hi                    : STD_LOGIC;
66
  SIGNAL in_lo                    : STD_LOGIC;
67
 
68
  SIGNAL dbg_prio_lo              : STD_LOGIC;
69
  SIGNAL dbg_prio_lo_and          : STD_LOGIC;
70
  SIGNAL dbg_prio_lo_or           : STD_LOGIC;
71
  SIGNAL dbg_prio_lo_or_and       : STD_LOGIC;
72
 
73
  SIGNAL dbg_prio_hi              : STD_LOGIC;
74
  SIGNAL dbg_prio_hi_and          : STD_LOGIC;
75
  SIGNAL dbg_prio_hi_or           : STD_LOGIC;
76
  SIGNAL dbg_prio_hi_or_and       : STD_LOGIC;
77
 
78
  SIGNAL out_level : STD_LOGIC_VECTOR(0 TO c_nof_dut-1);
79
 
80
BEGIN
81
 
82
  clk  <= NOT clk OR tb_end AFTER clk_period/2;
83
 
84
  p_in_stimuli : PROCESS
85
  BEGIN
86
    dbg_state <= 0;
87
    rst <= '1';
88
    in_hi <= '0';
89
    in_lo <= '0';
90
    proc_common_wait_some_cycles(clk, 1);
91
    rst <= '0';
92
    proc_common_wait_some_cycles(clk, 10);
93
    -- 1) Single hi pulse
94
    dbg_state <= 1;
95
    in_hi <= '1';
96
    proc_common_wait_some_cycles(clk, 1);
97
    in_hi <= '0';
98
    proc_common_wait_some_cycles(clk, 5);
99
    in_lo <= '1';
100
    proc_common_wait_some_cycles(clk, 1);
101
    in_hi <= '0';
102
    in_lo <= '0';
103
    proc_common_wait_some_cycles(clk, 10);
104
    -- 2) Second hi pulse during active lo gets ignored
105
    dbg_state <= 2;
106
    in_hi <= '1';
107
    proc_common_wait_some_cycles(clk, 1);
108
    in_hi <= '0';
109
    proc_common_wait_some_cycles(clk, 5);
110
    in_hi <= '1';
111
    in_lo <= '1';
112
    proc_common_wait_some_cycles(clk, 1);
113
    in_hi <= '0';
114
    in_lo <= '1';
115
    proc_common_wait_some_cycles(clk, 1);
116
    in_lo <= '0';
117
    proc_common_wait_some_cycles(clk, 10);
118
    -- 3) Second hi pulse while lo is just active, should be recognized as second out pulse
119
    dbg_state <= 3;
120
    in_hi <= '1';
121
    proc_common_wait_some_cycles(clk, 1);
122
    in_hi <= '0';
123
    proc_common_wait_some_cycles(clk, 5);
124
    in_hi <= '1';
125
    in_lo <= '1';
126
    proc_common_wait_some_cycles(clk, 1);
127
    in_hi <= '0';
128
    in_lo <= '0';
129
    proc_common_wait_some_cycles(clk, 5);
130
    proc_common_wait_some_cycles(clk, 1);
131
    in_hi <= '0';
132
    proc_common_wait_some_cycles(clk, 5);
133
    in_lo <= '1';
134
    proc_common_wait_some_cycles(clk, 1);
135
    in_hi <= '0';
136
    in_lo <= '0';
137
    proc_common_wait_some_cycles(clk, 10);
138
    -- 4) Continue active hi with single lo pulse
139
    dbg_state <= 4;
140
    in_hi <= '1';
141
    proc_common_wait_some_cycles(clk, 5);
142
    in_lo <= '1';
143
    proc_common_wait_some_cycles(clk, 1);
144
    in_lo <= '0';
145
    proc_common_wait_some_cycles(clk, 10);
146
    in_lo <= '1';
147
    proc_common_wait_some_cycles(clk, 3);
148
    in_lo <= '0';
149
    proc_common_wait_some_cycles(clk, 10);
150
    in_hi <= '0';
151
    proc_common_wait_some_cycles(clk, 3);
152
    in_lo <= '1';
153
    proc_common_wait_some_cycles(clk, 1);
154
    in_lo <= '0';
155
    proc_common_wait_some_cycles(clk, 10);
156
    -- 5) Active hi immediately after active lo
157
    dbg_state <= 5;
158
    in_hi <= '1';
159
    proc_common_wait_some_cycles(clk, 1);
160
    in_hi <= '0';
161
    proc_common_wait_some_cycles(clk, 5);
162
    in_lo <= '1';
163
    proc_common_wait_some_cycles(clk, 1);
164
    in_lo <= '0';
165
    in_hi <= '1';
166
    proc_common_wait_some_cycles(clk, 1);
167
    in_hi <= '0';
168
    proc_common_wait_some_cycles(clk, 5);
169
    in_lo <= '1';
170
    proc_common_wait_some_cycles(clk, 1);
171
    in_lo <= '0';
172
    proc_common_wait_some_cycles(clk, 10);
173
    -- 6) Simultaneous hi pulse and lo pulse
174
    dbg_state <= 6;
175
    in_hi <= '1';
176
    in_lo <= '1';
177
    proc_common_wait_some_cycles(clk, 1);
178
    in_hi <= '0';
179
    in_lo <= '0';
180
    proc_common_wait_some_cycles(clk, 5);
181
    in_lo <= '1';
182
    proc_common_wait_some_cycles(clk, 1);
183
    in_lo <= '0';
184
    proc_common_wait_some_cycles(clk, 10);
185
    -- 7) Multiple simultaneous hi pulse and lo pulse
186
    dbg_state <= 7;
187
    in_hi <= '1';
188
    in_lo <= '1';
189
    proc_common_wait_some_cycles(clk, 1);
190
    in_hi <= '0';
191
    in_lo <= '0';
192
    proc_common_wait_some_cycles(clk, 5);
193
    in_hi <= '1';
194
    in_lo <= '1';
195
    proc_common_wait_some_cycles(clk, 1);
196
    in_hi <= '0';
197
    in_lo <= '0';
198
    proc_common_wait_some_cycles(clk, 5);
199
    in_hi <= '1';
200
    in_lo <= '1';
201
    proc_common_wait_some_cycles(clk, 1);
202
    in_hi <= '0';
203
    in_lo <= '0';
204
    proc_common_wait_some_cycles(clk, 5);
205
    in_lo <= '1';  -- ensure low output if it was still high
206
    proc_common_wait_some_cycles(clk, 1);
207
    in_lo <= '0';
208
    proc_common_wait_some_cycles(clk, 10);
209
 
210
    dbg_state <= 255;
211
    proc_common_wait_some_cycles(clk, 10);
212
    tb_end <= '1';
213
    WAIT;
214
  END PROCESS;
215
 
216
  dbg_prio_lo              <= out_level(4);
217
  dbg_prio_lo_and          <= out_level(5);
218
  dbg_prio_lo_or           <= out_level(6);
219
  dbg_prio_lo_or_and       <= out_level(7);
220
 
221
  dbg_prio_hi              <= out_level(0);
222
  dbg_prio_hi_and          <= out_level(1);
223
  dbg_prio_hi_or           <= out_level(2);
224
  dbg_prio_hi_or_and       <= out_level(3);
225
 
226
  gen_dut : FOR I IN 0 TO c_nof_dut-1 GENERATE
227
    u_switch : ENTITY work.common_switch
228
    GENERIC MAP (
229
      g_rst_level    => '0',    -- output level at reset.
230
      --g_rst_level    => '1',
231
      g_priority_lo  => c_generics_matrix(I,0),
232
      g_or_high      => c_generics_matrix(I,1),
233
      g_and_low      => c_generics_matrix(I,2)
234
    )
235
    PORT MAP (
236
      clk         => clk,
237
      rst         => rst,
238
      switch_high => in_hi,
239
      switch_low  => in_lo,
240
      out_level   => out_level(I)
241
    );
242
  END GENERATE;
243
 
244
END tb;

powered by: WebSVN 2.1.0

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