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

Subversion Repositories mkjpeg

[/] [mkjpeg/] [trunk/] [design/] [zigzag/] [ZZ_TOP.VHD] - Blame information for rev 32

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

Line No. Rev Author Line
1 25 mikel262
-------------------------------------------------------------------------------
2
-- File Name :  ZZ_TOP.vhd
3
--
4
-- Project   : JPEG_ENC
5
--
6
-- Module    : ZZ_TOP
7
--
8
-- Content   : ZigZag Top level
9
--
10
-- Description : Zig Zag scan and Quantizer
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 32 mikel262
library work;
38
  use work.JPEG_PKG.all;
39 25 mikel262
-------------------------------------------------------------------------------
40
-------------------------------------------------------------------------------
41
----------------------------------- ENTITY ------------------------------------
42
-------------------------------------------------------------------------------
43
-------------------------------------------------------------------------------
44
entity ZZ_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 32 mikel262
        zig_sm_settings    : in  T_SM_SETTINGS;
53 25 mikel262
 
54
        -- RLE
55
        rle_buf_sel        : in  std_logic;
56
        rle_rdaddr         : in  std_logic_vector(5 downto 0);
57
        rle_data           : out std_logic_vector(11 downto 0);
58
 
59
        -- FDCT
60
        fdct_buf_sel       : out std_logic;
61
        fdct_rd_addr       : out std_logic_vector(5 downto 0);
62
        fdct_data          : in  std_logic_vector(11 downto 0);
63
        fdct_rden          : out std_logic;
64
 
65
        -- HOST
66
        qdata              : in  std_logic_vector(7 downto 0);
67 32 mikel262
        qaddr              : in  std_logic_vector(6 downto 0);
68 25 mikel262
        qwren              : in  std_logic
69
    );
70
end entity ZZ_TOP;
71
 
72
-------------------------------------------------------------------------------
73
-------------------------------------------------------------------------------
74
----------------------------------- ARCHITECTURE ------------------------------
75
-------------------------------------------------------------------------------
76
-------------------------------------------------------------------------------
77
architecture RTL of ZZ_TOP is
78
 
79
  signal dbuf_data      : std_logic_vector(11 downto 0);
80
  signal dbuf_q         : std_logic_vector(11 downto 0);
81
  signal dbuf_we        : std_logic;
82
  signal dbuf_waddr     : std_logic_vector(6 downto 0);
83
  signal dbuf_raddr     : std_logic_vector(6 downto 0);
84
  signal zigzag_di      : std_logic_vector(11 downto 0);
85
  signal zigzag_divalid : std_logic;
86
  signal zigzag_dout    : std_logic_vector(11 downto 0);
87
  signal zigzag_dovalid : std_logic;
88
  signal quant_dout     : std_logic_vector(11 downto 0);
89
  signal quant_dovalid  : std_logic;
90
  signal wr_cnt         : unsigned(5 downto 0);
91
  signal rd_cnt         : unsigned(5 downto 0);
92
  signal rd_en_d        : std_logic_vector(5 downto 0);
93
  signal rd_en          : std_logic;
94
  signal fdct_buf_sel_s : std_logic;
95
  signal zz_rd_addr     : std_logic_vector(5 downto 0);
96
  signal fifo_empty     : std_logic;
97
  signal fifo_rden      : std_logic;
98
 
99
-------------------------------------------------------------------------------
100
-- Architecture: begin
101
-------------------------------------------------------------------------------
102
begin
103
 
104
  fdct_rd_addr <= std_logic_vector(zz_rd_addr);
105
  rle_data     <= dbuf_q;
106
  fdct_buf_sel <= fdct_buf_sel_s;
107
  fdct_rden    <= rd_en;
108
 
109
  -------------------------------------------------------------------
110
  -- ZigZag Core
111
  -------------------------------------------------------------------
112
  U_zigzag : entity work.zigzag
113
  generic map
114
    (
115
      RAMADDR_W     => 6,
116
      RAMDATA_W     => 12
117
    )
118
  port map
119
    (
120
      rst        => RST,
121
      clk        => CLK,
122
      di         => zigzag_di,
123
      divalid    => zigzag_divalid,
124
      rd_addr    => rd_cnt,
125
      fifo_rden  => fifo_rden,
126
 
127
      fifo_empty => fifo_empty,
128
      dout       => zigzag_dout,
129
      dovalid    => zigzag_dovalid,
130
      zz_rd_addr => zz_rd_addr
131
    );
132
 
133
  zigzag_di      <= fdct_data;
134
  zigzag_divalid <= rd_en_d(1);
135
 
136
  -------------------------------------------------------------------
137
  -- Quantizer
138
  -------------------------------------------------------------------
139
  U_quantizer : entity work.quantizer
140
  generic map
141
    (
142
      SIZE_C        => 12,
143 32 mikel262
      RAMQADDR_W    => 7,
144 25 mikel262
      RAMQDATA_W    => 8
145
    )
146
  port map
147
    (
148
      rst      => RST,
149
      clk      => CLK,
150
      di       => zigzag_dout,
151
      divalid  => zigzag_dovalid,
152
      qdata    => qdata,
153
      qwaddr   => qaddr,
154
      qwren    => qwren,
155 32 mikel262
      cmp_idx  => zig_sm_settings.cmp_idx,
156 25 mikel262
 
157
      do       => quant_dout,
158
      dovalid  => quant_dovalid
159
    );
160
 
161
  -------------------------------------------------------------------
162
  -- DBUF
163
  -------------------------------------------------------------------
164
  U_RAMZ : entity work.RAMZ
165
  generic map
166
  (
167
      RAMADDR_W     => 7,
168
      RAMDATA_W     => 12
169
  )
170
  port map
171
  (
172
        d           => dbuf_data,
173
        waddr       => dbuf_waddr,
174
        raddr       => dbuf_raddr,
175
        we          => dbuf_we,
176
        clk         => CLK,
177
 
178
        q           => dbuf_q
179
  );
180
 
181
  dbuf_data  <= quant_dout;
182
  dbuf_waddr <= (not rle_buf_sel) & std_logic_vector(wr_cnt);
183
  dbuf_we    <= quant_dovalid;
184
  dbuf_raddr <= rle_buf_sel & rle_rdaddr;
185
 
186
  -------------------------------------------------------------------
187
  -- FIFO Ctrl
188
  -------------------------------------------------------------------
189
  p_fifo_ctrl : process(CLK, RST)
190
  begin
191
    if RST = '1' then
192
      fifo_rden   <= '0';
193
    elsif CLK'event and CLK = '1' then
194
      if fifo_empty = '0' then
195
        fifo_rden <= '1';
196
      else
197
        fifo_rden <= '0';
198
      end if;
199
    end if;
200
  end process;
201
 
202
  -------------------------------------------------------------------
203
  -- Counter1
204
  -------------------------------------------------------------------
205
  p_counter1 : process(CLK, RST)
206
  begin
207
    if RST = '1' then
208
      rd_en        <= '0';
209
      rd_en_d      <= (others => '0');
210
      rd_cnt       <= (others => '0');
211
    elsif CLK'event and CLK = '1' then
212
      rd_en_d <= rd_en_d(rd_en_d'length-2 downto 0) & rd_en;
213
 
214
      if start_pb = '1' then
215
        rd_cnt <= (others => '0');
216
        rd_en <= '1';
217
      end if;
218
 
219
      if rd_en = '1' then
220
        if rd_cnt = 64-1 then
221
          rd_cnt <= (others => '0');
222
          rd_en  <= '0';
223
        else
224
          rd_cnt <= rd_cnt + 1;
225
        end if;
226
      end if;
227
 
228
    end if;
229
  end process;
230
 
231
  -------------------------------------------------------------------
232
  -- wr_cnt
233
  -------------------------------------------------------------------
234
  p_wr_cnt : process(CLK, RST)
235
  begin
236
    if RST = '1' then
237
      wr_cnt   <= (others => '0');
238
      ready_pb <= '0';
239
    elsif CLK'event and CLK = '1' then
240
      ready_pb <= '0';
241
 
242
      if start_pb = '1' then
243
        wr_cnt <= (others => '0');
244
      end if;
245
 
246
      if quant_dovalid = '1' then
247
        if wr_cnt = 64-1 then
248
          wr_cnt <= (others => '0');
249
          ready_pb <= '1';
250
        else
251
          wr_cnt <=wr_cnt + 1;
252
        end if;
253
      end if;
254
    end if;
255
  end process;
256
 
257
  -------------------------------------------------------------------
258
  -- fdct_buf_sel
259
  -------------------------------------------------------------------
260
  p_buf_sel : process(CLK, RST)
261
  begin
262
    if RST = '1' then
263
      fdct_buf_sel_s   <= '0';
264
    elsif CLK'event and CLK = '1' then
265
      if start_pb = '1' then
266
        fdct_buf_sel_s <= not fdct_buf_sel_s;
267
      end if;
268
    end if;
269
  end process;
270
 
271
end architecture RTL;
272
-------------------------------------------------------------------------------
273
-- Architecture: end
274
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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