1 |
11 |
arniml |
-------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
|
|
-- Testbench for the
|
4 |
|
|
-- GCpad controller core
|
5 |
|
|
--
|
6 |
|
|
-- $Id: tb.vhd,v 1.1 2004-10-07 21:24:06 arniml Exp $
|
7 |
|
|
--
|
8 |
|
|
-- Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
|
9 |
|
|
--
|
10 |
|
|
-- All rights reserved
|
11 |
|
|
--
|
12 |
|
|
-- Redistribution and use in source and synthezised forms, with or without
|
13 |
|
|
-- modification, are permitted provided that the following conditions are met:
|
14 |
|
|
--
|
15 |
|
|
-- Redistributions of source code must retain the above copyright notice,
|
16 |
|
|
-- this list of conditions and the following disclaimer.
|
17 |
|
|
--
|
18 |
|
|
-- Redistributions in synthesized form must reproduce the above copyright
|
19 |
|
|
-- notice, this list of conditions and the following disclaimer in the
|
20 |
|
|
-- documentation and/or other materials provided with the distribution.
|
21 |
|
|
--
|
22 |
|
|
-- Neither the name of the author nor the names of other contributors may
|
23 |
|
|
-- be used to endorse or promote products derived from this software without
|
24 |
|
|
-- specific prior written permission.
|
25 |
|
|
--
|
26 |
|
|
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
27 |
|
|
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
28 |
|
|
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
29 |
|
|
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
30 |
|
|
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
31 |
|
|
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
32 |
|
|
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
33 |
|
|
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
34 |
|
|
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
35 |
|
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
36 |
|
|
-- POSSIBILITY OF SUCH DAMAGE.
|
37 |
|
|
--
|
38 |
|
|
-- Please report bugs to the author, but before you do so, please
|
39 |
|
|
-- make sure that this is not a derivative work and that
|
40 |
|
|
-- you have the latest version of this file.
|
41 |
|
|
--
|
42 |
|
|
-- The latest version of this file can be found at:
|
43 |
|
|
-- http://www.opencores.org/cvsweb.shtml/gamepads/
|
44 |
|
|
--
|
45 |
|
|
-- The project homepage is located at:
|
46 |
|
|
-- http://www.opencores.org/projects.cgi/web/gamepads/overview
|
47 |
|
|
--
|
48 |
|
|
-------------------------------------------------------------------------------
|
49 |
|
|
|
50 |
|
|
library ieee;
|
51 |
|
|
use ieee.std_logic_1164.all;
|
52 |
|
|
|
53 |
|
|
entity tb is
|
54 |
|
|
|
55 |
|
|
end tb;
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
use work.gcpad_pack.all;
|
59 |
|
|
|
60 |
|
|
architecture behav of tb is
|
61 |
|
|
|
62 |
|
|
constant period_c : time := 100 ns;
|
63 |
|
|
constant reset_level_c : natural := 0;
|
64 |
|
|
constant clocks_per_1us_c : natural := 10;
|
65 |
|
|
|
66 |
|
|
component gcpad_basic
|
67 |
|
|
generic (
|
68 |
|
|
reset_level_g : integer := 0;
|
69 |
|
|
clocks_per_1us_g : integer := 2
|
70 |
|
|
);
|
71 |
|
|
port (
|
72 |
|
|
clk_i : in std_logic;
|
73 |
|
|
reset_i : in std_logic;
|
74 |
|
|
pad_request_i : in std_logic;
|
75 |
|
|
pad_avail_o : out std_logic;
|
76 |
|
|
pad_data_io : inout std_logic;
|
77 |
|
|
but_a_o : out std_logic;
|
78 |
|
|
but_b_o : out std_logic;
|
79 |
|
|
but_x_o : out std_logic;
|
80 |
|
|
but_y_o : out std_logic;
|
81 |
|
|
but_z_o : out std_logic;
|
82 |
|
|
but_start_o : out std_logic;
|
83 |
|
|
but_tl_o : out std_logic;
|
84 |
|
|
but_tr_o : out std_logic;
|
85 |
|
|
but_left_o : out std_logic;
|
86 |
|
|
but_right_o : out std_logic;
|
87 |
|
|
but_up_o : out std_logic;
|
88 |
|
|
but_down_o : out std_logic;
|
89 |
|
|
ana_joy_x_o : out std_logic_vector(7 downto 0);
|
90 |
|
|
ana_joy_y_o : out std_logic_vector(7 downto 0);
|
91 |
|
|
ana_c_x_o : out std_logic_vector(7 downto 0);
|
92 |
|
|
ana_c_y_o : out std_logic_vector(7 downto 0);
|
93 |
|
|
ana_l_o : out std_logic_vector(7 downto 0);
|
94 |
|
|
ana_r_o : out std_logic_vector(7 downto 0)
|
95 |
|
|
);
|
96 |
|
|
end component;
|
97 |
|
|
|
98 |
|
|
signal clk_s : std_logic;
|
99 |
|
|
signal reset_s : std_logic;
|
100 |
|
|
|
101 |
|
|
signal pad_data_s : std_logic;
|
102 |
|
|
|
103 |
|
|
signal buttons_s : std_logic_vector(64 downto 0);
|
104 |
|
|
|
105 |
|
|
signal pad_request_s : std_logic;
|
106 |
|
|
signal pad_avail_s : std_logic;
|
107 |
|
|
|
108 |
|
|
begin
|
109 |
|
|
|
110 |
|
|
basic_b : gcpad_basic
|
111 |
|
|
generic map (
|
112 |
|
|
reset_level_g => reset_level_c,
|
113 |
|
|
clocks_per_1us_g => clocks_per_1us_c
|
114 |
|
|
)
|
115 |
|
|
port map (
|
116 |
|
|
clk_i => clk_s,
|
117 |
|
|
reset_i => reset_s,
|
118 |
|
|
pad_request_i => pad_request_s,
|
119 |
|
|
pad_avail_o => pad_avail_s,
|
120 |
|
|
pad_data_io => pad_data_s,
|
121 |
|
|
but_a_o => buttons_s(56),
|
122 |
|
|
but_b_o => buttons_s(57),
|
123 |
|
|
but_x_o => buttons_s(58),
|
124 |
|
|
but_y_o => buttons_s(59),
|
125 |
|
|
but_z_o => buttons_s(52),
|
126 |
|
|
but_start_o => buttons_s(60),
|
127 |
|
|
but_tl_o => buttons_s(54),
|
128 |
|
|
but_tr_o => buttons_s(53),
|
129 |
|
|
but_left_o => buttons_s(48),
|
130 |
|
|
but_right_o => buttons_s(49),
|
131 |
|
|
but_up_o => buttons_s(51),
|
132 |
|
|
but_down_o => buttons_s(50),
|
133 |
|
|
ana_joy_x_o => buttons_s(47 downto 40),
|
134 |
|
|
ana_joy_y_o => buttons_s(39 downto 32),
|
135 |
|
|
ana_c_x_o => buttons_s(31 downto 24),
|
136 |
|
|
ana_c_y_o => buttons_s(23 downto 16),
|
137 |
|
|
ana_l_o => buttons_s(15 downto 8),
|
138 |
|
|
ana_r_o => buttons_s( 7 downto 0)
|
139 |
|
|
);
|
140 |
|
|
|
141 |
|
|
buttons_s(64) <= '0';
|
142 |
|
|
buttons_s(63 downto 61) <= (others => '0');
|
143 |
|
|
buttons_s(55) <= '1';
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
-- pullup on pad_data
|
147 |
|
|
-- pad_data_s <= 'H';
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
stimuli: process
|
151 |
|
|
|
152 |
|
|
procedure check_request is
|
153 |
|
|
constant request_c : std_logic_vector(24 downto 0) := "H0H000000HH000000000000H0";
|
154 |
|
|
begin
|
155 |
|
|
|
156 |
|
|
-- read 25 bits from pad_data_s
|
157 |
|
|
for i in 0 to 24 loop
|
158 |
|
|
wait until pad_data_s = '0';
|
159 |
|
|
|
160 |
|
|
wait for 2 * clocks_per_1us_c * period_c;
|
161 |
|
|
if pad_data_s /= request_c(i) then
|
162 |
|
|
assert false
|
163 |
|
|
report "Found wrong level on pad_data_s while checking request packet!"
|
164 |
|
|
severity error;
|
165 |
|
|
end if;
|
166 |
|
|
|
167 |
|
|
wait for 2 * clocks_per_1us_c * period_c;
|
168 |
|
|
|
169 |
|
|
end loop;
|
170 |
|
|
|
171 |
|
|
|
172 |
|
|
end check_request;
|
173 |
|
|
|
174 |
|
|
procedure send_packet(packet : in std_logic_vector(64 downto 0)) is
|
175 |
|
|
variable time_low_v, time_high_v : time;
|
176 |
|
|
begin
|
177 |
|
|
-- send request;
|
178 |
|
|
pad_request_s <= '1';
|
179 |
|
|
wait for 1 * period_c;
|
180 |
|
|
pad_request_s <= '0';
|
181 |
|
|
|
182 |
|
|
check_request;
|
183 |
|
|
|
184 |
|
|
wait for 10 * 40 * period_c;
|
185 |
|
|
|
186 |
|
|
for i in packet'high downto 0 loop
|
187 |
|
|
if packet(i) = '0' then
|
188 |
|
|
time_low_v := 3 us;
|
189 |
|
|
time_high_v := 1 us;
|
190 |
|
|
else
|
191 |
|
|
time_low_v := 1 us;
|
192 |
|
|
time_high_v := 3 us;
|
193 |
|
|
end if;
|
194 |
|
|
|
195 |
|
|
pad_data_s <= '0';
|
196 |
|
|
wait for time_low_v;
|
197 |
|
|
|
198 |
|
|
pad_data_s <= 'H';
|
199 |
|
|
wait for time_high_v;
|
200 |
|
|
|
201 |
|
|
end loop;
|
202 |
|
|
|
203 |
|
|
wait until pad_avail_s = '1';
|
204 |
|
|
wait for 10 * period_c;
|
205 |
|
|
|
206 |
|
|
-- check result
|
207 |
|
|
for i in 1 to packet'high loop
|
208 |
|
|
assert packet(i) = buttons_s(i-1)
|
209 |
|
|
report "Button mismatch!"
|
210 |
|
|
severity error;
|
211 |
|
|
end loop;
|
212 |
|
|
|
213 |
|
|
end send_packet;
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
procedure timeout_gcpad is
|
217 |
|
|
begin
|
218 |
|
|
-- send request;
|
219 |
|
|
pad_request_s <= '1';
|
220 |
|
|
wait for 1 * period_c;
|
221 |
|
|
pad_request_s <= '0';
|
222 |
|
|
|
223 |
|
|
check_request;
|
224 |
|
|
|
225 |
|
|
wait until pad_avail_s = '1';
|
226 |
|
|
wait for 10 * period_c;
|
227 |
|
|
|
228 |
|
|
end timeout_gcpad;
|
229 |
|
|
|
230 |
|
|
begin
|
231 |
|
|
pad_data_s <= 'H';
|
232 |
|
|
pad_request_s <= '0';
|
233 |
|
|
|
234 |
|
|
wait until reset_s = '1';
|
235 |
|
|
wait for period_c * 4;
|
236 |
|
|
|
237 |
|
|
timeout_gcpad;
|
238 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000000000000000000001");
|
239 |
|
|
wait for clocks_per_1us_c * 100 * period_c;
|
240 |
|
|
send_packet(packet => "00011111111111111111111111111111111111111111111111111111111111111");
|
241 |
|
|
send_packet(packet => "00010000100000000000000000000000000000000000000000000000000000001");
|
242 |
|
|
send_packet(packet => "00001000100000000000000000000000000000000000000000000000000000001");
|
243 |
|
|
send_packet(packet => "00000100100000000000000000000000000000000000000000000000000000001");
|
244 |
|
|
send_packet(packet => "00000010100000000000000000000000000000000000000000000000000000001");
|
245 |
|
|
send_packet(packet => "00000001100000000000000000000000000000000000000000000000000000001");
|
246 |
|
|
send_packet(packet => "00001010101010101010101010101010101010101010101010101010101010101");
|
247 |
|
|
send_packet(packet => "00010101110101010101010101010101010101010101010101010101010101011");
|
248 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000000000000000000001");
|
249 |
|
|
send_packet(packet => "00000000110000000000000000000000000000000000000000000000000000001");
|
250 |
|
|
send_packet(packet => "00000000101000000000000000000000000000000000000000000000000000001");
|
251 |
|
|
send_packet(packet => "00000000100100000000000000000000000000000000000000000000000000001");
|
252 |
|
|
send_packet(packet => "00000000100010000000000000000000000000000000000000000000000000001");
|
253 |
|
|
send_packet(packet => "00000000100001000000000000000000000000000000000000000000000000001");
|
254 |
|
|
send_packet(packet => "00000000100000100000000000000000000000000000000000000000000000001");
|
255 |
|
|
send_packet(packet => "00000000100000010000000000000000000000000000000000000000000000001");
|
256 |
|
|
send_packet(packet => "00000000100000001000000000000000000000000000000000000000000000001");
|
257 |
|
|
send_packet(packet => "00000000100000000100000000000000000000000000000000000000000000001");
|
258 |
|
|
send_packet(packet => "00000000100000000010000000000000000000000000000000000000000000001");
|
259 |
|
|
send_packet(packet => "00000000100000000001000000000000000000000000000000000000000000001");
|
260 |
|
|
send_packet(packet => "00000000100000000000100000000000000000000000000000000000000000001");
|
261 |
|
|
send_packet(packet => "00000000100000000000010000000000000000000000000000000000000000001");
|
262 |
|
|
send_packet(packet => "00000000100000000000001000000000000000000000000000000000000000001");
|
263 |
|
|
send_packet(packet => "00000000100000000000000100000000000000000000000000000000000000001");
|
264 |
|
|
send_packet(packet => "00000000100000000000000010000000000000000000000000000000000000001");
|
265 |
|
|
send_packet(packet => "00000000100000000000000001000000000000000000000000000000000000001");
|
266 |
|
|
send_packet(packet => "00000000100000000000000000100000000000000000000000000000000000001");
|
267 |
|
|
send_packet(packet => "00000000100000000000000000010000000000000000000000000000000000001");
|
268 |
|
|
send_packet(packet => "00000000100000000000000000001000000000000000000000000000000000001");
|
269 |
|
|
send_packet(packet => "00000000100000000000000000000100000000000000000000000000000000001");
|
270 |
|
|
send_packet(packet => "00000000100000000000000000000010000000000000000000000000000000001");
|
271 |
|
|
send_packet(packet => "00000000100000000000000000000001000000000000000000000000000000001");
|
272 |
|
|
send_packet(packet => "00000000100000000000000000000000100000000000000000000000000000001");
|
273 |
|
|
send_packet(packet => "00000000100000000000000000000000010000000000000000000000000000001");
|
274 |
|
|
send_packet(packet => "00000000100000000000000000000000001000000000000000000000000000001");
|
275 |
|
|
send_packet(packet => "00000000100000000000000000000000000100000000000000000000000000001");
|
276 |
|
|
send_packet(packet => "00000000100000000000000000000000000010000000000000000000000000001");
|
277 |
|
|
send_packet(packet => "00000000100000000000000000000000000001000000000000000000000000001");
|
278 |
|
|
send_packet(packet => "00000000100000000000000000000000000000100000000000000000000000001");
|
279 |
|
|
send_packet(packet => "00000000100000000000000000000000000000010000000000000000000000001");
|
280 |
|
|
send_packet(packet => "00000000100000000000000000000000000000001000000000000000000000001");
|
281 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000100000000000000000000001");
|
282 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000010000000000000000000001");
|
283 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000001000000000000000000001");
|
284 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000100000000000000000001");
|
285 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000010000000000000000001");
|
286 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000001000000000000000001");
|
287 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000100000000000000001");
|
288 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000010000000000000001");
|
289 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000001000000000000001");
|
290 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000000100000000000001");
|
291 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000000010000000000001");
|
292 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000000001000000000001");
|
293 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000000000100000000001");
|
294 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000000000010000000001");
|
295 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000000000001000000001");
|
296 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000000000000100000001");
|
297 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000000000000010000001");
|
298 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000000000000001000001");
|
299 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000000000000000100001");
|
300 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000000000000000010001");
|
301 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000000000000000001001");
|
302 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000000000000000000101");
|
303 |
|
|
send_packet(packet => "00000000100000000000000000000000000000000000000000000000000000011");
|
304 |
|
|
|
305 |
|
|
|
306 |
|
|
wait for period_c * 2*40;
|
307 |
|
|
assert false
|
308 |
|
|
report "End of simulation reached."
|
309 |
|
|
severity failure;
|
310 |
|
|
|
311 |
|
|
end process stimuli;
|
312 |
|
|
|
313 |
|
|
|
314 |
|
|
|
315 |
|
|
-----------------------------------------------------------------------------
|
316 |
|
|
-- Clock Generator
|
317 |
|
|
-----------------------------------------------------------------------------
|
318 |
|
|
clk: process
|
319 |
|
|
begin
|
320 |
|
|
clk_s <= '0';
|
321 |
|
|
wait for period_c / 2;
|
322 |
|
|
clk_s <= '1';
|
323 |
|
|
wait for period_c / 2;
|
324 |
|
|
end process clk;
|
325 |
|
|
|
326 |
|
|
|
327 |
|
|
-----------------------------------------------------------------------------
|
328 |
|
|
-- Reset Generator
|
329 |
|
|
-----------------------------------------------------------------------------
|
330 |
|
|
reset: process
|
331 |
|
|
begin
|
332 |
|
|
if reset_level_c = 0 then
|
333 |
|
|
reset_s <= '0';
|
334 |
|
|
else
|
335 |
|
|
reset_s <= '1';
|
336 |
|
|
end if;
|
337 |
|
|
|
338 |
|
|
wait for period_c * 4 + 10 ns;
|
339 |
|
|
|
340 |
|
|
reset_s <= not reset_s;
|
341 |
|
|
|
342 |
|
|
wait;
|
343 |
|
|
end process reset;
|
344 |
|
|
|
345 |
|
|
end behav;
|
346 |
|
|
|
347 |
|
|
|
348 |
|
|
-------------------------------------------------------------------------------
|
349 |
|
|
-- File History:
|
350 |
|
|
--
|
351 |
|
|
-- $Log: not supported by cvs2svn $
|
352 |
|
|
-------------------------------------------------------------------------------
|