1 |
2 |
M_artin |
--==========================================================================================================--
|
2 |
|
|
-- --
|
3 |
|
|
-- Copyright (C) 2011 by Martin Neumann martin@neumanns-mail.de --
|
4 |
|
|
-- --
|
5 |
|
|
-- This source file may be used and distributed without restriction provided that this copyright statement --
|
6 |
|
|
-- is not removed from the file and that any derivative work contains the original copyright notice and --
|
7 |
|
|
-- the associated disclaimer. --
|
8 |
|
|
-- --
|
9 |
|
|
-- This software is provided ''as is'' and without any express or implied warranties, including, but not --
|
10 |
|
|
-- limited to, the implied warranties of merchantability and fitness for a particular purpose. in no event --
|
11 |
|
|
-- shall the author or contributors be liable for any direct, indirect, incidental, special, exemplary, or --
|
12 |
|
|
-- consequential damages (including, but not limited to, procurement of substitute goods or services; loss --
|
13 |
|
|
-- of use, data, or profits; or business interruption) however caused and on any theory of liability, --
|
14 |
|
|
-- whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way --
|
15 |
|
|
-- out of the use of this software, even if advised of the possibility of such damage. --
|
16 |
|
|
-- --
|
17 |
|
|
--==========================================================================================================--
|
18 |
|
|
-- --
|
19 |
|
|
-- File name : usb_commands.vhd --
|
20 |
|
|
-- Author : Martin Neumann martin@neumanns-mail.de --
|
21 |
|
|
-- Description : Defines, functions and procedures for the usb_Stimuli.vhd file - the USB data source for --
|
22 |
|
|
-- the test bench file. --
|
23 |
|
|
-- --
|
24 |
|
|
--==========================================================================================================--
|
25 |
|
|
-- --
|
26 |
|
|
-- Change history --
|
27 |
|
|
-- --
|
28 |
|
|
-- Version / date Description --
|
29 |
|
|
-- --
|
30 |
|
|
-- 01 05 Mar 2011 MN Initial version --
|
31 |
|
|
-- --
|
32 |
|
|
-- End change history --
|
33 |
|
|
--==========================================================================================================--
|
34 |
|
|
-- --
|
35 |
|
|
-- USB control concept --
|
36 |
|
|
-- ------------------- --
|
37 |
|
|
-- The usb signal controls the usb command execution and its proper timing : --
|
38 |
|
|
-- --
|
39 |
|
|
-- Each command in the test case file 'usb_stimuli.vhd' is a procedure call with an output signal 'usb'. -- --
|
40 |
|
|
-- Its states (of type usb_action) control the correct timing sequence of the process 'p_stimuli_bit' in --
|
41 |
|
|
-- the file'usb_master'. This procedure sets the signal usb first to any one of the active states, then --
|
42 |
|
|
-- after completion to inactive (idle). --
|
43 |
|
|
-- --
|
44 |
|
|
--==========================================================================================================--
|
45 |
|
|
-- --
|
46 |
|
|
-- Syntax Examples --
|
47 |
|
|
-- --
|
48 |
|
|
-- Procedure Function, Parameters --
|
49 |
|
|
-- --
|
50 |
|
|
-- list (T_No, 30); Test No listed in transcript and report file --
|
51 |
|
|
-- List ("Any Text Message "); Message any text --
|
52 |
|
|
-- Setup (usb, X"00", X"0"); usb setup: device address, endp address (+CRC5) --
|
53 |
|
|
-- send_D0 (usb, (X"10",X"46",X"11",X"47", --
|
54 |
|
|
-- X"12",X"48",X"13",X"49")); usb write data0 : byte string (+CRC16) --
|
55 |
|
|
-- send_D1 (usb, (X"20",X"36",X"21",X"37", --
|
56 |
|
|
-- X"22",X"38",X"23",X"39")); usb write data1 : byte string (+CRC16) --
|
57 |
|
|
-- send_ACK (usb); usb ACK Handshake --
|
58 |
|
|
-- send_NAK (usb); usb NAK Handshake --
|
59 |
|
|
-- send_STALL(usb); usb Stall Handshake --
|
60 |
|
|
-- send_NYET (usb); usb NYET (No Response Yet) Handshake --
|
61 |
|
|
-- wait_slv (usb); wait until transfer of USB-slave completed --
|
62 |
|
|
-- --
|
63 |
|
|
--==========================================================================================================--
|
64 |
|
|
|
65 |
|
|
LIBRARY IEEE;
|
66 |
|
|
USE IEEE.std_logic_1164.all;
|
67 |
|
|
USE IEEE.std_logic_textio.all;
|
68 |
|
|
USE IEEE.std_logic_arith.all;
|
69 |
|
|
USE IEEE.std_logic_unsigned.all;
|
70 |
|
|
USE std.textio.all;
|
71 |
|
|
|
72 |
|
|
PACKAGE usb_commands IS
|
73 |
|
|
|
74 |
|
|
--==========================================================================================================--
|
75 |
|
|
|
76 |
|
|
TYPE usb_action IS (idle, sync, pid, addr, rd, wr_odd, wr_even, wr_crc5, wr_crc16, reset, send_eop, recv_eop);
|
77 |
|
|
TYPE byte_array IS ARRAY (NATURAL RANGE <>) OF STD_LOGIC_VECTOR(7 DOWNTO 0);
|
78 |
|
|
|
79 |
|
|
SIGNAL usb_status : usb_action;
|
80 |
|
|
SIGNAL usb_busy : BOOLEAN := FALSE;
|
81 |
|
|
SHARED VARIABLE ok : BOOLEAN;
|
82 |
|
|
SHARED VARIABLE sv_usb_byte : STD_LOGIC_VECTOR(7 DOWNTO 0);
|
83 |
|
|
SHARED VARIABLE sv_usb_addr : STD_LOGIC_VECTOR(10 DOWNTO 0);
|
84 |
|
|
SHARED VARIABLE sv_read_loop : BOOLEAN := FALSE;
|
85 |
|
|
FILE screen : TEXT OPEN WRITE_MODE IS "STD_OUTPUT";
|
86 |
|
|
FILE outpdata : TEXT OPEN WRITE_MODE IS "Result.out";
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
PROCEDURE list(message : IN STRING);
|
90 |
|
|
PROCEDURE list(SIGNAL no_out : OUT NATURAL; no_in : IN NATURAL);
|
91 |
|
|
|
92 |
|
|
PROCEDURE end_of_test(stop : IN BOOLEAN := TRUE);
|
93 |
|
|
|
94 |
|
|
--==========================================================================================================--
|
95 |
|
|
|
96 |
|
|
PROCEDURE send_ACK (SIGNAL usb : OUT usb_action);
|
97 |
|
|
|
98 |
|
|
PROCEDURE send_NAK (SIGNAL usb : OUT usb_action);
|
99 |
|
|
|
100 |
|
|
PROCEDURE send_STALL(SIGNAL usb : OUT usb_action);
|
101 |
|
|
|
102 |
|
|
PROCEDURE send_NYET (SIGNAL usb : OUT usb_action);
|
103 |
|
|
|
104 |
|
|
PROCEDURE handshake(SIGNAL usb : OUT usb_action; CONSTANT pid_val : IN std_logic_vector(3 DOWNTO 0));
|
105 |
|
|
|
106 |
|
|
PROCEDURE setup(
|
107 |
|
|
SIGNAL usb : OUT usb_action;
|
108 |
|
|
CONSTANT device_addr : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
|
109 |
|
|
CONSTANT endp_addr : IN STD_LOGIC_VECTOR(3 DOWNTO 0)
|
110 |
|
|
);
|
111 |
|
|
|
112 |
|
|
PROCEDURE in_token(
|
113 |
|
|
SIGNAL usb : OUT usb_action;
|
114 |
|
|
CONSTANT device_addr : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
|
115 |
|
|
CONSTANT endp_addr : IN STD_LOGIC_VECTOR(3 DOWNTO 0)
|
116 |
|
|
);
|
117 |
|
|
|
118 |
|
|
PROCEDURE out_token(
|
119 |
|
|
SIGNAL usb : OUT usb_action;
|
120 |
|
|
CONSTANT device_addr : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
|
121 |
|
|
CONSTANT endp_addr : IN STD_LOGIC_VECTOR(3 DOWNTO 0)
|
122 |
|
|
);
|
123 |
|
|
|
124 |
|
|
PROCEDURE sof_token(
|
125 |
|
|
SIGNAL usb : OUT usb_action;
|
126 |
|
|
CONSTANT frame_no : IN STD_LOGIC_VECTOR(11 DOWNTO 0)
|
127 |
|
|
);
|
128 |
|
|
|
129 |
|
|
PROCEDURE token(
|
130 |
|
|
SIGNAL usb : OUT usb_action;
|
131 |
|
|
CONSTANT pid_val : IN std_logic_vector(3 DOWNTO 0);
|
132 |
|
|
CONSTANT token_val : IN STD_LOGIC_VECTOR(10 DOWNTO 0)
|
133 |
|
|
);
|
134 |
|
|
|
135 |
|
|
PROCEDURE send_d0(SIGNAL usb : OUT usb_action; CONSTANT wr_data : IN byte_array);
|
136 |
|
|
PROCEDURE send_D0(SIGNAL usb : OUT usb_action);
|
137 |
|
|
|
138 |
|
|
PROCEDURE send_d1(SIGNAL usb : OUT usb_action; CONSTANT wr_data : IN byte_array);
|
139 |
|
|
PROCEDURE send_D1(SIGNAL usb : OUT usb_action);
|
140 |
|
|
|
141 |
|
|
PROCEDURE send_d2(SIGNAL usb : OUT usb_action; CONSTANT wr_data : IN byte_array);
|
142 |
|
|
PROCEDURE send_D2(SIGNAL usb : OUT usb_action);
|
143 |
|
|
|
144 |
|
|
PROCEDURE send_dm(SIGNAL usb : OUT usb_action; CONSTANT wr_data : IN byte_array);
|
145 |
|
|
PROCEDURE send_Dm(SIGNAL usb : OUT usb_action);
|
146 |
|
|
|
147 |
|
|
PROCEDURE send_dx(
|
148 |
|
|
SIGNAL usb : OUT usb_action;
|
149 |
|
|
CONSTANT pid_val : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
|
150 |
|
|
CONSTANT wr_data : IN byte_array
|
151 |
|
|
);
|
152 |
|
|
PROCEDURE send_dx(
|
153 |
|
|
SIGNAL usb : OUT usb_action;
|
154 |
|
|
CONSTANT pid_val : IN STD_LOGIC_VECTOR(3 DOWNTO 0)
|
155 |
|
|
);
|
156 |
|
|
|
157 |
|
|
PROCEDURE send_RES(SIGNAL usb : OUT usb_action);
|
158 |
|
|
|
159 |
|
|
PROCEDURE wait_slv(SIGNAL usb : OUT usb_action);
|
160 |
|
|
|
161 |
|
|
--==========================================================================================================--
|
162 |
|
|
-- internal functions and procedures --
|
163 |
|
|
|
164 |
|
|
FUNCTION to_01x(d : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR;
|
165 |
|
|
|
166 |
|
|
FUNCTION hex_to_string(D: STD_LOGIC_VECTOR) RETURN STRING;
|
167 |
|
|
|
168 |
|
|
PROCEDURE HexWrite( VARIABLE L : INOUT LINE;
|
169 |
|
|
CONSTANT VALUE : IN STD_LOGIC_VECTOR;
|
170 |
|
|
CONSTANT JUSTIFIED: IN SIDE := right;
|
171 |
|
|
CONSTANT FIELD : IN WIDTH := 0);
|
172 |
|
|
|
173 |
|
|
PROCEDURE PrintLine (VARIABLE v_Line : INOUT Line);
|
174 |
|
|
|
175 |
|
|
END usb_commands;
|
176 |
|
|
|
177 |
|
|
--==========================================================================================================--
|
178 |
|
|
|
179 |
|
|
PACKAGE BODY usb_commands IS
|
180 |
|
|
|
181 |
|
|
FUNCTION to_01x(d : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR IS
|
182 |
|
|
VARIABLE result : STD_LOGIC_VECTOR (d'RANGE);
|
183 |
|
|
BEGIN
|
184 |
|
|
FOR i IN d'RANGE LOOP
|
185 |
|
|
IF d(i) ='0' OR d(i) ='L' THEN --reduce data to 0, 1 or X
|
186 |
|
|
result(i) := '0';
|
187 |
|
|
ELSIF d(i) ='1' OR d(i) ='H' THEN
|
188 |
|
|
result(i) := '1';
|
189 |
|
|
ELSE
|
190 |
|
|
result(i) := 'X';
|
191 |
|
|
END IF;
|
192 |
|
|
END LOOP;
|
193 |
|
|
RETURN result;
|
194 |
|
|
END to_01x;
|
195 |
|
|
|
196 |
|
|
--==========================================================================================================--
|
197 |
|
|
|
198 |
|
|
FUNCTION hex_to_string(d: STD_LOGIC_VECTOR) RETURN STRING is
|
199 |
|
|
-- vector is padded with leadin '0's if not modula 4 --
|
200 |
|
|
VARIABLE j, k, p : INTEGER;
|
201 |
|
|
VARIABLE d_ext : STD_LOGIC_VECTOR(1 to ((d'LENGTH +3)/4)*4);
|
202 |
|
|
VARIABLE nibble : STD_LOGIC_VECTOR(1 to 4);
|
203 |
|
|
VARIABLE result : STRING(1 TO (d'HIGH +4 - d'LOW)/4);
|
204 |
|
|
VARIABLE hex_val : STRING(1 TO 16) := "0123456789ABCDEF";
|
205 |
|
|
TYPE hex_type IS ARRAY (1 TO 16) OF STD_LOGIC_VECTOR(0 to 3);
|
206 |
|
|
CONSTANT hex_tbl : hex_type :=
|
207 |
|
|
("0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
|
208 |
|
|
"1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111");
|
209 |
|
|
BEGIN
|
210 |
|
|
j := d_ext'LENGTH - d'LENGTH;
|
211 |
|
|
IF j = 0 THEN
|
212 |
|
|
d_ext := to_01x(d);
|
213 |
|
|
ELSE
|
214 |
|
|
d_ext(1 TO j) := (OTHERS =>'0');
|
215 |
|
|
d_ext(j +1 TO d_ext'LENGTH) := to_01x(d);
|
216 |
|
|
END IF;
|
217 |
|
|
j := 1;
|
218 |
|
|
k := 1;
|
219 |
|
|
FOR i IN d_ext'RANGE LOOP
|
220 |
|
|
nibble(j) := d_ext(i);
|
221 |
|
|
IF j = 4 THEN --data nibble is ...
|
222 |
|
|
result(k) := 'X'; -- ... default X ...
|
223 |
|
|
HEX_CHAR: for h in 1 to 16 LOOP
|
224 |
|
|
IF nibble = hex_tbl(h) THEN
|
225 |
|
|
result(k) := hex_val(h); -- ... or 1 to F
|
226 |
|
|
EXIT HEX_CHAR;
|
227 |
|
|
END IF;
|
228 |
|
|
END LOOP;
|
229 |
|
|
k := k+1;
|
230 |
|
|
END IF;
|
231 |
|
|
j := (j MOD 4) +1;
|
232 |
|
|
END LOOP;
|
233 |
|
|
RETURN result;
|
234 |
|
|
END;
|
235 |
|
|
|
236 |
|
|
PROCEDURE HexWrite( VARIABLE L : INOUT LINE;
|
237 |
|
|
CONSTANT VALUE : IN STD_LOGIC_VECTOR;
|
238 |
|
|
CONSTANT JUSTIFIED: IN SIDE := right;
|
239 |
|
|
CONSTANT FIELD : IN WIDTH := 0) IS
|
240 |
|
|
BEGIN
|
241 |
|
|
write (L, STRING'(hex_to_string(VALUE)), JUSTIFIED, FIELD);
|
242 |
|
|
END;
|
243 |
|
|
|
244 |
|
|
--==========================================================================================================--
|
245 |
|
|
|
246 |
|
|
PROCEDURE list(message : IN STRING) IS
|
247 |
|
|
VARIABLE v_Line : line := NULL;
|
248 |
|
|
BEGIN
|
249 |
|
|
WAIT FOR 0 ns;
|
250 |
|
|
write(v_Line, " " & Message);
|
251 |
|
|
write(Screen, v_Line.all & LF);
|
252 |
|
|
writeline(OutpData, v_Line);
|
253 |
|
|
END list;
|
254 |
|
|
|
255 |
|
|
PROCEDURE list(SIGNAL no_out : OUT NATURAL; no_in : IN NATURAL) IS
|
256 |
|
|
VARIABLE v_Line : line := NULL;
|
257 |
|
|
BEGIN
|
258 |
|
|
IF usb_busy THEN -- set in usb_monitor
|
259 |
|
|
WAIT UNTIL NOT usb_busy;
|
260 |
|
|
END IF;
|
261 |
|
|
write(v_Line, STRING'("Test_No "), right, 25);
|
262 |
|
|
write(v_Line, no_in);
|
263 |
|
|
PrintLine(v_Line);
|
264 |
|
|
no_out <= no_in;
|
265 |
|
|
END list;
|
266 |
|
|
|
267 |
|
|
--==========================================================================================================--
|
268 |
|
|
|
269 |
|
|
PROCEDURE end_of_test(stop : IN BOOLEAN := TRUE) IS
|
270 |
|
|
BEGIN
|
271 |
|
|
IF usb_busy THEN -- set in usb_monitor
|
272 |
|
|
WAIT UNTIL NOT usb_busy;
|
273 |
|
|
END IF;
|
274 |
|
|
ASSERT stop = FALSE REPORT"End of Test" SEVERITY FAILURE;
|
275 |
|
|
END end_of_test;
|
276 |
|
|
|
277 |
|
|
--==========================================================================================================--
|
278 |
|
|
|
279 |
|
|
PROCEDURE PrintLine(VARIABLE v_Line : INOUT Line) IS
|
280 |
|
|
BEGIN
|
281 |
|
|
IF v_Line /= NULL THEN
|
282 |
|
|
write(Screen, v_Line.all & LF);
|
283 |
|
|
END IF;
|
284 |
|
|
writeline(OutpData, v_Line);
|
285 |
|
|
END PrintLine;
|
286 |
|
|
|
287 |
|
|
--==========================================================================================================--
|
288 |
|
|
|
289 |
|
|
PROCEDURE send_ACK(SIGNAL usb : OUT usb_action) IS
|
290 |
|
|
BEGIN
|
291 |
|
|
handshake(usb, X"2");
|
292 |
|
|
END send_ACK;
|
293 |
|
|
|
294 |
|
|
PROCEDURE send_NAK(SIGNAL usb : OUT usb_action) IS
|
295 |
|
|
BEGIN
|
296 |
|
|
handshake(usb, X"A");
|
297 |
|
|
END send_NAK;
|
298 |
|
|
|
299 |
|
|
PROCEDURE send_STALL(SIGNAL usb : OUT usb_action) IS
|
300 |
|
|
BEGIN
|
301 |
|
|
handshake(usb, X"E");
|
302 |
|
|
END send_STALL;
|
303 |
|
|
|
304 |
|
|
PROCEDURE send_NYET(SIGNAL usb : OUT usb_action) IS
|
305 |
|
|
BEGIN
|
306 |
|
|
handshake(usb, X"6");
|
307 |
|
|
END send_NYET;
|
308 |
|
|
|
309 |
|
|
PROCEDURE handshake(SIGNAL usb : OUT usb_action; CONSTANT pid_val : IN std_logic_vector(3 DOWNTO 0)) IS
|
310 |
|
|
BEGIN
|
311 |
|
|
usb <= sync;
|
312 |
|
|
WAIT UNTIL usb_status = sync;
|
313 |
|
|
WAIT UNTIL usb_status = idle;
|
314 |
|
|
sv_usb_byte := NOT pid_val & pid_val;
|
315 |
|
|
usb <= pid;
|
316 |
|
|
WAIT UNTIL usb_status = pid;
|
317 |
|
|
WAIT UNTIL usb_status = idle;
|
318 |
|
|
usb <= send_eop;
|
319 |
|
|
WAIT UNTIL usb_status = send_eop;
|
320 |
|
|
WAIT UNTIL usb_status = idle;
|
321 |
|
|
usb <= idle;
|
322 |
|
|
END handshake;
|
323 |
|
|
|
324 |
|
|
--==========================================================================================================--
|
325 |
|
|
|
326 |
|
|
PROCEDURE setup(
|
327 |
|
|
SIGNAL usb : OUT usb_action;
|
328 |
|
|
CONSTANT device_addr : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
|
329 |
|
|
CONSTANT endp_addr : IN STD_LOGIC_VECTOR(3 DOWNTO 0)
|
330 |
|
|
)IS
|
331 |
|
|
BEGIN
|
332 |
|
|
ASSERT device_addr(7) = '0' REPORT" Token device address out of range 0 to 127" SEVERITY FAILURE;
|
333 |
|
|
token(usb, X"D", endp_addr & device_addr(6 DOWNTO 0));
|
334 |
|
|
END setup;
|
335 |
|
|
|
336 |
|
|
PROCEDURE in_token(
|
337 |
|
|
SIGNAL usb : OUT usb_action;
|
338 |
|
|
CONSTANT device_addr : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
|
339 |
|
|
CONSTANT endp_addr : IN STD_LOGIC_VECTOR(3 DOWNTO 0)
|
340 |
|
|
)IS
|
341 |
|
|
BEGIN
|
342 |
|
|
ASSERT device_addr(7) = '0' REPORT" Token device address out of range 0 to 127" SEVERITY FAILURE;
|
343 |
|
|
token(usb, X"9", endp_addr & device_addr(6 DOWNTO 0));
|
344 |
|
|
END in_token;
|
345 |
|
|
|
346 |
|
|
PROCEDURE out_token(
|
347 |
|
|
SIGNAL usb : OUT usb_action;
|
348 |
|
|
CONSTANT device_addr : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
|
349 |
|
|
CONSTANT endp_addr : IN STD_LOGIC_VECTOR(3 DOWNTO 0)
|
350 |
|
|
)IS
|
351 |
|
|
BEGIN
|
352 |
|
|
ASSERT device_addr(7) = '0' REPORT" Token device address out of range 0 to 127" SEVERITY FAILURE;
|
353 |
|
|
token(usb, X"1", endp_addr & device_addr(6 DOWNTO 0));
|
354 |
|
|
END out_token;
|
355 |
|
|
|
356 |
|
|
PROCEDURE sof_token(
|
357 |
|
|
SIGNAL usb : OUT usb_action;
|
358 |
|
|
CONSTANT frame_no : IN STD_LOGIC_VECTOR(11 DOWNTO 0)
|
359 |
|
|
)IS
|
360 |
|
|
BEGIN
|
361 |
|
|
token(usb, X"5", frame_no(10 DOWNTO 0));
|
362 |
|
|
END sof_token;
|
363 |
|
|
|
364 |
|
|
PROCEDURE token(
|
365 |
|
|
SIGNAL usb : OUT usb_action;
|
366 |
|
|
CONSTANT pid_val : IN std_logic_vector(3 DOWNTO 0);
|
367 |
|
|
CONSTANT token_val : IN STD_LOGIC_VECTOR(10 DOWNTO 0)
|
368 |
|
|
)IS
|
369 |
|
|
BEGIN
|
370 |
|
|
usb <= sync;
|
371 |
|
|
WAIT UNTIL usb_status = sync;
|
372 |
|
|
WAIT UNTIL usb_status = idle;
|
373 |
|
|
sv_usb_byte := NOT pid_val & pid_val;
|
374 |
|
|
usb <= pid;
|
375 |
|
|
WAIT UNTIL usb_status = pid;
|
376 |
|
|
WAIT UNTIL usb_status = idle;
|
377 |
|
|
sv_usb_addr := token_val;
|
378 |
|
|
usb <= addr;
|
379 |
|
|
WAIT UNTIL usb_status = addr;
|
380 |
|
|
WAIT UNTIL usb_status = idle;
|
381 |
|
|
usb <= wr_crc5;
|
382 |
|
|
WAIT UNTIL usb_status = wr_crc5;
|
383 |
|
|
WAIT UNTIL usb_status = idle;
|
384 |
|
|
usb <= send_eop;
|
385 |
|
|
WAIT UNTIL usb_status = send_eop;
|
386 |
|
|
WAIT UNTIL usb_status = idle;
|
387 |
|
|
usb <= idle;
|
388 |
|
|
END token;
|
389 |
|
|
|
390 |
|
|
----==========================================================================================================--
|
391 |
|
|
|
392 |
|
|
PROCEDURE send_D0(SIGNAL usb : OUT usb_action; CONSTANT wr_data : IN byte_array) IS
|
393 |
|
|
BEGIN
|
394 |
|
|
send_dx(usb, X"3", wr_data);
|
395 |
|
|
END send_D0;
|
396 |
|
|
|
397 |
|
|
PROCEDURE send_D1(SIGNAL usb : OUT usb_action; CONSTANT wr_data : IN byte_array) IS
|
398 |
|
|
BEGIN
|
399 |
|
|
send_dx(usb, X"B", wr_data);
|
400 |
|
|
END send_D1;
|
401 |
|
|
|
402 |
|
|
PROCEDURE send_D2(SIGNAL usb : OUT usb_action; CONSTANT wr_data : IN byte_array) IS
|
403 |
|
|
BEGIN
|
404 |
|
|
send_dx(usb, X"7", wr_data);
|
405 |
|
|
END send_D2;
|
406 |
|
|
|
407 |
|
|
PROCEDURE send_Dm(SIGNAL usb : OUT usb_action; CONSTANT wr_data : IN byte_array) IS
|
408 |
|
|
BEGIN
|
409 |
|
|
send_dx(usb, X"F", wr_data);
|
410 |
|
|
END send_Dm;
|
411 |
|
|
|
412 |
|
|
PROCEDURE send_dx(
|
413 |
|
|
SIGNAL usb : OUT usb_action;
|
414 |
|
|
CONSTANT pid_val : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
|
415 |
|
|
CONSTANT wr_data : IN byte_array
|
416 |
|
|
)IS
|
417 |
|
|
BEGIN
|
418 |
|
|
usb <= sync;
|
419 |
|
|
WAIT UNTIL usb_status = sync;
|
420 |
|
|
WAIT UNTIL usb_status = idle;
|
421 |
|
|
sv_usb_byte := NOT pid_val & pid_val;
|
422 |
|
|
usb <= pid;
|
423 |
|
|
WAIT UNTIL usb_status = pid;
|
424 |
|
|
WAIT UNTIL usb_status = idle;
|
425 |
|
|
FOR i in 0 TO wr_data'LENGTH -1 LOOP
|
426 |
|
|
sv_usb_byte := wr_data(i);
|
427 |
|
|
IF i MOD 2 = 0 THEN
|
428 |
|
|
usb <= wr_even;
|
429 |
|
|
WAIT UNTIL usb_status = wr_even;
|
430 |
|
|
ELSE
|
431 |
|
|
usb <= wr_odd;
|
432 |
|
|
WAIT UNTIL usb_status = wr_odd;
|
433 |
|
|
END IF;
|
434 |
|
|
WAIT UNTIL usb_status = idle;
|
435 |
|
|
END LOOP;
|
436 |
|
|
usb <= wr_crc16;
|
437 |
|
|
WAIT UNTIL usb_status = wr_crc16;
|
438 |
|
|
WAIT UNTIL usb_status = idle;
|
439 |
|
|
usb <= send_eop;
|
440 |
|
|
WAIT UNTIL usb_status = send_eop;
|
441 |
|
|
WAIT UNTIL usb_status = idle;
|
442 |
|
|
usb <= idle;
|
443 |
|
|
END send_dx;
|
444 |
|
|
|
445 |
|
|
----==========================================================================================================--
|
446 |
|
|
|
447 |
|
|
PROCEDURE send_D0(SIGNAL usb : OUT usb_action) IS
|
448 |
|
|
BEGIN
|
449 |
|
|
send_dx(usb, X"3");
|
450 |
|
|
END send_D0;
|
451 |
|
|
|
452 |
|
|
PROCEDURE send_D1(SIGNAL usb : OUT usb_action) IS
|
453 |
|
|
BEGIN
|
454 |
|
|
send_dx(usb, X"B");
|
455 |
|
|
END send_D1;
|
456 |
|
|
|
457 |
|
|
PROCEDURE send_D2(SIGNAL usb : OUT usb_action) IS
|
458 |
|
|
BEGIN
|
459 |
|
|
send_dx(usb, X"7");
|
460 |
|
|
END send_D2;
|
461 |
|
|
|
462 |
|
|
PROCEDURE send_Dm(SIGNAL usb : OUT usb_action) IS
|
463 |
|
|
BEGIN
|
464 |
|
|
send_dx(usb, X"F");
|
465 |
|
|
END send_Dm;
|
466 |
|
|
|
467 |
|
|
PROCEDURE send_dx(
|
468 |
|
|
SIGNAL usb : OUT usb_action;
|
469 |
|
|
CONSTANT pid_val : IN STD_LOGIC_VECTOR(3 DOWNTO 0)
|
470 |
|
|
)IS
|
471 |
|
|
BEGIN
|
472 |
|
|
usb <= sync;
|
473 |
|
|
WAIT UNTIL usb_status = sync;
|
474 |
|
|
WAIT UNTIL usb_status = idle;
|
475 |
|
|
sv_usb_byte := NOT pid_val & pid_val;
|
476 |
|
|
usb <= pid;
|
477 |
|
|
WAIT UNTIL usb_status = pid;
|
478 |
|
|
WAIT UNTIL usb_status = idle;
|
479 |
|
|
usb <= wr_crc16;
|
480 |
|
|
WAIT UNTIL usb_status = wr_crc16;
|
481 |
|
|
WAIT UNTIL usb_status = idle;
|
482 |
|
|
usb <= send_eop;
|
483 |
|
|
WAIT UNTIL usb_status = send_eop;
|
484 |
|
|
WAIT UNTIL usb_status = idle;
|
485 |
|
|
usb <= idle;
|
486 |
|
|
END send_dx;
|
487 |
|
|
|
488 |
|
|
----==========================================================================================================--
|
489 |
|
|
|
490 |
|
|
PROCEDURE send_RES(SIGNAL usb : OUT usb_action) IS
|
491 |
|
|
BEGIN
|
492 |
|
|
usb <= reset;
|
493 |
|
|
WAIT UNTIL usb_status = reset;
|
494 |
|
|
WAIT UNTIL usb_status = idle;
|
495 |
|
|
usb <= idle;
|
496 |
|
|
END send_RES;
|
497 |
|
|
|
498 |
|
|
----==========================================================================================================--
|
499 |
|
|
|
500 |
|
|
PROCEDURE wait_slv(SIGNAL usb : OUT usb_action) IS
|
501 |
|
|
BEGIN
|
502 |
|
|
usb <= recv_eop;
|
503 |
|
|
WAIT UNTIL usb_status = recv_eop;
|
504 |
|
|
WAIT UNTIL usb_status = idle;
|
505 |
|
|
usb <= idle;
|
506 |
|
|
END wait_slv;
|
507 |
|
|
|
508 |
|
|
----==========================================================================================================--
|
509 |
|
|
END usb_commands;
|