1 |
34 |
mikel262 |
-------------------------------------------------------------------------------
|
2 |
|
|
-- File Name : QUANT_TOP.vhd
|
3 |
|
|
--
|
4 |
|
|
-- Project : JPEG_ENC
|
5 |
|
|
--
|
6 |
|
|
-- Module : QUANT_TOP
|
7 |
|
|
--
|
8 |
|
|
-- Content : Quantizer Top level
|
9 |
|
|
--
|
10 |
|
|
-- Description : Quantizer Top level
|
11 |
|
|
--
|
12 |
|
|
-- Spec. :
|
13 |
|
|
--
|
14 |
|
|
-- Author : Michal Krepa
|
15 |
|
|
--
|
16 |
|
|
-------------------------------------------------------------------------------
|
17 |
|
|
-- History :
|
18 |
|
|
-- 20090328: (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 QUANT_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 |
|
|
qua_sm_settings : in T_SM_SETTINGS;
|
53 |
|
|
|
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 |
|
|
-- ZIGZAG
|
60 |
|
|
zig_buf_sel : out std_logic;
|
61 |
|
|
zig_rd_addr : out std_logic_vector(5 downto 0);
|
62 |
|
|
zig_data : in std_logic_vector(11 downto 0);
|
63 |
|
|
|
64 |
|
|
-- HOST
|
65 |
|
|
qdata : in std_logic_vector(7 downto 0);
|
66 |
|
|
qaddr : in std_logic_vector(6 downto 0);
|
67 |
|
|
qwren : in std_logic
|
68 |
|
|
);
|
69 |
|
|
end entity QUANT_TOP;
|
70 |
|
|
|
71 |
|
|
-------------------------------------------------------------------------------
|
72 |
|
|
-------------------------------------------------------------------------------
|
73 |
|
|
----------------------------------- ARCHITECTURE ------------------------------
|
74 |
|
|
-------------------------------------------------------------------------------
|
75 |
|
|
-------------------------------------------------------------------------------
|
76 |
|
|
architecture RTL of QUANT_TOP is
|
77 |
|
|
|
78 |
|
|
signal dbuf_data : std_logic_vector(11 downto 0);
|
79 |
|
|
signal dbuf_q : std_logic_vector(11 downto 0);
|
80 |
|
|
signal dbuf_we : std_logic;
|
81 |
|
|
signal dbuf_waddr : std_logic_vector(6 downto 0);
|
82 |
|
|
signal dbuf_raddr : std_logic_vector(6 downto 0);
|
83 |
|
|
signal zigzag_di : std_logic_vector(11 downto 0);
|
84 |
|
|
signal zigzag_divalid : std_logic;
|
85 |
|
|
signal quant_dout : std_logic_vector(11 downto 0);
|
86 |
|
|
signal quant_dovalid : std_logic;
|
87 |
|
|
signal wr_cnt : unsigned(5 downto 0);
|
88 |
|
|
signal rd_cnt : unsigned(5 downto 0);
|
89 |
|
|
signal rd_en_d : std_logic_vector(5 downto 0);
|
90 |
|
|
signal rd_en : std_logic;
|
91 |
|
|
signal zig_buf_sel_s : std_logic;
|
92 |
|
|
signal zz_rd_addr : std_logic_vector(5 downto 0);
|
93 |
|
|
signal fifo_empty : std_logic;
|
94 |
|
|
|
95 |
|
|
-------------------------------------------------------------------------------
|
96 |
|
|
-- Architecture: begin
|
97 |
|
|
-------------------------------------------------------------------------------
|
98 |
|
|
begin
|
99 |
|
|
|
100 |
|
|
zig_rd_addr <= std_logic_vector(rd_cnt);
|
101 |
|
|
rle_data <= dbuf_q;
|
102 |
|
|
zig_buf_sel <= zig_buf_sel_s;
|
103 |
|
|
|
104 |
|
|
zigzag_di <= zig_data;
|
105 |
|
|
zigzag_divalid <= rd_en_d(0);
|
106 |
|
|
|
107 |
|
|
-------------------------------------------------------------------
|
108 |
|
|
-- Quantizer
|
109 |
|
|
-------------------------------------------------------------------
|
110 |
|
|
U_quantizer : entity work.quantizer
|
111 |
|
|
generic map
|
112 |
|
|
(
|
113 |
|
|
SIZE_C => 12,
|
114 |
|
|
RAMQADDR_W => 7,
|
115 |
|
|
RAMQDATA_W => 8
|
116 |
|
|
)
|
117 |
|
|
port map
|
118 |
|
|
(
|
119 |
|
|
rst => RST,
|
120 |
|
|
clk => CLK,
|
121 |
|
|
di => zigzag_di,
|
122 |
|
|
divalid => zigzag_divalid,
|
123 |
|
|
qdata => qdata,
|
124 |
|
|
qwaddr => qaddr,
|
125 |
|
|
qwren => qwren,
|
126 |
|
|
cmp_idx => qua_sm_settings.cmp_idx,
|
127 |
|
|
|
128 |
|
|
do => quant_dout,
|
129 |
|
|
dovalid => quant_dovalid
|
130 |
|
|
);
|
131 |
|
|
|
132 |
|
|
-------------------------------------------------------------------
|
133 |
|
|
-- DBUF
|
134 |
|
|
-------------------------------------------------------------------
|
135 |
|
|
U_RAMZ : entity work.RAMZ
|
136 |
|
|
generic map
|
137 |
|
|
(
|
138 |
|
|
RAMADDR_W => 7,
|
139 |
|
|
RAMDATA_W => 12
|
140 |
|
|
)
|
141 |
|
|
port map
|
142 |
|
|
(
|
143 |
|
|
d => dbuf_data,
|
144 |
|
|
waddr => dbuf_waddr,
|
145 |
|
|
raddr => dbuf_raddr,
|
146 |
|
|
we => dbuf_we,
|
147 |
|
|
clk => CLK,
|
148 |
|
|
|
149 |
|
|
q => dbuf_q
|
150 |
|
|
);
|
151 |
|
|
|
152 |
|
|
dbuf_data <= quant_dout;
|
153 |
|
|
dbuf_waddr <= (not rle_buf_sel) & std_logic_vector(wr_cnt);
|
154 |
|
|
dbuf_we <= quant_dovalid;
|
155 |
|
|
dbuf_raddr <= rle_buf_sel & rle_rdaddr;
|
156 |
|
|
|
157 |
|
|
-------------------------------------------------------------------
|
158 |
|
|
-- Counter1
|
159 |
|
|
-------------------------------------------------------------------
|
160 |
|
|
p_counter1 : process(CLK, RST)
|
161 |
|
|
begin
|
162 |
|
|
if RST = '1' then
|
163 |
|
|
rd_en <= '0';
|
164 |
|
|
rd_en_d <= (others => '0');
|
165 |
|
|
rd_cnt <= (others => '0');
|
166 |
|
|
elsif CLK'event and CLK = '1' then
|
167 |
|
|
rd_en_d <= rd_en_d(rd_en_d'length-2 downto 0) & rd_en;
|
168 |
|
|
|
169 |
|
|
if start_pb = '1' then
|
170 |
|
|
rd_cnt <= (others => '0');
|
171 |
|
|
rd_en <= '1';
|
172 |
|
|
end if;
|
173 |
|
|
|
174 |
|
|
if rd_en = '1' then
|
175 |
|
|
if rd_cnt = 64-1 then
|
176 |
|
|
rd_cnt <= (others => '0');
|
177 |
|
|
rd_en <= '0';
|
178 |
|
|
else
|
179 |
|
|
rd_cnt <= rd_cnt + 1;
|
180 |
|
|
end if;
|
181 |
|
|
end if;
|
182 |
|
|
|
183 |
|
|
end if;
|
184 |
|
|
end process;
|
185 |
|
|
|
186 |
|
|
-------------------------------------------------------------------
|
187 |
|
|
-- wr_cnt
|
188 |
|
|
-------------------------------------------------------------------
|
189 |
|
|
p_wr_cnt : process(CLK, RST)
|
190 |
|
|
begin
|
191 |
|
|
if RST = '1' then
|
192 |
|
|
wr_cnt <= (others => '0');
|
193 |
|
|
ready_pb <= '0';
|
194 |
|
|
elsif CLK'event and CLK = '1' then
|
195 |
|
|
ready_pb <= '0';
|
196 |
|
|
|
197 |
|
|
if start_pb = '1' then
|
198 |
|
|
wr_cnt <= (others => '0');
|
199 |
|
|
end if;
|
200 |
|
|
|
201 |
|
|
if quant_dovalid = '1' then
|
202 |
|
|
if wr_cnt = 64-1 then
|
203 |
|
|
wr_cnt <= (others => '0');
|
204 |
|
|
else
|
205 |
|
|
wr_cnt <=wr_cnt + 1;
|
206 |
|
|
end if;
|
207 |
|
|
|
208 |
|
|
-- give ready ahead to save cycles!
|
209 |
|
|
if wr_cnt = 64-1-3 then
|
210 |
|
|
ready_pb <= '1';
|
211 |
|
|
end if;
|
212 |
|
|
end if;
|
213 |
|
|
end if;
|
214 |
|
|
end process;
|
215 |
|
|
|
216 |
|
|
-------------------------------------------------------------------
|
217 |
|
|
-- zig_buf_sel
|
218 |
|
|
-------------------------------------------------------------------
|
219 |
|
|
p_buf_sel : process(CLK, RST)
|
220 |
|
|
begin
|
221 |
|
|
if RST = '1' then
|
222 |
|
|
zig_buf_sel_s <= '0';
|
223 |
|
|
elsif CLK'event and CLK = '1' then
|
224 |
|
|
if start_pb = '1' then
|
225 |
|
|
zig_buf_sel_s <= not zig_buf_sel_s;
|
226 |
|
|
end if;
|
227 |
|
|
end if;
|
228 |
|
|
end process;
|
229 |
|
|
|
230 |
|
|
end architecture RTL;
|
231 |
|
|
-------------------------------------------------------------------------------
|
232 |
|
|
-- Architecture: end
|
233 |
|
|
-------------------------------------------------------------------------------
|