1 |
8 |
eejlny |
--This library is free software; you can redistribute it and/or
|
2 |
|
|
--modify it under the terms of the GNU Lesser General Public
|
3 |
|
|
--License as published by the Free Software Foundation; either
|
4 |
|
|
--version 2.1 of the License, or (at your option) any later version.
|
5 |
|
|
|
6 |
|
|
--This library is distributed in the hope that it will be useful,
|
7 |
|
|
--but WITHOUT ANY WARRANTY; without even the implied warranty of
|
8 |
|
|
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
9 |
|
|
--Lesser General Public License for more details.
|
10 |
|
|
|
11 |
|
|
--You should have received a copy of the GNU Lesser General Public
|
12 |
|
|
--License along with this library; if not, write to the Free Software
|
13 |
|
|
--Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
14 |
|
|
|
15 |
|
|
-- e_mail : j.l.nunez-yanez@byacom.co.uk
|
16 |
|
|
|
17 |
|
|
-----------------------------------------------------
|
18 |
|
|
-- ENTITY = RLI_CCU (RLI Coding Control Unit) --
|
19 |
|
|
-- version = 1.0 --
|
20 |
|
|
-- last update = 6/6/01 --
|
21 |
|
|
-- author = Jose Nunez --
|
22 |
|
|
-----------------------------------------------------
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
-- FUNCTION
|
26 |
|
|
-- State machine to control the RLI coding process
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
-- PIN LIST
|
30 |
|
|
-- CODE_IN : 35 bits of normal compressed code
|
31 |
|
|
-- LENGTH_IN : 6 bits indicating how many bits valid in CODE_IN
|
32 |
|
|
-- COUNT : number of repetitions in a run length
|
33 |
|
|
-- RL_DETECTED : run length detection
|
34 |
|
|
-- CLEAR : asyncronus clear
|
35 |
|
|
-- CLK : master clk
|
36 |
|
|
-- CODE_OUT : code output 35 bits
|
37 |
|
|
-- LENGTH_OUT : length output
|
38 |
|
|
|
39 |
|
|
library ieee;
|
40 |
|
|
use ieee.std_logic_1164.all;
|
41 |
|
|
library dzx;
|
42 |
|
|
use dzx.bit_arith.all;
|
43 |
|
|
|
44 |
|
|
entity RLI_CCU is
|
45 |
|
|
port
|
46 |
|
|
(
|
47 |
|
|
CODE_IN : in bit_vector(34 downto 0) ;
|
48 |
|
|
MOVE_ENABLE_IN : in bit;
|
49 |
|
|
FLUSH_IN : in bit;
|
50 |
|
|
LENGTH_IN : in bit_vector (5 downto 0);
|
51 |
|
|
CODE_RLI : in bit_vector(4 downto 0);
|
52 |
|
|
CODE_RLI_LENGTH : in bit_vector(2 downto 0);
|
53 |
|
|
COUNT : in bit_vector(7 downto 0);
|
54 |
|
|
RL_DETECTED : in bit;
|
55 |
|
|
CLEAR : in bit ;
|
56 |
|
|
RESET: in bit;
|
57 |
|
|
CLK : in bit ;
|
58 |
|
|
CODE_OUT : out bit_vector(34 downto 0);
|
59 |
|
|
LENGTH_OUT : out bit_vector(5 downto 0)
|
60 |
|
|
);
|
61 |
|
|
end RLI_CCU;
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
architecture STRUCTURAL of RLI_CCU is
|
65 |
|
|
|
66 |
|
|
signal CURRENT_STATE : bit_vector(1 downto 0);
|
67 |
|
|
signal NEXT_STATE : bit_vector(1 downto 0);
|
68 |
|
|
signal COUNT_AUX: bit_vector(7 downto 0);
|
69 |
|
|
signal LENGTH_AUX: bit_vector(5 downto 0);
|
70 |
|
|
signal TOTAL_LENGTH: bit_vector(5 downto 0);
|
71 |
|
|
signal CODE_RLI_INT : bit_vector(34 downto 0);
|
72 |
|
|
signal CODE_RLI_STORED : bit_vector(4 downto 0);
|
73 |
|
|
signal CODE_RLI_LENGTH_STORED : bit_vector(2 downto 0);
|
74 |
|
|
signal CODE_OUT_AUX : bit_vector(34 downto 0);
|
75 |
|
|
signal LENGTH_OUT_AUX : bit_vector(5 downto 0);
|
76 |
|
|
|
77 |
|
|
begin
|
78 |
|
|
|
79 |
|
|
STATES : process (MOVE_ENABLE_IN, FLUSH_IN,RL_DETECTED,CURRENT_STATE,CODE_IN,LENGTH_IN, TOTAL_LENGTH,CODE_RLI_INT)
|
80 |
|
|
begin
|
81 |
|
|
|
82 |
|
|
case CURRENT_STATE is
|
83 |
|
|
when "00" => -- state 0 normal output
|
84 |
|
|
if (RL_DETECTED = '1') then
|
85 |
|
|
NEXT_STATE <= "01";
|
86 |
|
|
else
|
87 |
|
|
NEXT_STATE <= CURRENT_STATE;
|
88 |
|
|
end if;
|
89 |
|
|
if (MOVE_ENABLE_IN = '1' and FLUSH_IN = '1') then
|
90 |
|
|
CODE_OUT_AUX <= "00000000000000000000000000000000000";
|
91 |
|
|
LENGTH_OUT_AUX <= "000000";
|
92 |
|
|
else
|
93 |
|
|
CODE_OUT_AUX <= CODE_IN;
|
94 |
|
|
LENGTH_OUT_AUX <= LENGTH_IN;
|
95 |
|
|
end if;
|
96 |
|
|
|
97 |
|
|
when "01" => -- state 1 length set to zero
|
98 |
|
|
if (RL_DETECTED = '0' or FLUSH_IN = '0') then -- flush indicates terminate by flushing
|
99 |
|
|
NEXT_STATE <= "11";
|
100 |
|
|
else
|
101 |
|
|
NEXT_STATE <= "10";
|
102 |
|
|
end if;
|
103 |
|
|
CODE_OUT_AUX <= "00000000000000000000000000000000000";
|
104 |
|
|
LENGTH_OUT_AUX <= "000000";
|
105 |
|
|
|
106 |
|
|
when "10" => -- state 1 length set to zero
|
107 |
|
|
if (RL_DETECTED = '0' or FLUSH_IN = '0') then
|
108 |
|
|
NEXT_STATE <= "11";
|
109 |
|
|
else
|
110 |
|
|
NEXT_STATE <= CURRENT_STATE;
|
111 |
|
|
end if;
|
112 |
|
|
CODE_OUT_AUX <= "00000000000000000000000000000000000";
|
113 |
|
|
LENGTH_OUT_AUX <= "000000";
|
114 |
|
|
when "11" => -- state 2 output RL code
|
115 |
|
|
if (RL_DETECTED = '0') then
|
116 |
|
|
NEXT_STATE <= "00";
|
117 |
|
|
else
|
118 |
|
|
NEXT_STATE <= "01";
|
119 |
|
|
end if;
|
120 |
|
|
CODE_OUT_AUX <= CODE_RLI_INT; -- take the match loc from input add the special match type for RL and the count
|
121 |
|
|
LENGTH_OUT_AUX <= TOTAL_LENGTH; -- length out 16 or 10 one bit for the match
|
122 |
|
|
when others =>
|
123 |
|
|
NEXT_STATE <= "00";
|
124 |
|
|
CODE_OUT_AUX <= "00000000000000000000000000000000000";
|
125 |
|
|
LENGTH_OUT_AUX <= "000000";
|
126 |
|
|
end case;
|
127 |
|
|
|
128 |
|
|
end process STATES;
|
129 |
|
|
|
130 |
|
|
-- CODE_OUT <= CODE_OUT_AUX when MOVE_ENABLE_IN = '0' else "00000000000000000000000000000000000";
|
131 |
|
|
-- LENGTH_OUT <= LENGTH_OUT_AUX when MOVE_ENABLE_IN = '0' else "000000";
|
132 |
|
|
|
133 |
|
|
CODE_OUT <= CODE_OUT_AUX;
|
134 |
|
|
LENGTH_OUT <= LENGTH_OUT_AUX;
|
135 |
|
|
|
136 |
|
|
-- store RLI code inmediatly after RL is detected before NFL is incremented
|
137 |
|
|
|
138 |
|
|
STORED_RLI : process(CLK, CLEAR)
|
139 |
|
|
begin
|
140 |
|
|
|
141 |
|
|
if (CLEAR = '0') then
|
142 |
|
|
CODE_RLI_STORED <= "00000";
|
143 |
|
|
CODE_RLI_LENGTH_STORED <= "000";
|
144 |
|
|
elsif ((CLK'event) and (CLK='1')) then
|
145 |
|
|
if (RESET = '0') then
|
146 |
|
|
CODE_RLI_STORED <= "00000";
|
147 |
|
|
CODE_RLI_LENGTH_STORED <= "000";
|
148 |
|
|
elsif (CURRENT_STATE = "01") then -- save the first RLI code
|
149 |
|
|
CODE_RLI_STORED <= CODE_RLI;
|
150 |
|
|
CODE_RLI_LENGTH_STORED <= CODE_RLI_LENGTH;
|
151 |
|
|
else
|
152 |
|
|
CODE_RLI_STORED <= CODE_RLI_STORED;
|
153 |
|
|
CODE_RLI_LENGTH_STORED <= CODE_RLI_LENGTH_STORED;
|
154 |
|
|
end if;
|
155 |
|
|
end if;
|
156 |
|
|
|
157 |
|
|
end process STORED_RLI;
|
158 |
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
|
|
-- use 8 bits or 2 bits if the run length position is higher than zero
|
162 |
|
|
|
163 |
|
|
COUNT_AUX <= COUNT when CODE_RLI_STORED(3 downto 0)="0000" else COUNT(1 downto 0)&"000000";
|
164 |
|
|
LENGTH_AUX <= "001011" when CODE_RLI_STORED(3 downto 0)="0000" else "000101"; -- run length plus RLI type length (3)
|
165 |
|
|
TOTAL_LENGTH <= ("00" & CODE_RLI_LENGTH_STORED) + LENGTH_AUX;
|
166 |
|
|
|
167 |
|
|
BUILD_RLI_CODE : process(CODE_RLI_STORED, CODE_RLI_LENGTH_STORED, COUNT_AUX)
|
168 |
|
|
begin
|
169 |
|
|
case CODE_RLI_LENGTH_STORED is
|
170 |
|
|
when "001" => CODE_RLI_INT <= CODE_RLI_STORED(4) & "011" & COUNT_AUX & "00000000000000000000000";
|
171 |
|
|
when "010" => CODE_RLI_INT <= CODE_RLI_STORED(4 downto 3) & "011" & COUNT_AUX & "0000000000000000000000";
|
172 |
|
|
when "011" => CODE_RLI_INT <= CODE_RLI_STORED(4 downto 2) & "011" & COUNT_AUX & "000000000000000000000";
|
173 |
|
|
when "100" => CODE_RLI_INT <= CODE_RLI_STORED(4 downto 1) & "011" & COUNT_AUX & "00000000000000000000";
|
174 |
|
|
when "101" => CODE_RLI_INT <= CODE_RLI_STORED(4 downto 0) & "011" & COUNT_AUX & "0000000000000000000";
|
175 |
|
|
when others => CODE_RLI_INT <= "00000000000000000000000000000000000";
|
176 |
|
|
end case;
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
end process BUILD_RLI_CODE;
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
FLIP_FLOPS : process(CLK, CLEAR)
|
183 |
|
|
begin
|
184 |
|
|
|
185 |
|
|
if (CLEAR = '0') then
|
186 |
|
|
CURRENT_STATE <= "00"; --state 0
|
187 |
|
|
elsif ((CLK'event) and (CLK='1')) then
|
188 |
|
|
if (RESET = '0') then
|
189 |
|
|
CURRENT_STATE <= "00"; --state 0
|
190 |
|
|
else
|
191 |
|
|
CURRENT_STATE <= NEXT_STATE;
|
192 |
|
|
end if;
|
193 |
|
|
end if;
|
194 |
|
|
|
195 |
|
|
end process FLIP_FLOPS;
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
end STRUCTURAL;
|
200 |
|
|
|