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

Subversion Repositories uart_fpga_slow_control_migrated

[/] [uart_fpga_slow_control/] [trunk/] [code/] [gh_fifo_async16_rcsr_wf.vhd] - Blame information for rev 34

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 aborga
---------------------------------------------------------------------
2
--      Filename:       gh_fifo_async16_rcsr_wf.vhd
3
--
4
--
5
--      Description:
6
--              a simple Asynchronous FIFO - uses FASM style Memory
7
--              16 word depth with UART level read flags
8
--              has "Style #2" gray code address compare
9
--              
10
--      Copyright (c) 2007 by Howard LeFevre 
11
--              an OpenCores.org Project
12
--              free to use, but see documentation for conditions                                                                
13
--
14
--      Revision        History:
15
--      Revision        Date            Author          Comment
16
--      --------        ----------      ---------       -----------
17
--      1.0             01/20/07        h lefevre       Initial revision
18
--      
19
--------------------------------------------------------
20
 
21
library IEEE;
22
use IEEE.std_logic_1164.all;
23
use IEEE.std_logic_unsigned.all;
24
USE ieee.std_logic_arith.all;
25
 
26
entity gh_fifo_async16_rcsr_wf is
27
        GENERIC (data_width: INTEGER :=8 ); -- size of data bus
28
        port (
29
                clk_WR  : in STD_LOGIC; -- write clock
30
                clk_RD  : in STD_LOGIC; -- read clock
31
                rst     : in STD_LOGIC; -- resets counters
32
                rc_srst : in STD_LOGIC:='0'; -- resets counters (sync with clk_RD!!!)
33
                WR      : in STD_LOGIC; -- write control 
34
                RD      : in STD_LOGIC; -- read control
35
                D       : in STD_LOGIC_VECTOR (data_width-1 downto 0);
36
                Q       : out STD_LOGIC_VECTOR (data_width-1 downto 0);
37
                empty   : out STD_LOGIC; -- sync with clk_RD!!!
38
                q_full  : out STD_LOGIC; -- sync with clk_RD!!!
39
                h_full  : out STD_LOGIC; -- sync with clk_RD!!!
40
                a_full  : out STD_LOGIC; -- sync with clk_RD!!!
41
                full    : out STD_LOGIC);
42
end entity;
43
 
44
architecture a of gh_fifo_async16_rcsr_wf is
45
 
46
component gh_binary2gray IS
47
        GENERIC (size: INTEGER := 8);
48
        PORT(
49
                B   : IN STD_LOGIC_VECTOR(size-1 DOWNTO 0);
50
                G   : out STD_LOGIC_VECTOR(size-1 DOWNTO 0)
51
                );
52
end component;
53
 
54
component gh_gray2binary IS
55
        GENERIC (size: INTEGER := 8);
56
        PORT(
57
                G   : IN STD_LOGIC_VECTOR(size-1 DOWNTO 0);      -- gray code in
58
                B   : out STD_LOGIC_VECTOR(size-1 DOWNTO 0) -- binary value out
59
                );
60
end component;
61
 
62
        type ram_mem_type is array (15 downto 0)
63
                of STD_LOGIC_VECTOR (data_width-1 downto 0);
64
        signal ram_mem : ram_mem_type;
65
        signal iempty        : STD_LOGIC;
66
        signal diempty       : STD_LOGIC;
67
        signal ifull         : STD_LOGIC;
68
        signal add_WR_CE     : std_logic;
69
        signal add_WR        : std_logic_vector(4 downto 0); -- add_width -1 bits are used to address MEM
70
        signal add_WR_GC     : std_logic_vector(4 downto 0); -- add_width bits are used to compare
71
        signal iadd_WR_GC    : std_logic_vector(4 downto 0);
72
        signal n_add_WR      : std_logic_vector(4 downto 0); --   for empty, full flags
73
        signal add_WR_RS     : std_logic_vector(4 downto 0); -- synced to read clk
74
        signal add_RD_CE     : std_logic;
75
        signal add_RD        : std_logic_vector(4 downto 0);
76
        signal add_RD_GC     : std_logic_vector(4 downto 0);
77
        signal iadd_RD_GC    : std_logic_vector(4 downto 0);
78
        signal add_RD_GCwc   : std_logic_vector(4 downto 0);
79
        signal iadd_RD_GCwc  : std_logic_vector(4 downto 0);
80
        signal iiadd_RD_GCwc : std_logic_vector(4 downto 0);
81
        signal n_add_RD      : std_logic_vector(4 downto 0);
82
        signal add_RD_WS     : std_logic_vector(4 downto 0); -- synced to write clk
83
        signal srst_w        : STD_LOGIC;
84
        signal isrst_w       : STD_LOGIC;
85
        signal srst_r        : STD_LOGIC;
86
        signal isrst_r       : STD_LOGIC;
87
        signal c_add_RD      : std_logic_vector(4 downto 0);
88
        signal c_add_WR      : std_logic_vector(4 downto 0);
89
        signal c_add         : std_logic_vector(4 downto 0);
90
 
91
begin
92
 
93
--------------------------------------------
94
------- memory -----------------------------
95
--------------------------------------------
96
 
97
 
98
process (clk_WR)
99
begin
100
        if (rising_edge(clk_WR)) then
101
                if ((WR = '1') and (ifull = '0')) then
102
                        ram_mem(CONV_INTEGER(add_WR(3 downto 0))) <= D;
103
                end if;
104
        end if;
105
end process;
106
 
107
        Q <= ram_mem(CONV_INTEGER(add_RD(3 downto 0)));
108
 
109
-----------------------------------------
110
----- Write address counter -------------
111
-----------------------------------------
112
 
113
        add_WR_CE <= '0' when (ifull = '1') else
114
                     '0' when (WR = '0') else
115
                     '1';
116
 
117
        n_add_WR <= add_WR + "01";
118
 
119
U1 : gh_binary2gray
120
        generic map (size => 5)
121
        port map(
122
                B => n_add_WR,
123
                G => iadd_WR_GC
124
                );
125
 
126
process (clk_WR,rst)
127
begin
128
        if (rst = '1') then
129
                add_WR <= (others => '0');
130
                add_RD_WS(4 downto 3) <= "11";
131
                add_RD_WS(2 downto 0) <= (others => '0');
132
                add_WR_GC <= (others => '0');
133
        elsif (rising_edge(clk_WR)) then
134
                add_RD_WS <= add_RD_GCwc;
135
                if (srst_w = '1') then
136
                        add_WR <= (others => '0');
137
                        add_WR_GC <= (others => '0');
138
                elsif (add_WR_CE = '1') then
139
                        add_WR <= n_add_WR;
140
                        add_WR_GC <= iadd_WR_GC;
141
                else
142
                        add_WR <= add_WR;
143
                        add_WR_GC <= add_WR_GC;
144
                end if;
145
        end if;
146
end process;
147
 
148
        full <= ifull;
149
 
150
        ifull <= '0' when (iempty = '1') else -- just in case add_RD_WS is reset to all zero's
151
                 '0' when (add_RD_WS /= add_WR_GC) else ---- instend of "11 zero's" 
152
                 '1';
153
 
154
 
155
-----------------------------------------
156
----- Read address counter --------------
157
-----------------------------------------
158
 
159
 
160
        add_RD_CE <= '0' when (iempty = '1') else
161
                     '0' when (RD = '0') else
162
                     '1';
163
 
164
        n_add_RD <= add_RD + "01";
165
 
166
U2 : gh_binary2gray
167
        generic map (size => 5)
168
        port map(
169
                B => n_add_RD,
170
                G => iadd_RD_GC -- to be used for empty flag
171
                );
172
 
173
        iiadd_RD_GCwc <= (not n_add_RD(4)) & n_add_RD(3 downto 0);
174
 
175
U3 : gh_binary2gray
176
        generic map (size => 5)
177
        port map(
178
                B => iiadd_RD_GCwc,
179
                G => iadd_RD_GCwc -- to be used for full flag
180
                );
181
 
182
process (clk_RD,rst)
183
begin
184
        if (rst = '1') then
185
                add_RD <= (others => '0');
186
                add_WR_RS <= (others => '0');
187
                add_RD_GC <= (others => '0');
188
                add_RD_GCwc(4 downto 3) <= "11";
189
                add_RD_GCwc(2 downto 0) <= (others => '0');
190
                diempty <= '1';
191
        elsif (rising_edge(clk_RD)) then
192
                add_WR_RS <= add_WR_GC;
193
                diempty <= iempty;
194
                if (srst_r = '1') then
195
                        add_RD <= (others => '0');
196
                        add_RD_GC <= (others => '0');
197
                        add_RD_GCwc(4 downto 3) <= "11";
198
                        add_RD_GCwc(2 downto 0) <= (others => '0');
199
                elsif (add_RD_CE = '1') then
200
                        add_RD <= n_add_RD;
201
                        add_RD_GC <= iadd_RD_GC;
202
                        add_RD_GCwc <= iadd_RD_GCwc;
203
                else
204
                        add_RD <= add_RD;
205
                        add_RD_GC <= add_RD_GC;
206
                        add_RD_GCwc <= add_RD_GCwc;
207
                end if;
208
        end if;
209
end process;
210
 
211
        empty <= diempty;
212
 
213
        iempty <= '1' when (add_WR_RS = add_RD_GC) else
214
                  '0';
215
 
216
U4 : gh_gray2binary
217
        generic map (size => 5)
218
        port map(
219
                G => add_RD_GC,
220
                B => c_add_RD
221
                );
222
 
223
U5 : gh_gray2binary
224
        generic map (size => 5)
225
        port map(
226
                G => add_WR_RS,
227
                B => c_add_WR
228
                );
229
 
230
        c_add <= (c_add_WR - c_add_RD);
231
 
232
        q_full <= '0' when (iempty = '1') else
233
                  '0' when (c_add(4 downto 2) = "000") else
234
                  '1';
235
 
236
        h_full <= '0' when (iempty = '1') else
237
                  '0' when (c_add(4 downto 3) = "00") else
238
                  '1';
239
 
240
        a_full <= '0' when (iempty = '1') else
241
                  '0' when (c_add(4 downto 1) < "0111") else
242
                  '1';
243
 
244
----------------------------------
245
--- sync rest stuff --------------
246
--- rc_srst is sync with clk_RD --
247
--- srst_w is sync with clk_WR ---
248
----------------------------------
249
 
250
process (clk_WR,rst)
251
begin
252
        if (rst = '1') then
253
                srst_w <= '0';
254
                isrst_r <= '0';
255
        elsif (rising_edge(clk_WR)) then
256
                srst_w <= isrst_w;
257
                if (srst_w = '1') then
258
                        isrst_r <= '1';
259
                elsif (srst_w = '0') then
260
                        isrst_r <= '0';
261
                end if;
262
        end if;
263
end process;
264
 
265
process (clk_RD,rst)
266
begin
267
        if (rst = '1') then
268
                srst_r <= '0';
269
                isrst_w <= '0';
270
        elsif (rising_edge(clk_RD)) then
271
                srst_r <= rc_srst;
272
                if (rc_srst = '1') then
273
                        isrst_w <= '1';
274
                elsif (isrst_r = '1') then
275
                        isrst_w <= '0';
276
                end if;
277
        end if;
278
end process;
279
 
280
end architecture;

powered by: WebSVN 2.1.0

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