OpenCores
URL https://opencores.org/ocsvn/ft2232hcore/ft2232hcore/trunk

Subversion Repositories ft2232hcore

[/] [ft2232hcore/] [trunk/] [vhdl/] [usb_sync/] [usb_sync.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 wes314
 
2
-- FT2232H USB Device Core
3
-- Operates in FT245 Style Synchronous FIFO Mode for high speed data transfers
4
-- Designer: Wes Pope
5
-- License: Public Domain
6
 
7
 
8
library ieee;
9
use ieee.std_logic_1164.all;
10
use ieee.std_logic_arith.all;
11
use ieee.std_logic_unsigned.all;
12
 
13
entity usb_sync is
14
        port (
15
                -- Avalon bus signals
16
                signal clk : in std_logic;
17
                signal reset_n : in std_logic;
18
                signal read_n : in std_logic;
19
                signal write_n : in std_logic;
20
                signal irq : out std_logic;
21
                signal chipselect : in std_logic;
22
                signal address : in std_logic_vector(1 downto 0);
23
                signal readdata : out std_logic_vector (31 downto 0);
24
                signal writedata : in std_logic_vector (31 downto 0);
25
 
26
                -- FT2232 Bus Signals
27
                signal usb_clock : in std_logic;
28
                signal usb_data : inout std_logic_vector(7 downto 0);
29
                signal usb_rd_n : out std_logic;
30
                signal usb_wr_n : out std_logic;
31
                signal usb_oe_n : out std_logic;
32
                signal usb_rxf_n : in std_logic;
33
                signal usb_txe_n : in std_logic
34
                );
35
end entity usb_sync;
36
 
37
 
38
architecture rtl of usb_sync is
39
 
40
        signal rd_sig : std_logic;
41
        signal wr_sig : std_logic;
42
 
43
        signal data_addr_sig : std_logic;
44
        signal rx_status_addr_sig : std_logic;
45
        signal tx_status_addr_sig : std_logic;
46
 
47
        signal rx_fifo_rddone : std_logic := '0';
48
 
49
        signal rx_fifo_wrclk : std_logic;
50
        signal rx_fifo_rdreq : std_logic;
51
        signal rx_fifo_rdclk : std_logic;
52
        signal rx_fifo_wrreq : std_logic;
53
        signal rx_fifo_data : std_logic_vector(7 downto 0);
54
        signal rx_fifo_rdempty : std_logic;
55
        signal rx_fifo_wrfull : std_logic;
56
        signal rx_fifo_q : std_logic_vector(7 downto 0);
57
        signal rx_fifo_rdusedw : std_logic_vector(11 downto 0);
58
 
59
        signal tx_fifo_wrclk : std_logic;
60
        signal tx_fifo_rdreq : std_logic;
61
        signal tx_fifo_rdclk : std_logic;
62
        signal tx_fifo_wrreq : std_logic;
63
        signal tx_fifo_data : std_logic_vector(7 downto 0);
64
        signal tx_fifo_rdempty : std_logic;
65
        signal tx_fifo_wrfull : std_logic;
66
        signal tx_fifo_q : std_logic_vector(7 downto 0);
67
        signal tx_fifo_wrusedw : std_logic_vector(11 downto 0);
68
 
69
        signal ft2232_wait : integer range 0 to 1 := 0;
70
        signal ft2232_bus_oe_mode : integer range 0 to 3 := 0;
71
        signal ft2232_tx_fifo_read : std_logic;
72
        signal ft2232_rx_fifo_write : std_logic;
73
        signal ft2232_tx_please : std_logic;
74
        signal ft2232_rx_please : std_logic;
75
 
76
        COMPONENT dcfifo
77
        GENERIC (
78
                intended_device_family  : STRING;
79
                lpm_numwords                    : NATURAL;
80
                lpm_showahead                   : STRING;
81
                lpm_type                                : STRING;
82
                lpm_width                               : NATURAL;
83
                lpm_widthu                              : NATURAL;
84
                overflow_checking               : STRING;
85
                rdsync_delaypipe                : NATURAL;
86
                underflow_checking              : STRING;
87
                use_eab                                 : STRING;
88
                wrsync_delaypipe                : NATURAL
89
        );
90
        PORT (
91
                        wrclk   : IN STD_LOGIC ;
92
                        rdempty : OUT STD_LOGIC ;
93
                        rdreq   : IN STD_LOGIC ;
94
                        wrfull  : OUT STD_LOGIC ;
95
                        rdclk   : IN STD_LOGIC ;
96
                        q               : OUT STD_LOGIC_VECTOR (7 DOWNTO 0);
97
                        wrreq   : IN STD_LOGIC ;
98
                        data    : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
99
                        rdusedw : OUT STD_LOGIC_VECTOR (11 DOWNTO 0);
100
                        wrusedw : OUT STD_LOGIC_VECTOR (11 DOWNTO 0)
101
        );
102
        END COMPONENT;
103
 
104
begin
105
 
106
 
107
        rx_dcfifo : dcfifo
108
                GENERIC MAP (
109
                intended_device_family => "Cyclone II",
110
                lpm_numwords => 2047,
111
                lpm_showahead => "ON",
112
                lpm_type => "dcfifo",
113
                lpm_width => 8,
114
                lpm_widthu => 11,
115
                overflow_checking => "ON",
116
                rdsync_delaypipe => 4,
117
                underflow_checking => "ON",
118
                use_eab => "ON",
119
                wrsync_delaypipe => 4
120
        )
121
        PORT MAP (
122
                wrclk => rx_fifo_wrclk,
123
                rdreq => rx_fifo_rdreq,
124
                rdclk => rx_fifo_rdclk,
125
                wrreq => rx_fifo_wrreq,
126
                data => rx_fifo_data,
127
                rdempty => rx_fifo_rdempty,
128
                wrfull => rx_fifo_wrfull,
129
                q => rx_fifo_q,
130
                rdusedw => rx_fifo_rdusedw
131
        );
132
 
133
        tx_dcfifo : dcfifo
134
        GENERIC MAP (
135
                intended_device_family => "Cyclone II",
136
                lpm_numwords => 4095,
137
                lpm_showahead => "ON",
138
                lpm_type => "dcfifo",
139
                lpm_width => 8,
140
                lpm_widthu => 12,
141
                overflow_checking => "ON",
142
                rdsync_delaypipe => 4,
143
                underflow_checking => "ON",
144
                use_eab => "ON",
145
                wrsync_delaypipe => 4
146
        )
147
        PORT MAP (
148
                wrclk => tx_fifo_wrclk,
149
                rdreq => tx_fifo_rdreq,
150
                rdclk => tx_fifo_rdclk,
151
                wrreq => tx_fifo_wrreq,
152
                data => tx_fifo_data,
153
                rdempty => tx_fifo_rdempty,
154
                wrfull => tx_fifo_wrfull,
155
                q => tx_fifo_q,
156
                wrusedw => tx_fifo_wrusedw
157
        );
158
 
159
        -- USB2232 side
160
        rx_fifo_wrclk <= usb_clock;
161
        tx_fifo_rdclk <= usb_clock;
162
 
163
        ft2232_tx_please <= '1' when usb_txe_n = '0' and tx_fifo_rdempty = '0' and ft2232_wait = 1 else '0';
164
        ft2232_rx_please <= '1' when usb_rxf_n = '0' and rx_fifo_wrfull = '0' else '0';
165
 
166
        ft2232_tx_fifo_read <= '1' when ft2232_tx_please = '1' else '0';
167
        ft2232_rx_fifo_write <= '1' when ft2232_bus_oe_mode > 1 and ft2232_rx_please = '1' and ft2232_tx_please = '0' else '0';
168
 
169
        tx_fifo_rdreq <= ft2232_tx_fifo_read;
170
        rx_fifo_wrreq <= ft2232_rx_fifo_write;
171
 
172
        usb_rd_n <= '0' when ft2232_rx_fifo_write = '1' else '1';
173
        usb_wr_n <= '0' when ft2232_tx_fifo_read = '1' else '1';
174
        usb_oe_n <= '0' when ft2232_bus_oe_mode > 0 else '1';
175
        usb_data <= tx_fifo_q when ft2232_bus_oe_mode = 0 else (others => 'Z');
176
        rx_fifo_data <= usb_data when ft2232_bus_oe_mode > 0 and usb_rxf_n = '0';
177
 
178
 
179
        -- Handle FIFOs to USB2232 in synchronous mode
180
        process (usb_clock)
181
        begin
182
 
183
                if usb_clock'event and usb_clock = '1' then
184
 
185
                        -- Bias TX over RX
186
                        if (ft2232_tx_please = '1' or ft2232_rx_please = '0') then
187
 
188
                                ft2232_bus_oe_mode <= 0;
189
 
190
                                if (usb_txe_n = '0' and tx_fifo_rdempty = '0') then
191
                                        ft2232_wait <= ft2232_wait + 1;
192
                                else
193
                                        ft2232_wait <= 0;
194
                                end if;
195
 
196
                        elsif (ft2232_rx_please = '1') then
197
 
198
                                ft2232_wait <= 0;
199
 
200
                                -- Handle bus turn-around. Negate OE (and for atleast 1 clock)
201
                                if (ft2232_bus_oe_mode < 3) then
202
                                        ft2232_bus_oe_mode <= ft2232_bus_oe_mode + 1;
203
                                end if;
204
 
205
                        end if;
206
 
207
                end if;
208
 
209
        end process;
210
 
211
 
212
        -- Avalon Bus side
213
        rx_fifo_rdclk <= clk;
214
        tx_fifo_wrclk <= clk;
215
 
216
        wr_sig <= '1' when chipselect = '1' and write_n = '0' else '0';
217
        rd_sig <= '1' when chipselect = '1' and read_n = '0' else '0';
218
 
219
        data_addr_sig <= '1' when address = "00" else '0';
220
        rx_status_addr_sig <= '1' when address = "01" else '0';
221
        tx_status_addr_sig <= '1' when address = "10" else '0';
222
 
223
        irq <= '0';
224
 
225
        -- Handle FIFOs to Avalon Bus
226
        process (clk, reset_n)
227
        begin
228
 
229
                if reset_n = '0' then
230
 
231
                        readdata <= (others => '0');
232
                        rx_fifo_rddone <= '0';
233
 
234
                elsif clk'event and clk = '1' then
235
 
236
                        if (rd_sig = '1' and data_addr_sig = '1') then
237
                                -- read fifo with 2 clocks
238
                                readdata <= "000000000000000000000000" & rx_fifo_q;
239
                                if (rx_fifo_rddone = '0') then
240
                                        rx_fifo_rdreq <= '1';
241
                                        rx_fifo_rddone <= '1';
242
                                else
243
                                        rx_fifo_rdreq <= '0';
244
                                        rx_fifo_rddone <= '0';
245
                                end if;
246
                        end if;
247
 
248
                        if (wr_sig = '1' and data_addr_sig = '1') then
249
                                -- write fifo
250
                                tx_fifo_wrreq <= '1';
251
                                tx_fifo_data <= writedata(7 downto 0);
252
                        else
253
                                tx_fifo_wrreq <= '0';
254
                        end if;
255
 
256
                        if (rd_sig = '1' and rx_status_addr_sig = '1') then
257
                                -- read rx fifo stats
258
                                readdata <= "1000000000000000000" & rx_fifo_rdempty & rx_fifo_rdusedw;
259
                        end if;
260
 
261
                        if (rd_sig = '1' and tx_status_addr_sig = '1') then
262
                                -- read tx fifo stats
263
                                readdata <= "1000000000000000000" & tx_fifo_wrfull & tx_fifo_wrusedw;
264
                        end if;
265
 
266
                end if;
267
 
268
        end process;
269
 
270
end rtl;
271
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.