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

Subversion Repositories dirac

[/] [dirac/] [trunk/] [src/] [common/] [HALVING_MANAGER.vhd] - Blame information for rev 8

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

Line No. Rev Author Line
1 8 petebleack
-- ***** BEGIN LICENSE BLOCK *****
2
-- 
3
-- 
4
--  Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
-- 
6
--  The contents of this file are subject to the Mozilla Public License
7
--  Version 1.1 (the "License"); you may not use this file except in compliance
8
--  with the License. You may obtain a copy of the License at
9
--  http://www.mozilla.org/MPL/
10
-- 
11
--  Software distributed under the License is distributed on an "AS IS" basis,
12
--  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
13
--  the specific language governing rights and limitations under the License.
14
-- 
15
--  The Original Code is BBC Research and Development code.
16
-- 
17
--  The Initial Developer of the Original Code is the British Broadcasting
18
--  Corporation.
19
--  Portions created by the Initial Developer are Copyright (C) 2006.
20
--  All Rights Reserved.
21
-- 
22
--  Contributor(s): Peter Bleackley (Original author)
23
-- 
24
--  Alternatively, the contents of this file may be used under the terms of
25
--  the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
26
--  Public License Version 2.1 (the "LGPL"), in which case the provisions of
27
--  the GPL or the LGPL are applicable instead of those above. If you wish to
28
--  allow use of your version of this file only under the terms of the either
29
--  the GPL or LGPL and not to allow others to use your version of this file
30
--  under the MPL, indicate your decision by deleting the provisions above
31
--  and replace them with the notice and other provisions required by the GPL
32
--  or LGPL. If you do not delete the provisions above, a recipient may use
33
--  your version of this file under the terms of any one of the MPL, the GPL
34
--  or the LGPL.
35
-- * ***** END LICENSE BLOCK ***** */
36
 
37
library IEEE;
38
use IEEE.STD_LOGIC_1164.ALL;
39
use IEEE.STD_LOGIC_ARITH.ALL;
40
use IEEE.STD_LOGIC_UNSIGNED.ALL;
41
 
42
---- Uncomment the following library declaration if instantiating
43
---- any Xilinx primitives in this code.
44
--library UNISIM;
45
--use UNISIM.VComponents.all;
46
 
47
entity HALVING_MANAGER is
48
    Port ( TRIGGER_HALVING : in std_logic;
49
           INPUT_READY : in std_logic;
50
           NUMERATOR_IN : in std_logic_vector(9 downto 0);
51
           DENOMINATOR_IN : in std_logic_vector(9 downto 0);
52
                          CONTEXT : in std_logic_vector(5 downto 0);
53
           RESET : in std_logic;
54
           CLOCK : in std_logic;
55
           NUMERATOR_OUT : out std_logic_vector(9 downto 0);
56
           DENOMINATOR_OUT : out std_logic_vector(9 downto 0);
57
           OUTPUT_READY : out std_logic);
58
end HALVING_MANAGER;
59
 
60
architecture RTL of HALVING_MANAGER is
61
        type COUNTARRAY is array(45 downto 0) of std_logic_vector(2 downto 0);
62
        signal SHIFTS : COUNTARRAY;
63
        signal NUMERATOR : std_logic_vector (9 downto 0);
64
        signal DENOMINATOR : std_logic_vector (9 downto 0);
65
        signal NUMERATOR2 : std_logic_vector (9 downto 0);
66
        signal DENOMINATOR2 : std_logic_vector (9 downto 0);
67
        signal DENOMINATOR_INCREMENT : std_logic_vector (9 downto 0);
68
        signal GREATER_THAN_16 : std_logic;
69
        signal PERFORM_HALVING : std_logic;
70
        signal AFTER_TRIGGER : std_logic;
71
        signal LOAD : std_logic;
72
        signal CALCULATE_VALUES : std_logic;
73
 
74
begin
75
 
76
COUNT_HALVING_EVENTS : process (CLOCK)
77
begin
78
        if CLOCK'event and CLOCK = '1' then
79
                if RESET = '1' then
80
                        SHIFTS <= (others => "000");
81
                elsif TRIGGER_HALVING = '1' then
82
                        for I in 0 to 45 loop
83
                                if SHIFTS(I) /= "111" then
84
                                        SHIFTS(I) <= SHIFTS(I) + "001";
85
                                end if;
86
                        end loop;
87
                elsif CALCULATE_VALUES = '1' then
88
                        SHIFTS(conv_integer(CONTEXT)) <= SHIFTS(conv_integer(CONTEXT)) - "001";
89
                elsif GREATER_THAN_16 = '0' and LOAD = '0' and INPUT_READY = '1' then
90
                        SHIFTS(conv_integer(CONTEXT)) <= "000";
91
                end if;
92
        end if;
93
end process COUNT_HALVING_EVENTS;
94
 
95
NUMERATOR2 <= ('0' & NUMERATOR (9 downto 1)) + "0000000001";
96
DENOMINATOR2 <= ('0' & DENOMINATOR(9 downto 1)) + DENOMINATOR_INCREMENT;
97
 
98
HALVE_COUNTS :   process (CLOCK)
99
begin
100
        if CLOCK'event and CLOCK='1' then
101
                if RESET = '1' then
102
                        NUMERATOR <= "0000000001";
103
                        DENOMINATOR <= "0000000010";
104
                elsif CALCULATE_VALUES = '1' then
105
                        NUMERATOR <= NUMERATOR2;
106
                        DENOMINATOR <= DENOMINATOR2;
107
                elsif LOAD = '1' then
108
                        NUMERATOR <= NUMERATOR_IN;
109
                        DENOMINATOR <= DENOMINATOR_IN;
110
                end if;
111
        end if;
112
end process HALVE_COUNTS;
113
 
114
HALVING_PERMITTED : process (DENOMINATOR)
115
begin
116
        if DENOMINATOR > "0000010000" then
117
                GREATER_THAN_16 <= '1';
118
        else
119
                GREATER_THAN_16 <= '0';
120
        end if;
121
end process HALVING_PERMITTED;
122
 
123
HALVING_ACTIVE : process (INPUT_READY, SHIFTS, CONTEXT, GREATER_THAN_16)
124
begin
125
        if INPUT_READY = '1' and (SHIFTS(conv_integer(CONTEXT)) > "000") then
126
                PERFORM_HALVING <= GREATER_THAN_16;
127
        else
128
                PERFORM_HALVING <= '0';
129
        end if;
130
end process HALVING_ACTIVE;
131
 
132
SELECT_OUTPUT : process (NUMERATOR_IN, DENOMINATOR_IN, NUMERATOR, DENOMINATOR, TRIGGER_HALVING, PERFORM_HALVING, LOAD)
133
begin
134
        if (LOAD and (TRIGGER_HALVING nor PERFORM_HALVING)) = '1' then
135
                NUMERATOR_OUT <= NUMERATOR_IN;
136
                DENOMINATOR_OUT <= DENOMINATOR_IN;
137
        else
138
                NUMERATOR_OUT <= NUMERATOR;
139
                DENOMINATOR_OUT <= DENOMINATOR;
140
        end if;
141
end process SELECT_OUTPUT;
142
 
143
DELAY_TRIGGER : process (CLOCK)
144
begin
145
        if CLOCK'event and CLOCK = '1' then
146
                if RESET = '1' then
147
                        AFTER_TRIGGER <= '0';
148
                else
149
                        AFTER_TRIGGER <= INPUT_READY;
150
                end if;
151
        end if;
152
end process DELAY_TRIGGER;
153
 
154
CHOOSE_DENOMINATOR_INCREMENT : process (NUMERATOR, DENOMINATOR)
155
begin
156
        if (NUMERATOR (0) = '1') and (DENOMINATOR (0) = '0') then
157
                DENOMINATOR_INCREMENT <= "0000000001";
158
        else
159
                DENOMINATOR_INCREMENT <= "0000000010";
160
        end if;
161
end process CHOOSE_DENOMINATOR_INCREMENT;
162
 
163
LOAD <= INPUT_READY and not AFTER_TRIGGER;
164
 
165
CALCULATE_VALUES <= PERFORM_HALVING and AFTER_TRIGGER;
166
 
167
OUTPUT_READY <= INPUT_READY and (PERFORM_HALVING nor TRIGGER_HALVING);
168
 
169
end RTL;

powered by: WebSVN 2.1.0

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