1 |
2 |
M_artin |
--======================================================================================--
|
2 |
|
|
-- Verilog to VHDL conversion by Martin Neumann martin@neumnns-mail.de --
|
3 |
|
|
-- --
|
4 |
|
|
-- /////////////////////////////////////////////////////////////////// --
|
5 |
|
|
-- // // --
|
6 |
|
|
-- // USB 1.1 PHY // --
|
7 |
|
|
-- // // --
|
8 |
|
|
-- // // --
|
9 |
|
|
-- // Author: Rudolf Usselmann // --
|
10 |
|
|
-- // rudi@asics.ws // --
|
11 |
|
|
-- // // --
|
12 |
|
|
-- // // --
|
13 |
|
|
-- // Downloaded from: http://www.opencores.org/cores/usb_phy/ // --
|
14 |
|
|
-- // // --
|
15 |
|
|
-- /////////////////////////////////////////////////////////////////// --
|
16 |
|
|
-- // // --
|
17 |
|
|
-- // Copyright (C) 2000-2002 Rudolf Usselmann // --
|
18 |
|
|
-- // www.asics.ws // --
|
19 |
|
|
-- // rudi@asics.ws // --
|
20 |
|
|
-- // // --
|
21 |
|
|
-- // This source file may be used and distributed without // --
|
22 |
|
|
-- // restriction provided that this copyright statement is not // --
|
23 |
|
|
-- // removed from the file and that any derivative work contains // --
|
24 |
|
|
-- // the original copyright notice and the associated disclaimer. // --
|
25 |
|
|
-- // // --
|
26 |
|
|
-- // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY // --
|
27 |
|
|
-- // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // --
|
28 |
|
|
-- // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS // --
|
29 |
|
|
-- // FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR // --
|
30 |
|
|
-- // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, // --
|
31 |
|
|
-- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES // --
|
32 |
|
|
-- // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE // --
|
33 |
|
|
-- // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR // --
|
34 |
|
|
-- // BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // --
|
35 |
|
|
-- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // --
|
36 |
|
|
-- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT // --
|
37 |
|
|
-- // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // --
|
38 |
|
|
-- // POSSIBILITY OF SUCH DAMAGE. // --
|
39 |
|
|
-- // // --
|
40 |
|
|
-- /////////////////////////////////////////////////////////////////// --
|
41 |
|
|
--======================================================================================--
|
42 |
|
|
|
43 |
|
|
library ieee;
|
44 |
|
|
use ieee.std_logic_1164.all;
|
45 |
|
|
use ieee.std_logic_arith.all;
|
46 |
|
|
use ieee.std_logic_unsigned.all;
|
47 |
|
|
|
48 |
|
|
entity usb_phy is
|
49 |
|
|
generic (usb_rst_det : boolean := TRUE);
|
50 |
|
|
port (
|
51 |
|
|
clk : in std_logic; -- 60 MHz
|
52 |
|
|
rst : in std_logic;
|
53 |
|
|
phy_tx_mode : in std_logic; -- HIGH level for differential io mode (else single-ended)
|
54 |
|
|
usb_rst : out std_logic;
|
55 |
|
|
-- Transciever Interface
|
56 |
|
|
rxd, rxdp, rxdn : in std_logic;
|
57 |
|
|
txdp, txdn, txoe : out std_logic;
|
58 |
|
|
-- UTMI Interface
|
59 |
|
|
DataOut_i : in std_logic_vector(7 downto 0);
|
60 |
|
|
TxValid_i : in std_logic;
|
61 |
|
|
TxReady_o : out std_logic;
|
62 |
|
|
DataIn_o : out std_logic_vector(7 downto 0);
|
63 |
|
|
RxValid_o : out std_logic;
|
64 |
|
|
RxActive_o : out std_logic;
|
65 |
|
|
RxError_o : out std_logic;
|
66 |
|
|
LineState_o : out std_logic_vector(1 downto 0)
|
67 |
|
|
);
|
68 |
|
|
end usb_phy;
|
69 |
|
|
|
70 |
|
|
architecture RTL of usb_phy is
|
71 |
|
|
|
72 |
|
|
--component usb_tx_phy
|
73 |
|
|
--port (
|
74 |
|
|
-- clk : in std_logic;
|
75 |
|
|
-- rst : in std_logic;
|
76 |
|
|
-- fs_ce : in std_logic;
|
77 |
|
|
-- phy_mode : in std_logic;
|
78 |
|
|
-- -- Transciever Interface
|
79 |
|
|
-- txdp, txdn, txoe : out std_logic;
|
80 |
|
|
-- -- UTMI Interface
|
81 |
|
|
-- DataOut_i : in std_logic_vector(7 downto 0);
|
82 |
|
|
-- TxValid_i : in std_logic;
|
83 |
|
|
-- TxReady_o : out std_logic
|
84 |
|
|
--);
|
85 |
|
|
--end component;
|
86 |
|
|
--
|
87 |
|
|
--component usb_rx_phy
|
88 |
|
|
--port (
|
89 |
|
|
-- clk : in std_logic;
|
90 |
|
|
-- rst : in std_logic;
|
91 |
|
|
-- -- Transciever Interface
|
92 |
|
|
-- fs_ce : out std_logic;
|
93 |
|
|
-- rxd, rxdp, rxdn : in std_logic;
|
94 |
|
|
-- -- UTMI Interface
|
95 |
|
|
-- DataIn_o : out std_logic_vector(7 downto 0);
|
96 |
|
|
-- RxValid_o : out std_logic;
|
97 |
|
|
-- RxActive_o : out std_logic;
|
98 |
|
|
-- RxError_o : out std_logic;
|
99 |
|
|
-- RxEn_i : in std_logic;
|
100 |
|
|
-- LineState : out std_logic_vector(1 downto 0)
|
101 |
|
|
--);
|
102 |
|
|
--end component;
|
103 |
|
|
|
104 |
|
|
signal LineState : std_logic_vector(1 downto 0);
|
105 |
|
|
signal fs_ce : std_logic;
|
106 |
|
|
signal rst_cnt : std_logic_vector(4 downto 0);
|
107 |
|
|
signal txoe_out : std_logic;
|
108 |
|
|
signal usb_rst_out : std_logic := '0';
|
109 |
|
|
|
110 |
|
|
begin
|
111 |
|
|
|
112 |
|
|
--======================================================================================--
|
113 |
|
|
-- Misc Logic --
|
114 |
|
|
--======================================================================================--
|
115 |
|
|
|
116 |
|
|
usb_rst <= usb_rst_out;
|
117 |
|
|
LineState_o <= LineState;
|
118 |
|
|
txoe <= txoe_out;
|
119 |
|
|
|
120 |
|
|
--======================================================================================--
|
121 |
|
|
-- TX Phy --
|
122 |
|
|
--======================================================================================--
|
123 |
|
|
|
124 |
|
|
i_tx_phy: entity work.usb_tx_phy
|
125 |
|
|
port map (
|
126 |
|
|
clk => clk,
|
127 |
|
|
rst => rst,
|
128 |
|
|
fs_ce => fs_ce,
|
129 |
|
|
phy_mode => phy_tx_mode,
|
130 |
|
|
-- Transciever Interface
|
131 |
|
|
txdp => txdp,
|
132 |
|
|
txdn => txdn,
|
133 |
|
|
txoe => txoe_out,
|
134 |
|
|
-- UTMI Interface
|
135 |
|
|
DataOut_i => DataOut_i,
|
136 |
|
|
TxValid_i => TxValid_i,
|
137 |
|
|
TxReady_o => TxReady_o
|
138 |
|
|
);
|
139 |
|
|
|
140 |
|
|
--======================================================================================--
|
141 |
|
|
-- RX Phy and DPLL --
|
142 |
|
|
--======================================================================================--
|
143 |
|
|
|
144 |
|
|
i_rx_phy: entity work.usb_rx_phy
|
145 |
|
|
port map (
|
146 |
|
|
clk => clk,
|
147 |
|
|
rst => rst,
|
148 |
|
|
fs_ce_o => fs_ce,
|
149 |
|
|
-- Transciever Interface
|
150 |
|
|
rxd => rxd,
|
151 |
|
|
rxdp => rxdp,
|
152 |
|
|
rxdn => rxdn,
|
153 |
|
|
-- UTMI Interface
|
154 |
|
|
DataIn_o => DataIn_o,
|
155 |
|
|
RxValid_o => RxValid_o,
|
156 |
|
|
RxActive_o => RxActive_o,
|
157 |
|
|
RxError_o => RxError_o,
|
158 |
|
|
RxEn_i => txoe_out,
|
159 |
|
|
LineState => LineState
|
160 |
|
|
);
|
161 |
|
|
|
162 |
|
|
--======================================================================================--
|
163 |
|
|
-- Generate an USB Reset if we see SE0 for at least 2.5uS --
|
164 |
|
|
--======================================================================================--
|
165 |
|
|
|
166 |
|
|
usb_rst_g : if usb_rst_det generate
|
167 |
|
|
p_rst_cnt: process (clk, rst)
|
168 |
|
|
begin
|
169 |
|
|
if rst ='0' then
|
170 |
|
|
rst_cnt <= (others => '0');
|
171 |
|
|
elsif rising_edge(clk) then
|
172 |
|
|
if LineState /= "00" then
|
173 |
|
|
rst_cnt <= (others => '0');
|
174 |
|
|
elsif usb_rst_out ='0' and fs_ce ='1' then
|
175 |
|
|
rst_cnt <= rst_cnt + 1;
|
176 |
|
|
end if;
|
177 |
|
|
end if;
|
178 |
|
|
end process;
|
179 |
|
|
|
180 |
|
|
p_usb_rst_out: process (clk)
|
181 |
|
|
begin
|
182 |
|
|
if rising_edge(clk) then
|
183 |
|
|
if rst_cnt = "11111" then
|
184 |
|
|
usb_rst_out <= '1';
|
185 |
|
|
else
|
186 |
|
|
usb_rst_out <= '0';
|
187 |
|
|
end if;
|
188 |
|
|
end if;
|
189 |
|
|
end process;
|
190 |
|
|
end generate;
|
191 |
|
|
|
192 |
|
|
end RTL;
|