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

Subversion Repositories mkjpeg

[/] [mkjpeg/] [trunk/] [design/] [BufFifo/] [BUF_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
-------------------------------------------------------------------------------
2
-- File Name : BUF_FIFO.vhd
3
--
4
-- Project   : JPEG_ENC
5
--
6
-- Module    : BUF_FIFO
7
--
8
-- Content   : Input FIFO Buffer
9
--
10
-- Description : 
11
--
12
-- Spec.     : 
13
--
14
-- Author    : Michal Krepa
15
--
16
-------------------------------------------------------------------------------
17
-- History :
18
-- 20090311: (MK): Initial Creation.
19
-------------------------------------------------------------------------------
20
 
21
-------------------------------------------------------------------------------
22
-------------------------------------------------------------------------------
23
----------------------------------- LIBRARY/PACKAGE ---------------------------
24
-------------------------------------------------------------------------------
25
-------------------------------------------------------------------------------
26
 
27
-------------------------------------------------------------------------------
28
-- generic packages/libraries:
29
-------------------------------------------------------------------------------
30
library ieee;
31
  use ieee.std_logic_1164.all;
32
  use ieee.numeric_std.all;
33
 
34
-------------------------------------------------------------------------------
35
-- user packages/libraries:
36
-------------------------------------------------------------------------------
37
library work;
38
  use work.JPEG_PKG.all;
39
-------------------------------------------------------------------------------
40
-------------------------------------------------------------------------------
41
----------------------------------- ENTITY ------------------------------------
42
-------------------------------------------------------------------------------
43
-------------------------------------------------------------------------------
44
entity BUF_FIFO is
45
  port
46
  (
47
        CLK                : in  std_logic;
48
        RST                : in  std_logic;
49
        -- HOST PROG
50
        img_size_x         : in  std_logic_vector(15 downto 0);
51
        img_size_y         : in  std_logic_vector(15 downto 0);
52
        sof                : in  std_logic;
53
 
54
        -- HOST DATA
55
        iram_wren          : in  std_logic;
56 49 mikel262
        iram_wdata         : in  std_logic_vector(C_PIXEL_BITS-1 downto 0);
57 25 mikel262
        fifo_almost_full   : out std_logic;
58
 
59
        -- FDCT
60
        fdct_fifo_rd       : in  std_logic;
61
        fdct_fifo_q        : out std_logic_vector(23 downto 0);
62
        fdct_fifo_hf_full  : out std_logic
63
    );
64
end entity BUF_FIFO;
65
 
66
-------------------------------------------------------------------------------
67
-------------------------------------------------------------------------------
68
----------------------------------- ARCHITECTURE ------------------------------
69
-------------------------------------------------------------------------------
70
-------------------------------------------------------------------------------
71
architecture RTL of BUF_FIFO is
72
 
73 52 mikel262
  signal pixel_cnt        : unsigned(15 downto 0);
74
  signal line_cnt         : unsigned(15 downto 0);
75
 
76
  signal ramq             : STD_LOGIC_VECTOR(C_PIXEL_BITS-1 downto 0);
77
  signal ramd             : STD_LOGIC_VECTOR(C_PIXEL_BITS-1 downto 0);
78
  signal ramwaddr         : unsigned(log2(C_MAX_LINE_WIDTH*8)-1 downto 0);
79
  signal ramenw           : STD_LOGIC;
80
  signal ramraddr         : unsigned(log2(C_MAX_LINE_WIDTH*8)-1 downto 0);
81 49 mikel262
 
82 52 mikel262
  signal pix_inblk_cnt    : unsigned(7 downto 0);
83
  signal line_inblk_cnt   : unsigned(7 downto 0);
84 25 mikel262
 
85 52 mikel262
  signal read_block_cnt   : unsigned(12 downto 0);
86
  signal write_block_cnt  : unsigned(12 downto 0);
87 25 mikel262
 
88 52 mikel262
  signal ramraddr_int     : unsigned(23 downto 0);
89
  signal raddr_base_line  : unsigned(23 downto 0);
90
  signal raddr_tmp        : unsigned(15 downto 0);
91
  signal ramwaddr_d1      : unsigned(log2(C_MAX_LINE_WIDTH*8)-1 downto 0);
92 25 mikel262
 
93 52 mikel262
  signal block_lock       : unsigned(C_MAX_LINE_WIDTH/8-1 downto 0);
94 28 mikel262
 
95 25 mikel262
-------------------------------------------------------------------------------
96
-- Architecture: begin
97
-------------------------------------------------------------------------------
98 52 mikel262
begin
99 25 mikel262
  -------------------------------------------------------------------
100 28 mikel262
  -- RAM for SUB_FIFOs
101
  -------------------------------------------------------------------
102
  U_SUB_RAMZ : entity work.SUB_RAMZ
103
  generic map
104
  (
105 52 mikel262
           RAMADDR_W => log2(C_MAX_LINE_WIDTH*8),
106 28 mikel262
           RAMDATA_W => C_PIXEL_BITS
107
  )
108
  port map
109
  (
110
        d            => ramd,
111 52 mikel262
        waddr        => std_logic_vector(ramwaddr_d1),
112
        raddr        => std_logic_vector(ramraddr),
113 28 mikel262
        we           => ramenw,
114
        clk          => clk,
115
 
116
        q            => ramq
117
  );
118
 
119
  -------------------------------------------------------------------
120 52 mikel262
  -- register RAM data input
121 25 mikel262
  -------------------------------------------------------------------
122 52 mikel262
  p_mux1 : process(CLK, RST)
123 25 mikel262
  begin
124
    if RST = '1' then
125 52 mikel262
      ramenw           <= '0';
126
      ramd             <= (others => '0');
127 25 mikel262
    elsif CLK'event and CLK = '1' then
128 52 mikel262
      ramd      <= iram_wdata;
129
      ramenw    <= iram_wren;
130 25 mikel262
    end if;
131
  end process;
132
 
133
  -------------------------------------------------------------------
134 52 mikel262
  -- resolve RAM write address
135 25 mikel262
  -------------------------------------------------------------------
136
  p_pixel_cnt : process(CLK, RST)
137
  begin
138
    if RST = '1' then
139
      pixel_cnt   <= (others => '0');
140 52 mikel262
      line_cnt    <= (others => '0');
141
      ramwaddr    <= (others => '0');
142
      ramwaddr_d1 <= (others => '0');
143 25 mikel262
    elsif CLK'event and CLK = '1' then
144 52 mikel262
      ramwaddr_d1 <= ramwaddr;
145
 
146 25 mikel262
      if iram_wren = '1' then
147 52 mikel262
        -- pixel index in line
148 25 mikel262
        if pixel_cnt = unsigned(img_size_x)-1 then
149
          pixel_cnt <= (others => '0');
150 52 mikel262
          -- line counter
151
          line_cnt  <= line_cnt + 1;
152
          -- RAM is only 8 lines buffer
153
          if line_cnt(2 downto 0) = 8-1 then
154
            ramwaddr <= (others => '0');
155
          else
156
            ramwaddr  <= ramwaddr + 1;
157
          end if;
158 25 mikel262
        else
159
          pixel_cnt <= pixel_cnt + 1;
160 52 mikel262
          ramwaddr  <= ramwaddr + 1;
161 25 mikel262
        end if;
162
      end if;
163
 
164
      if sof = '1' then
165
        pixel_cnt <= (others => '0');
166 52 mikel262
        ramwaddr  <= (others => '0');
167 25 mikel262
      end if;
168
    end if;
169
  end process;
170
 
171 52 mikel262
  write_block_cnt <= pixel_cnt(15 downto 3);
172
 
173 25 mikel262
  -------------------------------------------------------------------
174 52 mikel262
  -- lock written blocks, unlock after read
175 25 mikel262
  -------------------------------------------------------------------
176 52 mikel262
  p_mux6 : process(CLK, RST)
177 25 mikel262
  begin
178
    if RST = '1' then
179 52 mikel262
      block_lock <= (others => '0');
180 25 mikel262
    elsif CLK'event and CLK = '1' then
181 52 mikel262
      if pixel_cnt(2 downto 0) = 8-1 then
182
        if line_cnt(2 downto 0) = 8-1 then
183
          block_lock(to_integer(write_block_cnt)) <= '1';
184 25 mikel262
        end if;
185 52 mikel262
      end if;
186
 
187
      if pix_inblk_cnt = 8-1 then
188
        if line_inblk_cnt = 8-1 then
189
          block_lock(to_integer(read_block_cnt)) <= '0';
190
        end if;
191
      end if;
192 25 mikel262
    end if;
193
  end process;
194 52 mikel262
 
195 25 mikel262
  -------------------------------------------------------------------
196 52 mikel262
  -- FIFO half full / almost full flag generation
197 25 mikel262
  -------------------------------------------------------------------
198 52 mikel262
  p_mux3 : process(CLK, RST)
199 25 mikel262
  begin
200
    if RST = '1' then
201 52 mikel262
      fdct_fifo_hf_full   <= '0';
202
      fifo_almost_full    <= '0';
203 25 mikel262
    elsif CLK'event and CLK = '1' then
204 52 mikel262
 
205
      if block_lock(to_integer(read_block_cnt)) = '1' then
206
        fdct_fifo_hf_full <= '1';
207
      else
208
        fdct_fifo_hf_full <= '0';
209
      end if;
210
 
211
      if write_block_cnt = unsigned(img_size_x(15 downto 3))-1 then
212
        if block_lock(0) = '1' then
213
          fifo_almost_full <= '1';
214 25 mikel262
        else
215 52 mikel262
          fifo_almost_full <= '0';
216 25 mikel262
        end if;
217 52 mikel262
      elsif block_lock(to_integer(write_block_cnt+1)) = '1' then
218
        fifo_almost_full <= '1';
219
      else
220
        fifo_almost_full <= '0';
221
      end if;
222
 
223 25 mikel262
    end if;
224
  end process;
225
 
226
  -------------------------------------------------------------------
227 52 mikel262
  -- read side
228 25 mikel262
  -------------------------------------------------------------------
229 52 mikel262
  p_mux5 : process(CLK, RST)
230 25 mikel262
  begin
231
    if RST = '1' then
232 52 mikel262
      read_block_cnt <= (others => '0');
233
      pix_inblk_cnt  <= (others => '0');
234
      line_inblk_cnt <= (others => '0');
235 25 mikel262
    elsif CLK'event and CLK = '1' then
236 52 mikel262
      if fdct_fifo_rd = '1' then
237
        if pix_inblk_cnt = 8-1 then
238
          pix_inblk_cnt <= (others => '0');
239
          if line_inblk_cnt = 8-1 then
240
            line_inblk_cnt <= (others => '0');
241
            if read_block_cnt = unsigned(img_size_x(15 downto 3))-1 then
242
              read_block_cnt <= (others => '0');
243
            else
244
              read_block_cnt <= read_block_cnt + 1;
245
            end if;
246
          else
247
            line_inblk_cnt <= line_inblk_cnt + 1;
248
          end if;
249 25 mikel262
        else
250 52 mikel262
          pix_inblk_cnt <= pix_inblk_cnt + 1;
251 25 mikel262
        end if;
252 52 mikel262
      end if;
253
 
254
      if sof = '1' then
255
        read_block_cnt <= (others => '0');
256
        pix_inblk_cnt  <= (others => '0');
257
        line_inblk_cnt <= (others => '0');
258
      end if;
259
 
260 25 mikel262
    end if;
261
  end process;
262
 
263 52 mikel262
  -- generate RAM data output based on 16 or 24 bit mode selection
264 51 mikel262
  fdct_fifo_q <= (ramq(15 downto 11) & "000" &
265
                 ramq(10 downto 5) & "00" &
266
                 ramq(4 downto 0) & "000") when C_PIXEL_BITS = 16 else
267
                 std_logic_vector(resize(unsigned(ramq), 24));
268 25 mikel262
 
269 28 mikel262
 
270 52 mikel262
  ramraddr <= ramraddr_int(ramraddr'range);
271
 
272 28 mikel262
  -------------------------------------------------------------------
273 52 mikel262
  -- resolve RAM read address
274 28 mikel262
  -------------------------------------------------------------------
275
  p_mux4 : process(CLK, RST)
276
  begin
277
    if RST = '1' then
278 52 mikel262
      ramraddr_int          <= (others => '0');
279 28 mikel262
    elsif CLK'event and CLK = '1' then
280 52 mikel262
      raddr_base_line <= line_inblk_cnt * unsigned(img_size_x);
281
      raddr_tmp       <= (read_block_cnt & "000") + pix_inblk_cnt;
282
 
283
      ramraddr_int <= raddr_tmp + raddr_base_line;
284 28 mikel262
    end if;
285
  end process;
286 25 mikel262
 
287
end architecture RTL;
288
-------------------------------------------------------------------------------
289
-- Architecture: end
290
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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