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

Subversion Repositories mkjpeg

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

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 34 mikel262
-- Description : Zig Zag scan
11 25 mikel262
--
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 34 mikel262
        -- Quantizer
55
        qua_buf_sel        : in  std_logic;
56
        qua_rdaddr         : in  std_logic_vector(5 downto 0);
57
        qua_data           : out std_logic_vector(11 downto 0);
58 25 mikel262
 
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 34 mikel262
        fdct_rden          : out std_logic
64 25 mikel262
    );
65
end entity ZZ_TOP;
66
 
67
-------------------------------------------------------------------------------
68
-------------------------------------------------------------------------------
69
----------------------------------- ARCHITECTURE ------------------------------
70
-------------------------------------------------------------------------------
71
-------------------------------------------------------------------------------
72
architecture RTL of ZZ_TOP is
73
 
74
  signal dbuf_data      : std_logic_vector(11 downto 0);
75
  signal dbuf_q         : std_logic_vector(11 downto 0);
76
  signal dbuf_we        : std_logic;
77
  signal dbuf_waddr     : std_logic_vector(6 downto 0);
78
  signal dbuf_raddr     : std_logic_vector(6 downto 0);
79
  signal zigzag_di      : std_logic_vector(11 downto 0);
80
  signal zigzag_divalid : std_logic;
81
  signal zigzag_dout    : std_logic_vector(11 downto 0);
82
  signal zigzag_dovalid : std_logic;
83
  signal wr_cnt         : unsigned(5 downto 0);
84
  signal rd_cnt         : unsigned(5 downto 0);
85
  signal rd_en_d        : std_logic_vector(5 downto 0);
86
  signal rd_en          : std_logic;
87
  signal fdct_buf_sel_s : std_logic;
88
  signal zz_rd_addr     : std_logic_vector(5 downto 0);
89
  signal fifo_empty     : std_logic;
90
  signal fifo_rden      : std_logic;
91
 
92
-------------------------------------------------------------------------------
93
-- Architecture: begin
94
-------------------------------------------------------------------------------
95
begin
96
 
97
  fdct_rd_addr <= std_logic_vector(zz_rd_addr);
98 34 mikel262
  qua_data     <= dbuf_q;
99 25 mikel262
  fdct_buf_sel <= fdct_buf_sel_s;
100
  fdct_rden    <= rd_en;
101
 
102
  -------------------------------------------------------------------
103
  -- ZigZag Core
104
  -------------------------------------------------------------------
105
  U_zigzag : entity work.zigzag
106
  generic map
107
    (
108
      RAMADDR_W     => 6,
109
      RAMDATA_W     => 12
110
    )
111
  port map
112
    (
113
      rst        => RST,
114
      clk        => CLK,
115
      di         => zigzag_di,
116
      divalid    => zigzag_divalid,
117
      rd_addr    => rd_cnt,
118
      fifo_rden  => fifo_rden,
119
 
120
      fifo_empty => fifo_empty,
121
      dout       => zigzag_dout,
122
      dovalid    => zigzag_dovalid,
123
      zz_rd_addr => zz_rd_addr
124
    );
125
 
126
  zigzag_di      <= fdct_data;
127
  zigzag_divalid <= rd_en_d(1);
128
 
129
  -------------------------------------------------------------------
130
  -- DBUF
131
  -------------------------------------------------------------------
132
  U_RAMZ : entity work.RAMZ
133
  generic map
134
  (
135
      RAMADDR_W     => 7,
136
      RAMDATA_W     => 12
137
  )
138
  port map
139
  (
140
        d           => dbuf_data,
141
        waddr       => dbuf_waddr,
142
        raddr       => dbuf_raddr,
143
        we          => dbuf_we,
144
        clk         => CLK,
145
 
146
        q           => dbuf_q
147
  );
148
 
149 34 mikel262
  dbuf_data  <= zigzag_dout;
150
  dbuf_waddr <= (not qua_buf_sel) & std_logic_vector(wr_cnt);
151
  dbuf_we    <= zigzag_dovalid;
152
  dbuf_raddr <= qua_buf_sel & qua_rdaddr;
153 25 mikel262
 
154
  -------------------------------------------------------------------
155
  -- FIFO Ctrl
156
  -------------------------------------------------------------------
157
  p_fifo_ctrl : process(CLK, RST)
158
  begin
159
    if RST = '1' then
160
      fifo_rden   <= '0';
161
    elsif CLK'event and CLK = '1' then
162
      if fifo_empty = '0' then
163
        fifo_rden <= '1';
164
      else
165
        fifo_rden <= '0';
166
      end if;
167
    end if;
168
  end process;
169
 
170
  -------------------------------------------------------------------
171
  -- Counter1
172
  -------------------------------------------------------------------
173
  p_counter1 : process(CLK, RST)
174
  begin
175
    if RST = '1' then
176
      rd_en        <= '0';
177
      rd_en_d      <= (others => '0');
178
      rd_cnt       <= (others => '0');
179
    elsif CLK'event and CLK = '1' then
180
      rd_en_d <= rd_en_d(rd_en_d'length-2 downto 0) & rd_en;
181
 
182
      if start_pb = '1' then
183
        rd_cnt <= (others => '0');
184
        rd_en <= '1';
185
      end if;
186
 
187
      if rd_en = '1' then
188
        if rd_cnt = 64-1 then
189
          rd_cnt <= (others => '0');
190
          rd_en  <= '0';
191
        else
192
          rd_cnt <= rd_cnt + 1;
193
        end if;
194
      end if;
195
 
196
    end if;
197
  end process;
198
 
199
  -------------------------------------------------------------------
200
  -- wr_cnt
201
  -------------------------------------------------------------------
202
  p_wr_cnt : process(CLK, RST)
203
  begin
204
    if RST = '1' then
205
      wr_cnt   <= (others => '0');
206
      ready_pb <= '0';
207
    elsif CLK'event and CLK = '1' then
208
      ready_pb <= '0';
209
 
210
      if start_pb = '1' then
211
        wr_cnt <= (others => '0');
212
      end if;
213
 
214 34 mikel262
      if zigzag_dovalid = '1' then
215 25 mikel262
        if wr_cnt = 64-1 then
216
          wr_cnt <= (others => '0');
217
        else
218
          wr_cnt <=wr_cnt + 1;
219
        end if;
220 34 mikel262
 
221
        -- give ready ahead to save cycles!
222
        if wr_cnt = 64-1-3 then
223
          ready_pb <= '1';
224
        end if;
225
 
226 25 mikel262
      end if;
227
    end if;
228
  end process;
229
 
230
  -------------------------------------------------------------------
231
  -- fdct_buf_sel
232
  -------------------------------------------------------------------
233
  p_buf_sel : process(CLK, RST)
234
  begin
235
    if RST = '1' then
236
      fdct_buf_sel_s   <= '0';
237
    elsif CLK'event and CLK = '1' then
238
      if start_pb = '1' then
239
        fdct_buf_sel_s <= not fdct_buf_sel_s;
240
      end if;
241
    end if;
242
  end process;
243
 
244
end architecture RTL;
245
-------------------------------------------------------------------------------
246
-- Architecture: end
247
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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