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 3

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

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

powered by: WebSVN 2.1.0

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