1 |
9 |
eejlny |
--This library is free software; you can redistribute it and/or
|
2 |
|
|
--modify it under the terms of the GNU Lesser General Public
|
3 |
|
|
--License as published by the Free Software Foundation; either
|
4 |
|
|
--version 2.1 of the License, or (at your option) any later version.
|
5 |
|
|
|
6 |
|
|
--This library is distributed in the hope that it will be useful,
|
7 |
|
|
--but WITHOUT ANY WARRANTY; without even the implied warranty of
|
8 |
|
|
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
9 |
|
|
--Lesser General Public License for more details.
|
10 |
|
|
|
11 |
|
|
--You should have received a copy of the GNU Lesser General Public
|
12 |
|
|
--License along with this library; if not, write to the Free Software
|
13 |
|
|
--Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
14 |
|
|
|
15 |
|
|
-- e_mail : j.l.nunez-yanez@byacom.co.uk
|
16 |
|
|
|
17 |
|
|
-----------------------------------------------------
|
18 |
|
|
-- ENTITY = OUTPUT_BUFFER_CU --
|
19 |
|
|
-- version = 1.0 --
|
20 |
|
|
-- last update = 31/6/01 --
|
21 |
|
|
-- author = Jose Nunez --
|
22 |
|
|
-----------------------------------------------------
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
-- FUNCTION
|
26 |
|
|
-- Control unit that controls the output buffer
|
27 |
|
|
|
28 |
|
|
-- PIN LIST
|
29 |
|
|
-- START : enable the buffer
|
30 |
|
|
-- STOP : all the uncompressed data has accessed the buffer
|
31 |
|
|
-- EMPTY : all the uncompressed data has left the buffer
|
32 |
|
|
-- BUS_ACKNOWLEDGE : the uncompressed bus in is granted
|
33 |
|
|
-- CODING_READ_ADDRESS : input buffer location that it is being read
|
34 |
|
|
-- CODING_WRITE_ADDRESS : input buffer location that it is being written
|
35 |
|
|
-- CLK : clock
|
36 |
|
|
-- CLEAR : clear
|
37 |
|
|
-- BUS_REQUEST : the input buffer is being requested
|
38 |
|
|
-- READY : buffer ready with data to be output to the uncompressed output bus
|
39 |
|
|
-- CLEAR_COUNTERS : counters are reset. Counters generate the addresses to the buffers
|
40 |
|
|
-- ENABLE_WRITE : enable writting to the buffer
|
41 |
|
|
-- ENABLE_READ : enable reading from the buffer
|
42 |
|
|
|
43 |
|
|
library ieee;
|
44 |
|
|
use ieee.std_logic_1164.all;
|
45 |
|
|
library dzx;
|
46 |
|
|
use dzx.bit_arith.all;
|
47 |
|
|
use dzx.bit_utils.all;
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
entity OUTPUT_BUFFER_CU is
|
51 |
|
|
port
|
52 |
|
|
(
|
53 |
|
|
WAITN : in bit;
|
54 |
|
|
FORCE_STOP : in bit;
|
55 |
|
|
START_D : in bit;
|
56 |
|
|
START_C : in bit;
|
57 |
|
|
FINISHED : in bit;
|
58 |
|
|
BUS_ACKNOWLEDGE : in bit;
|
59 |
|
|
CODING_READ_ADDRESS : in bit_vector(8 downto 0);
|
60 |
|
|
CODING_WRITE_ADDRESS : in bit_vector(8 downto 0);
|
61 |
|
|
THRESHOLD : in bit_vector(8 downto 0);
|
62 |
|
|
CLK : in bit;
|
63 |
|
|
CLEAR : in bit;
|
64 |
|
|
FLUSHING : out bit;
|
65 |
|
|
FINISHED_FLUSHING : out bit;
|
66 |
|
|
OVERFLOW_DETECTED : out bit;
|
67 |
|
|
ENABLE_WRITE : out bit;
|
68 |
|
|
ENABLE_READ : out bit;
|
69 |
|
|
READY : out bit;
|
70 |
|
|
CLEAR_COUNTERS : out bit;
|
71 |
|
|
OVERFLOW_CONTROL : out bit;
|
72 |
|
|
BUS_REQUEST : out bit
|
73 |
|
|
);
|
74 |
|
|
end OUTPUT_BUFFER_CU;
|
75 |
|
|
|
76 |
|
|
architecture STRUCTURAL of OUTPUT_BUFFER_CU is
|
77 |
|
|
|
78 |
|
|
signal CURRENT_STATE : bit_vector(3 downto 0);
|
79 |
|
|
signal NEXT_STATE : bit_vector(3 downto 0);
|
80 |
|
|
signal ENABLE_WRITE_AUX : bit;
|
81 |
|
|
signal OVERFLOW_CONTROL_AUX : bit;
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
begin
|
85 |
|
|
|
86 |
|
|
STATES : process (WAITN, THRESHOLD, START_C, START_D, CURRENT_STATE, FINISHED, CODING_READ_ADDRESS, CODING_WRITE_ADDRESS, BUS_ACKNOWLEDGE)
|
87 |
|
|
begin
|
88 |
|
|
case CURRENT_STATE is
|
89 |
|
|
when "0000" => -- state 0 buffer inactive
|
90 |
|
|
if (START_D = '0' or START_C = '0') then
|
91 |
|
|
NEXT_STATE <= "0001";
|
92 |
|
|
else
|
93 |
|
|
NEXT_STATE <= CURRENT_STATE;
|
94 |
|
|
end if;
|
95 |
|
|
ENABLE_READ <= '0';
|
96 |
|
|
ENABLE_WRITE_AUX <= '0';
|
97 |
|
|
BUS_REQUEST <= '1';
|
98 |
|
|
CLEAR_COUNTERS <= '1';
|
99 |
|
|
READY <= '1';
|
100 |
|
|
FLUSHING <= '1';
|
101 |
|
|
FINISHED_FLUSHING <= '1';
|
102 |
|
|
|
103 |
|
|
when "0001" => -- state 1 request the bus and start adding data to the buffer
|
104 |
|
|
if (FINISHED = '0') then
|
105 |
|
|
NEXT_STATE <= "1010";
|
106 |
|
|
elsif (CODING_WRITE_ADDRESS - CODING_READ_ADDRESS > THRESHOLD) then -- request the bus
|
107 |
|
|
NEXT_STATE <= "0101";
|
108 |
|
|
else
|
109 |
|
|
NEXT_STATE <= CURRENT_STATE;
|
110 |
|
|
end if;
|
111 |
|
|
ENABLE_READ <= '0';
|
112 |
|
|
ENABLE_WRITE_AUX <= '1';
|
113 |
|
|
BUS_REQUEST <= '1';
|
114 |
|
|
CLEAR_COUNTERS <= '0';
|
115 |
|
|
READY <= '1';
|
116 |
|
|
FLUSHING <= '1';
|
117 |
|
|
FINISHED_FLUSHING <= '1';
|
118 |
|
|
|
119 |
|
|
when "0010" => -- start reading data from the input buffer and writting as well
|
120 |
|
|
if (FINISHED = '0') then -- all the data has accessed the internal buffer
|
121 |
|
|
NEXT_STATE <= "0100";
|
122 |
|
|
else
|
123 |
|
|
NEXT_STATE <= "0110";
|
124 |
|
|
end if;
|
125 |
|
|
ENABLE_READ <= '1';
|
126 |
|
|
ENABLE_WRITE_AUX <= '1';
|
127 |
|
|
BUS_REQUEST <= '0';
|
128 |
|
|
CLEAR_COUNTERS <= '0';
|
129 |
|
|
READY <= '1';
|
130 |
|
|
FLUSHING <= '1';
|
131 |
|
|
FINISHED_FLUSHING <= '1';
|
132 |
|
|
|
133 |
|
|
when "0011" => -- now only writting to buffer
|
134 |
|
|
if (FINISHED = '0') then -- all the data has accessed the internal buffer active low
|
135 |
|
|
NEXT_STATE <= "1010";
|
136 |
|
|
elsif (CODING_WRITE_ADDRESS - CODING_READ_ADDRESS > THRESHOLD) then -- we have data ready to be output
|
137 |
|
|
NEXT_STATE <= "0101"; -- request the bus
|
138 |
|
|
else
|
139 |
|
|
NEXT_STATE <= CURRENT_STATE;
|
140 |
|
|
end if;
|
141 |
|
|
ENABLE_WRITE_AUX <= '1';
|
142 |
|
|
ENABLE_READ <= '0';
|
143 |
|
|
BUS_REQUEST <= '1';
|
144 |
|
|
CLEAR_COUNTERS <= '0';
|
145 |
|
|
READY <= '1';
|
146 |
|
|
FLUSHING <= '1';
|
147 |
|
|
FINISHED_FLUSHING <= '1';
|
148 |
|
|
|
149 |
|
|
when "0100" => -- now only reading. Flushing the buffer
|
150 |
|
|
if (CODING_WRITE_ADDRESS = CODING_READ_ADDRESS and WAITN = '1') then
|
151 |
|
|
NEXT_STATE <= "1001"; --it is over signal finish
|
152 |
|
|
else
|
153 |
|
|
NEXT_STATE <= CURRENT_STATE;
|
154 |
|
|
end if;
|
155 |
|
|
ENABLE_WRITE_AUX <= '0';
|
156 |
|
|
ENABLE_READ <= '1';
|
157 |
|
|
BUS_REQUEST <= '0';
|
158 |
|
|
CLEAR_COUNTERS <= '0';
|
159 |
|
|
READY <= '0';
|
160 |
|
|
FLUSHING <= '0';
|
161 |
|
|
FINISHED_FLUSHING <= '1';
|
162 |
|
|
|
163 |
|
|
when "0101" => -- state 1 request the bus and start adding data to the buffer
|
164 |
|
|
if (FINISHED = '0') then -- all the data has accessed the internal buffer active low. stop writting
|
165 |
|
|
NEXT_STATE <= "1010";
|
166 |
|
|
elsif (BUS_ACKNOWLEDGE = '0') then -- bus ready to received data
|
167 |
|
|
NEXT_STATE <= "0010";
|
168 |
|
|
else
|
169 |
|
|
NEXT_STATE <= CURRENT_STATE;
|
170 |
|
|
end if;
|
171 |
|
|
ENABLE_READ <= '0';
|
172 |
|
|
ENABLE_WRITE_AUX <= '1';
|
173 |
|
|
BUS_REQUEST <= '0';
|
174 |
|
|
CLEAR_COUNTERS <= '0';
|
175 |
|
|
READY <= '1';
|
176 |
|
|
FLUSHING <= '1';
|
177 |
|
|
FINISHED_FLUSHING <= '1';
|
178 |
|
|
|
179 |
|
|
when "0110" => -- start reading data from the input buffer and writting as well
|
180 |
|
|
if (FINISHED = '0') then -- all the data has accessed the internal buffer
|
181 |
|
|
NEXT_STATE <= "0100";
|
182 |
|
|
elsif (CODING_WRITE_ADDRESS = CODING_READ_ADDRESS + "000000001" and WAITN = '1') then -- we have empty the buffer wait
|
183 |
|
|
NEXT_STATE <= "0111";
|
184 |
|
|
else
|
185 |
|
|
NEXT_STATE <= CURRENT_STATE;
|
186 |
|
|
end if;
|
187 |
|
|
ENABLE_READ <= '1';
|
188 |
|
|
ENABLE_WRITE_AUX <= '1';
|
189 |
|
|
BUS_REQUEST <= '0';
|
190 |
|
|
CLEAR_COUNTERS <= '0';
|
191 |
|
|
READY <= '0';
|
192 |
|
|
FLUSHING <= '1';
|
193 |
|
|
FINISHED_FLUSHING <= '1';
|
194 |
|
|
|
195 |
|
|
when "0111" => -- transition to disable reading ready still active
|
196 |
|
|
|
197 |
|
|
if (WAITN = '1') then
|
198 |
|
|
NEXT_STATE <= "0011";
|
199 |
|
|
else
|
200 |
|
|
NEXT_STATE <= CURRENT_STATE;
|
201 |
|
|
end if;
|
202 |
|
|
ENABLE_WRITE_AUX <= '1';
|
203 |
|
|
ENABLE_READ <= '0';
|
204 |
|
|
BUS_REQUEST <= '0';
|
205 |
|
|
CLEAR_COUNTERS <= '0';
|
206 |
|
|
READY <= '0';
|
207 |
|
|
FLUSHING <= '1';
|
208 |
|
|
FINISHED_FLUSHING <= '1';
|
209 |
|
|
|
210 |
|
|
when "1000" => -- transition to finish
|
211 |
|
|
NEXT_STATE <= "1001";
|
212 |
|
|
ENABLE_WRITE_AUX <= '0';
|
213 |
|
|
ENABLE_READ <= '0';
|
214 |
|
|
BUS_REQUEST <= '1';
|
215 |
|
|
CLEAR_COUNTERS <= '1';
|
216 |
|
|
READY <= '1';
|
217 |
|
|
FLUSHING <= '0';
|
218 |
|
|
FINISHED_FLUSHING <= '1';
|
219 |
|
|
|
220 |
|
|
when "1001" => -- transition to finish
|
221 |
|
|
NEXT_STATE <= "0000";
|
222 |
|
|
ENABLE_WRITE_AUX <= '0';
|
223 |
|
|
ENABLE_READ <= '0';
|
224 |
|
|
BUS_REQUEST <= '1';
|
225 |
|
|
CLEAR_COUNTERS <= '1';
|
226 |
|
|
READY <= '1';
|
227 |
|
|
FLUSHING <= '1';
|
228 |
|
|
FINISHED_FLUSHING <= '0';
|
229 |
|
|
|
230 |
|
|
when "1010" => -- state 1 request the bus and start adding data to the buffer
|
231 |
|
|
if (BUS_ACKNOWLEDGE = '0') then -- bus ready to received data
|
232 |
|
|
NEXT_STATE <= "1011";
|
233 |
|
|
else
|
234 |
|
|
NEXT_STATE <= CURRENT_STATE;
|
235 |
|
|
end if;
|
236 |
|
|
ENABLE_READ <= '0';
|
237 |
|
|
ENABLE_WRITE_AUX <= '0';
|
238 |
|
|
BUS_REQUEST <= '0';
|
239 |
|
|
CLEAR_COUNTERS <= '0';
|
240 |
|
|
READY <= '1';
|
241 |
|
|
FLUSHING <= '1';
|
242 |
|
|
FINISHED_FLUSHING <= '1';
|
243 |
|
|
when "1011" => -- transition first enable the read of the buffers then signal ready in next cycle
|
244 |
|
|
NEXT_STATE <= "0100";
|
245 |
|
|
ENABLE_READ <= '1';
|
246 |
|
|
ENABLE_WRITE_AUX <= '0';
|
247 |
|
|
BUS_REQUEST <= '0';
|
248 |
|
|
CLEAR_COUNTERS <= '0';
|
249 |
|
|
READY <= '1';
|
250 |
|
|
FLUSHING <= '1';
|
251 |
|
|
FINISHED_FLUSHING <= '1';
|
252 |
|
|
|
253 |
|
|
when others =>
|
254 |
|
|
NEXT_STATE <= "0000";
|
255 |
|
|
ENABLE_READ <= '0';
|
256 |
|
|
ENABLE_WRITE_AUX <= '0';
|
257 |
|
|
BUS_REQUEST <= '1';
|
258 |
|
|
CLEAR_COUNTERS <= '1';
|
259 |
|
|
READY <= '1';
|
260 |
|
|
FLUSHING <= '1';
|
261 |
|
|
FINISHED_FLUSHING <= '1';
|
262 |
|
|
|
263 |
|
|
end case;
|
264 |
|
|
end process STATES;
|
265 |
|
|
|
266 |
|
|
|
267 |
|
|
|
268 |
|
|
|
269 |
|
|
FLIP_FLOPS : process(CLK, CLEAR)
|
270 |
|
|
begin
|
271 |
|
|
|
272 |
|
|
if (CLEAR = '0') then
|
273 |
|
|
CURRENT_STATE <= "0000"; --state 0
|
274 |
|
|
elsif ((CLK'event) and (CLK='1')) then
|
275 |
|
|
if (FORCE_STOP = '0') then
|
276 |
|
|
CURRENT_STATE <= "0000"; --state 0
|
277 |
|
|
else
|
278 |
|
|
CURRENT_STATE <= NEXT_STATE;
|
279 |
|
|
end if;
|
280 |
|
|
end if;
|
281 |
|
|
|
282 |
|
|
end process FLIP_FLOPS;
|
283 |
|
|
|
284 |
|
|
OVERFLOW_DETECTED <= '0' when ((CODING_READ_ADDRESS = CODING_WRITE_ADDRESS + "000000001") and (ENABLE_WRITE_AUX = '1')) else '1';
|
285 |
|
|
|
286 |
|
|
FLIP_FLOPS2 : process(CLK, CLEAR)
|
287 |
|
|
begin
|
288 |
|
|
|
289 |
|
|
if (CLEAR = '0') then
|
290 |
|
|
OVERFLOW_CONTROL_AUX <= '0'; --state 0
|
291 |
|
|
elsif ((CLK'event) and (CLK='1')) then
|
292 |
|
|
if (FORCE_STOP = '0') then
|
293 |
|
|
OVERFLOW_CONTROL_AUX <= '0'; --state 0
|
294 |
|
|
elsif (CODING_READ_ADDRESS = CODING_WRITE_ADDRESS + "110000000") then -- careful I change 256 to 484
|
295 |
|
|
OVERFLOW_CONTROL_AUX <= '1';
|
296 |
|
|
elsif (CODING_WRITE_ADDRESS = CODING_READ_ADDRESS + "000000001" and WAITN = '1') then-- buffer empty
|
297 |
|
|
OVERFLOW_CONTROL_AUX <= '0';
|
298 |
|
|
else
|
299 |
|
|
OVERFLOW_CONTROL_AUX <= OVERFLOW_CONTROL_AUX;
|
300 |
|
|
end if;
|
301 |
|
|
end if;
|
302 |
|
|
|
303 |
|
|
end process FLIP_FLOPS2;
|
304 |
|
|
|
305 |
|
|
OVERFLOW_CONTROL <= OVERFLOW_CONTROL_AUX;
|
306 |
|
|
|
307 |
|
|
|
308 |
|
|
ENABLE_WRITE <= ENABLE_WRITE_AUX;
|
309 |
|
|
|
310 |
|
|
end STRUCTURAL;
|
311 |
|
|
|