1 |
2 |
petebleack |
-- ***** BEGIN LICENSE BLOCK *****
|
2 |
|
|
--
|
3 |
|
|
-- $Id: ARITHMETICDECODER.vhd,v 1.1.1.1 2005-03-30 10:09:49 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 |
|
|
|
38 |
|
|
|
39 |
|
|
library IEEE;
|
40 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
41 |
|
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
42 |
|
|
use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
43 |
|
|
|
44 |
|
|
-- Uncomment the following lines to use the declarations that are
|
45 |
|
|
-- provided for instantiating Xilinx primitive components.
|
46 |
|
|
--library UNISIM;
|
47 |
|
|
--use UNISIM.VComponents.all;
|
48 |
|
|
|
49 |
|
|
entity ARITHMETICDECODER is
|
50 |
|
|
generic (PROB : std_logic_vector (9 downto 0) := "1010101010");
|
51 |
|
|
Port ( ENABLE : in std_logic;
|
52 |
|
|
DATA_IN : in std_logic;
|
53 |
|
|
RESET : in std_logic;
|
54 |
|
|
CLOCK : in std_logic;
|
55 |
|
|
SENDING : out std_logic;
|
56 |
|
|
DATA_OUT : out std_logic);
|
57 |
|
|
end ARITHMETICDECODER;
|
58 |
|
|
|
59 |
|
|
architecture RTL of ARITHMETICDECODER is
|
60 |
|
|
component INPUT_CONTROL
|
61 |
|
|
port( ENABLE : in std_logic;
|
62 |
|
|
DATA_IN : in std_logic;
|
63 |
|
|
BUFFER_CONTROL : in std_logic;
|
64 |
|
|
DEMAND : in std_logic;
|
65 |
|
|
RESET : in std_logic;
|
66 |
|
|
CLOCK : in std_logic;
|
67 |
|
|
SENDING : out std_logic;
|
68 |
|
|
DATA_OUT : out std_logic);
|
69 |
|
|
end component INPUT_CONTROL;
|
70 |
|
|
component STORAGE_REGISTER
|
71 |
|
|
Port ( LOAD : in std_logic_vector(15 downto 0);
|
72 |
|
|
SHIFT_IN : in std_logic;
|
73 |
|
|
SET_VALUE : in std_logic;
|
74 |
|
|
SHIFT_ALL : in std_logic;
|
75 |
|
|
SHIFT_MOST : in std_logic;
|
76 |
|
|
RESET : in std_logic;
|
77 |
|
|
CLOCK : in std_logic;
|
78 |
|
|
OUTPUT : out std_logic_vector(15 downto 0));
|
79 |
|
|
end component STORAGE_REGISTER;
|
80 |
|
|
component CONVERGENCE_CHECK
|
81 |
|
|
port ( HIGH_MSB : in std_logic;
|
82 |
|
|
LOW_MSB : in std_logic;
|
83 |
|
|
HIGH_SECONDBIT : in std_logic;
|
84 |
|
|
LOW_SECONDBIT : in std_logic;
|
85 |
|
|
CHECK : in std_logic;
|
86 |
|
|
TRIGGER_OUTPUT : out std_logic;
|
87 |
|
|
TRIGGER_FOLLOW : out std_logic);
|
88 |
|
|
end component CONVERGENCE_CHECK;
|
89 |
|
|
component ARITHMETIC_UNIT
|
90 |
|
|
port ( DIFFERENCE : in std_logic_vector(15 downto 0);
|
91 |
|
|
PROB : in std_logic_vector(9 downto 0);
|
92 |
|
|
LOW : in std_logic_vector(15 downto 0);
|
93 |
|
|
ENABLE : in std_logic;
|
94 |
|
|
RESET : in std_logic;
|
95 |
|
|
CLOCK : in std_logic;
|
96 |
|
|
DIFFERENCE_OUT0 : out std_logic_vector(15 downto 0);
|
97 |
|
|
DIFFERENCE_OUT1 : out std_logic_vector(15 downto 0);
|
98 |
|
|
RESULT_OUT0 : out std_logic_vector(15 downto 0);
|
99 |
|
|
RESULT_OUT1 : out std_logic_vector(15 downto 0);
|
100 |
|
|
DATA_LOAD : out std_logic);
|
101 |
|
|
end component ARITHMETIC_UNIT;
|
102 |
|
|
component SYMBOL_DETECTOR
|
103 |
|
|
port ( ENABLE : in std_logic;
|
104 |
|
|
DATA_IN : in std_logic_vector (15 downto 0);
|
105 |
|
|
THRESHOLD : in std_logic_vector (15 downto 0);
|
106 |
|
|
DATA_OUT : out std_logic);
|
107 |
|
|
end component SYMBOL_DETECTOR;
|
108 |
|
|
signal HIGH_SET : std_logic;
|
109 |
|
|
signal LOW_SET : std_logic;
|
110 |
|
|
signal SHIFT_ALL : std_logic;
|
111 |
|
|
signal DIFFERENCE_SHIFT_ALL : std_logic;
|
112 |
|
|
signal SHIFT_MOST : std_logic;
|
113 |
|
|
signal ZERO_OUTPUT : std_logic;
|
114 |
|
|
signal ARITHMETIC_UNIT_ENABLE : std_logic;
|
115 |
|
|
signal CONVERGENCE_TEST : std_logic;
|
116 |
|
|
signal TRIGGER_INPUT : std_logic;
|
117 |
|
|
signal TRIGGER_FOLLOW: std_logic;
|
118 |
|
|
signal DATA_LOAD: std_logic;
|
119 |
|
|
signal GET_DATA : std_logic;
|
120 |
|
|
signal DATA_AVAILABLE : std_logic;
|
121 |
|
|
signal BUFFERED_DATA : std_logic;
|
122 |
|
|
signal SYMBOL : std_logic;
|
123 |
|
|
signal HOLD : std_logic;
|
124 |
|
|
signal DIFFERENCE_IN : std_logic_vector (15 downto 0);
|
125 |
|
|
signal ARITHMETIC_UNIT_RESULT_OUT0 : std_logic_vector (15 downto 0);
|
126 |
|
|
signal ARITHMETIC_UNIT_RESULT_OUT1 : std_logic_vector (15 downto 0);
|
127 |
|
|
signal ARITHMETIC_UNIT_DIFFERENCE_OUT0 : std_logic_vector(15 downto 0);
|
128 |
|
|
signal ARITHMETIC_UNIT_DIFFERENCE_OUT1 : std_logic_vector(15 downto 0);
|
129 |
|
|
signal DIFFERENCE_VALUE : std_logic_vector (15 downto 0);
|
130 |
|
|
signal HIGH_VALUE : std_logic_vector (15 downto 0);
|
131 |
|
|
signal LOW_VALUE : std_logic_vector (15 downto 0);
|
132 |
|
|
signal CURRENT_VALUE : std_logic_vector (15 downto 0);
|
133 |
|
|
|
134 |
|
|
begin
|
135 |
|
|
-- input buffering
|
136 |
|
|
INBUFFER: INPUT_CONTROL
|
137 |
|
|
port map(ENABLE => ENABLE,
|
138 |
|
|
DATA_IN => DATA_IN,
|
139 |
|
|
BUFFER_CONTROL => HOLD,
|
140 |
|
|
DEMAND => GET_DATA,
|
141 |
|
|
RESET => RESET,
|
142 |
|
|
CLOCK => CLOCK,
|
143 |
|
|
SENDING => DATA_AVAILABLE,
|
144 |
|
|
DATA_OUT => BUFFERED_DATA);
|
145 |
|
|
|
146 |
|
|
-- Specify the registers
|
147 |
|
|
HIGH: STORAGE_REGISTER
|
148 |
|
|
port map( LOAD => ARITHMETIC_UNIT_RESULT_OUT0,
|
149 |
|
|
SHIFT_IN => '1',
|
150 |
|
|
SET_VALUE => HIGH_SET,
|
151 |
|
|
SHIFT_ALL => SHIFT_ALL,
|
152 |
|
|
SHIFT_MOST => SHIFT_MOST,
|
153 |
|
|
RESET => RESET,
|
154 |
|
|
CLOCK => CLOCK,
|
155 |
|
|
OUTPUT => HIGH_VALUE);
|
156 |
|
|
|
157 |
|
|
LOW: STORAGE_REGISTER
|
158 |
|
|
port map( LOAD => ARITHMETIC_UNIT_RESULT_OUT1,
|
159 |
|
|
SHIFT_IN => '0',
|
160 |
|
|
SET_VALUE => LOW_SET,
|
161 |
|
|
SHIFT_ALL => SHIFT_ALL,
|
162 |
|
|
SHIFT_MOST => SHIFT_MOST,
|
163 |
|
|
RESET => RESET,
|
164 |
|
|
CLOCK => CLOCK,
|
165 |
|
|
OUTPUT => LOW_VALUE);
|
166 |
|
|
|
167 |
|
|
DIFFERENCE: STORAGE_REGISTER
|
168 |
|
|
port map( LOAD => DIFFERENCE_IN,
|
169 |
|
|
SHIFT_IN => '1',
|
170 |
|
|
SET_VALUE => DATA_LOAD,
|
171 |
|
|
SHIFT_ALL => DIFFERENCE_SHIFT_ALL,
|
172 |
|
|
SHIFT_MOST => '0',
|
173 |
|
|
RESET => RESET,
|
174 |
|
|
CLOCK => CLOCK,
|
175 |
|
|
OUTPUT => DIFFERENCE_VALUE);
|
176 |
|
|
|
177 |
|
|
CURRENT: STORAGE_REGISTER
|
178 |
|
|
port map( LOAD => "0000000000000000",
|
179 |
|
|
SHIFT_IN => BUFFERED_DATA,
|
180 |
|
|
SET_VALUE => '0',
|
181 |
|
|
SHIFT_ALL => SHIFT_ALL,
|
182 |
|
|
SHIFT_MOST => SHIFT_MOST,
|
183 |
|
|
RESET => RESET,
|
184 |
|
|
CLOCK => CLOCK,
|
185 |
|
|
OUTPUT => CURRENT_VALUE);
|
186 |
|
|
-- The arithmetic
|
187 |
|
|
|
188 |
|
|
ARITH: ARITHMETIC_UNIT
|
189 |
|
|
port map(DIFFERENCE => DIFFERENCE_VALUE,
|
190 |
|
|
PROB => PROB,
|
191 |
|
|
LOW => LOW_VALUE,
|
192 |
|
|
ENABLE => ARITHMETIC_UNIT_ENABLE,
|
193 |
|
|
RESET => RESET,
|
194 |
|
|
CLOCK => CLOCK,
|
195 |
|
|
DIFFERENCE_OUT0 => ARITHMETIC_UNIT_DIFFERENCE_OUT0,
|
196 |
|
|
DIFFERENCE_OUT1 => ARITHMETIC_UNIT_DIFFERENCE_OUT1,
|
197 |
|
|
RESULT_OUT0 => ARITHMETIC_UNIT_RESULT_OUT0,
|
198 |
|
|
RESULT_OUT1 => ARITHMETIC_UNIT_RESULT_OUT1,
|
199 |
|
|
DATA_LOAD => DATA_LOAD);
|
200 |
|
|
|
201 |
|
|
--The convergence checks
|
202 |
|
|
|
203 |
|
|
CONVERGE: CONVERGENCE_CHECK
|
204 |
|
|
port map(HIGH_MSB => HIGH_VALUE(15),
|
205 |
|
|
LOW_MSB => LOW_VALUE(15),
|
206 |
|
|
HIGH_SECONDBIT => HIGH_VALUE(14),
|
207 |
|
|
LOW_SECONDBIT => LOW_VALUE(14),
|
208 |
|
|
CHECK => CONVERGENCE_TEST,
|
209 |
|
|
TRIGGER_OUTPUT => TRIGGER_INPUT,
|
210 |
|
|
TRIGGER_FOLLOW => TRIGGER_FOLLOW);
|
211 |
|
|
|
212 |
|
|
--The output unit
|
213 |
|
|
|
214 |
|
|
OUTPUT: SYMBOL_DETECTOR
|
215 |
|
|
port map(ENABLE => DATA_LOAD,
|
216 |
|
|
DATA_IN => CURRENT_VALUE,
|
217 |
|
|
THRESHOLD => ARITHMETIC_UNIT_RESULT_OUT1,
|
218 |
|
|
DATA_OUT => SYMBOL);
|
219 |
|
|
|
220 |
|
|
SENDING <= DATA_LOAD;
|
221 |
|
|
DATA_OUT <= SYMBOL;
|
222 |
|
|
-- Input logic
|
223 |
|
|
|
224 |
|
|
HIGH_SET <= ZERO_OUTPUT and DATA_LOAD;
|
225 |
|
|
ZERO_OUTPUT <= not SYMBOL;
|
226 |
|
|
LOW_SET <= SYMBOL and DATA_LOAD;
|
227 |
|
|
GET_DATA <= TRIGGER_INPUT or TRIGGER_FOLLOW;
|
228 |
|
|
HOLD <= DATA_LOAD or not GET_DATA;
|
229 |
|
|
|
230 |
|
|
-- Control logic for DIFFERENCE register
|
231 |
|
|
|
232 |
|
|
DIFFERENCE_SHIFT_ALL <= SHIFT_ALL or SHIFT_MOST;
|
233 |
|
|
|
234 |
|
|
-- Control logic for convergence check
|
235 |
|
|
|
236 |
|
|
-- CHECK <= DIFFERENCE_SHIFT_ALL or DATA_LOAD or RESET;
|
237 |
|
|
|
238 |
|
|
-- CONVERGENCE_TEST_DELAY: D_TYPE
|
239 |
|
|
-- port map( D => CHECK,
|
240 |
|
|
-- CLOCK => CLOCK,
|
241 |
|
|
-- Q => CONVERGENCE_TEST);
|
242 |
|
|
|
243 |
|
|
CONVERGENCE_TEST <= not DATA_LOAD;
|
244 |
|
|
|
245 |
|
|
-- Control logic for arithmetic unit
|
246 |
|
|
|
247 |
|
|
ARITHMETIC_UNIT_ENABLE <= GET_DATA nor DATA_LOAD;
|
248 |
|
|
|
249 |
|
|
-- Control Logic for input control
|
250 |
|
|
SHIFT_ALL <= TRIGGER_INPUT and DATA_AVAILABLE;
|
251 |
|
|
SHIFT_MOST <= TRIGGER_FOLLOW and DATA_AVAILABLE;
|
252 |
|
|
|
253 |
|
|
--Select new difference value
|
254 |
|
|
NEWDIFF : process(SYMBOL,ARITHMETIC_UNIT_DIFFERENCE_OUT0,ARITHMETIC_UNIT_DIFFERENCE_OUT1)
|
255 |
|
|
begin
|
256 |
|
|
if(SYMBOL = '1') then
|
257 |
|
|
DIFFERENCE_IN <= ARITHMETIC_UNIT_DIFFERENCE_OUT1;
|
258 |
|
|
else
|
259 |
|
|
DIFFERENCE_IN <= ARITHMETIC_UNIT_DIFFERENCE_OUT0;
|
260 |
|
|
end if;
|
261 |
|
|
end process NEWDIFF;
|
262 |
|
|
|
263 |
|
|
|
264 |
|
|
|
265 |
|
|
end RTL;
|