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

Subversion Repositories usb_fpga_2_14

[/] [usb_fpga_2_14/] [trunk/] [examples/] [memfifo/] [fpga-2.18/] [memfifo.vhd.old] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
library ieee;
2
use IEEE.std_logic_1164.all;
3
use IEEE.std_logic_arith.all;
4
use IEEE.std_logic_unsigned.all;
5
Library UNISIM;
6
use UNISIM.vcomponents.all;
7
 
8
--
9
--   Top level module: glues everything together.
10
--
11
 
12
entity memfifo is
13
     port (
14
        fxclk_in : in std_logic;
15
        ifclk_in : in std_logic;
16
        reset    : in std_logic;
17
        mode     : in std_logic_vector(1 downto 0);
18
        -- debug
19
        led1 : out std_logic_vector(9 downto 0);
20
        led2 : out std_logic_vector(19 downto 0);
21
        SW8  : in std_logic;
22
        SW10 : in std_logic;
23
        -- ddr3
24
        ddr3_dq      : inout std_logic_vector(15 downto 0);
25
        ddr3_dqs_n   : inout std_logic_vector(1 downto 0);
26
        ddr3_dqs_p   : inout std_logic_vector(1 downto 0);
27
        ddr3_addr    : out std_logic_vector(13 downto 0);
28
        ddr3_ba      : out std_logic_vector(2 downto 0);
29
        ddr3_ras_n   : out std_logic;
30
        ddr3_cas_n   : out std_logic;
31
        ddr3_we_n    : out std_logic;
32
        ddr3_reset_n : out std_logic;
33
        ddr3_ck_p    : out std_logic_vector(0 downto 0);
34
        ddr3_ck_n    : out std_logic_vector(0 downto 0);
35
        ddr3_cke     : out std_logic_vector(0 downto 0);
36
        ddr3_dm      : out std_logic_vector(1 downto 0);
37
        ddr3_odt     : out std_logic_vector(0 downto 0);
38
        -- ez-usb
39
        fd        : inout std_logic_vector(15 downto 0);
40
        SLWR      : out std_logic;
41
        SLRD      : out std_logic;
42
        SLOE      : out std_logic;
43
        FIFOADDR0 : out std_logic;
44
        FIFOADDR1 : out std_logic;
45
        PKTEND    : out std_logic;
46
        FLAGA     : in std_logic;
47
        FLAGB     : in std_logic
48
    );
49
end memfifo;
50
 
51
architecture RTL of memfifo is
52
 
53
 
54
component dram_fifo
55
    generic (
56
        -- fifo parameters, see "7 Series Memory Resources" user guide (ug743)
57
        ALMOST_EMPTY_OFFSET1 : INTEGER := 16;
58
        ALMOST_EMPTY_OFFSET2 : INTEGER := 16;
59
        ALMOST_FULL_OFFSET1 : INTEGER := 16;
60
        ALMOST_FULL_OFFSET2 : INTEGER := 16;
61
        FIRST_WORD_FALL_THROUGH : String := "TRUE";
62
        -- clock dividers for PLL outputs not used for memory interface, VCO frequency is 1200 MHz
63
        CLKOUT2_DIVIDE : INTEGER := 1;
64
        CLKOUT3_DIVIDE : INTEGER := 1;
65
        CLKOUT4_DIVIDE : INTEGER := 1;
66
        CLKOUT5_DIVIDE : INTEGER := 1;
67
        CLKOUT2_PHASE : INTEGER := 0;
68
        CLKOUT3_PHASE : INTEGER := 0;
69
        CLKOUT4_PHASE : INTEGER := 0;
70
        CLKOUT5_PHASE : INTEGER := 0
71
    );
72
    port (
73
        fxclk_in  : in std_logic;       -- 48 MHz input clock pin
74
        reset     : in std_logic;       -- reset in
75
        reset_out : out std_logic;      -- reset output
76
        -- PLL clock outputs not used for memory interface
77
        clkout2 : out std_logic;
78
        clkout3 : out std_logic;
79
        clkout4 : out std_logic;
80
        clkout5 : out std_logic;
81
 
82
        -- ddr3 pins
83
        ddr3_dq      : inout std_logic_vector(15  downto 0);
84
        ddr3_dqs_n   : inout std_logic_vector(1  downto 0);
85
        ddr3_dqs_p   : inout std_logic_vector(1  downto 0);
86
        ddr3_addr    : out std_logic_vector(13  downto 0);
87
        ddr3_ba      : out std_logic_vector(2  downto 0);
88
        ddr3_ras_n   : out std_logic;
89
        ddr3_cas_n   : out std_logic;
90
        ddr3_we_n    : out std_logic;
91
        ddr3_reset_n : out std_logic;
92
        ddr3_ck_p    : out std_logic_vector(0  downto 0);
93
        ddr3_ck_n    : out std_logic_vector(0  downto 0);
94
        ddr3_cke     : out std_logic_vector(0  downto 0);
95
        ddr3_dm      : out std_logic_vector(1  downto 0);
96
        ddr3_odt     : out std_logic_vector(0  downto 0);
97
 
98
        -- input fifo interface, see "7 Series Memory Resources" user guide (ug743)
99
        DI          : in std_logic_vector(127  downto 0);
100
        FULL        : out std_logic;
101
        ALMOSTFULL1 : out std_logic;
102
        ALMOSTFULL2 : out std_logic;
103
        WRERR       : out std_logic;
104
        WRCLK       : in std_logic;
105
        WREN        : in std_logic;
106
 
107
        -- output fifo interface, see "7 Series Memory Resources" user guide (ug743)
108
        DO           : out std_logic_vector(127  downto 0);
109
        EMPTY        : out std_logic;
110
        ALMOSTEMPTY1 : out std_logic;
111
        ALMOSTEMPTY2 : out std_logic;
112
        RDERR        : out std_logic;
113
        RDCLK        : in std_logic;
114
        RDEN         : in std_logic;
115
 
116
        -- free memory
117
        mem_free_out : out std_logic_vector(24 downto 0);
118
 
119
        -- for debugging
120
        status       : out std_logic_vector(9  downto 0)
121
    );
122
end component;
123
 
124
component ezusb_io
125
    generic (
126
        OUTEP : INTEGER := 2;                                 -- EP for FPGA -> EZ-USB transfers
127
        INEP  : INTEGER := 6                                  -- EP for EZ-USB -> FPGA transfers
128
    );
129
    port (
130
        ifclk     : out std_logic;
131
        reset     : in std_logic;                             -- asynchronous reset input
132
        reset_out : out std_logic;                            -- synchronous reset output
133
        -- pins
134
        ifclk_in   : in std_logic;
135
        fd         : inout std_logic_vector(15  downto 0);
136
        SLWR       : out std_logic;
137
        PKTEND     : out std_logic;
138
        SLRD       : out std_logic;
139
        SLOE       : out std_logic;
140
        FIFOADDR   : out std_logic_vector(1  downto 0);
141
        EMPTY_FLAG : in std_logic;
142
        FULL_FLAG  : in std_logic;
143
        -- signals for FPGA -> EZ-USB transfer
144
        DI        : in std_logic_vector(15  downto 0);         -- data written to EZ-USB
145
        DI_valid  : in std_logic;                              -- 1 indicates data valid; DI and DI_valid must be hold if DI_ready is 0
146
        DI_ready  : out std_logic;                             -- 1 if new data are accepted
147
        DI_enable : in std_logic;                              -- setting to 0 disables FPGA -> EZ-USB transfers
148
        pktend_timeout : in std_logic_vector(15  downto 0);    -- timeout in multiples of 65536 clocks before a short packet committed
149
                                                               -- setting to 0 disables this feature
150
        -- signals for EZ-USB -> FPGA transfer
151
        DO       : out std_logic_vector(15  downto 0);         -- data read from EZ-USB
152
        DO_valid : out std_logic;                              -- 1 indicated valid data
153
        DO_ready : in std_logic;                               -- setting to 1 enables writing new data to DO in next clock; DO and DO_valid are hold if DO_ready is 0
154
                                                               -- set to 0 to disable data reads
155
        -- debug output
156
        status : out std_logic_vector(3  downto 0)
157
    );
158
end component;
159
 
160
 
161
signal reset2      : std_logic;
162
signal reset_mem   : std_logic;
163
signal reset_usb   : std_logic;
164
signal ifclk       : std_logic;
165
signal reset_ifclk : std_logic;
166
signal mem_free    : std_logic_vector(24 downto 0);
167
signal status      : std_logic_vector(9 downto 0);
168
signal if_status   : std_logic_vector(3 downto 0);
169
signal mode_buf    : std_logic_vector(1 downto 0);
170
 
171
-- input fifo
172
signal DI           : std_logic_vector(127 downto 0);
173
signal FULL         : std_logic;
174
signal WRERR        : std_logic;
175
signal USB_DO_valid : std_logic;
176
signal DO_ready     : std_logic;
177
signal WREN         : std_logic;
178
signal wrerr_buf    : std_logic;
179
signal USB_DO       : std_logic_vector(15 downto 0);
180
signal in_data      : std_logic_vector(127 downto 0);
181
signal wr_cnt       : std_logic_vector(3 downto 0);
182
signal test_cnt     : std_logic_vector(6 downto 0);
183
signal test_cs      : std_logic_vector(13 downto 0);
184
signal in_valid     : std_logic;
185
signal test_sync    : std_logic;
186
signal clk_div      : std_logic_vector(1 downto 0);
187
 
188
-- output fifo
189
signal DO           : std_logic_vector(127 downto 0);
190
signal EMPTY        : std_logic;
191
signal RDERR        : std_logic;
192
signal USB_DI_ready : std_logic;
193
signal RDEN         : std_logic;
194
signal rderr_buf    : std_logic;
195
signal USB_DI_valid : std_logic;
196
signal rd_buf       : std_logic_vector(127 downto 0);
197
signal rd_cnt       : std_logic_vector(2 downto 0);
198
 
199
 
200
begin
201
    dram_fifo_inst : dram_fifo
202
    generic map (
203
        FIRST_WORD_FALL_THROUGH => "TRUE",                      -- Sets the FIFO FWFT to FALSE, TRUE
204
        ALMOST_EMPTY_OFFSET2    => 8
205
    )
206
    port map (
207
        fxclk_in  => fxclk_in,                                  -- 48 MHz input clock pin
208
        reset     => reset2,
209
        reset_out => reset_mem,                                 -- reset output
210
        clkout2   => open,                                      -- PLL clock outputs not used for memory interface
211
        clkout3   => open,
212
        clkout4   => open,
213
        clkout5   => open,
214
        -- Memory interface ports
215
        ddr3_dq      => ddr3_dq,
216
        ddr3_dqs_n   => ddr3_dqs_n,
217
        ddr3_dqs_p   => ddr3_dqs_p,
218
        ddr3_addr    => ddr3_addr,
219
        ddr3_ba      => ddr3_ba,
220
        ddr3_ras_n   => ddr3_ras_n,
221
        ddr3_cas_n   => ddr3_cas_n,
222
        ddr3_we_n    => ddr3_we_n,
223
        ddr3_reset_n => ddr3_reset_n,
224
        ddr3_ck_p    => ddr3_ck_p,
225
        ddr3_ck_n    => ddr3_ck_n,
226
        ddr3_cke     => ddr3_cke,
227
        ddr3_dm      => ddr3_dm,
228
        ddr3_odt     => ddr3_odt,
229
        -- input fifo interface, see "7 Series Memory Resources" user guide (ug743)
230
        DI          => DI,
231
        FULL        => FULL,           -- 1-bit output: Full flag
232
        ALMOSTFULL1 => open,           -- 1-bit output: Almost full flag
233
        ALMOSTFULL2 => open,           -- 1-bit output: Almost full flag
234
        WRERR       => WRERR,          -- 1-bit output: Write error
235
        WREN        => WREN,           -- 1-bit input: Write enable
236
        WRCLK       => ifclk,          -- 1-bit input: Rising edge write clock.
237
        -- output fifo interface, see "7 Series Memory Resources" user guide (ug743)
238
        DO           => DO,
239
        EMPTY        => EMPTY,         -- 1-bit output: Empty flag
240
        ALMOSTEMPTY1 => open,          -- 1-bit output: Almost empty flag
241
        ALMOSTEMPTY2 => open,          -- 1-bit output: Almost empty flag
242
        RDERR        => RDERR,         -- 1-bit output: Read error
243
        RDCLK        => ifclk,         -- 1-bit input: Read clock
244
        RDEN         => RDEN,          -- 1-bit input: Read enable
245
        -- free memory
246
        mem_free_out => mem_free,
247
        -- for debugging
248
        status       => status
249
    );
250
 
251
    ezusb_io_inst : ezusb_io
252
    generic map (
253
        OUTEP => 2,                     -- EP for FPGA -> EZ-USB transfers
254
        INEP  => 6                      -- EP for EZ-USB -> FPGA transfers
255
    )
256
    port map (
257
        ifclk     => ifclk,
258
        reset     => reset,             -- asynchronous reset input
259
        reset_out => reset_usb,         -- synchronous reset output
260
        -- pins
261
        ifclk_in   => ifclk_in,
262
        fd         => fd,
263
        SLWR       => SLWR,
264
        SLRD       => SLRD,
265
        SLOE       => SLOE,
266
        PKTEND     => PKTEND,
267
        FIFOADDR(0)=> FIFOADDR0,
268
        FIFOADDR(1)=> FIFOADDR1,
269
        EMPTY_FLAG => FLAGA,
270
        FULL_FLAG  => FLAGB,
271
        -- signals for FPGA -> EZ-USB transfer
272
        DI             => rd_buf(15 downto 0),  -- data written to EZ-USB
273
        DI_valid       => USB_DI_valid,         -- 1 indicates data valid; DI and DI_valid must be hold if DI_ready is 0
274
        DI_ready       => USB_DI_ready,         -- 1 if new data are accepted
275
        DI_enable      => '1',                  -- setting to 0 disables FPGA -> EZ-USB transfers
276
        pktend_timeout => conv_std_logic_vector(90,16),         -- timeout in multiples of 65536 clocks (approx. 0.1s @ 48 MHz) before a short packet committed
277
                                                -- setting to 0 disables this feature
278
        -- signals for EZ-USB -> FPGA transfer
279
        DO       => USB_DO,                     -- data read from EZ-USB
280
        DO_valid => USB_DO_valid,               -- 1 indicated valid data
281
        DO_ready => DO_ready,                   -- setting to 1 enables writing new data to DO in next clock; DO and DO_valid are hold if DO_ready is 0
282
        -- debug output
283
        status   => if_status
284
    );
285
 
286
    reset2 <= reset or reset_usb;
287
    DO_ready <= '1' when ( (mode_buf="00") and (reset_ifclk='0') and (FULL='0') ) else '0';
288
 
289
    -- debug board LEDs
290
    led1 <= status when (SW10='1') else (EMPTY & FULL & wrerr_buf & rderr_buf & if_status & FLAGB & FLAGA);
291
 
292
    led2(0) <= '1' when mem_free /= ( '1' & conv_std_logic_vector(0,24) ) else '0';
293
    led2(1) <= '1' when mem_free(23 downto 19) < conv_std_logic_vector(30,5) else '0';
294
    led2(2) <= '1' when mem_free(23 downto 19) < conv_std_logic_vector(29,5) else '0';
295
    led2(3) <= '1' when mem_free(23 downto 19) < conv_std_logic_vector(27,5) else '0';
296
    led2(4) <= '1' when mem_free(23 downto 19) < conv_std_logic_vector(25,5) else '0';
297
    led2(5) <= '1' when mem_free(23 downto 19) < conv_std_logic_vector(24,5) else '0';
298
    led2(6) <= '1' when mem_free(23 downto 19) < conv_std_logic_vector(22,5) else '0';
299
    led2(7) <= '1' when mem_free(23 downto 19) < conv_std_logic_vector(20,5) else '0';
300
    led2(8) <= '1' when mem_free(23 downto 19) < conv_std_logic_vector(19,5) else '0';
301
    led2(9) <= '1' when mem_free(23 downto 19) < conv_std_logic_vector(17,5) else '0';
302
    led2(10) <= '1' when mem_free(23 downto 19) < conv_std_logic_vector(15,5) else '0';
303
    led2(11) <= '1' when mem_free(23 downto 19) < conv_std_logic_vector(13,5) else '0';
304
    led2(12) <= '1' when mem_free(23 downto 19) < conv_std_logic_vector(12,5) else '0';
305
    led2(13) <= '1' when mem_free(23 downto 19) < conv_std_logic_vector(10,5) else '0';
306
    led2(14) <= '1' when mem_free(23 downto 19) < conv_std_logic_vector(8,5) else '0';
307
    led2(15) <= '1' when mem_free(23 downto 19) < conv_std_logic_vector(7,5) else '0';
308
    led2(16) <= '1' when mem_free(23 downto 19) < conv_std_logic_vector(5,5) else '0';
309
    led2(17) <= '1' when mem_free(23 downto 19) < conv_std_logic_vector(3,5) else '0';
310
    led2(18) <= '1' when mem_free(23 downto 19) < conv_std_logic_vector(2,5) else '0';
311
    led2(19) <= '1' when mem_free = conv_std_logic_vector(0,25) else '0';
312
 
313
    test_sync <= '1' when ( (wr_cnt="1110") or (wr_cnt(0)='1') ) else '0';
314
 
315
    dpifclk: process
316
    begin
317
        wait until ( ifclk'EVENT and (ifclk = '1') );
318
 
319
        -- reset
320
        reset_ifclk <= (reset or reset_usb) or reset_mem;
321
        if ( reset_ifclk = '1' ) then
322
            rderr_buf <= '0';
323
            wrerr_buf <= '0';
324
        else
325
            rderr_buf <= rderr_buf or RDERR;
326
            wrerr_buf <= wrerr_buf or WRERR;
327
        end if;
328
 
329
        -- FPGA -> EZ-USB FIFO
330
        if ( reset_ifclk = '1' ) then
331
            rd_cnt <= (others => '0');
332
            USB_DI_valid <= '0';
333
        else
334
            if ( USB_DI_ready = '1' ) then
335
                USB_DI_valid <= not EMPTY;
336
                if ( EMPTY = '0' ) then
337
                    if ( rd_cnt = "000" ) then
338
                        rd_buf <= DO;
339
                    else
340
                        rd_buf(111 downto 0) <= rd_buf(127 downto 16);
341
                    end if;
342
                    rd_cnt <= rd_cnt + 1;
343
                end if;
344
            end if;
345
        end if;
346
 
347
        if ( (reset_ifclk = '0') and (USB_DI_ready = '1') and (EMPTY = '0') and (rd_cnt = "000")) then
348
            RDEN <= '1';
349
        else
350
            RDEN <= '0';
351
        end if;
352
 
353
        -- data source
354
        if ( reset_ifclk = '1' ) then
355
            in_data <= (others => '0');
356
            in_valid <= '0';
357
            wr_cnt <= (others => '0');
358
            test_cnt <=(others => '0');
359
            test_cs <= conv_std_logic_vector(47,14);
360
            WREN <= '0';
361
            clk_div <= "11";
362
        else
363
            if ( FULL = '0' ) then
364
                if ( in_valid = '1' ) then
365
                    DI <= in_data;
366
                end if;
367
                if ( mode_buf = "00" ) then
368
                    if ( USB_DO_valid = '1' ) then
369
                        in_data <= USB_DO & in_data(127  downto 16);
370
                        if ( wr_cnt(2 downto 0) = "111") then
371
                            in_valid <= '1';
372
                        else
373
                            in_valid <= '0';
374
                        end if;
375
                        wr_cnt <= wr_cnt + 1;
376
                    else
377
                        in_valid <= '0';
378
                    end if;
379
                else
380
                    if ( clk_div = "00" ) then
381
                        if ( ( wr_cnt = "1111"  )  ) then
382
                            test_cs <= conv_std_logic_vector(47,14);
383
                            in_data(126 downto 120) <= test_cs(6 downto 0) xor test_cs(13 downto 7);
384
                            in_valid <= '1';
385
                        else
386
                            test_cnt <= test_cnt + conv_std_logic_vector(111,7);
387
                            test_cs <= test_cs + ( test_sync & test_cnt );
388
                            in_data(126  downto 120 ) <= test_cnt;
389
                            in_valid <= '0';
390
                        end if;
391
                        in_data(127 ) <= test_sync;
392
                        in_data(119  downto 0 ) <= in_data(127 downto 8 );
393
                        wr_cnt <= wr_cnt + 1;
394
                    else
395
                        in_valid <= '0';
396
                    end if;
397
                end if;
398
                if ( (mode_buf = "01") or ( (mode_buf = "11") and (SW8='1') ) ) then
399
                    clk_div <= "00";
400
                else
401
                    clk_div <= clk_div + 1;
402
                end if;
403
            end if;
404
        end if;
405
        if ( (reset_ifclk ='0') and (in_valid = '1') and (FULL='0') ) then
406
            WREN <='1';
407
        else
408
            WREN <='0';
409
        end if;
410
        mode_buf <= mode;
411
    end process dpifclk;
412
 
413
end RTL;
414
 

powered by: WebSVN 2.1.0

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