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

Subversion Repositories mkjpeg

[/] [mkjpeg/] [trunk/] [design/] [BufFifo/] [BUF_FIFO.vhd] - Blame information for rev 63

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 56 mikel262
 
74
  constant C_NUM_LINES    : integer := 8 + C_EXTRA_LINES;
75
 
76 52 mikel262
  signal pixel_cnt        : unsigned(15 downto 0);
77
  signal line_cnt         : unsigned(15 downto 0);
78
 
79
  signal ramq             : STD_LOGIC_VECTOR(C_PIXEL_BITS-1 downto 0);
80
  signal ramd             : STD_LOGIC_VECTOR(C_PIXEL_BITS-1 downto 0);
81 56 mikel262
  signal ramwaddr         : unsigned(log2(C_MAX_LINE_WIDTH*C_NUM_LINES)-1 downto 0);
82 52 mikel262
  signal ramenw           : STD_LOGIC;
83 56 mikel262
  signal ramraddr         : unsigned(log2(C_MAX_LINE_WIDTH*C_NUM_LINES)-1 downto 0);
84 49 mikel262
 
85 61 mikel262
  signal pix_inblk_cnt    : unsigned(3 downto 0);
86
  signal pix_inblk_cnt_d1 : unsigned(3 downto 0);
87 56 mikel262
  signal line_inblk_cnt   : unsigned(2 downto 0);
88 25 mikel262
 
89 52 mikel262
  signal read_block_cnt   : unsigned(12 downto 0);
90 56 mikel262
  signal read_block_cnt_d1 : unsigned(12 downto 0);
91 52 mikel262
  signal write_block_cnt  : unsigned(12 downto 0);
92 25 mikel262
 
93 56 mikel262
  signal ramraddr_int     : unsigned(16+log2(C_NUM_LINES)-1 downto 0);
94
  signal raddr_base_line  : unsigned(16+log2(C_NUM_LINES)-1 downto 0);
95 52 mikel262
  signal raddr_tmp        : unsigned(15 downto 0);
96 56 mikel262
  signal ramwaddr_d1      : unsigned(ramwaddr'range);
97 25 mikel262
 
98 56 mikel262
  signal line_lock        : unsigned(log2(C_NUM_LINES)-1 downto 0);
99 28 mikel262
 
100 56 mikel262
  signal memwr_line_cnt   : unsigned(log2(C_NUM_LINES)-1 downto 0);
101
 
102
  signal memrd_offs_cnt   : unsigned(log2(C_NUM_LINES)-1+1 downto 0);
103
  signal memrd_line       : unsigned(log2(C_NUM_LINES)-1 downto 0);
104
 
105
  signal wr_line_idx      : unsigned(15 downto 0);
106
  signal rd_line_idx      : unsigned(15 downto 0);
107
 
108
  signal image_write_end  : std_logic;
109
 
110
 
111
 
112 25 mikel262
-------------------------------------------------------------------------------
113
-- Architecture: begin
114
-------------------------------------------------------------------------------
115 52 mikel262
begin
116 25 mikel262
  -------------------------------------------------------------------
117 28 mikel262
  -- RAM for SUB_FIFOs
118
  -------------------------------------------------------------------
119
  U_SUB_RAMZ : entity work.SUB_RAMZ
120
  generic map
121
  (
122 56 mikel262
           RAMADDR_W => log2( C_MAX_LINE_WIDTH*C_NUM_LINES ),
123 28 mikel262
           RAMDATA_W => C_PIXEL_BITS
124
  )
125
  port map
126
  (
127
        d            => ramd,
128 52 mikel262
        waddr        => std_logic_vector(ramwaddr_d1),
129
        raddr        => std_logic_vector(ramraddr),
130 28 mikel262
        we           => ramenw,
131
        clk          => clk,
132
 
133
        q            => ramq
134
  );
135
 
136
  -------------------------------------------------------------------
137 52 mikel262
  -- register RAM data input
138 25 mikel262
  -------------------------------------------------------------------
139 52 mikel262
  p_mux1 : process(CLK, RST)
140 25 mikel262
  begin
141
    if RST = '1' then
142 52 mikel262
      ramenw           <= '0';
143
      ramd             <= (others => '0');
144 25 mikel262
    elsif CLK'event and CLK = '1' then
145 52 mikel262
      ramd      <= iram_wdata;
146
      ramenw    <= iram_wren;
147 25 mikel262
    end if;
148
  end process;
149
 
150
  -------------------------------------------------------------------
151 52 mikel262
  -- resolve RAM write address
152 25 mikel262
  -------------------------------------------------------------------
153
  p_pixel_cnt : process(CLK, RST)
154
  begin
155
    if RST = '1' then
156 56 mikel262
      pixel_cnt      <= (others => '0');
157
      memwr_line_cnt <= (others => '0');
158
      wr_line_idx    <= (others => '0');
159
      ramwaddr       <= (others => '0');
160
      ramwaddr_d1    <= (others => '0');
161
      image_write_end <= '0';
162 25 mikel262
    elsif CLK'event and CLK = '1' then
163 52 mikel262
      ramwaddr_d1 <= ramwaddr;
164
 
165 25 mikel262
      if iram_wren = '1' then
166 56 mikel262
        -- end of line
167 25 mikel262
        if pixel_cnt = unsigned(img_size_x)-1 then
168
          pixel_cnt <= (others => '0');
169 56 mikel262
          -- absolute write line index
170
          wr_line_idx <= wr_line_idx + 1;
171
 
172
          if wr_line_idx = unsigned(img_size_y)-1 then
173
            image_write_end <= '1';
174 52 mikel262
          end if;
175 56 mikel262
 
176
          -- memory line index
177
          if memwr_line_cnt = C_NUM_LINES-1 then
178
            memwr_line_cnt <= (others => '0');
179
            ramwaddr       <= (others => '0');
180
          else
181
            memwr_line_cnt <= memwr_line_cnt + 1;
182
            ramwaddr       <= ramwaddr + 1;
183
          end if;
184 25 mikel262
        else
185
          pixel_cnt <= pixel_cnt + 1;
186 52 mikel262
          ramwaddr  <= ramwaddr + 1;
187 25 mikel262
        end if;
188
      end if;
189
 
190
      if sof = '1' then
191 56 mikel262
        pixel_cnt      <= (others => '0');
192
        ramwaddr       <= (others => '0');
193
        memwr_line_cnt <= (others => '0');
194
        wr_line_idx    <= (others => '0');
195
        image_write_end <= '0';
196 25 mikel262
      end if;
197
    end if;
198
  end process;
199 52 mikel262
 
200 25 mikel262
  -------------------------------------------------------------------
201 52 mikel262
  -- FIFO half full / almost full flag generation
202 25 mikel262
  -------------------------------------------------------------------
203 52 mikel262
  p_mux3 : process(CLK, RST)
204 25 mikel262
  begin
205
    if RST = '1' then
206 52 mikel262
      fdct_fifo_hf_full   <= '0';
207
      fifo_almost_full    <= '0';
208 25 mikel262
    elsif CLK'event and CLK = '1' then
209 52 mikel262
 
210 56 mikel262
      if rd_line_idx + 8 <= wr_line_idx then
211 52 mikel262
        fdct_fifo_hf_full <= '1';
212
      else
213
        fdct_fifo_hf_full <= '0';
214
      end if;
215
 
216 58 mikel262
      fifo_almost_full <= '0';
217 61 mikel262
      if wr_line_idx = rd_line_idx + C_NUM_LINES-1 then
218
        if pixel_cnt >= unsigned(img_size_x)-1-1 then
219 58 mikel262
          fifo_almost_full <= '1';
220
        end if;
221 61 mikel262
      elsif wr_line_idx > rd_line_idx + C_NUM_LINES-1 then
222
        fifo_almost_full <= '1';
223 52 mikel262
      end if;
224 61 mikel262
 
225 52 mikel262
 
226 25 mikel262
    end if;
227
  end process;
228
 
229
  -------------------------------------------------------------------
230 52 mikel262
  -- read side
231 25 mikel262
  -------------------------------------------------------------------
232 52 mikel262
  p_mux5 : process(CLK, RST)
233 25 mikel262
  begin
234
    if RST = '1' then
235 56 mikel262
      memrd_offs_cnt <= (others => '0');
236 52 mikel262
      read_block_cnt <= (others => '0');
237
      pix_inblk_cnt  <= (others => '0');
238
      line_inblk_cnt <= (others => '0');
239 56 mikel262
      rd_line_idx    <= (others => '0');
240
      pix_inblk_cnt_d1  <= (others => '0');
241
      read_block_cnt_d1 <= (others => '0');
242 25 mikel262
    elsif CLK'event and CLK = '1' then
243 56 mikel262
      pix_inblk_cnt_d1 <= pix_inblk_cnt;
244
      read_block_cnt_d1 <= read_block_cnt;
245
 
246
      -- BUF FIFO read
247 52 mikel262
      if fdct_fifo_rd = '1' then
248 56 mikel262
        -- last pixel in block
249 52 mikel262
        if pix_inblk_cnt = 8-1 then
250
          pix_inblk_cnt <= (others => '0');
251 56 mikel262
 
252
          -- last line in 8
253 52 mikel262
          if line_inblk_cnt = 8-1 then
254
            line_inblk_cnt <= (others => '0');
255 56 mikel262
 
256
            -- last block in last line
257 52 mikel262
            if read_block_cnt = unsigned(img_size_x(15 downto 3))-1 then
258
              read_block_cnt <= (others => '0');
259 56 mikel262
              rd_line_idx <= rd_line_idx + 8;
260
              if memrd_offs_cnt + 8 > C_NUM_LINES-1 then
261
                memrd_offs_cnt <= memrd_offs_cnt + 8 - C_NUM_LINES;
262
              else
263
                memrd_offs_cnt <= memrd_offs_cnt + 8;
264
              end if;
265 52 mikel262
            else
266
              read_block_cnt <= read_block_cnt + 1;
267
            end if;
268
          else
269
            line_inblk_cnt <= line_inblk_cnt + 1;
270
          end if;
271 56 mikel262
 
272 25 mikel262
        else
273 52 mikel262
          pix_inblk_cnt <= pix_inblk_cnt + 1;
274 25 mikel262
        end if;
275 52 mikel262
      end if;
276
 
277 56 mikel262
      if memrd_offs_cnt + (line_inblk_cnt) > C_NUM_LINES-1 then
278
        memrd_line <= memrd_offs_cnt(memrd_line'range) + (line_inblk_cnt) - (C_NUM_LINES);
279
      else
280
        memrd_line <= memrd_offs_cnt(memrd_line'range) + (line_inblk_cnt);
281
      end if;
282
 
283 52 mikel262
      if sof = '1' then
284 56 mikel262
        memrd_line     <= (others => '0');
285
        memrd_offs_cnt <= (others => '0');
286 52 mikel262
        read_block_cnt <= (others => '0');
287
        pix_inblk_cnt  <= (others => '0');
288
        line_inblk_cnt <= (others => '0');
289 56 mikel262
        rd_line_idx    <= (others => '0');
290 52 mikel262
      end if;
291
 
292 25 mikel262
    end if;
293
  end process;
294
 
295 52 mikel262
  -- generate RAM data output based on 16 or 24 bit mode selection
296 51 mikel262
  fdct_fifo_q <= (ramq(15 downto 11) & "000" &
297
                 ramq(10 downto 5) & "00" &
298
                 ramq(4 downto 0) & "000") when C_PIXEL_BITS = 16 else
299
                 std_logic_vector(resize(unsigned(ramq), 24));
300 25 mikel262
 
301 28 mikel262
 
302 52 mikel262
  ramraddr <= ramraddr_int(ramraddr'range);
303
 
304 28 mikel262
  -------------------------------------------------------------------
305 52 mikel262
  -- resolve RAM read address
306 28 mikel262
  -------------------------------------------------------------------
307
  p_mux4 : process(CLK, RST)
308
  begin
309
    if RST = '1' then
310 52 mikel262
      ramraddr_int          <= (others => '0');
311 28 mikel262
    elsif CLK'event and CLK = '1' then
312 56 mikel262
      raddr_base_line <= (memrd_line) * unsigned(img_size_x);
313
      raddr_tmp       <= (read_block_cnt_d1 & "000") + pix_inblk_cnt_d1;
314 52 mikel262
 
315
      ramraddr_int <= raddr_tmp + raddr_base_line;
316 28 mikel262
    end if;
317
  end process;
318 25 mikel262
 
319
end architecture RTL;
320
-------------------------------------------------------------------------------
321
-- Architecture: end
322
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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