OpenCores
URL https://opencores.org/ocsvn/dirac/dirac/trunk

Subversion Repositories dirac

[/] [dirac/] [trunk/] [src/] [decoder/] [ARITHMETICDECODER.vhd] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 petebleack
-- ***** BEGIN LICENSE BLOCK *****
2
-- 
3
-- $Id: ARITHMETICDECODER.vhd,v 1.4 2006-10-05 16:17:12 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 2 petebleack
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
    Port ( ENABLE : in std_logic;
51
           DATA_IN : in std_logic;
52 5 petebleack
                          NEWCONTEXT :  in std_logic;
53
                          CONTEXT_SELECT : in std_logic_vector (5 downto 0);
54 9 petebleack
                          HALVECOUNTS : in std_logic;
55 2 petebleack
                          RESET : in std_logic;
56
           CLOCK : in std_logic;
57
           SENDING : out std_logic;
58
           DATA_OUT : out std_logic);
59
end ARITHMETICDECODER;
60
 
61
architecture RTL of ARITHMETICDECODER is
62
        component INPUT_CONTROL
63 5 petebleack
        generic(WIDTH : integer range 1 to 16);
64 2 petebleack
        port(     ENABLE : in std_logic;
65 5 petebleack
           DATA_IN : in std_logic_vector (WIDTH -1 downto 0);
66 2 petebleack
           BUFFER_CONTROL : in std_logic;
67
           DEMAND : in std_logic;
68
           RESET : in std_logic;
69
           CLOCK : in std_logic;
70
           SENDING : out std_logic;
71 5 petebleack
           DATA_OUT : out std_logic_vector (WIDTH - 1 downto 0));
72 2 petebleack
        end component INPUT_CONTROL;
73
        component STORAGE_REGISTER
74
        Port ( LOAD : in std_logic_vector(15 downto 0);
75
                          SHIFT_IN : in std_logic;
76
           SET_VALUE : in std_logic;
77
           SHIFT_ALL : in std_logic;
78
           SHIFT_MOST : in std_logic;
79
                          RESET : in std_logic;
80
           CLOCK : in std_logic;
81
           OUTPUT : out std_logic_vector(15 downto 0));
82
        end component STORAGE_REGISTER;
83
        component CONVERGENCE_CHECK
84
        port    ( HIGH_MSB : in std_logic;
85
           LOW_MSB : in std_logic;
86
           HIGH_SECONDBIT : in std_logic;
87
           LOW_SECONDBIT : in std_logic;
88
           CHECK : in std_logic;
89
           TRIGGER_OUTPUT : out std_logic;
90
           TRIGGER_FOLLOW : out std_logic);
91
        end component CONVERGENCE_CHECK;
92
        component ARITHMETIC_UNIT
93
        port    ( DIFFERENCE : in std_logic_vector(15 downto 0);
94 10 petebleack
           PROB : in std_logic_vector(7 downto 0);
95 2 petebleack
                          LOW : in std_logic_vector(15 downto 0);
96
                          ENABLE : in std_logic;
97
                          RESET :       in std_logic;
98
           CLOCK : in std_logic;
99
           DIFFERENCE_OUT0 : out std_logic_vector(15 downto 0);
100
                          DIFFERENCE_OUT1 : out std_logic_vector(15 downto 0);
101
           RESULT_OUT0 : out std_logic_vector(15 downto 0);
102
                          RESULT_OUT1 : out std_logic_vector(15 downto 0);
103
           DATA_LOAD : out std_logic);
104
        end component ARITHMETIC_UNIT;
105
        component SYMBOL_DETECTOR
106
        port ( ENABLE : in std_logic;
107
           DATA_IN : in std_logic_vector (15 downto 0);
108
           THRESHOLD : in std_logic_vector (15 downto 0);
109
                          DATA_OUT : out std_logic);
110
        end component SYMBOL_DETECTOR;
111 5 petebleack
        component CONTEXT_MANAGER
112 9 petebleack
        port (  CONTEXT_NUMBER : in std_logic_vector(5 downto 0);
113
                        SET : in std_logic;
114
                        UPDATE : in std_logic;
115
                        DATA_IN : in std_logic;
116
                        HALVECOUNTS : in std_logic;
117 5 petebleack
           RESET : in std_logic;
118
           CLOCK : in std_logic;
119 10 petebleack
           PROB : out std_logic_vector(7 downto 0);
120 9 petebleack
                          READY : out std_logic);
121 5 petebleack
        end component CONTEXT_MANAGER;
122 2 petebleack
        signal HIGH_SET : std_logic;
123
        signal LOW_SET  : std_logic;
124
        signal SHIFT_ALL :      std_logic;
125
        signal DIFFERENCE_SHIFT_ALL :   std_logic;
126
        signal SHIFT_MOST :     std_logic;
127
        signal ZERO_OUTPUT :    std_logic;
128
        signal ARITHMETIC_UNIT_ENABLE : std_logic;
129
        signal CONVERGENCE_TEST :       std_logic;
130
        signal TRIGGER_INPUT : std_logic;
131
        signal TRIGGER_FOLLOW:  std_logic;
132
        signal DATA_LOAD: std_logic;
133
        signal GET_DATA :       std_logic;
134
        signal DATA_AVAILABLE : std_logic;
135
        signal BUFFERED_DATA : std_logic;
136
        signal SYMBOL : std_logic;
137
        signal HOLD : std_logic;
138 9 petebleack
        signal PROB_AVAILABLE : std_logic;
139 2 petebleack
        signal DIFFERENCE_IN : std_logic_vector (15 downto 0);
140
        signal ARITHMETIC_UNIT_RESULT_OUT0 :    std_logic_vector (15 downto 0);
141
        signal ARITHMETIC_UNIT_RESULT_OUT1 :    std_logic_vector (15 downto 0);
142
        signal ARITHMETIC_UNIT_DIFFERENCE_OUT0 : std_logic_vector(15 downto 0);
143
        signal ARITHMETIC_UNIT_DIFFERENCE_OUT1 : std_logic_vector(15 downto 0);
144
        signal DIFFERENCE_VALUE : std_logic_vector (15 downto 0);
145
        signal HIGH_VALUE : std_logic_vector (15 downto 0);
146
        signal LOW_VALUE : std_logic_vector (15 downto 0);
147
        signal CURRENT_VALUE : std_logic_vector (15 downto 0);
148 10 petebleack
        signal PROB :   std_logic_vector (7 downto 0);
149 5 petebleack
        signal DATA_IN2 : std_logic_vector(0 downto 0);
150
        signal BUFFERED_DATA2 : std_logic_vector(0 downto 0);
151 2 petebleack
 
152 9 petebleack
 
153 2 petebleack
begin
154
-- input buffering
155
INBUFFER:       INPUT_CONTROL
156 5 petebleack
        generic map (WIDTH => 1)
157 2 petebleack
        port map(ENABLE => ENABLE,
158 5 petebleack
        DATA_IN => DATA_IN2,
159 2 petebleack
        BUFFER_CONTROL => HOLD,
160
        DEMAND => GET_DATA,
161
        RESET => RESET,
162
        CLOCK => CLOCK,
163
        SENDING => DATA_AVAILABLE,
164 5 petebleack
        DATA_OUT => BUFFERED_DATA2);
165 2 petebleack
 
166 5 petebleack
        DATA_IN2(0) <= DATA_IN;
167
        BUFFERED_DATA <= BUFFERED_DATA2(0);
168
 
169
--      Context
170
 
171
 PROBABILITY : CONTEXT_MANAGER
172
                        port map(CONTEXT_NUMBER => CONTEXT_SELECT,
173 9 petebleack
                        SET => NEWCONTEXT,
174
                        UPDATE =>DATA_LOAD,
175
                        DATA_IN => SYMBOL,
176
                        HALVECOUNTS => HALVECOUNTS,
177 5 petebleack
                        RESET => RESET,
178
                        CLOCK => CLOCK,
179 9 petebleack
                        PROB => PROB,
180
                        READY => PROB_AVAILABLE);
181 5 petebleack
 
182 2 petebleack
-- Specify the registers
183
  HIGH: STORAGE_REGISTER
184
         port map( LOAD => ARITHMETIC_UNIT_RESULT_OUT0,
185
                          SHIFT_IN => '1',
186
           SET_VALUE => HIGH_SET,
187
           SHIFT_ALL => SHIFT_ALL,
188
           SHIFT_MOST => SHIFT_MOST,
189
                          RESET => RESET,
190
           CLOCK => CLOCK,
191
           OUTPUT => HIGH_VALUE);
192
 
193
LOW:    STORAGE_REGISTER
194
        port map( LOAD => ARITHMETIC_UNIT_RESULT_OUT1,
195
                          SHIFT_IN => '0',
196
           SET_VALUE => LOW_SET,
197
           SHIFT_ALL => SHIFT_ALL,
198
           SHIFT_MOST => SHIFT_MOST,
199
                          RESET => RESET,
200
           CLOCK => CLOCK,
201
           OUTPUT => LOW_VALUE);
202
 
203
DIFFERENCE:     STORAGE_REGISTER
204
        port map( LOAD =>       DIFFERENCE_IN,
205
                                SHIFT_IN => '1',
206
                                SET_VALUE => DATA_LOAD,
207
                                SHIFT_ALL => DIFFERENCE_SHIFT_ALL,
208
                                SHIFT_MOST => '0',
209
                                RESET => RESET,
210
                                CLOCK => CLOCK,
211
                                OUTPUT => DIFFERENCE_VALUE);
212
 
213
CURRENT:        STORAGE_REGISTER
214
        port map( LOAD => "0000000000000000",
215
                          SHIFT_IN => BUFFERED_DATA,
216
           SET_VALUE => '0',
217
           SHIFT_ALL => SHIFT_ALL,
218
           SHIFT_MOST => SHIFT_MOST,
219
                          RESET => RESET,
220
           CLOCK => CLOCK,
221
           OUTPUT => CURRENT_VALUE);
222
-- The arithmetic
223
 
224
ARITH: ARITHMETIC_UNIT
225
        port map(DIFFERENCE => DIFFERENCE_VALUE,
226
           PROB => PROB,
227
                          LOW => LOW_VALUE,
228
           ENABLE => ARITHMETIC_UNIT_ENABLE,
229
                          RESET => RESET,
230
           CLOCK => CLOCK,
231
           DIFFERENCE_OUT0 => ARITHMETIC_UNIT_DIFFERENCE_OUT0,
232
                          DIFFERENCE_OUT1 => ARITHMETIC_UNIT_DIFFERENCE_OUT1,
233
           RESULT_OUT0 => ARITHMETIC_UNIT_RESULT_OUT0,
234
                          RESULT_OUT1 => ARITHMETIC_UNIT_RESULT_OUT1,
235
           DATA_LOAD => DATA_LOAD);
236
 
237
--The convergence checks
238
 
239
CONVERGE: CONVERGENCE_CHECK
240
        port map(HIGH_MSB => HIGH_VALUE(15),
241
           LOW_MSB => LOW_VALUE(15),
242
           HIGH_SECONDBIT => HIGH_VALUE(14),
243
           LOW_SECONDBIT => LOW_VALUE(14),
244
           CHECK => CONVERGENCE_TEST,
245
           TRIGGER_OUTPUT => TRIGGER_INPUT,
246
           TRIGGER_FOLLOW => TRIGGER_FOLLOW);
247
 
248
--The output unit
249
 
250
OUTPUT: SYMBOL_DETECTOR
251
        port map(ENABLE => DATA_LOAD,
252
           DATA_IN => CURRENT_VALUE,
253
           THRESHOLD =>  ARITHMETIC_UNIT_RESULT_OUT1,
254
                          DATA_OUT => SYMBOL);
255
 
256
        SENDING <= DATA_LOAD;
257
        DATA_OUT <= SYMBOL;
258
-- Input logic
259
 
260
        HIGH_SET <= ZERO_OUTPUT and DATA_LOAD;
261
        ZERO_OUTPUT <= not SYMBOL;
262
        LOW_SET <= SYMBOL and DATA_LOAD;
263
        GET_DATA <= TRIGGER_INPUT or TRIGGER_FOLLOW;
264
        HOLD <=         DATA_LOAD or not GET_DATA;
265
 
266
-- Control logic for DIFFERENCE register
267
 
268
        DIFFERENCE_SHIFT_ALL <= SHIFT_ALL or SHIFT_MOST;
269
 
270
  CONVERGENCE_TEST <= not DATA_LOAD;
271
 
272
-- Control logic for arithmetic unit
273
 
274 9 petebleack
        ARITHMETIC_UNIT_ENABLE <=  PROB_AVAILABLE and not(GET_DATA or DATA_LOAD or NEWCONTEXT);
275 2 petebleack
 
276
-- Control Logic for input control
277
        SHIFT_ALL <= TRIGGER_INPUT and DATA_AVAILABLE;
278
        SHIFT_MOST <= TRIGGER_FOLLOW and DATA_AVAILABLE;
279
 
280
--Select new difference value
281
NEWDIFF : process(SYMBOL,ARITHMETIC_UNIT_DIFFERENCE_OUT0,ARITHMETIC_UNIT_DIFFERENCE_OUT1)
282
        begin
283
                if(SYMBOL = '1') then
284
                        DIFFERENCE_IN <= ARITHMETIC_UNIT_DIFFERENCE_OUT1;
285
                else
286
                        DIFFERENCE_IN <= ARITHMETIC_UNIT_DIFFERENCE_OUT0;
287
                end if;
288
        end process NEWDIFF;
289
 
290
end RTL;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.