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

Subversion Repositories uart16750

[/] [uart16750/] [trunk/] [rtl/] [vhdl/] [slib_fifo.vhd] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 hasw
--
2
-- FIFO
3
--
4
-- Author:   Sebastian Witt
5
-- Date:     29.01.2008
6
-- Version:  1.1
7
--
8
-- This code is free software; you can redistribute it and/or
9
-- modify it under the terms of the GNU Lesser General Public
10
-- License as published by the Free Software Foundation; either
11
-- version 2.1 of the License, or (at your option) any later version.
12
--
13
-- This code is distributed in the hope that it will be useful,
14
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
15
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
-- Lesser General Public License for more details.
17
--
18
-- You should have received a copy of the GNU Lesser General Public
19
-- License along with this library; if not, write to the
20
-- Free Software  Foundation, Inc., 59 Temple Place, Suite 330,
21
-- Boston, MA  02111-1307  USA
22
--
23
 
24
LIBRARY IEEE;
25
USE IEEE.std_logic_1164.all;
26
USE IEEE.std_logic_unsigned.all;
27
USE IEEE.numeric_std.all;
28
 
29
 
30
entity slib_fifo is
31
    generic (
32
        WIDTH       : integer := 8;                             -- FIFO width
33
        SIZE_E      : integer := 6                              -- FIFO size (2^SIZE_E)
34
    );
35
    port (
36
        CLK         : in std_logic;                             -- Clock
37
        RST         : in std_logic;                             -- Reset
38
        CLEAR       : in std_logic;                             -- Clear FIFO
39
        WRITE       : in std_logic;                             -- Write to FIFO
40
        READ        : in std_logic;                             -- Read from FIFO
41
        D           : in std_logic_vector(WIDTH-1 downto 0);    -- FIFO input
42
        Q           : out std_logic_vector(WIDTH-1 downto 0);   -- FIFO output
43
        EMPTY       : out std_logic;                            -- FIFO is empty
44
        FULL        : out std_logic;                            -- FIFO is full
45
        USAGE       : out std_logic_vector(SIZE_E-1 downto 0)   -- FIFO usage
46
    );
47
end slib_fifo;
48
 
49
architecture rtl of slib_fifo is
50
    -- Signals
51
    signal iEMPTY   : std_logic;                                -- Internal EMPTY
52
    signal iFULL    : std_logic;                                -- Internal FULL
53
    signal iWRAddr  : std_logic_vector(SIZE_E downto 0);        -- FIFO write address
54
    signal iRDAddr  : std_logic_vector(SIZE_E downto 0);        -- FIFO read address
55
    signal iUSAGE   : std_logic_vector(SIZE_E-1 downto 0);      -- FIFO usage
56
    -- FIFO memory
57
    type FIFO_Mem_Type is array (2**SIZE_E-1 downto 0) of std_logic_vector(WIDTH-1 downto 0);
58
    signal iFIFOMem : FIFO_Mem_Type;
59
 
60
begin
61
    -- Full signal (biggest difference of read and write address)
62
    iFULL <= '1' when (iRDAddr(SIZE_E-1 downto 0) = iWRAddr(SIZE_E-1 downto 0)) and
63
                      (iRDAddr(SIZE_E)           /= iWRAddr(SIZE_E)) else '0';
64
 
65
    -- Empty signal (read address same as write address)
66
    iEMPTY <= '1' when (iRDAddr = iWRAddr) else '0';
67
 
68
    -- Write and read address counter
69
    FF_ADDR: process (RST, CLK)
70
    begin
71
        if (RST = '1') then
72
            iWRAddr <= (others => '0');
73
            iRDAddr <= (others => '0');
74
        elsif (CLK'event and CLK='1') then
75
            if (WRITE = '1' and iFULL = '0') then       -- Write to FIFO
76
                iWRAddr <= iWRAddr + '1';
77
            end if;
78
 
79
            if (READ = '1' and iEMPTY = '0') then       -- Read from FIFO
80
                iRDAddr <= iRDAddr + '1';
81
            end if;
82
 
83
            if (CLEAR = '1') then                       -- Reset FIFO
84
                iWRAddr <= (others => '0');
85
                iRDAddr <= (others => '0');
86
            end if;
87
        end if;
88
    end process;
89
 
90
    -- FIFO memory process
91
    FF_MEM: process (RST, CLK)
92
    begin
93
        if (RST = '1') then
94
            iFIFOMem(2**SIZE_E-1 downto 0) <= (others => (others => '0'));
95
        elsif (CLK'event and CLK = '1') then
96
            if (WRITE = '1' and iFULL = '0') then
97
                iFIFOMem(CONV_INTEGER(iWRAddr(SIZE_E-1 downto 0))) <= D;
98
            end if;
99
        end if;
100
    end process;
101
 
102
    -- Usage counter
103
    FF_USAGE: process (RST, CLK)
104
    begin
105
        if (RST = '1') then
106
            iUSAGE <= (others => '0');
107
        elsif (CLK'event and CLK = '1') then
108
            if (CLEAR = '1') then
109
                iUSAGE <= (others => '0');
110
            else
111
                if (READ = '0' and WRITE = '1' and iFULL = '0') then
112
                    iUSAGE <= iUSAGE + '1';
113
                end if;
114
                if (WRITE = '0' and READ = '1' and iEMPTY = '0') then
115
                    iUSAGE <= iUSAGE - '1';
116
                end if;
117
            end if;
118
        end if;
119
    end process;
120
 
121
    -- Output signals
122
    Q     <= iFIFOMem(CONV_INTEGER(iRDAddr(SIZE_E-1 downto 0)));
123
    EMPTY <= iEMPTY;
124
    FULL  <= iFULL;
125
    USAGE <= iUSAGE;
126
 
127
end rtl;
128
 
129
 

powered by: WebSVN 2.1.0

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