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

Subversion Repositories mkjpeg

[/] [mkjpeg/] [trunk/] [design/] [rle/] [RLE_TOP.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 : RLE_TOP.vhd
3
--
4
-- Project   : JPEG_ENC
5
--
6
-- Module    : RLE_TOP
7
--
8
-- Content   : Run Length Encoder top level
9
--
10
-- Description :
11
--
12
-- Spec.     :
13
--
14
-- Author    : Michal Krepa
15
--
16
-------------------------------------------------------------------------------
17
-- History :
18
-- 20090301: (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 RLE_TOP is
45
  port
46
  (
47
        CLK                : in  std_logic;
48
        RST                : in  std_logic;
49
        -- CTRL
50
        start_pb           : in  std_logic;
51
        ready_pb           : out std_logic;
52
        rle_sm_settings    : in T_SM_SETTINGS;
53
 
54
        -- HUFFMAN
55
        huf_buf_sel        : in  std_logic;
56
        huf_rden           : in  std_logic;
57
        huf_runlength      : out std_logic_vector(3 downto 0);
58
        huf_size           : out std_logic_vector(3 downto 0);
59
        huf_amplitude      : out std_logic_vector(11 downto 0);
60
        huf_dval           : out std_logic;
61
        huf_fifo_empty     : out std_logic;
62
 
63 34 mikel262
        -- Quantizer
64
        qua_buf_sel        : out std_logic;
65
        qua_rd_addr        : out std_logic_vector(5 downto 0);
66
        qua_data           : in  std_logic_vector(11 downto 0);
67 25 mikel262
 
68
        -- HostIF
69
        sof                : in  std_logic
70
    );
71
end entity RLE_TOP;
72
 
73
-------------------------------------------------------------------------------
74
-------------------------------------------------------------------------------
75
----------------------------------- ARCHITECTURE ------------------------------
76
-------------------------------------------------------------------------------
77
-------------------------------------------------------------------------------
78
architecture RTL of RLE_TOP is
79
 
80
  signal dbuf_data      : std_logic_vector(19 downto 0);
81
  signal dbuf_q         : std_logic_vector(19 downto 0);
82
  signal dbuf_we        : std_logic;
83
 
84
  signal rle_runlength  : std_logic_vector(3 downto 0);
85
  signal rle_size       : std_logic_vector(3 downto 0);
86
  signal rle_amplitude  : std_logic_vector(11 downto 0);
87
  signal rle_dovalid    : std_logic;
88
  signal rle_di         : std_logic_vector(11 downto 0);
89
  signal rle_divalid    : std_logic;
90
 
91 34 mikel262
  signal qua_buf_sel_s  : std_logic;
92 25 mikel262
  signal huf_dval_p0    : std_logic;
93
 
94
  signal wr_cnt         : unsigned(5 downto 0);
95
 
96
-------------------------------------------------------------------------------
97
-- Architecture: begin
98
-------------------------------------------------------------------------------
99
begin
100
 
101
  huf_runlength <= dbuf_q(19 downto 16);
102
  huf_size      <= dbuf_q(15 downto 12);
103
  huf_amplitude <= dbuf_q(11 downto 0);
104 34 mikel262
  qua_buf_sel   <= qua_buf_sel_s;
105 25 mikel262
 
106
  -------------------------------------------------------------------
107
  -- RLE Core
108
  -------------------------------------------------------------------
109
  U_rle : entity work.rle
110
  generic map
111
    (
112
      RAMADDR_W  => 6,
113
      RAMDATA_W  => 12
114
    )
115
  port map
116
    (
117
      rst        => RST,
118
      clk        => CLK,
119
      di         => rle_di,
120
      start_pb   => start_pb,
121
      sof        => sof,
122
      rle_sm_settings => rle_sm_settings,
123
 
124
      runlength  => rle_runlength,
125
      size       => rle_size,
126
      amplitude  => rle_amplitude,
127 36 mikel262
      dovalid    => rle_dovalid,
128
      rd_addr    => qua_rd_addr
129 25 mikel262
    );
130
 
131 34 mikel262
  rle_di      <= qua_data;
132 25 mikel262
 
133
  -------------------------------------------------------------------
134
  -- Double Fifo
135
  -------------------------------------------------------------------
136
  U_RleDoubleFifo : entity work.RleDoubleFifo
137
  port map
138
  (
139
        CLK                => CLK,
140
        RST                => RST,
141
        -- RLE
142
        data_in            => dbuf_data,
143
        wren               => dbuf_we,
144
        -- HUFFMAN
145
        buf_sel            => huf_buf_sel,
146
        rd_req             => huf_rden,
147
        fifo_empty         => huf_fifo_empty,
148
        data_out           => dbuf_q
149
    );
150
  dbuf_data  <= rle_runlength & rle_size & rle_amplitude;
151
  dbuf_we    <= rle_dovalid;
152
 
153
 
154
 
155 36 mikel262
 
156 25 mikel262
  -------------------------------------------------------------------
157
  -- ready_pb
158
  -------------------------------------------------------------------
159
  p_ready_pb : process(CLK, RST)
160
  begin
161
    if RST = '1' then
162
      ready_pb <= '0';
163
      wr_cnt   <= (others => '0');
164
    elsif CLK'event and CLK = '1' then
165
      ready_pb <= '0';
166
 
167
      if start_pb = '1' then
168
        wr_cnt <= (others => '0');
169
      end if;
170
 
171
      -- detect EOB (0,0) - end of RLE block
172
      if rle_dovalid = '1' then
173
 
174
        -- ZERO EXTENSION
175
        if unsigned(rle_runlength) = 15 and unsigned(rle_size) = 0 then
176
          wr_cnt <= wr_cnt + 16;
177
        else
178
          wr_cnt <= wr_cnt + 1 + resize(unsigned(rle_runlength), wr_cnt'length);
179
        end if;
180
 
181
        -- EOB can only be on AC!
182
        if dbuf_data = (dbuf_data'range => '0') and wr_cnt /= 0 then
183
          ready_pb <= '1';
184
        else
185 40 mikel262
          if wr_cnt + resize(unsigned(rle_runlength), wr_cnt'length) = 64-1 then
186 25 mikel262
            ready_pb <= '1';
187
          end if;
188
        end if;
189
      end if;
190
 
191
    end if;
192
  end process;
193
 
194
  -------------------------------------------------------------------
195
  -- fdct_buf_sel
196
  -------------------------------------------------------------------
197
  p_buf_sel : process(CLK, RST)
198
  begin
199
    if RST = '1' then
200 34 mikel262
      qua_buf_sel_s   <= '0';
201 25 mikel262
    elsif CLK'event and CLK = '1' then
202
      if start_pb = '1' then
203 34 mikel262
        qua_buf_sel_s <= not qua_buf_sel_s;
204 25 mikel262
      end if;
205
    end if;
206
  end process;
207
 
208
  -------------------------------------------------------------------
209
  -- output data valid
210
  -------------------------------------------------------------------
211
  p_dval : process(CLK, RST)
212
  begin
213
    if RST = '1' then
214
      huf_dval_p0 <= '0';
215 38 mikel262
      --huf_dval    <= '0';
216 25 mikel262
    elsif CLK'event and CLK = '1' then
217
      huf_dval_p0 <= huf_rden;
218 38 mikel262
      --huf_dval    <= huf_rden;
219 25 mikel262
    end if;
220
  end process;
221 38 mikel262
 
222
  huf_dval    <= huf_rden;
223 25 mikel262
 
224
end architecture RTL;
225
-------------------------------------------------------------------------------
226
-- Architecture: end
227
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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