1 |
25 |
mikel262 |
-------------------------------------------------------------------------------
|
2 |
|
|
-- File Name : BUF_FIFO.vhd
|
3 |
|
|
--
|
4 |
|
|
-- Project : JPEG_ENC
|
5 |
|
|
--
|
6 |
|
|
-- Module : BUF_FIFO
|
7 |
|
|
--
|
8 |
|
|
-- Content : Input FIFO Buffer
|
9 |
|
|
--
|
10 |
|
|
-- Description :
|
11 |
|
|
--
|
12 |
|
|
-- Spec. :
|
13 |
|
|
--
|
14 |
|
|
-- Author : Michal Krepa
|
15 |
|
|
--
|
16 |
|
|
-------------------------------------------------------------------------------
|
17 |
|
|
-- History :
|
18 |
|
|
-- 20090311: (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 BUF_FIFO is
|
45 |
|
|
port
|
46 |
|
|
(
|
47 |
|
|
CLK : in std_logic;
|
48 |
|
|
RST : in std_logic;
|
49 |
|
|
-- HOST PROG
|
50 |
|
|
img_size_x : in std_logic_vector(15 downto 0);
|
51 |
|
|
img_size_y : in std_logic_vector(15 downto 0);
|
52 |
|
|
sof : in std_logic;
|
53 |
|
|
|
54 |
|
|
-- HOST DATA
|
55 |
|
|
iram_wren : in std_logic;
|
56 |
|
|
iram_wdata : in std_logic_vector(23 downto 0);
|
57 |
|
|
fifo_almost_full : out std_logic;
|
58 |
|
|
|
59 |
|
|
-- FDCT
|
60 |
|
|
fdct_block_cnt : in std_logic_vector(12 downto 0);
|
61 |
|
|
fdct_fifo_rd : in std_logic;
|
62 |
|
|
fdct_fifo_empty : out std_logic;
|
63 |
|
|
fdct_fifo_q : out std_logic_vector(23 downto 0);
|
64 |
|
|
fdct_fifo_hf_full : out std_logic
|
65 |
|
|
);
|
66 |
|
|
end entity BUF_FIFO;
|
67 |
|
|
|
68 |
|
|
-------------------------------------------------------------------------------
|
69 |
|
|
-------------------------------------------------------------------------------
|
70 |
|
|
----------------------------------- ARCHITECTURE ------------------------------
|
71 |
|
|
-------------------------------------------------------------------------------
|
72 |
|
|
-------------------------------------------------------------------------------
|
73 |
|
|
architecture RTL of BUF_FIFO is
|
74 |
|
|
|
75 |
|
|
constant C_NUM_SUBF : integer := ((C_MAX_LINE_WIDTH/8));
|
76 |
|
|
|
77 |
|
|
type T_DATA_ARR is array (0 to C_NUM_SUBF-1) of std_logic_vector(23 downto 0);
|
78 |
|
|
type T_CNT_ARR is array (0 to C_NUM_SUBF-1) of
|
79 |
|
|
std_logic_vector(7-C_MEMORY_OPTIMIZED downto 0);
|
80 |
|
|
|
81 |
|
|
signal fifo_rd : std_logic_vector(C_NUM_SUBF-1 downto 0);
|
82 |
|
|
signal fifo_wr : std_logic_vector(C_NUM_SUBF-1 downto 0);
|
83 |
|
|
signal fifo_data : std_logic_vector(23 downto 0);
|
84 |
|
|
signal fifo_data_d1 : std_logic_vector(23 downto 0);
|
85 |
|
|
signal fifo_q : T_DATA_ARR;
|
86 |
|
|
signal fifo_full : std_logic_vector(C_NUM_SUBF-1 downto 0);
|
87 |
|
|
signal fifo_empty : std_logic_vector(C_NUM_SUBF-1 downto 0);
|
88 |
|
|
signal fifo_half_full : std_logic_vector(C_NUM_SUBF-1 downto 0);
|
89 |
|
|
signal fifo_count : T_CNT_ARR;
|
90 |
|
|
|
91 |
|
|
signal pixel_cnt : unsigned(15 downto 0);
|
92 |
|
|
signal wblock_cnt : unsigned(12 downto 0);
|
93 |
|
|
signal last_idx : unsigned(12 downto 0);
|
94 |
|
|
signal idx_reg : unsigned(log2(C_NUM_SUBF)-1 downto 0);
|
95 |
|
|
|
96 |
|
|
-------------------------------------------------------------------------------
|
97 |
|
|
-- Architecture: begin
|
98 |
|
|
-------------------------------------------------------------------------------
|
99 |
|
|
begin
|
100 |
|
|
|
101 |
|
|
-------------------------------------------------------------------
|
102 |
|
|
-- SUB_FIFOs
|
103 |
|
|
-------------------------------------------------------------------
|
104 |
|
|
G_SUB_FIFO : for i in 0 to C_NUM_SUBF-1 generate
|
105 |
|
|
|
106 |
|
|
U_SUB_FIFO : entity work.FIFO
|
107 |
|
|
generic map
|
108 |
|
|
(
|
109 |
|
|
DATA_WIDTH => 24,
|
110 |
|
|
ADDR_WIDTH => 7-C_MEMORY_OPTIMIZED
|
111 |
|
|
)
|
112 |
|
|
port map
|
113 |
|
|
(
|
114 |
|
|
rst => RST,
|
115 |
|
|
clk => CLK,
|
116 |
|
|
rinc => fifo_rd(i),
|
117 |
|
|
winc => fifo_wr(i),
|
118 |
|
|
datai => fifo_data,
|
119 |
|
|
|
120 |
|
|
datao => fifo_q(i),
|
121 |
|
|
fullo => fifo_full(i),
|
122 |
|
|
emptyo => fifo_empty(i),
|
123 |
|
|
count => fifo_count(i)
|
124 |
|
|
);
|
125 |
|
|
end generate G_SUB_FIFO;
|
126 |
|
|
|
127 |
|
|
-------------------------------------------------------------------
|
128 |
|
|
-- FIFO almost full
|
129 |
|
|
-------------------------------------------------------------------
|
130 |
|
|
p_fifo_almost_full : process(CLK, RST)
|
131 |
|
|
begin
|
132 |
|
|
if RST = '1' then
|
133 |
|
|
fifo_almost_full <= '1';
|
134 |
|
|
last_idx <= (others => '0');
|
135 |
|
|
elsif CLK'event and CLK = '1' then
|
136 |
|
|
if img_size_x = (img_size_x'range => '0') then
|
137 |
|
|
last_idx <= (others => '0');
|
138 |
|
|
else
|
139 |
|
|
last_idx <= unsigned(img_size_x(15 downto 3))-1;
|
140 |
|
|
end if;
|
141 |
|
|
|
142 |
|
|
if last_idx > 0 then
|
143 |
|
|
if C_MEMORY_OPTIMIZED = 0 then
|
144 |
|
|
if unsigned(fifo_count(to_integer(last_idx)-2)) > to_unsigned(128-2*8,8) then
|
145 |
|
|
fifo_almost_full <= '1';
|
146 |
|
|
else
|
147 |
|
|
fifo_almost_full <= '0';
|
148 |
|
|
end if;
|
149 |
|
|
else
|
150 |
|
|
if unsigned(fifo_count(to_integer(last_idx))) = to_unsigned(64,8) then
|
151 |
|
|
fifo_almost_full <= '1';
|
152 |
|
|
else
|
153 |
|
|
fifo_almost_full <= '0';
|
154 |
|
|
end if;
|
155 |
|
|
end if;
|
156 |
|
|
end if;
|
157 |
|
|
end if;
|
158 |
|
|
end process;
|
159 |
|
|
|
160 |
|
|
-------------------------------------------------------------------
|
161 |
|
|
-- pixel_cnt
|
162 |
|
|
-------------------------------------------------------------------
|
163 |
|
|
p_pixel_cnt : process(CLK, RST)
|
164 |
|
|
begin
|
165 |
|
|
if RST = '1' then
|
166 |
|
|
pixel_cnt <= (others => '0');
|
167 |
|
|
elsif CLK'event and CLK = '1' then
|
168 |
|
|
if iram_wren = '1' then
|
169 |
|
|
if pixel_cnt = unsigned(img_size_x)-1 then
|
170 |
|
|
pixel_cnt <= (others => '0');
|
171 |
|
|
else
|
172 |
|
|
pixel_cnt <= pixel_cnt + 1;
|
173 |
|
|
end if;
|
174 |
|
|
end if;
|
175 |
|
|
|
176 |
|
|
if sof = '1' then
|
177 |
|
|
pixel_cnt <= (others => '0');
|
178 |
|
|
end if;
|
179 |
|
|
end if;
|
180 |
|
|
end process;
|
181 |
|
|
|
182 |
|
|
wblock_cnt <= pixel_cnt(pixel_cnt'high downto 3);
|
183 |
|
|
|
184 |
|
|
-------------------------------------------------------------------
|
185 |
|
|
-- FIFO half full
|
186 |
|
|
-------------------------------------------------------------------
|
187 |
|
|
p_half_full : process(CLK, RST)
|
188 |
|
|
begin
|
189 |
|
|
if RST = '1' then
|
190 |
|
|
for i in 0 to C_NUM_SUBF-1 loop
|
191 |
|
|
fifo_half_full(i) <= '0';
|
192 |
|
|
end loop;
|
193 |
|
|
elsif CLK'event and CLK = '1' then
|
194 |
|
|
for i in 0 to C_NUM_SUBF-1 loop
|
195 |
|
|
if unsigned(fifo_count(i)) >= 64 then
|
196 |
|
|
fifo_half_full(i) <= '1';
|
197 |
|
|
else
|
198 |
|
|
fifo_half_full(i) <= '0';
|
199 |
|
|
end if;
|
200 |
|
|
end loop;
|
201 |
|
|
end if;
|
202 |
|
|
end process;
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
-------------------------------------------------------------------
|
206 |
|
|
-- Mux1
|
207 |
|
|
-------------------------------------------------------------------
|
208 |
|
|
p_mux1 : process(CLK, RST)
|
209 |
|
|
begin
|
210 |
|
|
if RST = '1' then
|
211 |
|
|
fifo_data <= (others => '0');
|
212 |
|
|
for i in 0 to C_NUM_SUBF-1 loop
|
213 |
|
|
fifo_wr(i) <= '0';
|
214 |
|
|
end loop;
|
215 |
|
|
elsif CLK'event and CLK = '1' then
|
216 |
|
|
for i in 0 to C_NUM_SUBF-1 loop
|
217 |
|
|
if wblock_cnt(log2(C_NUM_SUBF)-1 downto 0) = i then
|
218 |
|
|
fifo_wr(i) <= iram_wren;
|
219 |
|
|
else
|
220 |
|
|
fifo_wr(i) <= '0';
|
221 |
|
|
end if;
|
222 |
|
|
end loop;
|
223 |
|
|
|
224 |
|
|
fifo_data <= iram_wdata;
|
225 |
|
|
end if;
|
226 |
|
|
end process;
|
227 |
|
|
|
228 |
|
|
-------------------------------------------------------------------
|
229 |
|
|
-- Mux2
|
230 |
|
|
-------------------------------------------------------------------
|
231 |
|
|
p_mux2 : process(CLK, RST)
|
232 |
|
|
begin
|
233 |
|
|
if RST = '1' then
|
234 |
|
|
for i in 0 to C_NUM_SUBF-1 loop
|
235 |
|
|
fifo_rd(i) <= '0';
|
236 |
|
|
end loop;
|
237 |
|
|
fdct_fifo_empty <= '0';
|
238 |
|
|
fdct_fifo_q <= (others => '0');
|
239 |
|
|
fdct_fifo_hf_full <= '0';
|
240 |
|
|
idx_reg <= (others => '0');
|
241 |
|
|
elsif CLK'event and CLK = '1' then
|
242 |
|
|
idx_reg <= unsigned(fdct_block_cnt(log2(C_NUM_SUBF)-1 downto 0));
|
243 |
|
|
|
244 |
|
|
for i in 0 to C_NUM_SUBF-1 loop
|
245 |
|
|
if idx_reg = i then
|
246 |
|
|
fifo_rd(i) <= fdct_fifo_rd;
|
247 |
|
|
else
|
248 |
|
|
fifo_rd(i) <= '0';
|
249 |
|
|
end if;
|
250 |
|
|
end loop;
|
251 |
|
|
|
252 |
|
|
fdct_fifo_empty <= fifo_empty(to_integer(idx_reg));
|
253 |
|
|
fdct_fifo_q <= fifo_q(to_integer(idx_reg));
|
254 |
|
|
fdct_fifo_hf_full <= fifo_half_full(to_integer(idx_reg));
|
255 |
|
|
end if;
|
256 |
|
|
end process;
|
257 |
|
|
|
258 |
|
|
|
259 |
|
|
|
260 |
|
|
end architecture RTL;
|
261 |
|
|
-------------------------------------------------------------------------------
|
262 |
|
|
-- Architecture: end
|
263 |
|
|
-------------------------------------------------------------------------------
|