1 |
9 |
petebleack |
-- ***** BEGIN LICENSE BLOCK *****
|
2 |
|
|
--
|
3 |
|
|
-- $Id: DECODERTESTBENCH.VHD,v 1.1 2006-09-06 18:41:06 petebleackley Exp $ $Name: not supported by cvs2svn $
|
4 |
|
|
-- *
|
5 |
|
|
-- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
6 |
|
|
-- *
|
7 |
|
|
-- * The contents of this file are subject to the Mozilla Public License
|
8 |
|
|
-- * Version 1.1 (the "License"); you may not use this file except in compliance
|
9 |
|
|
-- * with the License. You may obtain a copy of the License at
|
10 |
|
|
-- * http://www.mozilla.org/MPL/
|
11 |
|
|
-- *
|
12 |
|
|
-- * Software distributed under the License is distributed on an "AS IS" basis,
|
13 |
|
|
-- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
14 |
|
|
-- * the specific language governing rights and limitations under the License.
|
15 |
|
|
-- *
|
16 |
|
|
-- * The Original Code is BBC Research and Development code.
|
17 |
|
|
-- *
|
18 |
|
|
-- * The Initial Developer of the Original Code is the British Broadcasting
|
19 |
|
|
-- * Corporation.
|
20 |
|
|
-- * Portions created by the Initial Developer are Copyright (C) 2004.
|
21 |
|
|
-- * All Rights Reserved.
|
22 |
|
|
-- *
|
23 |
|
|
-- * Contributor(s): Peter Bleackley (Original author)
|
24 |
|
|
-- *
|
25 |
|
|
-- * Alternatively, the contents of this file may be used under the terms of
|
26 |
|
|
-- * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
|
27 |
|
|
-- * Public License Version 2.1 (the "LGPL"), in which case the provisions of
|
28 |
|
|
-- * the GPL or the LGPL are applicable instead of those above. If you wish to
|
29 |
|
|
-- * allow use of your version of this file only under the terms of the either
|
30 |
|
|
-- * the GPL or LGPL and not to allow others to use your version of this file
|
31 |
|
|
-- * under the MPL, indicate your decision by deleting the provisions above
|
32 |
|
|
-- * and replace them with the notice and other provisions required by the GPL
|
33 |
|
|
-- * or LGPL. If you do not delete the provisions above, a recipient may use
|
34 |
|
|
-- * your version of this file under the terms of any one of the MPL, the GPL
|
35 |
|
|
-- * or the LGPL.
|
36 |
|
|
-- * ***** END LICENSE BLOCK ***** */
|
37 |
|
|
LIBRARY ieee;
|
38 |
|
|
USE ieee.std_logic_1164.ALL;
|
39 |
|
|
USE ieee.numeric_std.ALL;
|
40 |
|
|
use IEEE.std_logic_textio.all;
|
41 |
|
|
use ieee.std_logic_arith.all;
|
42 |
|
|
use ieee.std_logic_unsigned.all;
|
43 |
|
|
use STD.textio.all;
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
entity DECODERTESTBENCH is
|
47 |
|
|
end DECODERTESTBENCH;
|
48 |
|
|
|
49 |
|
|
architecture BEHAVIOUR of DECODERTESTBENCH is
|
50 |
|
|
|
51 |
|
|
component ARITHMETICDECODER
|
52 |
|
|
port (ENABLE : in std_logic;
|
53 |
|
|
DATA_IN : in std_logic;
|
54 |
|
|
NEWCONTEXT : in std_logic;
|
55 |
|
|
CONTEXT_SELECT : in std_logic_vector (5 downto 0);
|
56 |
|
|
HALVECOUNTS : in std_logic;
|
57 |
|
|
RESET : in std_logic;
|
58 |
|
|
CLOCK : in std_logic;
|
59 |
|
|
SENDING : out std_logic;
|
60 |
|
|
DATA_OUT : out std_logic);
|
61 |
|
|
end component ARITHMETICDECODER;
|
62 |
|
|
component EXP_GOLOMB_DECODER
|
63 |
|
|
port ( ENABLE : in std_logic;
|
64 |
|
|
DATA_IN : in std_logic;
|
65 |
|
|
RESET : in std_logic;
|
66 |
|
|
CLOCK : in std_logic;
|
67 |
|
|
READY : out std_logic;
|
68 |
|
|
DATA_OUT : out std_logic_vector (31 downto 0));
|
69 |
|
|
end component EXP_GOLOMB_DECODER;
|
70 |
|
|
signal BYTES_INPUT : std_logic_vector (31 downto 0);
|
71 |
|
|
type STATUS is (OFFSET,FIND_START,GET_SIZE,FEED_DATA,PAUSE,FINISHED);
|
72 |
|
|
signal DECODER_STATE : STATUS := OFFSET;
|
73 |
|
|
signal ENABLE_DECODER : std_logic;
|
74 |
|
|
signal DECODER_DATA_IN : std_logic;
|
75 |
|
|
signal NEWCONTEXT : std_logic;
|
76 |
|
|
signal CONTEXT_SELECT : std_logic_vector (5 downto 0);
|
77 |
|
|
signal HALVECOUNTS : std_logic;
|
78 |
|
|
signal FLUSH : std_logic;
|
79 |
|
|
signal RESET : std_logic;
|
80 |
|
|
signal CLOCK : std_logic := '0';
|
81 |
|
|
signal SENDING : std_logic;
|
82 |
|
|
signal DATA_OUT : std_logic;
|
83 |
|
|
signal GETCONTEXT : std_logic;
|
84 |
|
|
signal EG_ENABLE : std_logic;
|
85 |
|
|
signal EG_DATA_IN : std_logic;
|
86 |
|
|
signal EG_READY : std_logic;
|
87 |
|
|
signal INIT : std_logic := '1';
|
88 |
|
|
-- signal LAST_BYTE : integer;
|
89 |
|
|
-- signal AFTER_FLUSH : std_logic;
|
90 |
|
|
-- signal BITPOS2 : integer;
|
91 |
|
|
-- signal COMPDATA : integer;
|
92 |
|
|
signal BYTES_TO_DECODE : std_logic_vector (31 downto 0);
|
93 |
|
|
type CHARFILE is file of character;
|
94 |
|
|
file HEADERFILE : CHARFILE open read_mode is "test1.hdr";
|
95 |
|
|
file DIRACFILE : CHARFILE open read_mode is "test1.dr1";
|
96 |
|
|
file CONTEXTFILE : CHARFILE open read_mode is "test1.ctx";
|
97 |
|
|
file TARGETFILE : CHARFILE open read_mode is "test1.dr0";
|
98 |
|
|
type INTARRAY is array (5 downto 0) of integer;
|
99 |
|
|
constant PERIOD : time := 10 ns;
|
100 |
|
|
begin
|
101 |
|
|
|
102 |
|
|
UUT : ARITHMETICDECODER
|
103 |
|
|
port map(ENABLE => ENABLE_DECODER,
|
104 |
|
|
DATA_IN => DECODER_DATA_IN,
|
105 |
|
|
NEWCONTEXT => NEWCONTEXT,
|
106 |
|
|
CONTEXT_SELECT => CONTEXT_SELECT,
|
107 |
|
|
HALVECOUNTS => HALVECOUNTS,
|
108 |
|
|
RESET => RESET,
|
109 |
|
|
CLOCK => CLOCK,
|
110 |
|
|
SENDING => SENDING,
|
111 |
|
|
DATA_OUT => DATA_OUT);
|
112 |
|
|
|
113 |
|
|
EGD : EXP_GOLOMB_DECODER
|
114 |
|
|
port map(ENABLE => EG_ENABLE,
|
115 |
|
|
DATA_IN => EG_DATA_IN,
|
116 |
|
|
RESET => RESET,
|
117 |
|
|
CLOCK => CLOCK,
|
118 |
|
|
READY => EG_READY,
|
119 |
|
|
DATA_OUT => BYTES_TO_DECODE);
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
CLOCK <= not CLOCK after PERIOD/2;
|
123 |
|
|
|
124 |
|
|
--DELAY_FLUSH_SIGNAL : process (CLOCK)
|
125 |
|
|
--begin
|
126 |
|
|
-- if CLOCK'event and CLOCK = '1' then
|
127 |
|
|
-- AFTER_FLUSH <= FLUSH;
|
128 |
|
|
-- end if;
|
129 |
|
|
--end process DELAY_FLUSH_SIGNAL;
|
130 |
|
|
|
131 |
|
|
TESTBENCH : process (CLOCK)
|
132 |
|
|
variable SCAN : INTARRAY;
|
133 |
|
|
variable READPLACE : integer := 5;
|
134 |
|
|
variable BITPOSITION : integer;
|
135 |
|
|
variable DIRACDATA : integer;
|
136 |
|
|
variable DIRACREAD : character;
|
137 |
|
|
variable TARGETREAD : character;
|
138 |
|
|
variable PAUSECOUNT : integer;
|
139 |
|
|
begin
|
140 |
|
|
if CLOCK'event and CLOCK='1' then
|
141 |
|
|
if DECODER_STATE = OFFSET then
|
142 |
|
|
if READPLACE = 0 then
|
143 |
|
|
DECODER_STATE <= FIND_START;
|
144 |
|
|
BITPOSITION := 0;
|
145 |
|
|
-- elsif AFTER_FLUSH = '1' and READPLACE = 4 then
|
146 |
|
|
-- SCAN(5) := LAST_BYTE;
|
147 |
|
|
else
|
148 |
|
|
if READPLACE < 5 and INIT = '1' then
|
149 |
|
|
INIT <= '0';
|
150 |
|
|
end if;
|
151 |
|
|
read(TARGETFILE,TARGETREAD);
|
152 |
|
|
SCAN(READPLACE) := character'pos(TARGETREAD);
|
153 |
|
|
READPLACE := READPLACE - 1;
|
154 |
|
|
|
155 |
|
|
end if;
|
156 |
|
|
elsif DECODER_STATE = FIND_START then
|
157 |
|
|
if SCAN (5 downto 1) = ( 16#42#, 16#42#, 16#43#, 16#44#, 16#AC# ) then
|
158 |
|
|
--BITPOS2 <= BITPOSITION;
|
159 |
|
|
--COMPDATA <= SCAN(0);
|
160 |
|
|
DECODER_STATE <= GET_SIZE;
|
161 |
|
|
if BITPOSITION = 0 then
|
162 |
|
|
BITPOSITION := 128;
|
163 |
|
|
end if;
|
164 |
|
|
elsif SCAN(5 downto 1) = (16#42#, 16#42#, 16#43#, 16#44#, 16#D0# ) then
|
165 |
|
|
DECODER_STATE <= FINISHED;
|
166 |
|
|
elsif BITPOSITION = 0 then
|
167 |
|
|
read(TARGETFILE,TARGETREAD);
|
168 |
|
|
read(HEADERFILE,DIRACREAD);
|
169 |
|
|
SCAN(0) := character'pos(TARGETREAD);
|
170 |
|
|
DIRACDATA := character'pos(DIRACREAD);
|
171 |
|
|
BITPOSITION := 128;
|
172 |
|
|
else
|
173 |
|
|
for I in 5 downto 1 loop
|
174 |
|
|
if SCAN(I) > 127 then
|
175 |
|
|
SCAN(I) := SCAN(I) - 128;
|
176 |
|
|
end if;
|
177 |
|
|
SCAN(I) := SCAN(I)*2;
|
178 |
|
|
if SCAN(I-1) > 127 then
|
179 |
|
|
SCAN(I) := SCAN(I) + 1;
|
180 |
|
|
end if;
|
181 |
|
|
end loop;
|
182 |
|
|
if SCAN(0) > 127 then
|
183 |
|
|
SCAN(0) := SCAN(0) - 128;
|
184 |
|
|
end if;
|
185 |
|
|
SCAN(0) := SCAN(0)*2;
|
186 |
|
|
BITPOSITION := BITPOSITION/2;
|
187 |
|
|
end if;
|
188 |
|
|
elsif DECODER_STATE = GET_SIZE then
|
189 |
|
|
if EG_READY = '1' then
|
190 |
|
|
DECODER_STATE <= FEED_DATA;
|
191 |
|
|
BITPOSITION := 128;
|
192 |
|
|
EG_ENABLE <= '0';
|
193 |
|
|
BYTES_INPUT <= (others => '0');
|
194 |
|
|
elsif EG_ENABLE = '1' then
|
195 |
|
|
EG_ENABLE <= '0';
|
196 |
|
|
else
|
197 |
|
|
if BITPOSITION = 128 then
|
198 |
|
|
READ(HEADERFILE,DIRACREAD);
|
199 |
|
|
DIRACDATA := character'pos(DIRACREAD);
|
200 |
|
|
end if;
|
201 |
|
|
if (DIRACDATA rem (BITPOSITION*2))/BITPOSITION = 1 then
|
202 |
|
|
EG_DATA_IN <= '1';
|
203 |
|
|
else
|
204 |
|
|
EG_DATA_IN <= '0';
|
205 |
|
|
end if;
|
206 |
|
|
EG_ENABLE <= '1';
|
207 |
|
|
if BITPOSITION = 1 then
|
208 |
|
|
BITPOSITION := 128;
|
209 |
|
|
else
|
210 |
|
|
BITPOSITION := BITPOSITION/2;
|
211 |
|
|
end if;
|
212 |
|
|
end if;
|
213 |
|
|
elsif DECODER_STATE = FEED_DATA then
|
214 |
|
|
if FLUSH = '1' then
|
215 |
|
|
DECODER_STATE <= OFFSET;
|
216 |
|
|
ENABLE_DECODER <= '0';
|
217 |
|
|
-- if BITPOSITION = 128 then
|
218 |
|
|
-- READPLACE := 4;
|
219 |
|
|
-- else
|
220 |
|
|
READPLACE := 5;
|
221 |
|
|
-- end if;
|
222 |
|
|
elsif BITPOSITION = 0 then
|
223 |
|
|
DECODER_STATE <= PAUSE;
|
224 |
|
|
BYTES_INPUT <= BYTES_INPUT + 1;
|
225 |
|
|
ENABLE_DECODER <= '0';
|
226 |
|
|
PAUSECOUNT := 0;
|
227 |
|
|
else
|
228 |
|
|
if BITPOSITION = 128 then
|
229 |
|
|
if BYTES_INPUT < BYTES_TO_DECODE then
|
230 |
|
|
read(DIRACFILE,DIRACREAD);
|
231 |
|
|
DIRACDATA := character'pos(DIRACREAD);
|
232 |
|
|
else
|
233 |
|
|
DIRACDATA := 0;
|
234 |
|
|
end if;
|
235 |
|
|
end if;
|
236 |
|
|
if (DIRACDATA rem (BITPOSITION*2))/BITPOSITION = 1 then
|
237 |
|
|
DECODER_DATA_IN <= '1';
|
238 |
|
|
else
|
239 |
|
|
DECODER_DATA_IN <= '0';
|
240 |
|
|
end if;
|
241 |
|
|
ENABLE_DECODER <= '1';
|
242 |
|
|
BITPOSITION := BITPOSITION/2;
|
243 |
|
|
end if;
|
244 |
|
|
elsif DECODER_STATE = PAUSE then
|
245 |
|
|
if FLUSH = '1' then
|
246 |
|
|
DECODER_STATE <= OFFSET;
|
247 |
|
|
READPLACE := 5;
|
248 |
|
|
elsif PAUSECOUNT > 7 then
|
249 |
|
|
DECODER_STATE <= FEED_DATA;
|
250 |
|
|
BITPOSITION := 128;
|
251 |
|
|
elsif SENDING = '1' then
|
252 |
|
|
PAUSECOUNT := 0;
|
253 |
|
|
else
|
254 |
|
|
PAUSECOUNT := PAUSECOUNT+1;
|
255 |
|
|
end if;
|
256 |
|
|
else --DECODER_STATE = FINISHED;
|
257 |
|
|
report "Finished" severity failure;
|
258 |
|
|
end if;
|
259 |
|
|
end if;
|
260 |
|
|
end process TESTBENCH;
|
261 |
|
|
|
262 |
|
|
RESET <= INIT or FLUSH;
|
263 |
|
|
|
264 |
|
|
GETCONTEXT <= (RESET or SENDING) and not NEWCONTEXT;
|
265 |
|
|
|
266 |
|
|
CONTEXT : process (CLOCK)
|
267 |
|
|
variable CONTEXTREAD : character;
|
268 |
|
|
variable CONTEXTDATA : integer;
|
269 |
|
|
variable READPOSITION : integer;
|
270 |
|
|
variable NUMBER_READ : integer :=0;
|
271 |
|
|
begin
|
272 |
|
|
if CLOCK'event and CLOCK = '1' then
|
273 |
|
|
if GETCONTEXT = '1' then
|
274 |
|
|
read(CONTEXTFILE,CONTEXTREAD);
|
275 |
|
|
NUMBER_READ := NUMBER_READ + 1;
|
276 |
|
|
CONTEXTDATA := character'pos(CONTEXTREAD);
|
277 |
|
|
if (CONTEXTDATA rem 2) = 1 then
|
278 |
|
|
FLUSH <= '1';
|
279 |
|
|
else
|
280 |
|
|
FLUSH <= '0';
|
281 |
|
|
if(CONTEXTDATA rem 4)/2 = 1 then
|
282 |
|
|
HALVECOUNTS <= '1';
|
283 |
|
|
else
|
284 |
|
|
HALVECOUNTS <= '0';
|
285 |
|
|
end if;
|
286 |
|
|
READPOSITION := 128;
|
287 |
|
|
for I in 5 downto 0 loop
|
288 |
|
|
if (CONTEXTDATA rem (READPOSITION*2))/READPOSITION = 1 then
|
289 |
|
|
CONTEXT_SELECT(I) <= '1';
|
290 |
|
|
else
|
291 |
|
|
CONTEXT_SELECT(I) <= '0';
|
292 |
|
|
end if;
|
293 |
|
|
READPOSITION := READPOSITION/2;
|
294 |
|
|
end loop;
|
295 |
|
|
NEWCONTEXT <= '1';
|
296 |
|
|
end if;
|
297 |
|
|
else
|
298 |
|
|
NEWCONTEXT <= '0';
|
299 |
|
|
FLUSH <= '0';
|
300 |
|
|
HALVECOUNTS <= '0';
|
301 |
|
|
end if;
|
302 |
|
|
end if;
|
303 |
|
|
end process CONTEXT;
|
304 |
|
|
|
305 |
|
|
|
306 |
|
|
CHECK_RESULTS : process (CLOCK)
|
307 |
|
|
variable DATA : integer;
|
308 |
|
|
variable COMPARISON : integer;
|
309 |
|
|
variable COMP2 : integer;
|
310 |
|
|
--variable BITPOSITION : integer;
|
311 |
|
|
variable INDEX : integer;
|
312 |
|
|
variable COMPREAD : character;
|
313 |
|
|
begin
|
314 |
|
|
if CLOCK'event and CLOCK = '1' then
|
315 |
|
|
if RESET = '1' then
|
316 |
|
|
-- DATA := 0;
|
317 |
|
|
-- BITPOSITION := BITPOS2;
|
318 |
|
|
-- read(TARGETFILE,COMPREAD);
|
319 |
|
|
-- COMPARISON := character'pos(COMPREAD);
|
320 |
|
|
-- COMP2 := 0;
|
321 |
|
|
INDEX := 128;
|
322 |
|
|
elsif SENDING = '1' then
|
323 |
|
|
if INDEX = 128 then
|
324 |
|
|
DATA := 0;
|
325 |
|
|
read(TARGETFILE,COMPREAD);
|
326 |
|
|
COMPARISON := character'pos(COMPREAD);
|
327 |
|
|
COMP2 := 0;
|
328 |
|
|
end if;
|
329 |
|
|
if DATA_OUT = '1' then
|
330 |
|
|
DATA:=DATA+INDEX;
|
331 |
|
|
end if;
|
332 |
|
|
if (COMPARISON rem (INDEX*2))/INDEX = 1 then
|
333 |
|
|
COMP2 := COMP2 + INDEX;
|
334 |
|
|
end if;
|
335 |
|
|
assert COMP2 = DATA report "Decoder has Diverged" severity failure;
|
336 |
|
|
if INDEX = 1 then
|
337 |
|
|
-- read(TARGETFILE,COMPREAD);
|
338 |
|
|
-- COMPARISON := character'pos(COMPREAD);
|
339 |
|
|
-- LAST_BYTE <= COMPARISON;
|
340 |
|
|
-- COMP2 := 0;
|
341 |
|
|
-- DATA := 0;
|
342 |
|
|
-- BITPOSITION := 128;
|
343 |
|
|
INDEX := 128;
|
344 |
|
|
else
|
345 |
|
|
-- BITPOSITION := BITPOSITION/2;
|
346 |
|
|
INDEX := INDEX/2;
|
347 |
|
|
end if;
|
348 |
|
|
end if;
|
349 |
|
|
end if;
|
350 |
|
|
end process CHECK_RESULTS;
|
351 |
|
|
|
352 |
|
|
end architecture BEHAVIOUR;
|
353 |
|
|
|
354 |
|
|
|
355 |
|
|
|
356 |
|
|
|
357 |
|
|
|
358 |
|
|
|
359 |
|
|
|
360 |
|
|
|
361 |
|
|
|