1 |
5 |
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_fs_port.vhdl --
|
21 |
|
|
-- Author : Martin Neumann martin@neumanns-mail.de --
|
22 |
|
|
-- Description : Wrapper for a USB full speed slave operating at 60MHz clock frequency --
|
23 |
|
|
-- --
|
24 |
|
|
--==========================================================================================================--
|
25 |
|
|
-- --
|
26 |
|
|
-- Change history: --
|
27 |
|
|
-- --
|
28 |
|
|
--------------------------------------------------------------------------------------------------------------
|
29 |
|
|
-- Version:| Author:| Date: | Comment: --
|
30 |
|
|
--------------------------------------------------------------------------------------------------------------
|
31 |
|
|
-- 1.0 | MN |05 Mar 2011| Initial version --
|
32 |
|
|
-- 1.1 | MN |13 Feb 2012| added d_oe to entity, changed polarity of syncronized reset (reset_syc) --
|
33 |
|
|
-- End change history --
|
34 |
|
|
--==========================================================================================================--
|
35 |
|
|
|
36 |
|
|
LIBRARY IEEE;
|
37 |
|
|
USE IEEE.std_logic_1164.all;
|
38 |
|
|
|
39 |
|
|
ENTITY usb_fs_port IS
|
40 |
|
|
GENERIC (
|
41 |
|
|
VENDORID : STD_LOGIC_VECTOR(15 DOWNTO 0);
|
42 |
|
|
PRODUCTID : STD_LOGIC_VECTOR(15 DOWNTO 0);
|
43 |
|
|
VERSIONBCD : STD_LOGIC_VECTOR(15 DOWNTO 0);
|
44 |
|
|
SELFPOWERED : BOOLEAN := FALSE;
|
45 |
|
|
BUFSIZE_BITS : INTEGER RANGE 7 to 12 := 7);
|
46 |
|
|
PORT (
|
47 |
|
|
clk : IN STD_LOGIC;
|
48 |
|
|
rst_neg_ext : IN STD_LOGIC;
|
49 |
|
|
reset_syc : OUT STD_LOGIC; -- RST_NEG_EXT inverted and streched to next clock
|
50 |
|
|
d_pos : INOUT STD_LOGIC;
|
51 |
|
|
d_neg : INOUT STD_LOGIC;
|
52 |
|
|
d_oe : OUT STD_LOGIC;
|
53 |
|
|
USB_rst : OUT STD_LOGIC; -- USB reset detected (SE0 > 2.5 us)
|
54 |
|
|
online : OUT STD_LOGIC; -- High when the device is in Config state.
|
55 |
|
|
RXval : OUT STD_LOGIC; -- High if a received byte available on RXDAT.
|
56 |
|
|
RXdat : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); -- Received data byte, valid if RXVAL is high.
|
57 |
|
|
RXrdy : IN STD_LOGIC; -- High if application is ready to receive.
|
58 |
|
|
RXlen : OUT STD_LOGIC_VECTOR(BUFSIZE_BITS-1 DOWNTO 0); -- No of bytes available in receive buffer.
|
59 |
|
|
TXval : IN STD_LOGIC; -- High if the application has data to send.
|
60 |
|
|
TXdat : IN STD_LOGIC_VECTOR(7 DOWNTO 0); -- Data byte to send, must be valid if TXVAL is high.
|
61 |
|
|
TXrdy : OUT STD_LOGIC; -- High if the entity is ready to accept the next byte.
|
62 |
|
|
TXroom : OUT STD_LOGIC_VECTOR(BUFSIZE_BITS-1 DOWNTO 0); -- No of free bytes in transmit buffer.
|
63 |
|
|
TXcork : IN STD_LOGIC; -- Temp. suppress transmissions at the outgoing endpoint.
|
64 |
|
|
FPGA_ready : OUT STD_LOGIC); -- connect FPGA_ready to the pullup resistor logic
|
65 |
|
|
END usb_fs_port;
|
66 |
|
|
|
67 |
|
|
ARCHITECTURE rtl OF usb_fs_port IS
|
68 |
|
|
|
69 |
|
|
CONSTANT DriverMode : STD_LOGIC := '1'; -- HIGH level for differential io mode (else single-ended)
|
70 |
|
|
CONSTANT tx_wait : STD_LOGIC := '0'; -- Don't suppress temporarily transmissions at the outgoing endpoint.
|
71 |
|
|
|
72 |
|
|
SIGNAL Phy_DataIn : STD_LOGIC_VECTOR(7 DOWNTO 0);
|
73 |
|
|
SIGNAL Phy_DataOut : STD_LOGIC_VECTOR(7 DOWNTO 0);
|
74 |
|
|
SIGNAL Phy_Linestate : STD_LOGIC_VECTOR(1 DOWNTO 0);
|
75 |
|
|
SIGNAL Phy_Opmode : STD_LOGIC_VECTOR(1 DOWNTO 0);
|
76 |
|
|
SIGNAL Phy_RxActive : STD_LOGIC;
|
77 |
|
|
SIGNAL Phy_RxError : STD_LOGIC;
|
78 |
|
|
SIGNAL Phy_RxValid : STD_LOGIC;
|
79 |
|
|
SIGNAL Phy_Termselect : STD_LOGIC := 'L';
|
80 |
|
|
SIGNAL Phy_TxReady : STD_LOGIC;
|
81 |
|
|
SIGNAL Phy_TxValid : STD_LOGIC;
|
82 |
|
|
SIGNAL Phy_XcvrSelect : STD_LOGIC := 'L';
|
83 |
|
|
SIGNAL usb_rst_phy : STD_LOGIC;
|
84 |
|
|
SIGNAL usb_rst_slv : STD_LOGIC;
|
85 |
|
|
SIGNAL reset_int : STD_LOGIC;
|
86 |
|
|
SIGNAL reset_tmp : STD_LOGIC;
|
87 |
|
|
SIGNAL rxd : STD_LOGIC;
|
88 |
|
|
SIGNAL txdn : STD_LOGIC;
|
89 |
|
|
SIGNAL txdp : STD_LOGIC;
|
90 |
|
|
SIGNAL txoe : STD_LOGIC;
|
91 |
|
|
|
92 |
|
|
FUNCTION neg(value : STD_LOGIC) RETURN STD_LOGIC IS
|
93 |
|
|
BEGIN
|
94 |
|
|
RETURN NOT value;
|
95 |
|
|
END neg;
|
96 |
|
|
|
97 |
|
|
FUNCTION is_valid(data : STD_LOGIC_VECTOR) RETURN BOOLEAN IS
|
98 |
|
|
VARIABLE result : BOOLEAN;
|
99 |
|
|
BEGIN
|
100 |
|
|
result := TRUE;
|
101 |
|
|
FOR i IN data'low TO data'high LOOP
|
102 |
|
|
IF (data(i) ='W' OR data(i) ='Z' OR data(i) ='U' OR data(i) ='X') THEN
|
103 |
|
|
result := FALSE;
|
104 |
|
|
END IF;
|
105 |
|
|
END LOOP;
|
106 |
|
|
RETURN result;
|
107 |
|
|
END is_valid;
|
108 |
|
|
|
109 |
|
|
BEGIN
|
110 |
|
|
|
111 |
|
|
p_rst_neg : PROCESS(rst_neg_ext, clk)
|
112 |
|
|
BEGIN
|
113 |
|
|
IF rst_neg_ext ='0' THEN
|
114 |
|
|
reset_tmp <= '1';
|
115 |
|
|
reset_int <= '1';
|
116 |
|
|
ELSIF clk'EVENT AND clk ='1' THEN
|
117 |
|
|
reset_tmp <= NOT rst_neg_ext;
|
118 |
|
|
reset_int <= reset_tmp;
|
119 |
|
|
END IF;
|
120 |
|
|
END PROCESS;
|
121 |
|
|
|
122 |
|
|
reset_syc <= reset_int;
|
123 |
|
|
|
124 |
|
|
rxd <= d_pos AND NOT d_neg;
|
125 |
|
|
usb_rst <= usb_rst_phy OR usb_rst_slv;
|
126 |
|
|
|
127 |
|
|
d_oe <= NOT txoe;
|
128 |
|
|
d_pos <= txdp WHEN txoe = '0' ELSE 'Z';
|
129 |
|
|
d_neg <= txdn WHEN txoe = '0' ELSE 'Z';
|
130 |
|
|
|
131 |
|
|
usb_phy_1 : ENTITY work.usb_phy --Open Cores USB Phy, designed by Rudolf Usselmanns
|
132 |
|
|
GENERIC MAP (
|
133 |
|
|
usb_rst_det => TRUE
|
134 |
|
|
)
|
135 |
|
|
PORT MAP (
|
136 |
|
|
clk => clk, -- i
|
137 |
|
|
rst => neg(reset_int), -- i
|
138 |
|
|
phy_tx_mode => DriverMode, -- i
|
139 |
|
|
usb_rst => usb_rst_phy, -- o
|
140 |
|
|
txdp => txdp, -- o
|
141 |
|
|
txdn => txdn, -- o
|
142 |
|
|
txoe => txoe, -- o
|
143 |
|
|
rxd => rxd, -- i
|
144 |
|
|
rxdp => d_pos, -- i
|
145 |
|
|
rxdn => d_neg, -- i
|
146 |
|
|
DataOut_i => Phy_DataOut, -- i (7 downto 0);
|
147 |
|
|
TxValid_i => Phy_TxValid, -- i
|
148 |
|
|
TxReady_o => Phy_TxReady, -- o
|
149 |
|
|
DataIn_o => Phy_DataIn, -- o (7 downto 0);
|
150 |
|
|
RxValid_o => Phy_RxValid, -- o
|
151 |
|
|
RxActive_o => Phy_RxActive, -- o
|
152 |
|
|
RxError_o => Phy_RxError, -- o
|
153 |
|
|
LineState_o => Phy_LineState -- o (1 downto 0)
|
154 |
|
|
);
|
155 |
|
|
|
156 |
|
|
usb_serial_1 : ENTITY work.usb_serial -- Joris van Rantwijk's USB Serial
|
157 |
|
|
GENERIC MAP (
|
158 |
|
|
VENDORID => VENDORID,
|
159 |
|
|
PRODUCTID => PRODUCTID,
|
160 |
|
|
VERSIONBCD => VERSIONBCD,
|
161 |
|
|
HSSUPPORT => FALSE,
|
162 |
|
|
SELFPOWERED => SELFPOWERED,
|
163 |
|
|
RXBUFSIZE_BITS => BUFSIZE_BITS,
|
164 |
|
|
TXBUFSIZE_BITS => BUFSIZE_BITS)
|
165 |
|
|
PORT MAP (
|
166 |
|
|
clk => clk, -- i 60 MHz UTMI clock.
|
167 |
|
|
reset => reset_int, -- i Synchronous reset; clear buffers and re-attach to the bus.
|
168 |
|
|
usbrst => usb_rst_slv, -- o High for one clock when a reset signal is detected on the USB bus.
|
169 |
|
|
highspeed => OPEN, -- o High when the device is operating (or suspended) in high speed mode.
|
170 |
|
|
suspend => OPEN, -- o High if device suspended, drive asynchronously the UTMI SuspendM pin.
|
171 |
|
|
online => online, -- o High when the device is in the Configured state.
|
172 |
|
|
RXval => RXval, -- o High if a received byte is available on RXDAT.
|
173 |
|
|
RXdat => RXdat, -- o (7 downto 0) - Received data byte, valid if RXVAL is high.
|
174 |
|
|
RXrdy => RXrdy, -- i High if the application is ready to receive the next byte.
|
175 |
|
|
RXlen => RXlen, -- o (RXBUFSIZE_BITS-1 downto 0) - No of bytes available in receive buffer.
|
176 |
|
|
TXval => TXval, -- i High if the application has data to send.
|
177 |
|
|
TXdat => TXdat, -- i (7 downto 0) - Data byte to send, must be valid if TXVAL is high.
|
178 |
|
|
TXrdy => TXrdy, -- o High if the entity is ready to accept the next byte.
|
179 |
|
|
TXroom => TXroom, -- o (TXBUFSIZE_BITS-1 downto 0) - No of free bytes in transmit buffer.
|
180 |
|
|
TXcork => TXcork, -- i Temporarily suppress transmissions at the outgoing endpoint.
|
181 |
|
|
Phy_DataIn => Phy_DataIn, -- i (7 downto 0)
|
182 |
|
|
Phy_DataOut => Phy_DataOut, -- o (7 downto 0)
|
183 |
|
|
Phy_TxValid => Phy_TxValid, -- o
|
184 |
|
|
Phy_TxReady => Phy_TxReady, -- i
|
185 |
|
|
Phy_RxActive => Phy_RxActive, -- i
|
186 |
|
|
Phy_RxValid => Phy_RxValid, -- i
|
187 |
|
|
Phy_RxError => Phy_RxError, -- i
|
188 |
|
|
Phy_LineState => Phy_LineState, -- i (1 downto 0)
|
189 |
|
|
Phy_OPmode => Phy_OPmode, -- o (1 downto 0) Phy_OPmode "01" -> non-driving
|
190 |
|
|
Phy_xcvrselect => OPEN, -- o Phy_OPmode "00" -> normal
|
191 |
|
|
Phy_termselect => FPGA_ready, -- o Phy_OPmode "10" -> disable bit stuffing
|
192 |
|
|
Phy_reset => OPEN -- o );
|
193 |
|
|
);
|
194 |
|
|
|
195 |
|
|
p_tx_data_valid : PROCESS (clk)
|
196 |
|
|
BEGIN
|
197 |
|
|
IF rising_edge(clk) THEN
|
198 |
|
|
IF TXval = '1' THEN
|
199 |
|
|
ASSERT is_valid(TXdat) REPORT "USB_FS_port: TX input has invalid data" SEVERITY ERROR;
|
200 |
|
|
END IF;
|
201 |
|
|
END IF;
|
202 |
|
|
END PROCESS;
|
203 |
|
|
|
204 |
|
|
END rtl;
|
205 |
|
|
|