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

Subversion Repositories btc_dsha256

[/] [btc_dsha256/] [trunk/] [rtl/] [vhdl/] [misc/] [sync_fifo_infer.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 nuxi1209
------------------------------------------------------------------- 
2
--                                                               --
3
--  Copyright (C) 2013 Author and VariStream Studio              --
4
--  Author : Yu Peng                                             --
5
--                                                               -- 
6
--  This source file may be used and distributed without         -- 
7
--  restriction provided that this copyright statement is not    -- 
8
--  removed from the file and that any derivative work contains  -- 
9
--  the original copyright notice and the associated disclaimer. -- 
10
--                                                               -- 
11
--  This source file is free software; you can redistribute it   -- 
12
--  and/or modify it under the terms of the GNU Lesser General   -- 
13
--  Public License as published by the Free Software Foundation; -- 
14
--  either version 2.1 of the License, or (at your option) any   -- 
15
--  later version.                                               -- 
16
--                                                               -- 
17
--  This source is distributed in the hope that it will be       -- 
18
--  useful, but WITHOUT ANY WARRANTY; without even the implied   -- 
19
--  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      -- 
20
--  PURPOSE.  See the GNU Lesser General Public License for more -- 
21
--  details.                                                     -- 
22
--                                                               -- 
23
--  You should have received a copy of the GNU Lesser General    -- 
24
--  Public License along with this source; if not, download it   -- 
25
--  from http://www.opencores.org/lgpl.shtml                     -- 
26
--                                                               -- 
27
------------------------------------------------------------------- 
28 2 nuxi1209
-- Description:
29
--   Implement BRAM according to gADDRESS_WIDTH and gDATA_WIDTH
30
--   Maxim number of data word is (2**gADDRESS_WIDTH - 1)
31 3 nuxi1209
-------------------------------------------------------------------
32 2 nuxi1209
 
33
LIBRARY ieee;
34
USE ieee.std_logic_1164.all;
35
USE ieee.std_logic_unsigned.all;
36
USE ieee.std_logic_arith.all;
37
--use synplify.attributes.all;
38
 
39
entity sync_fifo_infer is
40
        generic (
41
                gADDRESS_WIDTH : integer range 4 to (integer'HIGH) := 8;
42
                gDATA_WIDTH : integer := 32;
43
                gDYNAMIC_PROG_FULL_TH : boolean := false;
44
                gDYNAMIC_PROG_EMPTY_TH : boolean := false;
45
                gOUTPUT_PIPELINE_NUM : integer range 1 to (integer'HIGH) := 1
46
                );
47
        port(
48
                iClk : in std_logic := '0';
49
                iReset_sync : in std_logic := '0';
50
 
51
                ivProgFullTh : in std_logic_vector(gADDRESS_WIDTH-1 downto 0) := conv_std_logic_vector(2**gADDRESS_WIDTH-3, gADDRESS_WIDTH);
52
                ivProgEmptyTh : in std_logic_vector(gADDRESS_WIDTH-1 downto 0) := conv_std_logic_vector(2, gADDRESS_WIDTH);
53
 
54
                iWrEn : in std_logic := '0';
55
                iRdEn : in std_logic := '0';
56
                ivDataIn : in std_logic_vector(gDATA_WIDTH-1 downto 0) := (others=>'0');
57
                ovDataOut : out std_logic_vector(gDATA_WIDTH-1 downto 0) := (others=>'0');
58
                oDataOutValid : out std_logic := '0';
59
 
60
                oFull : out std_logic := '0';
61
                oEmpty : out std_logic := '1';
62
                oAlmostFull : out std_logic := '0';
63
                oAlmostEmpty : out std_logic := '1';
64
                oProgFull : out std_logic := '0';
65
                oProgEmpty : out std_logic := '1';
66
 
67
                oOverflow : out std_logic := '0';
68
                oUnderflow : out std_logic := '0'
69
        );
70
end sync_fifo_infer;
71
 
72
ARCHITECTURE behavioral OF sync_fifo_infer IS
73
 
74
        component sdpram_infer_read_first_outreg is
75
            generic (
76
                gADDRESS_WIDTH : integer := 5;
77
                gDATA_WIDTH : integer := 24
78
                );
79
            port (
80
                iClk : in std_logic;
81
                iReset_sync : in std_logic;
82
                iWe : in std_logic;
83
                ivWrAddr : in std_logic_vector(gADDRESS_WIDTH-1 downto 0);
84
                        ivRdAddr : in std_logic_vector(gADDRESS_WIDTH-1 downto 0);
85
                ivDataIn : in std_logic_vector(gDATA_WIDTH-1 downto 0);
86
                ovDataOut : out std_logic_vector(gDATA_WIDTH-1 downto 0)
87
                );
88
        end component;
89
 
90
        component sdpram_infer_read_first_outreset is
91
            generic (
92
                gADDRESS_WIDTH : integer := 5;
93
                gDATA_WIDTH : integer := 24
94
                );
95
            port (
96
                iClk : in std_logic;
97
                iReset_sync : in std_logic;
98
                iWe : in std_logic;
99
                ivWrAddr : in std_logic_vector(gADDRESS_WIDTH-1 downto 0);
100
                        ivRdAddr : in std_logic_vector(gADDRESS_WIDTH-1 downto 0);
101
                ivDataIn : in std_logic_vector(gDATA_WIDTH-1 downto 0);
102
                ovDataOut : out std_logic_vector(gDATA_WIDTH-1 downto 0)
103
                );
104
        end component;
105
 
106
        component pipelines_without_reset IS
107
                GENERIC (gBUS_WIDTH : integer := 1; gNB_PIPELINES: integer range 1 to 255 := 2);
108
                PORT(
109
                        iClk                            : IN            STD_LOGIC;
110
                        iInput                          : IN            STD_LOGIC;
111
                        ivInput                         : IN            STD_LOGIC_VECTOR(gBUS_WIDTH-1 downto 0);
112
                        oDelayed_output         : OUT           STD_LOGIC;
113
                        ovDelayed_output        : OUT           STD_LOGIC_VECTOR(gBUS_WIDTH-1 downto 0)
114
                );
115
        END component;
116
 
117
        signal svWriteAddr : std_logic_vector(gADDRESS_WIDTH-1 downto 0) := (others=>'0');
118
        signal svReadAddr : std_logic_vector(gADDRESS_WIDTH-1 downto 0) := (others=>'0');
119
        signal sEffectiveWrEn : std_logic := '0';
120
        signal sEffectiveRdEn : std_logic := '0';
121
        signal svFifoCount : std_logic_vector(gADDRESS_WIDTH-1 downto 0) := (others=>'0');
122
        signal svProgFullThM1 : std_logic_vector(gADDRESS_WIDTH-1 downto 0) := conv_std_logic_vector(2**gADDRESS_WIDTH-4, gADDRESS_WIDTH);
123
        signal svProgEmptyThP1 : std_logic_vector(gADDRESS_WIDTH-1 downto 0) := conv_std_logic_vector(3, gADDRESS_WIDTH);
124
        signal sFifoFull : std_logic := '0';
125
        signal sFifoEmpty : std_logic := '1';
126
        signal sAlmostFull : std_logic := '0';
127
        signal sAlmostEmpty : std_logic := '1';
128
        signal sProgFull : std_logic := '0';
129
        signal sProgEmpty : std_logic := '1';
130
        signal sFifoOverflow : std_logic := '0';
131
        signal sFifoUnderflow : std_logic := '0';
132
 
133
        signal svMemDataOut : std_logic_vector(gDATA_WIDTH-1 downto 0) := (others=>'0');
134
        signal sMemDataOutValid : std_logic := '0';
135
        signal svPipeDataOut : std_logic_vector(gDATA_WIDTH-1 downto 0) := (others=>'0');
136
        signal sPipeDataOutValid: std_logic := '0';
137
 
138
 
139
BEGIN
140
        sdpram_gen_1: if gOUTPUT_PIPELINE_NUM = 1 generate
141
                sdpram_inst: sdpram_infer_read_first_outreset
142
                    generic map(
143
                        gADDRESS_WIDTH => gADDRESS_WIDTH,
144
                        gDATA_WIDTH => gDATA_WIDTH
145
                        )
146
                    port map(
147
                        iClk => iClk,
148
                        iReset_sync => iReset_sync,
149
                        iWe => iWrEn,
150
                        ivWrAddr => svWriteAddr,
151
                                ivRdAddr => svReadAddr,
152
                        ivDataIn => ivDataIn,
153
                        ovDataOut => svMemDataOut
154
                        );
155
 
156
                process(iClk)
157
                begin
158
                        if rising_edge(iClk) then
159
                                if iReset_sync = '1' then
160
                                        sMemDataOutValid <= '0';
161
                                else
162
                                        sMemDataOutValid <= iRdEn;
163
                                end if;
164
                        end if;
165
                end process;
166
        end generate;
167
 
168
        sdpram_gen_others: if gOUTPUT_PIPELINE_NUM > 1 generate
169
                sdpram_inst: sdpram_infer_read_first_outreg
170
                    generic map(
171
                        gADDRESS_WIDTH => gADDRESS_WIDTH,
172
                        gDATA_WIDTH => gDATA_WIDTH
173
                        )
174
                    port map(
175
                        iClk => iClk,
176
                        iReset_sync => iReset_sync,
177
                        iWe => iWrEn,
178
                        ivWrAddr => svWriteAddr,
179
                                ivRdAddr => svReadAddr,
180
                        ivDataIn => ivDataIn,
181
                        ovDataOut => svMemDataOut
182
                        );
183
 
184
                process(iClk)
185
                begin
186
                        if rising_edge(iClk) then
187
                                sMemDataOutValid <= iRdEn;
188
                        end if;
189
                end process;
190
        end generate;
191
 
192
        -----------------------------------------------------------------------------------------------
193
        -- Generate the write and read pointers
194
        -----------------------------------------------------------------------------------------------
195
        process(iClk)
196
        begin
197
                if rising_edge(iClk) then
198
                        if iReset_sync = '1' then
199
                                svWriteAddr <= (others=>'0');
200
                        elsif sEffectiveWrEn = '1' then
201
                                svWriteAddr <= svWriteAddr + '1';
202
                        end if;
203
                end if;
204
        end process;
205
 
206
        process(iClk)
207
        begin
208
                if rising_edge(iClk) then
209
                        if iReset_sync = '1' then
210
                                svReadAddr <= (others=>'0');
211
                        elsif sEffectiveRdEn = '1' then
212
                                svReadAddr <= svReadAddr + '1';
213
                        end if;
214
                end if;
215
        end process;
216
 
217
        -----------------------------------------------------------------------------------------------
218
        -- Generate Fifo Flags
219
        -----------------------------------------------------------------------------------------------
220
        sEffectiveWrEn <= iWrEn and (not sFifoFull);
221
        sEffectiveRdEn <= iRdEn and (not sFifoEmpty);
222
 
223
        ProgFullThM1_gen_dynamic : if gDYNAMIC_PROG_FULL_TH = true generate
224
                process (iClk)
225
                begin
226
                        if rising_edge(iClk) then
227
                                svProgFullThM1 <= ivProgFullTh - '1';
228
                        end if;
229
                end process;
230
        end generate;
231
 
232
        ProgFullThM1_gen_static : if gDYNAMIC_PROG_FULL_TH = false generate
233
                svProgFullThM1 <= ivProgFullTh - '1';
234
        end generate;
235
 
236
        ProgEmptyThM1_gen_dynamic : if gDYNAMIC_PROG_EMPTY_TH = true generate
237
                process (iClk)
238
                begin
239
                        if rising_edge(iClk) then
240
                                svProgEmptyThP1 <= ivProgEmptyTh + '1';
241
                        end if;
242
                end process;
243
        end generate;
244
 
245
        ProgEmptyThM1_gen_static : if gDYNAMIC_PROG_EMPTY_TH = false generate
246
                svProgEmptyThP1 <= ivProgEmptyTh + '1';
247
        end generate;
248
 
249
        process (iClk)
250
        begin
251
                if rising_edge(iClk) then
252
                        if (iReset_sync = '1') then
253
                                svFifoCount <= (others => '0');
254
                                sFifoFull <= '0';
255
                                sFifoEmpty <= '1';
256
                                sAlmostFull <= '0';
257
                                sAlmostEmpty <= '1';
258
                                sProgFull <= '0';
259
                                sProgEmpty <= '1';
260
 
261
                                sFifoOverflow <= '0';
262
                                sFifoUnderflow <= '0';
263
                        else
264
                                -- Fifo count when it is read or written
265
                                if (sEffectiveWrEn = '1') and (sEffectiveRdEn = '0') then
266
                                        svFifoCount <= svFifoCount + '1';
267
                                elsif (sEffectiveWrEn = '0') and (sEffectiveRdEn = '1') then
268
                                        svFifoCount <= svFifoCount - '1';
269
                                end if;
270
 
271
                                if svFifoCount = conv_std_logic_vector((2**gADDRESS_WIDTH)-2, gADDRESS_WIDTH) then
272
                                        if (iWrEn = '1') and (iRdEn = '0') then
273
                                                sFifoFull <= '1';
274
                                        else
275
                                                sFifoFull <= '0';
276
                                        end if;
277
                                elsif svFifoCount = conv_std_logic_vector((2**gADDRESS_WIDTH)-1, gADDRESS_WIDTH) then
278
                                        if iRdEn = '1' then
279
                                                sFifoFull <= '0';
280
                                        else
281
                                                sFifoFull <= '1';
282
                                        end if;
283
                                else
284
                                        sFifoFull <= '0';
285
                                end if;
286
 
287
                                if svFifoCount = conv_std_logic_vector(1, gADDRESS_WIDTH) then
288
                                        if (iWrEn = '0') and (iRdEn = '1') then
289
                                                sFifoEmpty <= '1';
290
                                        else
291
                                                sFifoEmpty <= '0';
292
                                        end if;
293
                                elsif svFifoCount = conv_std_logic_vector(0, gADDRESS_WIDTH) then
294
                                        if (iWrEn = '1') then
295
                                                sFifoEmpty <= '0';
296
                                        else
297
                                                sFifoEmpty <= '1';
298
                                        end if;
299
                                else
300
                                        sFifoEmpty <= '0';
301
                                end if;
302
 
303
                                if svFifoCount = conv_std_logic_vector((2**gADDRESS_WIDTH)-3, gADDRESS_WIDTH) then
304
                                        if (iWrEn = '1') and (iRdEn = '0') then
305
                                                sAlmostFull <= '1';
306
                                        else
307
                                                sAlmostFull <= '0';
308
                                        end if;
309
                                elsif svFifoCount = conv_std_logic_vector((2**gADDRESS_WIDTH)-2, gADDRESS_WIDTH) then
310
                                        if (iWrEn = '0') and (iRdEn = '1') then
311
                                                sAlmostFull <= '0';
312
                                        else
313
                                                sAlmostFull <= '1';
314
                                        end if;
315
                                elsif svFifoCount = conv_std_logic_vector((2**gADDRESS_WIDTH)-1, gADDRESS_WIDTH) then
316
                                        sAlmostFull <= '1';
317
                                else
318
                                        sAlmostFull <= '0';
319
                                end if;
320
 
321
                                if svFifoCount = conv_std_logic_vector(2, gADDRESS_WIDTH) then
322
                                        if (iWrEn = '0') and (iRdEn = '1') then
323
                                                sAlmostEmpty <= '1';
324
                                        else
325
                                                sAlmostEmpty <= '0';
326
                                        end if;
327
                                elsif svFifoCount = conv_std_logic_vector(1, gADDRESS_WIDTH) then
328
                                        if (iWrEn = '1') and (iRdEn = '0') then
329
                                                sAlmostEmpty <= '0';
330
                                        else
331
                                                sAlmostEmpty <= '1';
332
                                        end if;
333
                                elsif svFifoCount = conv_std_logic_vector(0, gADDRESS_WIDTH) then
334
                                        sAlmostEmpty <= '1';
335
                                else
336
                                        sAlmostEmpty <= '0';
337
                                end if;
338
 
339
                                if svFifoCount = svProgFullThM1 then
340
                                        if (iWrEn = '1') and (iRdEn = '0') then
341
                                                sProgFull <= '1';
342
                                        else
343
                                                sProgFull <= '0';
344
                                        end if;
345
                                elsif svFifoCount = ivProgFullTh then
346
                                        if (iWrEn = '0') and (iRdEn = '1') then
347
                                                sProgFull <= '0';
348
                                        else
349
                                                sProgFull <= '1';
350
                                        end if;
351
                                elsif svFifoCount > ivProgFullTh then
352
                                        sProgFull <= '1';
353
                                else
354
                                        sProgFull <= '0';
355
                                end if;
356
 
357
                                if svFifoCount = svProgEmptyThP1 then
358
                                        if (iWrEn = '0') and (iRdEn = '1') then
359
                                                sProgEmpty <= '1';
360
                                        else
361
                                                sProgEmpty <= '0';
362
                                        end if;
363
                                elsif svFifoCount = ivProgEmptyTh then
364
                                        if (iWrEn = '1') and (iRdEn = '0') then
365
                                                sProgEmpty <= '0';
366
                                        else
367
                                                sProgEmpty <= '1';
368
                                        end if;
369
                                elsif svFifoCount < ivProgEmptyTh then
370
                                        sProgEmpty <= '1';
371
                                else
372
                                        sProgEmpty <= '0';
373
                                end if;
374
                                --------------------------------
375
                                -- Generate the error flag
376
                                -------------------------------
377
                                if sFifoFull = '1' and iWrEn = '1'  then
378
                                        sFifoOverflow <= '1';
379
                                end if;
380
 
381
                                if sFifoEmpty = '1' and iRdEn = '1'  then
382
                                        sFifoUnderflow <= '1';
383
                                end if;
384
                        end if;
385
                end if;
386
        end process;
387
 
388
        oFull <= sFifoFull;
389
        oEmpty <= sFifoEmpty;
390
        oAlmostFull <= sAlmostFull;
391
        oAlmostEmpty <= sAlmostEmpty;
392
        oProgFull <= sProgFull;
393
        oProgEmpty <= sProgEmpty;
394
        oOverflow <= sFifoOverflow;
395
        oUnderflow <= sFifoUnderflow;
396
 
397
        -------------------------------------------------------------------------------------
398
        -- This section generates the code for the output pipelines
399
        -------------------------------------------------------------------------------------
400
        OutputPipeline_gen_1: if gOUTPUT_PIPELINE_NUM = 1 generate
401
                ovDataOut <= svMemDataOut;
402
                oDataOutValid <= sMemDataOutValid;
403
        end generate;
404
 
405
        OutputPipeline_gen_2: if gOUTPUT_PIPELINE_NUM = 2 generate
406
                process (iClk)
407
                begin
408
                        if rising_edge(iClk) then
409
                                if (iReset_sync = '1') then
410
                                        ovDataOut <= (others=>'0');
411
                                        oDataOutValid <= '0';
412
                                else
413
                                        ovDataOut <= svMemDataOut;
414
                                        oDataOutValid <= sMemDataOutValid;
415
                                end if;
416
                        end if;
417
                end process;
418
        end generate;
419
 
420
        OutputPipeline_gen_others: if gOUTPUT_PIPELINE_NUM > 2 generate
421
                pipelines_without_reset_inst_output: pipelines_without_reset
422
                        GENERIC map(
423
                                gBUS_WIDTH => gDATA_WIDTH,
424
                                gNB_PIPELINES => (gOUTPUT_PIPELINE_NUM-1)
425
                        )
426
                        PORT map(
427
                                iClk => iClk,
428
                                iInput => sMemDataOutValid,
429
                                ivInput => svMemDataOut,
430
                                oDelayed_output => sPipeDataOutValid,
431
                                ovDelayed_output => svPipeDataOut
432
                        );
433
 
434
                process (iClk)
435
                begin
436
                        if rising_edge(iClk) then
437
                                if (iReset_sync = '1') then
438
                                        ovDataOut <= (others=>'0');
439
                                        oDataOutValid <= '0';
440
                                else
441
                                        ovDataOut <= svPipeDataOut;
442
                                        oDataOutValid <= sPipeDataOutValid;
443
                                end if;
444
                        end if;
445
                end process;
446
        end generate;
447
 
448
END behavioral;
449
 
450
 
451
 

powered by: WebSVN 2.1.0

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