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

Subversion Repositories mkjpeg

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

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

powered by: WebSVN 2.1.0

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