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

Subversion Repositories mkjpeg

[/] [mkjpeg/] [trunk/] [design/] [common/] [FIFO.vhd] - Blame information for rev 52

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

Line No. Rev Author Line
1 25 mikel262
library IEEE;
2
  use IEEE.STD_LOGIC_1164.all;
3
  use IEEE.NUMERIC_STD.all;
4
 
5
entity RAMF is
6
  generic (
7
        RAMD_W : INTEGER := 12;
8
        RAMA_W : INTEGER := 6
9
  );
10
  port (
11
        d                 : in  STD_LOGIC_VECTOR(RAMD_W-1 downto 0);
12
        waddr             : in  STD_LOGIC_VECTOR(RAMA_W-1 downto 0);
13
        raddr             : in  STD_LOGIC_VECTOR(RAMA_W-1 downto 0);
14
        we                : in  STD_LOGIC;
15
        clk               : in  STD_LOGIC;
16
 
17
        q                 : out STD_LOGIC_VECTOR(RAMD_W-1 downto 0)
18
  );
19
end RAMF;
20
 
21
architecture RTL of RAMF is
22
  type mem_type is array ((2**RAMA_W)-1 downto 0) of
23
                              STD_LOGIC_VECTOR(RAMD_W-1 downto 0);
24
  signal mem                    : mem_type;
25
  signal read_addr              : STD_LOGIC_VECTOR(RAMA_W-1 downto 0);
26
 
27
begin
28
 
29
  -------------------------------------------------------------------------------
30
  q_sg:
31
  -------------------------------------------------------------------------------
32
  q <= mem(TO_INTEGER(UNSIGNED(read_addr)));
33
 
34
  -------------------------------------------------------------------------------
35
  read_proc: -- register read address
36
  -------------------------------------------------------------------------------
37
  process (clk)
38
  begin
39
    if clk = '1' and clk'event then
40
      read_addr <= raddr;
41
    end if;
42
  end process;
43
 
44
  -------------------------------------------------------------------------------
45
  write_proc: --write access
46
  -------------------------------------------------------------------------------
47
  process (clk) begin
48
    if clk = '1' and clk'event then
49
      if we = '1'  then
50
        mem(TO_INTEGER(UNSIGNED(waddr))) <= d;
51
      end if;
52
    end if;
53
  end process;
54
 
55
end RTL;
56
----------------------------------------------------------------------------------
57
 
58
library IEEE;
59
  use IEEE.STD_LOGIC_1164.all;
60
  use IEEE.STD_LOGIC_UNSIGNED.all;
61
library WORK;
62
 
63
entity FIFO is
64
  generic (
65
        DATA_WIDTH         : INTEGER   := 12;
66
        ADDR_WIDTH         : INTEGER   := 2
67
       );
68
  port (
69
        rst               : in  STD_LOGIC;
70
        clk               : in  STD_LOGIC;
71
        rinc              : in  STD_LOGIC;
72
        winc              : in  STD_LOGIC;
73
        datai             : in  STD_LOGIC_VECTOR(DATA_WIDTH-1 downto 0);
74
 
75
        datao             : out STD_LOGIC_VECTOR(DATA_WIDTH-1 downto 0);
76
        fullo             : out STD_LOGIC;
77
        emptyo            : out STD_LOGIC;
78
        count             : out STD_LOGIC_VECTOR (ADDR_WIDTH downto 0)
79
        );
80
end FIFO;
81
 
82
architecture RTL of FIFO is
83
 
84
  signal raddr_reg        : STD_LOGIC_VECTOR(ADDR_WIDTH-1 downto 0);
85
  signal waddr_reg        : STD_LOGIC_VECTOR(ADDR_WIDTH-1 downto 0);
86
  signal count_reg        : STD_LOGIC_VECTOR(ADDR_WIDTH downto 0);
87
  signal rd_en_reg        : STD_LOGIC;
88
  signal wr_en_reg        : STD_LOGIC;
89
  signal empty_reg        : STD_LOGIC;
90
  signal full_reg         : STD_LOGIC;
91
  signal ramq             : STD_LOGIC_VECTOR(DATA_WIDTH-1 downto 0);
92
  signal ramd             : STD_LOGIC_VECTOR (DATA_WIDTH-1 downto 0);
93
  signal ramwaddr         : STD_LOGIC_VECTOR (ADDR_WIDTH-1 downto 0);
94
  signal ramenw           : STD_LOGIC;
95
  signal ramraddr         : STD_LOGIC_VECTOR (ADDR_WIDTH-1 downto 0);
96
  signal ramenr           : STD_LOGIC;
97
 
98
  constant ZEROS_C        : STD_LOGIC_VECTOR(ADDR_WIDTH downto 0) := (others => '0');
99
  constant ONES_C         : STD_LOGIC_VECTOR(ADDR_WIDTH downto 0) := (others => '1');
100
 
101
  component RAMF
102
  generic (
103
           RAMD_W : INTEGER := 12;
104
           RAMA_W : INTEGER := 6
105
  );
106
  port (
107
        d                 : in  STD_LOGIC_VECTOR(RAMD_W-1 downto 0);
108
        waddr             : in  STD_LOGIC_VECTOR(RAMA_W-1 downto 0);
109
        raddr             : in  STD_LOGIC_VECTOR(RAMA_W-1 downto 0);
110
        we                : in  STD_LOGIC;
111
        clk               : in  STD_LOGIC;
112
 
113
        q                 : out STD_LOGIC_VECTOR(RAMD_W-1 downto 0)
114
  );
115
  end component;
116
begin
117
 
118
  U_RAMF : RAMF
119
  generic map (
120
           RAMD_W => DATA_WIDTH,
121
           RAMA_W => ADDR_WIDTH
122
  )
123
  port map (
124
        d            => ramd,
125
        waddr        => ramwaddr,
126
        raddr        => ramraddr,
127
        we           => ramenw,
128
        clk          => clk,
129
 
130
        q            => ramq
131
  );
132
 
133
  ramd                    <= datai;
134
 
135
  ramwaddr                <= waddr_reg;
136
 
137
  ramenw                  <= wr_en_reg;
138
 
139
  ramraddr                <= raddr_reg;
140
 
141
  ramenr                  <= '1';
142
 
143
  datao                   <= ramq;
144
 
145
  emptyo                  <= empty_reg;
146
 
147
  fullo                   <= full_reg;
148
 
149
  rd_en_reg               <= (rinc and not empty_reg);
150
 
151
  wr_en_reg               <= (winc and not full_reg);
152
 
153
  count <= count_reg;
154
 
155
  process(clk)
156
  begin
157
    if clk = '1' and clk'event then
158
      if rst = '1' then
159
        empty_reg         <= '1';
160
      else
161
        if count_reg = ZEROS_C or
162
          (count_reg = 1 and rd_en_reg = '1' and wr_en_reg = '0') then
163
          empty_reg       <= '1';
164
        else
165
          empty_reg       <= '0';
166
        end if;
167
      end if;
168
    end if;
169
  end process;
170
 
171
  process(clk)
172
  begin
173
    if clk = '1' and clk'event then
174
      if rst = '1' then
175
        full_reg          <= '0';
176
      else
177
        if count_reg = 2**ADDR_WIDTH or
178
          (count_reg = 2**ADDR_WIDTH-1 and wr_en_reg = '1' and rd_en_reg = '0') then
179
          full_reg        <= '1';
180
        else
181
          full_reg        <= '0';
182
        end if;
183
      end if;
184
    end if;
185
  end process;
186
 
187
  process(clk)
188
  begin
189
    if clk = '1' and clk'event then
190
      if rst = '1' then
191
        raddr_reg         <= (others => '0');
192
      else
193
        if rd_en_reg = '1' then
194
          raddr_reg       <= raddr_reg + '1';
195
        end if;
196
      end if;
197
    end if;
198
  end process;
199
 
200
  process(clk)
201
  begin
202
    if clk = '1' and clk'event then
203
      if rst = '1' then
204
        waddr_reg         <= (others => '0');
205
      else
206
        if wr_en_reg = '1' then
207
          waddr_reg       <= waddr_reg + '1';
208
        end if;
209
      end if;
210
    end if;
211
  end process;
212
 
213
  process(clk)
214
  begin
215
    if clk = '1' and clk'event then
216
      if rst = '1' then
217
        count_reg         <= (others => '0');
218
      else
219
        if (rd_en_reg = '1' and wr_en_reg = '0') or (rd_en_reg = '0' and wr_en_reg = '1') then
220
          if rd_en_reg = '1' then
221
            count_reg     <= count_reg - '1';
222
          else
223
            count_reg     <= count_reg + '1';
224
          end if;
225
        end if;
226
      end if;
227
    end if;
228
  end process;
229
 
230
end RTL;

powered by: WebSVN 2.1.0

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