1 |
2 |
M_artin |
|
2 |
|
|
--==========================================================================================================--
|
3 |
|
|
-- --
|
4 |
|
|
-- Copyright (C) 2011 by Martin Neumann martin@neumanns-mail.de --
|
5 |
|
|
-- --
|
6 |
|
|
-- This source file may be used and distributed without restriction provided that this copyright statement --
|
7 |
|
|
-- is not removed from the file and that any derivative work contains the original copyright notice and --
|
8 |
|
|
-- the associated disclaimer. --
|
9 |
|
|
-- --
|
10 |
|
|
-- This software is provided ''as is'' and without any express or implied warranties, including, but not --
|
11 |
|
|
-- limited to, the implied warranties of merchantability and fitness for a particular purpose. in no event --
|
12 |
|
|
-- shall the author or contributors be liable for any direct, indirect, incidental, special, exemplary, or --
|
13 |
|
|
-- consequential damages (including, but not limited to, procurement of substitute goods or services; loss --
|
14 |
|
|
-- of use, data, or profits; or business interruption) however caused and on any theory of liability, --
|
15 |
|
|
-- whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way --
|
16 |
|
|
-- out of the use of this software, even if advised of the possibility of such damage. --
|
17 |
|
|
-- --
|
18 |
|
|
--==========================================================================================================--
|
19 |
|
|
-- --
|
20 |
|
|
-- File name : USB_tb.vhd --
|
21 |
|
|
-- Author : Martin Neumann martin@neumanns-mail.de --
|
22 |
|
|
-- Description : USB test bench used with usb_mster.vhd, usb_Stimuli.vhd and usb_fs_monitor.vhd. --
|
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 |
|
|
LIBRARY work, IEEE;
|
36 |
|
|
USE IEEE.std_logic_1164.ALL;
|
37 |
|
|
USE work.usb_commands.ALL;
|
38 |
|
|
|
39 |
|
|
ENTITY usb_tb IS
|
40 |
|
|
END usb_tb;
|
41 |
|
|
|
42 |
|
|
ARCHITECTURE sim OF usb_tb IS
|
43 |
|
|
|
44 |
|
|
CONSTANT BUFSIZE_BITS : POSITIVE := 8;
|
45 |
|
|
|
46 |
|
|
SIGNAL FPGA_ready : STD_LOGIC;
|
47 |
|
|
SIGNAL RXdat : STD_LOGIC_VECTOR(7 DOWNTO 0);
|
48 |
|
|
SIGNAL RXlen : STD_LOGIC_VECTOR(BUFSIZE_BITS-1 DOWNTO 0);
|
49 |
|
|
SIGNAL RXrdy : STD_LOGIC;
|
50 |
|
|
SIGNAL RXval : STD_LOGIC;
|
51 |
|
|
SIGNAL TXcork : STD_LOGIC;
|
52 |
|
|
SIGNAL TXdat : STD_LOGIC_VECTOR(7 DOWNTO 0);
|
53 |
|
|
SIGNAL TXrdy : STD_LOGIC;
|
54 |
|
|
SIGNAL TXroom : STD_LOGIC_VECTOR(BUFSIZE_BITS-1 DOWNTO 0);
|
55 |
|
|
SIGNAL TXval : STD_LOGIC;
|
56 |
|
|
SIGNAL USB_rst : STD_LOGIC;
|
57 |
|
|
SIGNAL online : STD_LOGIC;
|
58 |
|
|
SIGNAL clk_12MHz : STD_LOGIC;
|
59 |
|
|
SIGNAL clk_60MHz : STD_LOGIC;
|
60 |
|
|
SIGNAL rst_neg_ext : STD_LOGIC;
|
61 |
|
|
SIGNAL rst_neg_syc : STD_LOGIC;
|
62 |
|
|
SIGNAL usb_Dn : STD_LOGIC := 'L';
|
63 |
|
|
SIGNAL usb_Dp : STD_LOGIC := 'Z'; -- allow forcing 'H', avoid 'X'
|
64 |
|
|
|
65 |
|
|
BEGIN
|
66 |
|
|
|
67 |
|
|
p_clk_60MHz : PROCESS
|
68 |
|
|
BEGIN
|
69 |
|
|
clk_60MHz <= '0';
|
70 |
|
|
WAIT FOR 2 ns;
|
71 |
|
|
While true loop
|
72 |
|
|
clk_60MHz <= '0';
|
73 |
|
|
WAIT FOR 8000 ps;
|
74 |
|
|
clk_60MHz <= '1';
|
75 |
|
|
-- WAIT FOR 8667 ps; -- 60 MHz
|
76 |
|
|
WAIT FOR 8393 ps; -- 61 MHz
|
77 |
|
|
-- WAIT FOR 8949 ps; -- 59 MHz
|
78 |
|
|
end loop;
|
79 |
|
|
END PROCESS;
|
80 |
|
|
|
81 |
|
|
p_clk_12MHz : PROCESS
|
82 |
|
|
BEGIN
|
83 |
|
|
clk_12MHz <= '0';
|
84 |
|
|
WAIT FOR 20866 ps;
|
85 |
|
|
clk_12MHz <= '1';
|
86 |
|
|
WAIT FOR 41600 ps;
|
87 |
|
|
clk_12MHz <= '0';
|
88 |
|
|
WAIT FOR 20867 ps;
|
89 |
|
|
END PROCESS;
|
90 |
|
|
|
91 |
|
|
p_rst_neg_ext : PROCESS
|
92 |
|
|
BEGIN
|
93 |
|
|
rst_neg_ext <= '0';
|
94 |
|
|
WAIT FOR 301 ns;
|
95 |
|
|
rst_neg_ext <= '1';
|
96 |
|
|
WAIT;
|
97 |
|
|
END PROCESS;
|
98 |
|
|
|
99 |
|
|
usb_fs_master : ENTITY work.usb_fs_master
|
100 |
|
|
port map (
|
101 |
|
|
usb_clk => clk_12MHz,
|
102 |
|
|
int_clk => clk_60MHz,
|
103 |
|
|
rst_neg_ext => rst_neg_ext,
|
104 |
|
|
usb_Dp => usb_dp,
|
105 |
|
|
usb_Dn => usb_dn,
|
106 |
|
|
RXval => RXval,
|
107 |
|
|
RXdat => RXdat,
|
108 |
|
|
RXrdy => RXrdy,
|
109 |
|
|
RXlen => RXlen,
|
110 |
|
|
TXval => TXval,
|
111 |
|
|
TXdat => TXdat,
|
112 |
|
|
TXrdy => TXrdy,
|
113 |
|
|
TXroom => TXroom,
|
114 |
|
|
TXcork => TXcork
|
115 |
|
|
);
|
116 |
|
|
|
117 |
|
|
usb_dp <= 'H' WHEN FPGA_ready ='1' ELSE 'L'; -- connect FPGA_ready to the pullup resistor logic, ....
|
118 |
|
|
usb_dn <= 'L'; -- ... keeping usb_dp='L' during FPGA initialization.
|
119 |
|
|
|
120 |
|
|
usb_fs_slave_1 : ENTITY work.usb_fs_slave
|
121 |
|
|
GENERIC MAP(
|
122 |
|
|
VENDORID => X"FB9A",
|
123 |
|
|
PRODUCTID => X"FB9A",
|
124 |
|
|
VERSIONBCD => X"0020",
|
125 |
|
|
SELFPOWERED => FALSE,
|
126 |
|
|
BUFSIZE_BITS => BUFSIZE_BITS)
|
127 |
|
|
PORT MAP(
|
128 |
|
|
clk => clk_60MHz, -- i
|
129 |
|
|
rst_neg_ext => rst_neg_ext, -- i
|
130 |
|
|
rst_neg_syc => rst_neg_syc, -- o RST_NEG_EXT streched to next clock
|
131 |
|
|
d_pos => usb_dp, -- io Pos USB data line
|
132 |
|
|
d_neg => usb_dn, -- io Neg USB data line
|
133 |
|
|
USB_rst => USB_rst, -- o USB reset detected (SE0 > 2.5 us)
|
134 |
|
|
online => online, -- o High when the device is in Config state.
|
135 |
|
|
RXval => RXval, -- o High if a received byte available on RXDAT.
|
136 |
|
|
RXdat => RXdat, -- o Received data byte, valid if RXVAL is high.
|
137 |
|
|
RXrdy => RXrdy, -- i High if application is ready to receive.
|
138 |
|
|
RXlen => RXlen, -- o No of bytes available in receive buffer.
|
139 |
|
|
TXval => TXval, -- i High if the application has data to send.
|
140 |
|
|
TXdat => TXdat, -- i Data byte to send, must be valid if TXVAL is high.
|
141 |
|
|
TXrdy => TXrdy, -- o High if the entity is ready to accept the next byte.
|
142 |
|
|
TXroom => TXroom, -- o No of free bytes in transmit buffer.
|
143 |
|
|
TXcork => TXcork, -- i Temp. suppress transmissions at the outgoing endpoint.
|
144 |
|
|
FPGA_ready => FPGA_ready -- o Connect FPGA_ready to the pullup resistor logic
|
145 |
|
|
);
|
146 |
|
|
|
147 |
|
|
END sim;
|
148 |
|
|
|