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

Subversion Repositories xmatchpro

[/] [xmatchpro/] [trunk/] [xmw4-comdec/] [xmatch_sim7/] [src/] [CODING_BUFFER_CU.vhd] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 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       = CODING_BUFFER_CU                --
19
--  version      = 1.0                             --
20
--  last update  = 1/5/00                        --
21
--  author       = Jose Nunez                      --
22
-----------------------------------------------------
23
 
24
 
25
-- FUNCTION
26
-- Control unit that controls the coding buffer
27
 
28
 
29
--  PIN LIST
30
--  START : enable writting to the buffer
31
--  FINISHED : the block has been process output the data that it is left in the buffer
32
--  OVERFLOW = 64 bit of compressed data available.
33
--  THRESHOLD : start reading from the buffer
34
--  CODING_READ_ADDRESS : buffer location that it is being read
35
--  CODING_WRITE_ADDRESS : buffer location that it is being written
36
--  CLK : clock
37
--  CLEAR : clear
38
--  CODING_OVERFLOW : the CU detects a coding overflow stop inputting uncompressed data 
39
--  CODING_UNDERFLOW : the CU detects a coding underflow stop outputting compressed data
40
--  ENABLE_WRITE : enable writting to the buffer
41
--  ENABLE_READ : enable reading from the buffer
42
 
43
library ieee;
44
use ieee.std_logic_1164.all;
45
library dzx;
46
use dzx.bit_arith.all;
47
use dzx.bit_utils.all;
48
 
49
 
50
entity CODING_BUFFER_CU is
51
port
52
(
53
    FORCE_STOP : in bit;
54
    WAITN : in bit;
55
          START : in bit;
56
          FINISHED : in bit;
57
          BUS_ACKNOWLEDGE : in bit;
58
          THRESHOLD_LEVEL : in bit_vector(8 downto 0);
59
          CODING_READ_ADDRESS : in bit_vector(8 downto 0);
60
          CODING_WRITE_ADDRESS : in bit_vector(8 downto 0);
61
          CLK : in bit;
62
          CLEAR : in bit;
63
          BUS_REQUEST : out bit;
64
          FLUSHING : out bit;
65
          CODING_OVERFLOW : out bit;
66
          CODING_UNDERFLOW : out bit;
67
          ENABLE_WRITE : out bit;
68
          FINISH : out bit; -- the buffer process
69
      CLEAR_COUNTERS : out bit;
70
          ENABLE_READ : out bit
71
);
72
end CODING_BUFFER_CU;
73
 
74
architecture STRUCTURAL of CODING_BUFFER_CU is
75
 
76
signal CURRENT_STATE : bit_vector(3 downto 0);
77
signal NEXT_STATE : bit_vector(3 downto 0);
78
signal CODING_OVERFLOW_AUX : bit;
79
signal CODING_UNDERFLOW_AUX : bit;
80
signal FLUSHING_AUX : bit;
81
signal FINISH_OP : bit; -- data valid control next state is finish
82
signal ENABLE_WRITE_AUX : bit;
83
 
84
 
85
 
86
begin
87
 
88
STATES : process (FINISH_OP, START, THRESHOLD_LEVEL, CURRENT_STATE, FINISHED, CODING_UNDERFLOW_AUX, CODING_OVERFLOW_AUX, CODING_READ_ADDRESS, CODING_WRITE_ADDRESS, BUS_ACKNOWLEDGE)
89
begin
90
case CURRENT_STATE is
91
        when "0000" =>  -- state 0 buffer inactive
92
                if (START = '0') then
93
                        NEXT_STATE <= "0001";
94
                else
95
                        NEXT_STATE <= CURRENT_STATE;
96
                end if;
97
                ENABLE_READ <= '0';
98
                ENABLE_WRITE_AUX <= '0';
99
                BUS_REQUEST <= '1';
100
                FLUSHING_AUX <= '1';
101
                FINISH <= '1';
102
            CLEAR_COUNTERS <= '1';
103
 
104
         when "0001" =>  -- state 1 start adding data to the buffer
105
                if (FINISHED = '0') then
106
                        NEXT_STATE <= "1001"; -- request the bus but do not write
107
                elsif (CODING_WRITE_ADDRESS - CODING_READ_ADDRESS > THRESHOLD_LEVEL) then
108
                        NEXT_STATE <= "0110"; -- request the bus
109
                else
110
                        NEXT_STATE <= CURRENT_STATE;
111
                end if;
112
                ENABLE_READ <= '0';
113
                ENABLE_WRITE_AUX <= '1';
114
                BUS_REQUEST <= '1';
115
                FLUSHING_AUX <= '1';
116
                FINISH <= '1';
117
            CLEAR_COUNTERS <= '0';
118
 
119
         when "0010" =>    -- state 2 writting and reading data
120
             if (FINISHED = '0') then -- finished active low
121
                    NEXT_STATE <= "0101"; -- empty the buffer
122
                 elsif (CODING_OVERFLOW_AUX = '0') then
123
                        NEXT_STATE <= "0011"; -- stop writting data
124
                 elsif (CODING_UNDERFLOW_AUX = '1') then
125
                        NEXT_STATE <= "0100"; -- stop reading data
126
                 else
127
                        NEXT_STATE <= CURRENT_STATE;
128
                 end if;
129
                 ENABLE_READ <= '1';
130
                 ENABLE_WRITE_AUX <= '1';
131
                 BUS_REQUEST <= '0';
132
                 FLUSHING_AUX <= '1';
133
             FINISH <= '1';
134
             CLEAR_COUNTERS <= '0';
135
 
136
         when "0011" => -- only reading
137
                 if (CODING_OVERFLOW_AUX = '1') then
138
                        NEXT_STATE <= "0010";
139
                 else
140
                NEXT_STATE <= CURRENT_STATE;
141
                 end if;
142
                 ENABLE_WRITE_AUX <= '0';
143
                 ENABLE_READ  <= '1';
144
                 BUS_REQUEST <= '0';
145
             FLUSHING_AUX <= '1';
146
                 FINISH <= '1';
147
             CLEAR_COUNTERS <= '0';
148
 
149
 
150
         when "0100" => -- only writting
151
           if (FINISHED = '0') then
152
                                NEXT_STATE <= "1001"; -- request the bus but do not write
153
                 elsif (CODING_WRITE_ADDRESS - CODING_READ_ADDRESS > THRESHOLD_LEVEL) then
154
                                NEXT_STATE <= "0110"; --request the bus 
155
                 else
156
                                NEXT_STATE <= CURRENT_STATE;
157
                 end if;
158
                 ENABLE_WRITE_AUX <= '1';
159
                 ENABLE_READ  <= '0';
160
                 BUS_REQUEST <= '1';
161
             FLUSHING_AUX <= '1';
162
             FINISH <= '1';
163
             CLEAR_COUNTERS <= '0';
164
 
165
        when "1001" => -- continue to request but do not write or read
166
                  if (BUS_ACKNOWLEDGE = '0') then
167
                        NEXT_STATE <= "0101";  -- only read ( from memory empty the buffer)
168
                  else
169
                    NEXT_STATE <= CURRENT_STATE;
170
                  end if;
171
 
172
                 ENABLE_WRITE_AUX <= '0';
173
                 ENABLE_READ  <= '0';
174
                 BUS_REQUEST <= '0';
175
                 FLUSHING_AUX <= '0';
176
                 FINISH <= '1';
177
                CLEAR_COUNTERS <= '0';
178
 
179
         when "0101" => -- emptying the buffer only reading
180
                 if (FINISH_OP = '1') then
181
                        NEXT_STATE <= "1000";  -- end 
182
                 else
183
                NEXT_STATE <= CURRENT_STATE;
184
                 end if;
185
                 ENABLE_WRITE_AUX <= '0';
186
                 ENABLE_READ  <= '1';
187
                 BUS_REQUEST <= '0';
188
             FLUSHING_AUX <= '0';
189
             FINISH <= '1';
190
             CLEAR_COUNTERS <= '0';
191
 
192
 
193
         when "0110" => -- request the bus
194
                 if (FINISHED = '0') then
195
                          NEXT_STATE <= "1001"; -- request the bus but do not write. nothing else to write
196
           elsif(CODING_OVERFLOW_AUX = '0') then
197
                    NEXT_STATE <="0111"; -- stop writting continue request
198
                 elsif (BUS_ACKNOWLEDGE = '0') then
199
                          NEXT_STATE <= "0010";  -- read and write  
200
                 else
201
               NEXT_STATE <= CURRENT_STATE;
202
                 end if;
203
                 ENABLE_WRITE_AUX <= '1';
204
                 ENABLE_READ  <= '0';
205
                 BUS_REQUEST <= '0';
206
                 FLUSHING_AUX <= '1';
207
                 FINISH <= '1';
208
                 CLEAR_COUNTERS <= '0';
209
 
210
         when "0111" => -- request the bus
211
                 if (BUS_ACKNOWLEDGE = '0') then
212
                        NEXT_STATE <= "0010";  -- read and write  
213
                 else
214
                NEXT_STATE <= CURRENT_STATE;
215
                 end if;
216
                 ENABLE_WRITE_AUX <= '0';
217
                 ENABLE_READ  <= '0';
218
                 BUS_REQUEST <= '0';
219
      FLUSHING_AUX <= '1';
220
      FINISH <= '1';
221
      CLEAR_COUNTERS <= '0';
222
         when "1000" =>
223
                 NEXT_STATE <= "0000";
224
                 ENABLE_WRITE_AUX <= '0';
225
                 ENABLE_READ  <= '0';
226
                 BUS_REQUEST <= '1';
227
         FLUSHING_AUX <= '1';
228
         FINISH <= '0';
229
         CLEAR_COUNTERS <= '0';
230
 
231
 
232
         when others =>
233
        NEXT_STATE <= "0000";
234
                ENABLE_READ <= '0';
235
                ENABLE_WRITE_AUX <= '0';
236
                BUS_REQUEST <= '1';
237
                FLUSHING_AUX <= '1';
238
                FINISH <= '1';
239
        CLEAR_COUNTERS <= '0';
240
 
241
 
242
 
243
 
244
end  case;
245
end process STATES;
246
 
247
CODING_OVERFLOW_AUX <= '0' when ((CODING_READ_ADDRESS(8 downto 1) = CODING_WRITE_ADDRESS(8 downto 1) + "00000001") and ENABLE_WRITE_AUX = '1') else '1'; -- direct output error condition
248
CODING_UNDERFLOW_AUX <= '1' when (CODING_WRITE_ADDRESS(8 downto 1) = CODING_READ_ADDRESS(8 downto 1) + "00000001") else '0';
249
 
250
-- coding undeflow active when read address > write address
251
 
252
CODING_OVERFLOW <= CODING_OVERFLOW_AUX;
253
 
254
-- only coding underflow if not in flusing state
255
-- coding underflow if coding_write_address = coding_read address => about to finish
256
-- data valid control
257
 
258
FINISH_OP <= '1' when (CODING_WRITE_ADDRESS = CODING_READ_ADDRESS and WAITN = '1') else '0'; -- only finish when WAITN is inactive
259
 
260
CODING_UNDERFLOW <= (CODING_UNDERFLOW_AUX and FLUSHING_AUX) or FINISH_OP;
261
FLUSHING <= FLUSHING_AUX;
262
ENABLE_WRITE <= ENABLE_WRITE_AUX;
263
 
264
FLIP_FLOPS : process(CLK, CLEAR)
265
begin
266
 
267
if (CLEAR = '0') then
268
        CURRENT_STATE <= "0000"; --state 0
269
elsif ((CLK'event) and (CLK='1')) then
270
     if (FORCE_STOP = '0') then
271
                                CURRENT_STATE <= "0000";
272
     else
273
                                CURRENT_STATE <= NEXT_STATE;
274
     end if;
275
end if;
276
 
277
end process FLIP_FLOPS;
278
 
279
 
280
 
281
end STRUCTURAL;
282
 

powered by: WebSVN 2.1.0

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