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

Subversion Repositories deflatecore

[/] [deflatecore/] [trunk/] [search.vhd] - Blame information for rev 20

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

Line No. Rev Author Line
1 5 smallcode
--------------------------------------------------------------------------------
2 17 smallcode
-- Create Date:    Open source, from 12c core hosted at  www.opencores.org
3 5 smallcode
-- Design Name:    
4 17 smallcode
-- Module Name:    Log function base 2
5 5 smallcode
-- Project Name:   Deflate
6
-- Target Device:  
7 17 smallcode
-- Dependencies: 
8 5 smallcode
-- 
9 17 smallcode
-- Revision: NA
10 5 smallcode
-- Additional Comments:
11 17 smallcode
-- Use this to convert the memeory lengths to the 2^x values
12
-- to dynamically assign the widths of the address
13 14 smallcode
-- 
14 5 smallcode
--------------------------------------------------------------------------------
15 17 smallcode
 
16 5 smallcode
library IEEE;
17
use IEEE.std_logic_1164.all;
18
use IEEE.numeric_std.all;
19
 
20
--Function to find the log of a number 
21
--Is used to convert the addresses
22
package mat is
23
         function log2(v: in natural) return natural;
24
end package mat;
25
 
26
--Function definition
27
library IEEE;
28
use IEEE.std_logic_1164.all;
29
use IEEE.numeric_std.all;
30
 
31
 
32
package body mat is
33
 
34
function log2(v: in natural) return natural is
35
        variable n: natural;
36
        variable logn: natural;
37
begin
38
        n := 1;
39
        for i in 0 to 128 loop
40
                logn := i;
41
                exit when (n>=v);
42
                n := n * 2;
43
        end loop;
44
        return logn;
45
end function log2;
46
end package body mat;
47
--End of the package
48
 
49
 
50 17 smallcode
 
51
 
52
--------------------------------------------------------------------------------
53
-- Create Date:    17:24:38 20/05/2006
54
-- Design Name:    
55
-- Module Name:    
56
-- Project Name:   Deflate
57
-- Target Device:  
58
-- Dependencies: hahskey.vhdl
59
-- 
60
-- Revision:
61
-- Revision 0.50 - Works but not optimised
62
-- Additional Comments:
63
-- This componenet controls the data input and stores the data alongwith 
64
-- the source in 32k buffers ,
65
-- It recieves the data directly and then on finding a minimum match 
66
-- Drives its match output high along with the match address on the address output
67
-- and the current offset on the next clock cycle
68
-- waits for the next +ve edge on the Active data input 
69
-- to go high before resuming, the output/ input is +ve edge triggered
70
-- 
71
--------------------------------------------------------------------------------
72
 
73 5 smallcode
library IEEE;
74
use IEEE.STD_LOGIC_1164.ALL;
75
use IEEE.STD_LOGIC_ARITH.ALL;
76
use IEEE.STD_LOGIC_UNSIGNED.ALL;
77
use work.mat.all;
78
 
79 17 smallcode
entity input_process is
80
        Generic
81
              (
82
                         -- Number of bits in the key
83
                         Hash_Width      : natural := 32;
84
                         -- Data bus width
85
                         Data_Width      : natural := 8;
86
                         -- Buffer allocated to the hash table and the source buffer = 32k tables
87
                         -- The key buffer has to be equal to the Hash_Width above and 
88
                         -- the source buffer of  Dat width 
89
                         -- Start address for the memory bank at which the hash keys need to be stored
90
                         -- The end address is calculated by adding the length of the table to that address  
91
                         Length_of_Table : natural :=   32768
92
                         );
93
        Port
94
              (
95
                         --Outputs to read/write the key values.
96
                         hash_tbl_dat    : inout std_logic_vector ( Hash_Width - 1 downto 0);
97
                         --Port to read/write data values
98
                         source_buff_dat : inout std_logic_vector ( Data_Width - 1 downto 0);
99
                         -- Matching 4 bytes fond for the last 4 inputs
100
                         Match,
101
                         -- Ready for crunching
102
                         Ready,
103
                         -- The sync signals to the memory, read write operations 
104
                         -- done simultaneously on both memry banks
105
                         -- The design will currently work with SRAM and will need a wrapper to  
106
                         -- work with DRAM
107
                         -- Active data on output
108
                         Act_data_out,
109
                         --Read or write operation 0 = read, 1 = write
110
                         RW              : out bit      ;
111
                         -- Current address in buffers
112
          Curr_addres     : out std_logic_vector (log2 ( Length_of_Table ) - 1 downto 0);
113
                         --******
114
                         --Input signals
115
                         --Data in
116
                         source_dat : inout std_logic_vector ( Data_Width - 1 downto 0);
117
                         -- Input Data Clock
118
                         Act_dat,
119
                         -- Clock
120
                         Src_clk,
121
                         -- Reset
122
                         Reset : in bit
123
 
124
                         );
125
end input_process;
126
 
127
architecture mealy_machine of input_process is
128
component hash_key is
129 14 smallcode
generic
130
       (
131
                 hash_width: natural := 32;
132
                 data_width: natural := 8);
133
port
134
       (
135
                 data_in: in std_logic_vector(data_width -1 downto 0);
136
                 hash_out: out std_logic_vector (hash_width -1 downto 0);
137
                 Clock,
138
                 reset,
139
                 start : in bit;
140
                 ready,
141
                 busy: out bit);
142 5 smallcode
end component;
143 17 smallcode
       -- Buffer address start for the key table
144
Signal key_address,
145
       buffer_address:   std_logic_vector (log2 ( Length_of_Table ) - 1 downto 0);
146
                 -- Accept a 32 bit hash input  
147
signal hg1:    std_logic_vector ( (Hash_Width -1) downto 0);
148
-- 8 bit io buffer      
149
signal Buffer_1 : std_logic_vector (Data_Width-1 downto 0);
150
--Component signals from the key algorithm
151
signal Algo_start,
152
       Algo_clk,
153
                 Algo_rst,
154
                 Algo_op,
155
                 Algo_bsy,       -- Algorithm sync aignals
156
                 Search_done,
157
                 Busy,
158
                 red_rst,
159
                 red_opr,
160
                 val_match: bit := '0';  --Internal sync sgnals                                    
161
signal mode,
162
       store_count :integer;
163 5 smallcode
 
164
begin
165
 
166 17 smallcode
--Unlike the sub components this module has a slightly complex reset cycle
167
--It resets the offset counters to 0, uses the next 7 clock cyces to read the 
168
--start addresses for the data and key buffer
169 5 smallcode
 
170 17 smallcode
resetter: process (Src_Clk)
171
variable tmp: integer;
172
variable red: bit :='0';
173
Begin
174
 if Src_Clk'event and Src_Clk = '1' then
175
  if mode /= 0 then
176
    red_rst <= '0';
177
         tmp := 0;
178
  else
179
    case tmp  is
180
            when 0 =>
181
                                buffer_address (7 downto 0) <= source_dat;
182
       when 1 =>
183
                      buffer_address (14 downto 8) <= source_dat (6 downto 0);
184
       when 2 =>
185
                                key_address    (7 downto 0) <= source_dat;
186
                 when 3 =>
187
                      key_address    (14 downto 8) <= source_dat (6 downto 0);
188
       when 4 =>
189
                      red_rst <= '1';
190
       when others =>
191
                                red_rst <= '0';
192
     end case;
193
          end if;
194
 end if;
195
end process resetter;
196 8 smallcode
 
197 17 smallcode
--The main input mealy machine is defined below
198
-- It has 6 states of operation
199
-- Mode 0 : Reset
200
-- Mode 1 : Wait
201
-- Mode 2 :     Active data input generationg a key for it and the last 3 bytes
202
-- Mode 3 : Storing the key and the input data
203
-- Mode 4 : Searching the hash buffer for a 4 byte match
204
-- Mode 5 : Match found, on the next clock cycle output current buffer offet
205
--          and on the second clock cycle output the match offset    
206
 
207
input_control : process (Act_dat, Src_Clk, Reset )
208 14 smallcode
begin
209 17 smallcode
--+ Ve edge triggered
210
 if Src_Clk'event and Src_Clk = '1' then
211
   -- Mealy machine
212
        If Reset = '1' or ( mode = 0 and red_rst ='0' ) then
213
     mode <= 0;
214
   elsif        mode < 2 and Act_dat = '1' then
215
          mode <= 2;
216
        elsif   mode = 2 and Algo_bsy = '0' and store_count < 3 then
217
          mode <= 3;
218
        elsif   mode = 2 and Algo_bsy = '0' then
219
          mode <= 4;
220
        elsif   mode = 4 and Search_done = '1' and val_match = '1' then
221
          mode <= 5;
222
        elsif   mode = 4 and Search_done = '1' then
223
          mode <= 3;
224
        elsif   ( mode = 5 or mode = 3 ) and Busy = '0' then
225
          mode <= 1;
226
        else
227
          mode <= mode;
228 14 smallcode
   end if;
229
 end if;
230 17 smallcode
end process input_control;
231
--************************************************
232
-- Algorithm component addition
233
Key_Gen: hash_key port map
234
                 (
235
                                          data_in => Buffer_1,
236
                           hash_out => hg1,
237
                           Clock => Algo_clk,
238
                           reset => Algo_rst,
239
                           start => Algo_start,
240
                           ready => Algo_op,
241
                           busy  => Algo_bsy
242
                                          );
243
-- ************************************************
244
Ready <= red_rst or red_opr;
245
end mealy_machine;

powered by: WebSVN 2.1.0

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