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_tc_02.vhd --
|
20 |
|
|
-- Author : Martin Neumann martin@neumanns-mail.de --
|
21 |
|
|
-- Description : Copy and rename this file to usb_stimuli.vhd before running a new simulation! --
|
22 |
|
|
-- --
|
23 |
|
|
--==========================================================================================================--
|
24 |
|
|
-- --
|
25 |
|
|
-- Change history --
|
26 |
|
|
-- --
|
27 |
|
|
-- Version / date Description --
|
28 |
|
|
-- --
|
29 |
|
|
-- 01 05 Mar 2011 MN Initial version --
|
30 |
|
|
-- --
|
31 |
|
|
-- End change history --
|
32 |
|
|
--==========================================================================================================--
|
33 |
|
|
|
34 |
|
|
LIBRARY work, IEEE;
|
35 |
|
|
USE IEEE.std_logic_1164.ALL;
|
36 |
|
|
USE IEEE.std_logic_arith.ALL;
|
37 |
|
|
USE work.usb_commands.ALL;
|
38 |
|
|
|
39 |
|
|
ENTITY USB_Stimuli IS PORT(
|
40 |
|
|
-- Test Control Interface --
|
41 |
|
|
USB : OUT usb_action;
|
42 |
|
|
t_no : OUT NATURAL;
|
43 |
|
|
-- Application Interface
|
44 |
|
|
clk : IN STD_LOGIC;
|
45 |
|
|
rst_neg_ext : OUT STD_LOGIC;
|
46 |
|
|
RXval : IN STD_LOGIC; -- RX bytes available
|
47 |
|
|
RXdat : IN STD_LOGIC_VECTOR(7 DOWNTO 0); -- Received data bytes
|
48 |
|
|
RXrdy : OUT STD_LOGIC := '0'; -- Application ready for data
|
49 |
|
|
RXlen : IN STD_LOGIC_VECTOR(7 DOWNTO 0); -- Number of bytes available
|
50 |
|
|
TXval : OUT STD_LOGIC := '0'; -- Application has valid data
|
51 |
|
|
TXdat : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); -- Data byte to send
|
52 |
|
|
TXrdy : IN STD_LOGIC; -- Entity is ready for data
|
53 |
|
|
TXroom : IN STD_LOGIC_VECTOR(7 DOWNTO 0); -- No of free bytes in TX
|
54 |
|
|
TXcork : OUT STD_LOGIC := '1'); -- Hold TX transmission
|
55 |
|
|
END USB_Stimuli;
|
56 |
|
|
|
57 |
|
|
ARCHITECTURE sim OF usb_stimuli IS
|
58 |
|
|
|
59 |
|
|
SIGNAL rd_data : byte_array(0 TO 7);
|
60 |
|
|
SIGNAL TX_load : STD_LOGIC := '0';
|
61 |
|
|
|
62 |
|
|
BEGIN
|
63 |
|
|
|
64 |
|
|
p_stimuli_data : PROCESS
|
65 |
|
|
BEGIN
|
66 |
|
|
list("*****************************");
|
67 |
|
|
list("* Results of tc_02.vhd *");
|
68 |
|
|
list("*****************************");
|
69 |
|
|
list(" ");
|
70 |
|
|
list(T_No, 10);
|
71 |
|
|
rst_neg_ext <= '0';
|
72 |
|
|
WAIT FOR 301 ns;
|
73 |
|
|
rst_neg_ext <= '1';
|
74 |
|
|
WAIT FOR 40 ns;
|
75 |
|
|
list("Reset completed, initializing");
|
76 |
|
|
TX_load <= '1';
|
77 |
|
|
list(T_No, 20);
|
78 |
|
|
setup(usb, X"00", X"0"); --Send Setup to addr 0, endp 0 ..
|
79 |
|
|
send_D0(usb,(X"80",X"06",X"00",X"01",X"00",X"00",X"40",X"00")); -- .. 'Get Device descriptor'
|
80 |
|
|
wait_slv(usb); --Recv ACK
|
81 |
|
|
in_token(usb, X"00", X"0"); --Send IN-Token
|
82 |
|
|
wait_slv(usb); --Recv Data1 Device Discriptor
|
83 |
|
|
send_ack(usb); --Send ACK
|
84 |
|
|
out_token(usb, X"00", X"0");
|
85 |
|
|
send_D0(usb); --Send Zero Data
|
86 |
|
|
wait_slv(usb);
|
87 |
|
|
|
88 |
|
|
list(T_No, 30);
|
89 |
|
|
setup(usb, X"00", X"0"); --Setup to addr 0, endp 0 ..
|
90 |
|
|
send_D0(usb,(X"00",X"05",X"03",X"00",X"00",X"00",X"00",X"00")); -- .. 'Set Address'
|
91 |
|
|
wait_slv(usb); --Recv ACK
|
92 |
|
|
in_token(usb, X"00", X"0"); --Send IN-Token
|
93 |
|
|
wait_slv(usb); --Recv Data0 zero Length
|
94 |
|
|
send_ack(usb); --Send ACK
|
95 |
|
|
|
96 |
|
|
--Now we may use the new address :
|
97 |
|
|
list(T_No, 50);
|
98 |
|
|
out_token(usb, X"03", X"1"); --Send Out-Token to Endpoint 1
|
99 |
|
|
send_D0(usb, (X"11",X"22",X"33",X"44",X"55",X"66",X"77",X"88"));
|
100 |
|
|
wait_slv(usb);
|
101 |
|
|
list(T_No, 51);
|
102 |
|
|
out_token(usb, X"03", X"1"); --Send Out-Token to Endpoint 1
|
103 |
|
|
send_D0(usb, (X"11",X"12",X"13",X"14",X"15",X"16",X"17",X"18"));
|
104 |
|
|
wait_slv(usb);
|
105 |
|
|
TXcork <= '0'; --Release TX buffer
|
106 |
|
|
FOR i IN 0 TO 5 LOOP
|
107 |
|
|
list(T_No, 60+i);
|
108 |
|
|
in_token(usb, X"03", X"1"); --Send IN-Token to Endpoint 1
|
109 |
|
|
wait_slv(usb); --Recv Data ?
|
110 |
|
|
send_ack(usb); --Send ACK
|
111 |
|
|
END LOOP;
|
112 |
|
|
-- list(T_No, 70);
|
113 |
|
|
-- in_token(usb, X"03", X"1"); --Send IN-Token to Endpoint 1
|
114 |
|
|
-- wait_slv(usb); --Recv Data ?
|
115 |
|
|
-- send_ack(usb); --Send ACK
|
116 |
|
|
IF usb_busy THEN --is a usb_monitor signal
|
117 |
|
|
WAIT UNTIL NOT usb_busy;
|
118 |
|
|
END IF;
|
119 |
|
|
WAIT FOR 300 ns;
|
120 |
|
|
send_RES(usb);
|
121 |
|
|
WAIT FOR 1 us;
|
122 |
|
|
ASSERT FALSE REPORT"End of Test" SEVERITY FAILURE;
|
123 |
|
|
END PROCESS;
|
124 |
|
|
|
125 |
|
|
p_rd_data : PROCESS
|
126 |
|
|
VARIABLE i : NATURAL := 0;
|
127 |
|
|
BEGIN
|
128 |
|
|
WAIT UNTIL rising_edge(clk);
|
129 |
|
|
RXrdy <= '1';
|
130 |
|
|
IF i < 8 THEN
|
131 |
|
|
RXrdy <= '1';
|
132 |
|
|
IF RXval ='1' THEN
|
133 |
|
|
rd_data(i) <= RXdat;
|
134 |
|
|
END IF;
|
135 |
|
|
ELSE
|
136 |
|
|
RXrdy <= '0';
|
137 |
|
|
END IF;
|
138 |
|
|
END PROCESS;
|
139 |
|
|
|
140 |
|
|
p_wr_data : PROCESS
|
141 |
|
|
VARIABLE i : NATURAL := 0;
|
142 |
|
|
BEGIN
|
143 |
|
|
WAIT UNTIL rising_edge(clk);
|
144 |
|
|
IF i < 333 AND TXrdy ='1' and TX_load ='1' THEN
|
145 |
|
|
TXval <= '1';
|
146 |
|
|
TXdat <= CONV_STD_LOGIC_VECTOR(i,8);
|
147 |
|
|
i := i +1;
|
148 |
|
|
ELSE
|
149 |
|
|
TXval <= '0';
|
150 |
|
|
END IF;
|
151 |
|
|
END PROCESS;
|
152 |
|
|
|
153 |
|
|
END sim;
|