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

Subversion Repositories btc_dsha256

[/] [btc_dsha256/] [trunk/] [rtl/] [vhdl/] [misc/] [sync_fifo_fwft_infer.vhd] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 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
-- Description:
29
--   Implement BRAM according to gADDRESS_WIDTH and gDATA_WIDTH
30
--   Maxim number of data word is (2**gADDRESS_WIDTH - 1)
31
-------------------------------------------------------------------
32
 
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_fwft_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
                );
46
        port(
47
                iClk : in std_logic := '0';
48
                iReset_sync : in std_logic := '0';
49
 
50
                ivProgFullTh : in std_logic_vector(gADDRESS_WIDTH-1 downto 0) := conv_std_logic_vector(2**gADDRESS_WIDTH-3, gADDRESS_WIDTH);
51
                ivProgEmptyTh : in std_logic_vector(gADDRESS_WIDTH-1 downto 0) := conv_std_logic_vector(2, gADDRESS_WIDTH);
52
 
53
                iWrEn : in std_logic := '0';
54
                iRdEn : in std_logic := '0';
55
                ivDataIn : in std_logic_vector(gDATA_WIDTH-1 downto 0) := (others=>'0');
56
                ovDataOut : out std_logic_vector(gDATA_WIDTH-1 downto 0) := (others=>'0');
57
                oDataOutValid : out std_logic := '0';
58
 
59
                oFull : out std_logic := '0';
60
                oEmpty : out std_logic := '1';
61
                oAlmostFull : out std_logic := '0';
62
                oAlmostEmpty : out std_logic := '1';
63
                oProgFull : out std_logic := '0';
64
                oProgEmpty : out std_logic := '1';
65
 
66
                oOverflow : out std_logic := '0';
67
                oUnderflow : out std_logic := '0'
68
        );
69
end sync_fifo_fwft_infer;
70
 
71
ARCHITECTURE behavioral OF sync_fifo_fwft_infer IS
72
 
73
        component sdpram_infer_read_first is
74
            generic (
75
                gADDRESS_WIDTH : integer := 5;
76
                gDATA_WIDTH : integer := 24
77
                );
78
            port (
79
                iClk : in std_logic;
80
                iReset_sync : in std_logic;
81
                iWe : in std_logic;
82
                ivWrAddr : in std_logic_vector(gADDRESS_WIDTH-1 downto 0);
83
                        ivRdAddr : in std_logic_vector(gADDRESS_WIDTH-1 downto 0);
84
                ivDataIn : in std_logic_vector(gDATA_WIDTH-1 downto 0);
85
                ovDataOut : out std_logic_vector(gDATA_WIDTH-1 downto 0)
86
                );
87
        end component;
88
 
89
        component pipelines_without_reset IS
90
                GENERIC (gBUS_WIDTH : integer := 1; gNB_PIPELINES: integer range 1 to 255 := 2);
91
                PORT(
92
                        iClk                            : IN            STD_LOGIC;
93
                        iInput                          : IN            STD_LOGIC;
94
                        ivInput                         : IN            STD_LOGIC_VECTOR(gBUS_WIDTH-1 downto 0);
95
                        oDelayed_output         : OUT           STD_LOGIC;
96
                        ovDelayed_output        : OUT           STD_LOGIC_VECTOR(gBUS_WIDTH-1 downto 0)
97
                );
98
        END component;
99
 
100
        signal svWriteAddr : std_logic_vector(gADDRESS_WIDTH-1 downto 0) := (others=>'0');
101
        signal svReadAddr : std_logic_vector(gADDRESS_WIDTH-1 downto 0) := (others=>'0');
102
        signal sEffectiveWrEn : std_logic := '0';
103
        signal sEffectiveRdEn : std_logic := '0';
104
        signal svFifoCount : std_logic_vector(gADDRESS_WIDTH-1 downto 0) := (others=>'0');
105
        signal svProgFullThM1 : std_logic_vector(gADDRESS_WIDTH-1 downto 0) := conv_std_logic_vector(2**gADDRESS_WIDTH-4, gADDRESS_WIDTH);
106
        signal svProgEmptyThP1 : std_logic_vector(gADDRESS_WIDTH-1 downto 0) := conv_std_logic_vector(3, gADDRESS_WIDTH);
107
        signal sFifoFull : std_logic := '0';
108
        signal sFifoEmpty : std_logic := '1';
109
        signal sAlmostFull : std_logic := '0';
110
        signal sAlmostEmpty : std_logic := '1';
111
        signal sProgFull : std_logic := '0';
112
        signal sProgEmpty : std_logic := '1';
113
        signal sFifoOverflow : std_logic := '0';
114
        signal sFifoUnderflow : std_logic := '0';
115
 
116
        signal svMemDataOut : std_logic_vector(gDATA_WIDTH-1 downto 0) := (others=>'0');
117
        signal sMemDataOutValid : std_logic := '0';
118
        signal svPipeDataOut : std_logic_vector(gDATA_WIDTH-1 downto 0) := (others=>'0');
119
        signal sPipeDataOutValid: std_logic := '0';
120
 
121
 
122
BEGIN
123
        sdpram_inst: sdpram_infer_read_first
124
            generic map(
125
                gADDRESS_WIDTH => gADDRESS_WIDTH,
126
                gDATA_WIDTH => gDATA_WIDTH
127
                )
128
            port map(
129
                iClk => iClk,
130
                iReset_sync => iReset_sync,
131
                iWe => iWrEn,
132
                ivWrAddr => svWriteAddr,
133
                        ivRdAddr => svReadAddr,
134
                ivDataIn => ivDataIn,
135
                ovDataOut => svMemDataOut
136
                );
137
 
138
        sMemDataOutValid <= iRdEn;
139
 
140
        -----------------------------------------------------------------------------------------------
141
        -- Generate the write and read pointers
142
        -----------------------------------------------------------------------------------------------
143
        process(iClk)
144
        begin
145
                if rising_edge(iClk) then
146
                        if iReset_sync = '1' then
147
                                svWriteAddr <= (others=>'0');
148
                        elsif sEffectiveWrEn = '1' then
149
                                svWriteAddr <= svWriteAddr + '1';
150
                        end if;
151
                end if;
152
        end process;
153
 
154
        process(iClk)
155
        begin
156
                if rising_edge(iClk) then
157
                        if iReset_sync = '1' then
158
                                svReadAddr <= (others=>'0');
159
                        elsif sEffectiveRdEn = '1' then
160
                                svReadAddr <= svReadAddr + '1';
161
                        end if;
162
                end if;
163
        end process;
164
 
165
        -----------------------------------------------------------------------------------------------
166
        -- Generate Fifo Flags
167
        -----------------------------------------------------------------------------------------------
168
        sEffectiveWrEn <= iWrEn and (not sFifoFull);
169
        sEffectiveRdEn <= iRdEn and (not sFifoEmpty);
170
 
171
        ProgFullThM1_gen_dynamic : if gDYNAMIC_PROG_FULL_TH = true generate
172
                process (iClk)
173
                begin
174
                        if rising_edge(iClk) then
175
                                svProgFullThM1 <= ivProgFullTh - '1';
176
                        end if;
177
                end process;
178
        end generate;
179
 
180
        ProgFullThM1_gen_static : if gDYNAMIC_PROG_FULL_TH = false generate
181
                svProgFullThM1 <= ivProgFullTh - '1';
182
        end generate;
183
 
184
        ProgEmptyThM1_gen_dynamic : if gDYNAMIC_PROG_EMPTY_TH = true generate
185
                process (iClk)
186
                begin
187
                        if rising_edge(iClk) then
188
                                svProgEmptyThP1 <= ivProgEmptyTh + '1';
189
                        end if;
190
                end process;
191
        end generate;
192
 
193
        ProgEmptyThM1_gen_static : if gDYNAMIC_PROG_EMPTY_TH = false generate
194
                svProgEmptyThP1 <= ivProgEmptyTh + '1';
195
        end generate;
196
 
197
        process (iClk)
198
        begin
199
                if rising_edge(iClk) then
200
                        if (iReset_sync = '1') then
201
                                svFifoCount <= (others => '0');
202
                                sFifoFull <= '0';
203
                                sFifoEmpty <= '1';
204
                                sAlmostFull <= '0';
205
                                sAlmostEmpty <= '1';
206
                                sProgFull <= '0';
207
                                sProgEmpty <= '1';
208
 
209
                                sFifoOverflow <= '0';
210
                                sFifoUnderflow <= '0';
211
                        else
212
                                -- Fifo count when it is read or written
213
                                if (sEffectiveWrEn = '1') and (sEffectiveRdEn = '0') then
214
                                        svFifoCount <= svFifoCount + '1';
215
                                elsif (sEffectiveWrEn = '0') and (sEffectiveRdEn = '1') then
216
                                        svFifoCount <= svFifoCount - '1';
217
                                end if;
218
 
219
                                if svFifoCount = conv_std_logic_vector((2**gADDRESS_WIDTH)-2, gADDRESS_WIDTH) then
220
                                        if (iWrEn = '1') and (iRdEn = '0') then
221
                                                sFifoFull <= '1';
222
                                        else
223
                                                sFifoFull <= '0';
224
                                        end if;
225
                                elsif svFifoCount = conv_std_logic_vector((2**gADDRESS_WIDTH)-1, gADDRESS_WIDTH) then
226
                                        if iRdEn = '1' then
227
                                                sFifoFull <= '0';
228
                                        else
229
                                                sFifoFull <= '1';
230
                                        end if;
231
                                else
232
                                        sFifoFull <= '0';
233
                                end if;
234
 
235
                                if svFifoCount = conv_std_logic_vector(1, gADDRESS_WIDTH) then
236
                                        if (iWrEn = '0') and (iRdEn = '1') then
237
                                                sFifoEmpty <= '1';
238
                                        else
239
                                                sFifoEmpty <= '0';
240
                                        end if;
241
                                elsif svFifoCount = conv_std_logic_vector(0, gADDRESS_WIDTH) then
242
                                        if (iWrEn = '1') then
243
                                                sFifoEmpty <= '0';
244
                                        else
245
                                                sFifoEmpty <= '1';
246
                                        end if;
247
                                else
248
                                        sFifoEmpty <= '0';
249
                                end if;
250
 
251
                                if svFifoCount = conv_std_logic_vector((2**gADDRESS_WIDTH)-3, gADDRESS_WIDTH) then
252
                                        if (iWrEn = '1') and (iRdEn = '0') then
253
                                                sAlmostFull <= '1';
254
                                        else
255
                                                sAlmostFull <= '0';
256
                                        end if;
257
                                elsif svFifoCount = conv_std_logic_vector((2**gADDRESS_WIDTH)-2, gADDRESS_WIDTH) then
258
                                        if (iWrEn = '0') and (iRdEn = '1') then
259
                                                sAlmostFull <= '0';
260
                                        else
261
                                                sAlmostFull <= '1';
262
                                        end if;
263
                                elsif svFifoCount = conv_std_logic_vector((2**gADDRESS_WIDTH)-1, gADDRESS_WIDTH) then
264
                                        sAlmostFull <= '1';
265
                                else
266
                                        sAlmostFull <= '0';
267
                                end if;
268
 
269
                                if svFifoCount = conv_std_logic_vector(2, gADDRESS_WIDTH) then
270
                                        if (iWrEn = '0') and (iRdEn = '1') then
271
                                                sAlmostEmpty <= '1';
272
                                        else
273
                                                sAlmostEmpty <= '0';
274
                                        end if;
275
                                elsif svFifoCount = conv_std_logic_vector(1, gADDRESS_WIDTH) then
276
                                        if (iWrEn = '1') and (iRdEn = '0') then
277
                                                sAlmostEmpty <= '0';
278
                                        else
279
                                                sAlmostEmpty <= '1';
280
                                        end if;
281
                                elsif svFifoCount = conv_std_logic_vector(0, gADDRESS_WIDTH) then
282
                                        sAlmostEmpty <= '1';
283
                                else
284
                                        sAlmostEmpty <= '0';
285
                                end if;
286
 
287
                                if svFifoCount = svProgFullThM1 then
288
                                        if (iWrEn = '1') and (iRdEn = '0') then
289
                                                sProgFull <= '1';
290
                                        else
291
                                                sProgFull <= '0';
292
                                        end if;
293
                                elsif svFifoCount = ivProgFullTh then
294
                                        if (iWrEn = '0') and (iRdEn = '1') then
295
                                                sProgFull <= '0';
296
                                        else
297
                                                sProgFull <= '1';
298
                                        end if;
299
                                elsif svFifoCount > ivProgFullTh then
300
                                        sProgFull <= '1';
301
                                else
302
                                        sProgFull <= '0';
303
                                end if;
304
 
305
                                if svFifoCount = svProgEmptyThP1 then
306
                                        if (iWrEn = '0') and (iRdEn = '1') then
307
                                                sProgEmpty <= '1';
308
                                        else
309
                                                sProgEmpty <= '0';
310
                                        end if;
311
                                elsif svFifoCount = ivProgEmptyTh then
312
                                        if (iWrEn = '1') and (iRdEn = '0') then
313
                                                sProgEmpty <= '0';
314
                                        else
315
                                                sProgEmpty <= '1';
316
                                        end if;
317
                                elsif svFifoCount < ivProgEmptyTh then
318
                                        sProgEmpty <= '1';
319
                                else
320
                                        sProgEmpty <= '0';
321
                                end if;
322
                                --------------------------------
323
                                -- Generate the error flag
324
                                -------------------------------
325
                                if sFifoFull = '1' and iWrEn = '1'  then
326
                                        sFifoOverflow <= '1';
327
                                end if;
328
 
329
                                if sFifoEmpty = '1' and iRdEn = '1'  then
330
                                        sFifoUnderflow <= '1';
331
                                end if;
332
                        end if;
333
                end if;
334
        end process;
335
 
336
        oFull <= sFifoFull;
337
        oEmpty <= sFifoEmpty;
338
        oAlmostFull <= sAlmostFull;
339
        oAlmostEmpty <= sAlmostEmpty;
340
        oProgFull <= sProgFull;
341
        oProgEmpty <= sProgEmpty;
342
        oOverflow <= sFifoOverflow;
343
        oUnderflow <= sFifoUnderflow;
344
 
345
        ovDataOut <= svMemDataOut;
346
        oDataOutValid <= sMemDataOutValid;
347
 
348
END behavioral;
349
 
350
 
351
 

powered by: WebSVN 2.1.0

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