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

Subversion Repositories dirac

[/] [dirac/] [tags/] [dirac_0_0_1_0/] [src/] [encoder/] [ARITHMETICCODER.vhd] - Blame information for rev 14

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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