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

Subversion Repositories dirac

[/] [dirac/] [trunk/] [src/] [common/] [CONTEXT_MANAGER.vhd] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 petebleack
         -- ***** BEGIN LICENSE BLOCK *****
2
-- 
3 10 petebleack
-- $Id: CONTEXT_MANAGER.vhd,v 1.3 2006-10-05 16:17:11 petebleackley Exp $ $Name: not supported by cvs2svn $
4 5 petebleack
-- *
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 CONTEXT_MANAGER is
49
    Port (      CONTEXT_NUMBER : in std_logic_vector(5 downto 0);
50 8 petebleack
                        SET : in std_logic;
51
                        UPDATE : in std_logic;
52
                        DATA_IN : in std_logic;
53
                        HALVECOUNTS : in std_logic;
54 5 petebleack
           RESET : in std_logic;
55
           CLOCK : in std_logic;
56 10 petebleack
           PROB : out std_logic_vector(7 downto 0);
57 8 petebleack
                          READY : out std_logic);
58 5 petebleack
end CONTEXT_MANAGER;
59
 
60
architecture RTL of CONTEXT_MANAGER is
61 8 petebleack
 
62 10 petebleack
        type MATRIX is array (45 downto 0) of std_logic_vector(15 downto 0);
63
        signal PROBABILITY : MATRIX;
64
        constant HALF : std_logic_vector(15 downto 0) := "0000000100000010";
65
        signal FRACTION : std_logic_vector(15 downto 0);
66
        signal FRACTION2 : std_logic_vector(15 downto 0);
67
        signal RESET_FLAGS : std_logic_vector (45 downto 0);
68
        signal NEWPROB : std_logic_vector(15 downto 0);
69
        signal RATIO : std_logic_vector(15 downto 0);
70 8 petebleack
        signal UPDATE_PROB : std_logic;
71
        signal PROB_CHANGED : std_logic;
72
        signal LOAD_DATA : std_logic;
73
        signal OLD_CONTEXT : std_logic_vector (5 downto 0);
74
        signal READ_ADDRESS : std_logic_vector (5 downto 0);
75
        signal DATA_FETCHED : std_logic;
76
        signal CONTEXT_VALID : std_logic;
77
        signal DATA_READY : std_logic_vector (1 downto 0);
78
 
79
        component DIVIDER
80 10 petebleack
        port ( NUMERATOR : in std_logic_vector(7 downto 0);
81
           DENOMINATOR : in std_logic_vector(7 downto 0);
82 8 petebleack
                          RESET : in std_logic;
83
           CLOCK : in std_logic;
84 10 petebleack
           QUOTIENT : out std_logic_vector(7 downto 0));
85 8 petebleack
        end component DIVIDER;
86
        component UPDATER
87 10 petebleack
        port    ( NUMERATOR : in std_logic_vector(7 downto 0);
88
           DENOMINATOR : in std_logic_vector(7 downto 0);
89 8 petebleack
           ENABLE : in std_logic;
90
           DATA_IN : in std_logic;
91
           RESET : in std_logic;
92
           CLOCK : in std_logic;
93 10 petebleack
           NUMERATOR_OUT : out std_logic_vector(7 downto 0);
94
           DENOMINATOR_OUT : out std_logic_vector(7 downto 0);
95 8 petebleack
                          UPDATE : out std_logic);
96
        end component UPDATER;
97
        component HALVING_MANAGER
98
        port ( TRIGGER_HALVING : in std_logic;
99
           INPUT_READY : in std_logic;
100 10 petebleack
           NUMERATOR_IN : in std_logic_vector(7 downto 0);
101
           DENOMINATOR_IN : in std_logic_vector(7 downto 0);
102 8 petebleack
                          CONTEXT : in std_logic_vector(5 downto 0);
103
           RESET : in std_logic;
104
           CLOCK : in std_logic;
105 10 petebleack
           NUMERATOR_OUT : out std_logic_vector(7 downto 0);
106
           DENOMINATOR_OUT : out std_logic_vector(7 downto 0);
107 8 petebleack
           OUTPUT_READY : out std_logic);
108
        end component HALVING_MANAGER;
109
 
110 5 petebleack
begin
111 8 petebleack
 
112
FLAGS: process(CLOCK)
113
begin
114
        if (CLOCK'event and CLOCK='1') then
115
                if (RESET='1') then
116
                        RESET_FLAGS <= (others => '1');
117
                elsif LOAD_DATA = '1' then
118
                                RESET_FLAGS(conv_integer(OLD_CONTEXT)) <= '0';
119
                end if;
120 5 petebleack
        end if;
121 8 petebleack
end process FLAGS;
122 5 petebleack
 
123 8 petebleack
LOAD_DATA <= UPDATE_PROB and UPDATE;
124
 
125
 
126
MEMORY: process(CLOCK)
127
begin
128
        if (CLOCK'event and CLOCK='1') then
129
                if SET='1' then
130
                        READ_ADDRESS <= CONTEXT_NUMBER;
131
                end if;
132
                if (LOAD_DATA = '1') then
133
                        PROBABILITY(conv_integer(OLD_CONTEXT)) <=       NEWPROB;
134
                end if;
135
        end if;
136
end process MEMORY;
137
RATIO <= PROBABILITY(conv_integer(READ_ADDRESS));
138
 
139
CHOOSE_FRACTION : process (READ_ADDRESS,RESET_FLAGS,RATIO)
140
begin
141
        if (RESET_FLAGS(conv_integer(READ_ADDRESS))='1') then
142
                FRACTION <= HALF;
143
        else
144
                FRACTION <= RATIO;
145
        end if;
146
end process CHOOSE_FRACTION;
147
 
148
 
149
DIVISION : DIVIDER
150 10 petebleack
        port map (NUMERATOR => FRACTION2(15 downto 8),
151
        DENOMINATOR => FRACTION2(7 downto 0),
152 8 petebleack
        RESET => RESET,
153
        CLOCK => CLOCK,
154
        QUOTIENT => PROB);
155
 
156
PROBUPDATE : UPDATER
157 10 petebleack
        port map (NUMERATOR => FRACTION2(15 downto 8),
158
        DENOMINATOR => FRACTION2(7 downto 0),
159 8 petebleack
        ENABLE => PROB_CHANGED,
160
        DATA_IN => DATA_IN,
161
        RESET => RESET,
162
        CLOCK => CLOCK,
163 10 petebleack
        NUMERATOR_OUT => NEWPROB(15 downto 8),
164
        DENOMINATOR_OUT => NEWPROB(7 downto 0),
165 8 petebleack
        UPDATE => UPDATE_PROB);
166
 
167
REFRESH: HALVING_MANAGER
168
        port map (TRIGGER_HALVING => HALVECOUNTS,
169
        INPUT_READY => DATA_FETCHED,
170 10 petebleack
        NUMERATOR_IN => FRACTION(15 downto 8),
171
        DENOMINATOR_IN => FRACTION(7 downto 0),
172 8 petebleack
        CONTEXT => CONTEXT_NUMBER,
173
        RESET => RESET,
174
        CLOCK => CLOCK,
175 10 petebleack
        NUMERATOR_OUT => FRACTION2(15 downto 8),
176
        DENOMINATOR_OUT => FRACTION2(7 downto 0),
177 8 petebleack
        OUTPUT_READY => PROB_CHANGED);
178
 
179
 
180
DELAY_CONTEXT : process (CLOCK)
181
begin
182
        if CLOCK'event and CLOCK = '1' then
183
                        OLD_CONTEXT <= CONTEXT_NUMBER;
184
        end if;
185
end process DELAY_CONTEXT;
186
 
187
 
188
IS_DATA_READY : process (CLOCK)
189
begin
190
        if CLOCK'event and CLOCK='1' then
191
                if RESET='1' then
192
                        DATA_READY <= "00";
193
                else
194
                        DATA_READY <= DATA_READY(0) & PROB_CHANGED;
195
                end if;
196
        end if;
197
end process IS_DATA_READY;
198
 
199
CONTEXT_LOADED : process (CLOCK)
200
begin
201
        if CLOCK'event and CLOCK='1' then
202
                if RESET='1' then
203
                        CONTEXT_VALID <= '0';
204
                elsif SET = '1' then
205
                        CONTEXT_VALID <= '1';
206
                elsif UPDATE =  '1' then
207
                        CONTEXT_VALID <= '0';
208
                end if;
209
        end if;
210
end process CONTEXT_LOADED;
211
 
212
DATA_FETCHED <= CONTEXT_VALID and not SET;
213
 
214
 
215
READY <= (DATA_READY(1) and DATA_READY (0));-- and not SET;
216
 
217
 
218 5 petebleack
end RTL;

powered by: WebSVN 2.1.0

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