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

Subversion Repositories vga_lcd

[/] [vga_lcd/] [tags/] [rel_1/] [rtl/] [vhdl/] [fifo_dc.vhd] - Blame information for rev 62

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 rudi
--
2
-- File fifo.vhd (universal FIFO)
3
-- Author : Richard Herveille
4
-- rev. 0.1 May 04th, 2001 : Initial release
5
-- rev. 1.0 May 17th, 2001 : Changed core to use dual_ported_memory entity => wrapper around target specific dual ported RAM.
6
--          
7
--          WARNING: DO NOT CHANGE THIS FILE
8
--                   CHANGE "DPM.VHD" FOR TARGET SPECIFIC MEMORY BLOCKS
9
--
10
-- rev. 1.1: June 23nd, 2001. Removed unused "drptr" and "fifo_cnt" signals
11
-- rev. 1.2: June 29th, 2001. Changed core to reflect changes in "dpm.vhd".
12
 
13
library ieee;
14
use ieee.std_logic_1164.all;
15
use ieee.std_logic_arith.all;
16
 
17
entity FIFO_DC is
18
        generic(
19
                DEPTH : natural := 128;
20
                DWIDTH : natural := 32
21
        );
22
        port(
23
                rclk : in std_logic;                          -- read clock input
24
                wclk : in std_logic;                          -- write clock input
25
                aclr : in std_logic := '1';                   -- active low asynchronous clear
26
 
27
                D : in std_logic_vector(DWIDTH -1 downto 0);  -- Data input
28
                wreq : in std_logic;                          -- write request
29
 
30
                Q : out std_logic_vector(DWIDTH -1 downto 0); -- Data output
31
                rreq : in std_logic;                          -- read request
32
 
33
                rd_empty,                                     -- FIFO is empty, synchronous to read clock
34
                rd_full,                                      -- FIFO is full, synchronous to read clock
35
                wr_empty,                                     -- FIFO is empty, synchronous to write clock
36
                wr_full : out std_logic                       -- FIFO is full, synchronous to write clock
37
        );
38
end entity FIFO_DC;
39
 
40
architecture structural of FIFO_DC is
41
        -- dual ported memory wrapper
42
        component dual_ported_memory is
43
        generic(
44
                AWIDTH : natural := 8;
45
                DWIDTH : natural := 32
46
        );
47
        port(
48
                wclk : in std_logic;                          -- write clock input
49
                D : in std_logic_vector(DWIDTH -1 downto 0);  -- Data input
50
                waddr : in unsigned(AWIDTH -1 downto 0);      -- write clock address input
51
                wreq : in std_logic;                          -- write request
52
 
53
                rclk : in std_logic;                          -- read clock input
54
                Q : out std_logic_vector(DWIDTH -1 downto 0); -- Data output
55
                raddr : in unsigned(AWIDTH -1 downto 0)       -- read clock address input
56
        );
57
        end component dual_ported_memory;
58
 
59
        -- bitcount, return no.of bits required for 'n'
60
        function bitcount(n : in natural) return natural is
61
                variable tmp : unsigned(32 downto 1);
62
                variable cnt : integer;
63
        begin
64
                tmp := conv_unsigned(n, 32);
65
                cnt := 32;
66
 
67
                while ( (tmp(cnt) = '0') and (cnt > 0) ) loop
68
                        cnt := cnt -1;
69
                end loop;
70
 
71
                return natural(cnt);
72
        end function bitcount;
73
 
74
        constant AWIDTH : natural := bitcount(DEPTH -1); -- 256 entries: range 255 downto 0
75
 
76
        signal rptr, wptr : unsigned(AWIDTH -1 downto 0);
77
        signal ifull, iempty, wempty, wfull, rempty, rfull : std_logic;
78
begin
79
        --
80
        -- Pointers
81
        --
82
        -- read pointer
83
        gen_rd_ptr: process(rclk, aclr)
84
        begin
85
                if (aclr = '0') then
86
                        rptr  <= (others => '0');
87
                elsif (rclk'event and rclk = '1') then
88
                        if (rreq = '1') then
89
                                rptr  <= rptr +1;
90
                        end if;
91
                end if;
92
        end process gen_rd_ptr;
93
 
94
        -- write pointer
95
        gen_wr_ptr: process(wclk, aclr)
96
        begin
97
                if (aclr = '0') then
98
                        wptr <= (others => '0');
99
                elsif (wclk'event and wclk = '1') then
100
                        if (wreq = '1') then
101
                                wptr <= wptr +1;
102
                        end if;
103
                end if;
104
        end process gen_wr_ptr;
105
 
106
        -- insert memory block. dual_ported_memory is a wrapper around a target specific dual ported RAM
107
        mem: dual_ported_memory generic map(AWIDTH => AWIDTH, DWIDTH => DWIDTH)
108
                port map(wclk => wclk, D => D, waddr => wptr, wreq => wreq, rclk => rclk, Q => Q, raddr => rptr);
109
 
110
        --
111
        -- status flags
112
        --
113
        iempty <= '1' when (rptr = wptr) else '0';
114
        ifull  <= '1' when ( (wptr - rptr) >= (DEPTH -2) ) else '0';
115
 
116
        rd_flags: process(rclk, aclr)
117
        begin
118
                if (aclr = '0') then
119
                        rempty   <= '1';
120
                        rfull    <=  '0';
121
                        rd_empty <= '1';
122
                        rd_full  <=  '0';
123
                elsif (rclk'event and rclk = '1') then
124
                        rempty   <= iempty;
125
                        rfull    <= ifull;
126
                        rd_empty <= rempty;
127
                        rd_full  <= rfull;
128
                end if;
129
        end process rd_flags;
130
 
131
        wr_flags: process(wclk, aclr)
132
        begin
133
                if (aclr = '0') then
134
                        wempty   <= '1';
135
                        wfull    <=  '0';
136
                        wr_empty <= '1';
137
                        wr_full  <=  '0';
138
                elsif (wclk'event and wclk = '1') then
139
                        wempty   <= iempty;
140
                        wfull    <= ifull;
141
                        wr_empty <= wempty;
142
                        wr_full  <= wfull;
143
                end if;
144
        end process wr_flags;
145
end architecture structural;

powered by: WebSVN 2.1.0

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