1 |
2 |
rehnmaak |
--
|
2 |
|
|
-- USB 2.0 VHDL package
|
3 |
|
|
--
|
4 |
|
|
|
5 |
|
|
library ieee;
|
6 |
|
|
use ieee.std_logic_1164.all, ieee.numeric_std.all;
|
7 |
|
|
|
8 |
|
|
package usb_pkg is
|
9 |
|
|
|
10 |
|
|
-- Initialization, handshake, reset.
|
11 |
|
|
component usb_init is
|
12 |
|
|
generic (
|
13 |
|
|
HSSUPPORT : boolean := false ); -- Support high speed mode
|
14 |
|
|
port (
|
15 |
|
|
CLK : in std_logic; -- 60 MHz UTMI clock
|
16 |
|
|
RESET : in std_logic; -- Synchronous reset
|
17 |
|
|
I_USBRST : out std_logic; -- High when bus reset signal detected
|
18 |
|
|
I_HIGHSPEED : out std_logic; -- High when attached at high speed
|
19 |
|
|
I_SUSPEND : out std_logic; -- High when suspended
|
20 |
|
|
P_CHIRPK : out std_logic;
|
21 |
|
|
PHY_RESET : out std_logic;
|
22 |
|
|
PHY_LINESTATE : in std_logic_vector(1 downto 0);
|
23 |
|
|
PHY_OPMODE : out std_logic_vector(1 downto 0);
|
24 |
|
|
PHY_XCVRSELECT : out std_logic;
|
25 |
|
|
PHY_TERMSELECT : out std_logic );
|
26 |
|
|
end component usb_init;
|
27 |
|
|
|
28 |
|
|
-- Packet-level logic and CRC handling.
|
29 |
|
|
component usb_packet is
|
30 |
|
|
port (
|
31 |
|
|
CLK : in std_logic; -- 60 MHz UTMI clock
|
32 |
|
|
RESET : in std_logic; -- Synchronous reset of this entity
|
33 |
|
|
P_CHIRPK : in std_logic; -- High to force chirp K transmission
|
34 |
|
|
P_RXACT : out std_logic; -- High while receiving a packet
|
35 |
|
|
P_RXRDY : out std_logic; -- Indicates arrival of a byte
|
36 |
|
|
P_RXFIN : out std_logic; -- Indicates successfull completion
|
37 |
|
|
P_RXDAT : out std_logic_vector(7 downto 0); -- Received byte value
|
38 |
|
|
P_TXACT : in std_logic; -- High while transmitting a packet
|
39 |
|
|
P_TXRDY : out std_logic; -- Request for next data byte
|
40 |
|
|
P_TXDAT : in std_logic_vector(7 downto 0); -- Data byte to transmit
|
41 |
|
|
PHY_DATAIN : in std_logic_vector(7 downto 0);
|
42 |
|
|
PHY_DATAOUT : out std_logic_vector(7 downto 0);
|
43 |
|
|
PHY_TXVALID : out std_logic;
|
44 |
|
|
PHY_TXREADY : in std_logic;
|
45 |
|
|
PHY_RXACTIVE : in std_logic;
|
46 |
|
|
PHY_RXVALID : in std_logic;
|
47 |
|
|
PHY_RXERROR : in std_logic );
|
48 |
|
|
end component usb_packet;
|
49 |
|
|
|
50 |
|
|
-- Transaction-level logic.
|
51 |
|
|
component usb_transact is
|
52 |
|
|
generic (
|
53 |
|
|
HSSUPPORT : boolean := false ); -- Support high speed mode
|
54 |
|
|
port (
|
55 |
|
|
CLK : in std_logic; -- 60 MHz UTMI clock
|
56 |
|
|
RESET : in std_logic; -- Synchronous reset of this entity
|
57 |
|
|
T_IN : out std_logic; -- High during IN transactions
|
58 |
|
|
T_OUT : out std_logic; -- High during OUT transactions
|
59 |
|
|
T_SETUP : out std_logic; -- High during SETUP transactions
|
60 |
|
|
T_PING : out std_logic; -- High during PING transactions
|
61 |
|
|
T_FIN : out std_logic; -- Indicates successfull completion
|
62 |
|
|
T_ADDR : in std_logic_vector(6 downto 0); -- Device address
|
63 |
|
|
T_ENDPT : out std_logic_vector(3 downto 0); -- Endpoint number
|
64 |
|
|
T_NAK : in std_logic; -- Triggers a NAK response to IN/OUT
|
65 |
|
|
T_STALL : in std_logic; -- Triggers a STALL response to IN/OUT
|
66 |
|
|
T_NYET : in std_logic; -- Triggers a NYET response to OUT
|
67 |
|
|
T_SEND : in std_logic; -- High while application has data to send
|
68 |
|
|
T_ISYNC : in std_logic; -- Sync bit to use for IN transactions
|
69 |
|
|
T_OSYNC : out std_logic; -- Sync bit used in the OUT transaction
|
70 |
|
|
T_RXRDY : out std_logic; -- Indicates arrival of received byte
|
71 |
|
|
T_RXDAT : out std_logic_vector(7 downto 0); -- Received data
|
72 |
|
|
T_TXRDY : out std_logic; -- Requests next data byte to transmit
|
73 |
|
|
T_TXDAT : in std_logic_vector(7 downto 0); -- Data to transmit
|
74 |
|
|
I_HIGHSPEED : in std_logic;
|
75 |
|
|
P_RXACT : in std_logic;
|
76 |
|
|
P_RXRDY : in std_logic;
|
77 |
|
|
P_RXFIN : in std_logic;
|
78 |
|
|
P_RXDAT : in std_logic_vector(7 downto 0);
|
79 |
|
|
P_TXACT : out std_logic;
|
80 |
|
|
P_TXRDY : in std_logic;
|
81 |
|
|
P_TXDAT : out std_logic_vector(7 downto 0) );
|
82 |
|
|
end component usb_transact;
|
83 |
|
|
|
84 |
|
|
-- Default control endpoint.
|
85 |
|
|
component usb_control is
|
86 |
|
|
generic (
|
87 |
|
|
NENDPT : integer range 1 to 15 ); -- Highest endpoint number in use
|
88 |
|
|
port (
|
89 |
|
|
CLK : in std_logic; -- 60 MHz UTMI clock
|
90 |
|
|
RESET : in std_logic; -- Synchronous reset of this entity
|
91 |
|
|
C_ADDR : out std_logic_vector(6 downto 0); -- Current device address
|
92 |
|
|
C_CONFD : out std_logic; -- High when in Configured state
|
93 |
|
|
C_CLRIN : out std_logic_vector(1 to NENDPT); -- Trigger clearing of sync bit for IN endpoint
|
94 |
|
|
C_CLROUT : out std_logic_vector(1 to NENDPT); -- Trigger clearing of sync bit for OUT endpoint
|
95 |
|
|
C_HLTIN : in std_logic_vector(1 to NENDPT); -- Current status of halt bit for IN endpoint
|
96 |
|
|
C_HLTOUT : in std_logic_vector(1 to NENDPT); -- Current status of halt bit for OUT endpoint
|
97 |
|
|
C_SHLTIN : out std_logic_vector(1 to NENDPT); -- Trigger setting of halt bit for IN endpoint
|
98 |
|
|
C_SHLTOUT : out std_logic_vector(1 to NENDPT); -- Trigger setting of halt bit for OUT endpoint
|
99 |
|
|
C_DSCBUSY : out std_logic; -- High when accessing descriptor memory
|
100 |
|
|
C_DSCRD : out std_logic; -- Descriptor read enable
|
101 |
|
|
C_DSCTYP : out std_logic_vector(2 downto 0); -- Requested descriptor type
|
102 |
|
|
C_DSCINX : out std_logic_vector(7 downto 0); -- Requested descriptor index
|
103 |
|
|
C_DSCOFF : out std_logic_vector(7 downto 0); -- Offset within requested descriptor
|
104 |
|
|
C_DSCLEN : in std_logic_vector(7 downto 0); -- Length of selected descriptor
|
105 |
|
|
C_SELFPOWERED : in std_logic; -- High if the device is not drawing bus power
|
106 |
|
|
T_IN : in std_logic;
|
107 |
|
|
T_OUT : in std_logic;
|
108 |
|
|
T_SETUP : in std_logic;
|
109 |
|
|
T_PING : in std_logic;
|
110 |
|
|
T_FIN : in std_logic;
|
111 |
|
|
T_NAK : out std_logic;
|
112 |
|
|
T_STALL : out std_logic;
|
113 |
|
|
T_NYET : out std_logic;
|
114 |
|
|
T_SEND : out std_logic;
|
115 |
|
|
T_ISYNC : out std_logic;
|
116 |
|
|
T_OSYNC : in std_logic;
|
117 |
|
|
T_RXRDY : in std_logic;
|
118 |
|
|
T_RXDAT : in std_logic_vector(7 downto 0);
|
119 |
|
|
T_TXRDY : in std_logic;
|
120 |
|
|
T_TXDAT : out std_logic_vector(7 downto 0) );
|
121 |
|
|
end component usb_control;
|
122 |
|
|
|
123 |
|
|
-- Serial data transfer core.
|
124 |
|
|
component usb_serial is
|
125 |
|
|
generic (
|
126 |
|
|
VENDORID : std_logic_vector(15 downto 0); -- Vendor ID
|
127 |
|
|
PRODUCTID : std_logic_vector(15 downto 0); -- Product ID
|
128 |
|
|
VERSIONBCD : std_logic_vector(15 downto 0); -- Product version
|
129 |
|
|
HSSUPPORT : boolean := false; -- Support high speed mode
|
130 |
|
|
SELFPOWERED : boolean := false; -- Device does not use bus power
|
131 |
|
|
RXBUFSIZE_BITS: integer range 7 to 12 := 11; -- Size of receive buffer
|
132 |
|
|
TXBUFSIZE_BITS: integer range 7 to 12 := 10 ); -- Size of transmit buffer
|
133 |
|
|
port (
|
134 |
|
|
CLK : in std_logic; -- 60 MHz UTMI clock
|
135 |
|
|
RESET : in std_logic; -- Synchronous reset
|
136 |
|
|
USBRST : out std_logic; -- Reset signal detected on bus
|
137 |
|
|
HIGHSPEED : out std_logic; -- Device operating in high speed mode
|
138 |
|
|
SUSPEND : out std_logic; -- Device is suspended
|
139 |
|
|
ONLINE : out std_logic; -- Device is in Configured state
|
140 |
|
|
RXVAL : out std_logic; -- Received byte available on RXDAT
|
141 |
|
|
RXDAT : out std_logic_vector(7 downto 0);
|
142 |
|
|
RXRDY : in std_logic; -- Application ready for next byte
|
143 |
|
|
RXLEN : out std_logic_vector(RXBUFSIZE_BITS-1 downto 0);
|
144 |
|
|
TXVAL : in std_logic; -- Application has data to send
|
145 |
|
|
TXDAT : in std_logic_vector(7 downto 0);
|
146 |
|
|
TXRDY : out std_logic; -- Entity ready to accept next byte
|
147 |
|
|
TXROOM : out std_logic_vector(TXBUFSIZE_BITS-1 downto 0);
|
148 |
|
|
TXCORK : in std_logic; -- Suppress data transmission
|
149 |
|
|
PHY_DATAIN : in std_logic_vector(7 downto 0);
|
150 |
|
|
PHY_DATAOUT : out std_logic_vector(7 downto 0);
|
151 |
|
|
PHY_TXVALID : out std_logic;
|
152 |
|
|
PHY_TXREADY : in std_logic;
|
153 |
|
|
PHY_RXACTIVE : in std_logic;
|
154 |
|
|
PHY_RXVALID : in std_logic;
|
155 |
|
|
PHY_RXERROR : in std_logic;
|
156 |
|
|
PHY_LINESTATE : in std_logic_vector(1 downto 0);
|
157 |
|
|
PHY_OPMODE : out std_logic_vector(1 downto 0);
|
158 |
|
|
PHY_XCVRSELECT: out std_logic;
|
159 |
|
|
PHY_TERMSELECT: out std_logic;
|
160 |
|
|
PHY_RESET : out std_logic );
|
161 |
|
|
end component usb_serial;
|
162 |
|
|
|
163 |
|
|
end package usb_pkg;
|