1 |
8 |
petebleack |
-- ***** BEGIN LICENSE BLOCK *****
|
2 |
|
|
--
|
3 |
10 |
petebleack |
-- $Id: HALVING_MANAGER.vhd,v 1.2 2006-10-05 16:17:11 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 |
8 |
petebleack |
-- * ***** 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 library declaration if instantiating
|
44 |
|
|
---- any Xilinx primitives in this code.
|
45 |
|
|
--library UNISIM;
|
46 |
|
|
--use UNISIM.VComponents.all;
|
47 |
|
|
|
48 |
|
|
entity HALVING_MANAGER is
|
49 |
|
|
Port ( TRIGGER_HALVING : in std_logic;
|
50 |
|
|
INPUT_READY : in std_logic;
|
51 |
10 |
petebleack |
NUMERATOR_IN : in std_logic_vector(7 downto 0);
|
52 |
|
|
DENOMINATOR_IN : in std_logic_vector(7 downto 0);
|
53 |
8 |
petebleack |
CONTEXT : in std_logic_vector(5 downto 0);
|
54 |
|
|
RESET : in std_logic;
|
55 |
|
|
CLOCK : in std_logic;
|
56 |
10 |
petebleack |
NUMERATOR_OUT : out std_logic_vector(7 downto 0);
|
57 |
|
|
DENOMINATOR_OUT : out std_logic_vector(7 downto 0);
|
58 |
8 |
petebleack |
OUTPUT_READY : out std_logic);
|
59 |
|
|
end HALVING_MANAGER;
|
60 |
|
|
|
61 |
|
|
architecture RTL of HALVING_MANAGER is
|
62 |
|
|
type COUNTARRAY is array(45 downto 0) of std_logic_vector(2 downto 0);
|
63 |
|
|
signal SHIFTS : COUNTARRAY;
|
64 |
10 |
petebleack |
signal NUMERATOR : std_logic_vector (7 downto 0);
|
65 |
|
|
signal DENOMINATOR : std_logic_vector (7 downto 0);
|
66 |
|
|
signal NUMERATOR2 : std_logic_vector (7 downto 0);
|
67 |
|
|
signal DENOMINATOR2 : std_logic_vector (7 downto 0);
|
68 |
|
|
signal DENOMINATOR_INCREMENT : std_logic_vector (7 downto 0);
|
69 |
8 |
petebleack |
signal GREATER_THAN_16 : std_logic;
|
70 |
|
|
signal PERFORM_HALVING : std_logic;
|
71 |
|
|
signal AFTER_TRIGGER : std_logic;
|
72 |
|
|
signal LOAD : std_logic;
|
73 |
|
|
signal CALCULATE_VALUES : std_logic;
|
74 |
|
|
|
75 |
|
|
begin
|
76 |
|
|
|
77 |
|
|
COUNT_HALVING_EVENTS : process (CLOCK)
|
78 |
|
|
begin
|
79 |
|
|
if CLOCK'event and CLOCK = '1' then
|
80 |
|
|
if RESET = '1' then
|
81 |
|
|
SHIFTS <= (others => "000");
|
82 |
|
|
elsif TRIGGER_HALVING = '1' then
|
83 |
|
|
for I in 0 to 45 loop
|
84 |
|
|
if SHIFTS(I) /= "111" then
|
85 |
|
|
SHIFTS(I) <= SHIFTS(I) + "001";
|
86 |
|
|
end if;
|
87 |
|
|
end loop;
|
88 |
|
|
elsif CALCULATE_VALUES = '1' then
|
89 |
|
|
SHIFTS(conv_integer(CONTEXT)) <= SHIFTS(conv_integer(CONTEXT)) - "001";
|
90 |
|
|
elsif GREATER_THAN_16 = '0' and LOAD = '0' and INPUT_READY = '1' then
|
91 |
|
|
SHIFTS(conv_integer(CONTEXT)) <= "000";
|
92 |
|
|
end if;
|
93 |
|
|
end if;
|
94 |
|
|
end process COUNT_HALVING_EVENTS;
|
95 |
|
|
|
96 |
10 |
petebleack |
NUMERATOR2 <= ('0' & NUMERATOR (7 downto 1)) + "0000000001";
|
97 |
|
|
DENOMINATOR2 <= ('0' & DENOMINATOR(7 downto 1)) + DENOMINATOR_INCREMENT;
|
98 |
8 |
petebleack |
|
99 |
|
|
HALVE_COUNTS : process (CLOCK)
|
100 |
|
|
begin
|
101 |
|
|
if CLOCK'event and CLOCK='1' then
|
102 |
|
|
if RESET = '1' then
|
103 |
10 |
petebleack |
NUMERATOR <= "00000001";
|
104 |
|
|
DENOMINATOR <= "00000010";
|
105 |
8 |
petebleack |
elsif CALCULATE_VALUES = '1' then
|
106 |
|
|
NUMERATOR <= NUMERATOR2;
|
107 |
|
|
DENOMINATOR <= DENOMINATOR2;
|
108 |
|
|
elsif LOAD = '1' then
|
109 |
|
|
NUMERATOR <= NUMERATOR_IN;
|
110 |
|
|
DENOMINATOR <= DENOMINATOR_IN;
|
111 |
|
|
end if;
|
112 |
|
|
end if;
|
113 |
|
|
end process HALVE_COUNTS;
|
114 |
|
|
|
115 |
|
|
HALVING_PERMITTED : process (DENOMINATOR)
|
116 |
|
|
begin
|
117 |
10 |
petebleack |
if DENOMINATOR > "00010000" then
|
118 |
8 |
petebleack |
GREATER_THAN_16 <= '1';
|
119 |
|
|
else
|
120 |
|
|
GREATER_THAN_16 <= '0';
|
121 |
|
|
end if;
|
122 |
|
|
end process HALVING_PERMITTED;
|
123 |
|
|
|
124 |
|
|
HALVING_ACTIVE : process (INPUT_READY, SHIFTS, CONTEXT, GREATER_THAN_16)
|
125 |
|
|
begin
|
126 |
|
|
if INPUT_READY = '1' and (SHIFTS(conv_integer(CONTEXT)) > "000") then
|
127 |
|
|
PERFORM_HALVING <= GREATER_THAN_16;
|
128 |
|
|
else
|
129 |
|
|
PERFORM_HALVING <= '0';
|
130 |
|
|
end if;
|
131 |
|
|
end process HALVING_ACTIVE;
|
132 |
|
|
|
133 |
|
|
SELECT_OUTPUT : process (NUMERATOR_IN, DENOMINATOR_IN, NUMERATOR, DENOMINATOR, TRIGGER_HALVING, PERFORM_HALVING, LOAD)
|
134 |
|
|
begin
|
135 |
|
|
if (LOAD and (TRIGGER_HALVING nor PERFORM_HALVING)) = '1' then
|
136 |
|
|
NUMERATOR_OUT <= NUMERATOR_IN;
|
137 |
|
|
DENOMINATOR_OUT <= DENOMINATOR_IN;
|
138 |
|
|
else
|
139 |
|
|
NUMERATOR_OUT <= NUMERATOR;
|
140 |
|
|
DENOMINATOR_OUT <= DENOMINATOR;
|
141 |
|
|
end if;
|
142 |
|
|
end process SELECT_OUTPUT;
|
143 |
|
|
|
144 |
|
|
DELAY_TRIGGER : process (CLOCK)
|
145 |
|
|
begin
|
146 |
|
|
if CLOCK'event and CLOCK = '1' then
|
147 |
|
|
if RESET = '1' then
|
148 |
|
|
AFTER_TRIGGER <= '0';
|
149 |
|
|
else
|
150 |
|
|
AFTER_TRIGGER <= INPUT_READY;
|
151 |
|
|
end if;
|
152 |
|
|
end if;
|
153 |
|
|
end process DELAY_TRIGGER;
|
154 |
|
|
|
155 |
|
|
CHOOSE_DENOMINATOR_INCREMENT : process (NUMERATOR, DENOMINATOR)
|
156 |
|
|
begin
|
157 |
|
|
if (NUMERATOR (0) = '1') and (DENOMINATOR (0) = '0') then
|
158 |
10 |
petebleack |
DENOMINATOR_INCREMENT <= "00000001";
|
159 |
8 |
petebleack |
else
|
160 |
10 |
petebleack |
DENOMINATOR_INCREMENT <= "00000010";
|
161 |
8 |
petebleack |
end if;
|
162 |
|
|
end process CHOOSE_DENOMINATOR_INCREMENT;
|
163 |
|
|
|
164 |
|
|
LOAD <= INPUT_READY and not AFTER_TRIGGER;
|
165 |
|
|
|
166 |
|
|
CALCULATE_VALUES <= PERFORM_HALVING and AFTER_TRIGGER;
|
167 |
|
|
|
168 |
|
|
OUTPUT_READY <= INPUT_READY and (PERFORM_HALVING nor TRIGGER_HALVING);
|
169 |
|
|
|
170 |
|
|
end RTL;
|