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

Subversion Repositories xmatchpro

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 eejlny
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.std_logic_arith.all;
4
use ieee.std_logic_unsigned.all;
5
 
6
-- Uncomment the following library declaration if using
7
-- arithmetic functions with Signed or Unsigned values
8
--use IEEE.NUMERIC_STD.ALL;
9
 
10
-- Uncomment the following library declaration if instantiating
11
-- any Xilinx primitives in this code.
12
--library UNISIM;
13
--use UNISIM.VComponents.all;
14
 
15
entity xmatch_controller is
16
port
17
(
18
        rst_CODMU       : IN STD_LOGIC;
19
        clk_CODMU       : IN STD_LOGIC;
20
        rst_HOST                : IN STD_LOGIC;
21
        clk_HOST        : IN STD_LOGIC;
22
        din_HOST        : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
23
        wr_en_HOST      : IN STD_LOGIC;
24
        rd_en_HOST      : IN STD_LOGIC;
25
        dout_HOST       : OUT STD_LOGIC_VECTOR(31 DOWNTO 0);
26
        full_HOST       : OUT STD_LOGIC;
27
        empty_HOST      : OUT STD_LOGIC;
28
        command_CR_HOST : in std_logic_vector(31 DOWNTO 0);
29
        status_CDI_HOST : out std_logic_vector(31 DOWNTO 0)
30
);
31
end xmatch_controller;
32
 
33
architecture Behavioral of xmatch_controller is
34
 
35
component level1r is port
36
(
37
        CS                                                              : in bit ;
38
        RW                                                              : in bit;
39
        ADDRESS                                                 : in bit_vector(3 downto 0);
40
        CONTROL_IN                                              : in std_logic_vector(31 downto 0);
41
        CONTROL_OUT_C                                   : out std_logic_vector (31 downto 0);
42
        CONTROL_OUT_D                                   : out std_logic_vector (31 downto 0);
43
        CLK                                                             : in bit ;
44
        CLEAR                                                           : in bit;
45
        BUS_ACKNOWLEDGE_CC                      : in bit;
46
        BUS_ACKNOWLEDGE_CU                      : in bit;
47
        BUS_ACKNOWLEDGE_DC                      : in bit;
48
        BUS_ACKNOWLEDGE_DU                      : in bit;
49
        WAIT_CU                                                 : in bit;
50
        WAIT_CC                                                         : in bit;
51
        WAIT_DC                                                         : in bit;
52
        WAIT_DU                                                         : in bit;
53
        U_DATAIN                                                : in bit_vector(31 downto 0);
54
        C_DATAIN                                                : in bit_vector(31 downto 0);
55
        U_DATAOUT                                               : out std_logic_vector(31 downto 0);
56
        C_DATAOUT                                               : out std_logic_vector(31 downto 0);
57
        FINISHED_C                                              : out bit;
58
        FINISHED_D                                              : out bit;
59
        COMPRESSING                                     : out bit;
60
        FLUSHING_C                                              : out bit;
61
        FLUSHING_D                                              : out bit;
62
        DECOMPRESSING                                   : out bit;
63
        U_DATA_VALID                                    : out bit;
64
        C_DATA_VALID                                    : out bit;
65
        DECODING_OVERFLOW                       : out bit;
66
        CODING_OVERFLOW                                 : out bit;
67
        CRC_ERROR                                               : out bit;
68
        INTERRUPT_REQUEST                       : out bit;
69
        INTERRUPT_ACKNOWLEDGE           : in bit;
70
        BUS_REQUEST_CC                          : out bit;
71
        BUS_REQUEST_CU                          : out bit;
72
        BUS_REQUEST_DC                          : out bit;
73
        BUS_REQUEST_DU                          : out bit
74
);
75
end component;
76
--
77
--  component fifo_32x512
78
--    port (
79
--      clk: IN std_logic;
80
--      srst: IN std_logic;
81
--      din: IN std_logic_VECTOR(31 downto 0);
82
--      wr_en: IN std_logic;
83
--      rd_en: IN std_logic;
84
--      dout: OUT std_logic_VECTOR(31 downto 0);
85
--      full: OUT std_logic;
86
--      empty: OUT std_logic);
87
--  end component;
88
 
89
component fifo_32x512 is port
90
(
91
    rst : IN STD_LOGIC;
92
    wr_clk : IN STD_LOGIC;
93
    rd_clk : IN STD_LOGIC;
94
    din : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
95
    wr_en : IN STD_LOGIC;
96
    rd_en : IN STD_LOGIC;
97
    dout : OUT STD_LOGIC_VECTOR(31 DOWNTO 0);
98
    full : OUT STD_LOGIC;
99
    empty : OUT STD_LOGIC
100
  );
101
end component;
102
 
103
-- All signals to convert from std_logic to bit
104
signal CS_bit                                           : bit;
105
signal RW_bit                                           : bit;
106
signal ADDRESS_bit                              : bit_vector (3 downto 0);
107
signal CONTROL_std                              : std_logic_vector (31 downto 0);
108
signal CLK_bit                                  : bit;
109
signal CLEAR_bit                                        : bit;
110
signal BUS_ACKNOWLEDGE_CC_bit   : bit := '1';
111
signal BUS_ACKNOWLEDGE_CU_bit   : bit := '1';
112
signal BUS_ACKNOWLEDGE_DC_bit   : bit := '1';
113
signal BUS_ACKNOWLEDGE_DU_bit : bit := '1';
114
signal WAIT_CU_bit                              : bit;
115
signal WAIT_CC_bit                              : bit;
116
signal WAIT_DC_bit                              : bit;
117
signal WAIT_DU_bit                              : bit;
118
signal U_DATAIN_bit                             : bit_vector (31 downto 0);
119
signal C_DATAIN_bit                             : bit_vector (31 downto 0);
120
signal C_DATAOUT_std                            : std_logic_vector (31 downto 0);
121
signal U_DATAOUT_std                            : std_logic_vector (31 downto 0);
122
signal FINISHED_C_bit                   : bit;
123
signal FINISHED_D_bit                   : bit;
124
signal U_DATA_VALID_bit                 : bit;
125
signal C_DATA_VALID_bit                 : bit;
126
signal INTERUPT_ACKNWLDGE_bit : bit;
127
signal BUS_REQUEST_CC_bit               : bit;
128
signal BUS_REQUEST_CU_bit               : bit;
129
signal BUS_REQUEST_DC_bit               : bit;
130
signal BUS_REQUEST_DU_bit               : bit;
131
signal COMPRESSING_bit                  : bit;
132
signal FLUSHING_C_bit                   : bit;
133
signal FLUSHING_D_bit                   : bit;
134
signal DECOMPRESSING_bit                : bit;
135
signal DECODING_OVERFLOW_bit    : bit;
136
signal CODING_OVERFLOW_bit      : bit;
137
signal CRC_ERROR_bit                            : bit;
138
signal INTERRUPT_REQUEST_bit    : bit;
139
 
140
signal U_DATAIN_reg                             : std_logic_vector(31 downto 0);
141
signal C_DATAIN_reg                             : std_logic_vector(31 downto 0);
142
 
143
-- Signals used for FIFO
144
signal FIFO_read_signal                 : std_logic := '0';
145
signal FIFO_data_out                            : std_logic_vector(31 downto 0);
146
signal FIFO_write_signal                : std_logic := '0';
147
signal FIFO_data_in                             : std_logic_vector(31 downto 0);
148
 
149
-- State machine
150
type states is  (       IDLE,
151
                                                COMPRESS_START,
152
                                                COMPRESS_START1,
153
                                                COMPRESS_START2,
154
                                                COMPRESS_INIT_BLOCKSIZE,
155
                                                COMPRESS_INIT_COMMAND,
156
                                                COMPRESS_WAIT_FILESIZE,
157
                                                COMPRESS_WAIT,
158
                                                COMPRESS_WAIT_BUS_ACK_CU,
159
                                                COMPRESS_WAIT_SEND,
160
                                                COMPRESS_SEND_DATA,
161
                                                COMPRESS_WAIT_REQ_CU,
162
                                                COMPRESS_WAIT_CU_SEND,
163
                                                COMPRESS_WAIT_INTERRUPT_REQUEST,
164
                                                COMPRESS_WAIT_NEXT_PACKET,
165
                                                DECOMPRESS_START,
166
                                                DECOMPRESS_START1,
167
                                                DECOMPRESS_START2,
168
                                                DECOMPRESS_INIT_BLOCKSIZE,
169
                                                DECOMPRESS_INIT_COMMAND,
170
                                                DECOMPRESS_WAIT,
171
                                                DECOMPRESS_WAIT_BUS_ACK_DC,
172
                                                DECOMPRESS_WAIT_SEND,
173
                                                DECOMPRESS_SEND_DATA,
174
                                                DECOMPRESS_WAIT_REQ_DC,
175
                                                DECOMPRESS_WAIT_DC_SEND,
176
                                                DECOMPRESS_WAIT_FINISH_DC,
177
                                                DECOMPRESS_WAIT_INTERRUPT_REQUEST,
178
                                                DECOMPRESS_WAIT_NEXT_PACKET,
179
                                                END_STATE);
180
signal cur_state     : states;
181
signal next_state    : states;
182
 
183
signal reg_ADDRESS              :  std_logic_vector(3 downto 0);
184
signal reg_CONTROL              :  std_logic_vector(3 downto 0);
185
signal reg_THRESHOLD            :  std_logic_vector(7 downto 0);
186
signal reg_BLOCKSIZE            :  std_logic_vector(15 downto 0);
187
 
188
signal full_CODMU               :  STD_LOGIC;
189
signal empty_CODMU              :  STD_LOGIC;
190
 
191
signal clr_CODMU                        :  STD_LOGIC;
192
 
193
signal CLR_XMATCH_C             :  STD_LOGIC := '1';
194
signal CLR_XMATCH_D             :  STD_LOGIC := '1';
195
 
196
signal reg_STATUS_CDI   :  std_logic_vector(31 downto 0) := x"00000001";
197
 
198
signal reg_FILESIZE : std_logic_vector(28 downto 0) := (others => '0');
199
 
200
signal counter_BLOCKSIZE : std_logic_vector(15 downto 0) := x"0000"; -- used for check if the uncompressed file almost reach 0
201
begin
202
 
203
status_CDI_HOST <= reg_STATUS_CDI;
204
 
205
xmatchpro : level1r
206
port map (
207
        CS                                                      => CS_bit,
208
        RW                                                      => RW_bit,
209
        ADDRESS                                                 => ADDRESS_bit,
210
        CONTROL_IN                                      => CONTROL_std,
211
        CONTROL_OUT_C                           => open,
212
        CONTROL_OUT_D                           => open,
213
        CLK                                                     => CLK_bit,
214
        CLEAR                                           => CLEAR_bit,
215
        BUS_ACKNOWLEDGE_CC              => BUS_ACKNOWLEDGE_CC_bit,
216
        BUS_ACKNOWLEDGE_CU              => BUS_ACKNOWLEDGE_CU_bit,
217
        BUS_ACKNOWLEDGE_DC              => BUS_ACKNOWLEDGE_DC_bit,
218
        BUS_ACKNOWLEDGE_DU              => BUS_ACKNOWLEDGE_DU_bit,
219
        WAIT_CU                                                 => WAIT_CU_bit,
220
   WAIT_CC                                              => WAIT_CC_bit,
221
   WAIT_DC                                              => WAIT_DC_bit,
222
        WAIT_DU                                                 => WAIT_DU_bit,
223
        U_DATAIN                                        => U_DATAIN_bit,
224
        C_DATAIN                                        => C_DATAIN_bit,
225
        U_DATAOUT                                       => U_DATAOUT_std,
226
        C_DATAOUT                                       => C_DATAOUT_std,
227
        FINISHED_C                                      => FINISHED_C_bit,
228
        FINISHED_D                                      => FINISHED_D_bit,
229
        COMPRESSING                             => COMPRESSING_bit,
230
        FLUSHING_C                                      => FLUSHING_C_bit,
231
        FLUSHING_D                                      => FLUSHING_D_bit,
232
        DECOMPRESSING                           => DECOMPRESSING_bit,
233
        U_DATA_VALID                            => U_DATA_VALID_bit,
234
        C_DATA_VALID                            => C_DATA_VALID_bit,
235
        DECODING_OVERFLOW               => DECODING_OVERFLOW_bit,
236
        CODING_OVERFLOW                         => CODING_OVERFLOW_bit,
237
        CRC_ERROR                                       => CRC_ERROR_bit,
238
        INTERRUPT_REQUEST               => INTERRUPT_REQUEST_bit,
239
        INTERRUPT_ACKNOWLEDGE   => INTERUPT_ACKNWLDGE_bit,
240
        BUS_REQUEST_CC                  => BUS_REQUEST_CC_bit,
241
        BUS_REQUEST_CU                  => BUS_REQUEST_CU_bit,
242
        BUS_REQUEST_DC                  => BUS_REQUEST_DC_bit,
243
        BUS_REQUEST_DU                  => BUS_REQUEST_DU_bit
244
 
245
);
246
 
247
---- FIFO Loopback
248
--FIFO_loopback : fifo_32x512
249
--  PORT MAP (
250
--    rst => not rst_HOST,
251
--       wr_clk => clk_HOST,
252
--       rd_clk => clk_HOST,
253
--    din => din_HOST,
254
--    wr_en => wr_en_HOST,
255
--    rd_en => rd_en_HOST,
256
--    dout => dout_HOST,
257
--    full => full_HOST,
258
--    empty => empty_HOST
259
--  );
260
 
261
FIFO_HOST2CODMU : fifo_32x512
262
  PORT MAP (
263
    rst => not rst_HOST,
264
         wr_clk => clk_HOST,
265
         rd_clk => clk_CODMU,
266
    din => din_HOST,
267
    wr_en => wr_en_HOST,
268
    rd_en => FIFO_read_signal,
269
    dout => FIFO_data_out,
270
    full => full_HOST,
271
    empty => empty_CODMU
272
  );
273
 
274
-- rst_CODMU was replaced with rst_HOST in FIFO_CODMU2HOST
275
FIFO_CODMU2HOST : fifo_32x512
276
  PORT MAP (
277
    rst => not rst_HOST,
278
         wr_clk => clk_CODMU,
279
         rd_clk => clk_HOST,
280
    din => FIFO_data_in,
281
    wr_en => FIFO_write_signal,
282
    rd_en => rd_en_HOST,
283
    dout => dout_HOST,
284
    full => full_CODMU,
285
    empty => empty_HOST
286
  );
287
 
288
-- Clock and Reset Declaration, convert from std_logic to bit to be used in Xmatch
289
CLK_bit         <= to_bit (clk_CODMU);
290
--CLEAR_bit     <= (to_bit (rst_CODMU)) and ((to_bit (CLR_XMATCH_C)) xor (to_bit (not CLR_XMATCH_D)));
291
CLEAR_bit       <= (to_bit (rst_HOST)) and ((to_bit (CLR_XMATCH_C)) xor (to_bit (not CLR_XMATCH_D)));
292
 
293
-- Note: This is bit mapping of Bus2IP_Data example
294
-- Bus2IP_Data <= "1101 1100 00001000 0000000000100000";
295
-- 1101 is the Compression Channel at R1C Register called Uncompressed Block Size Register for ADDRESS
296
-- 1100 is the Compression Channel at R0C Register called Command Register for CONTROL
297
-- 00001000 is equivalent to 8 for THRESHOLD
298
-- 0000000000100000 is equivalent to 32 which means 32 Bytes size
299
 
300
-- The IP Core read from source address and send in both U_DATAIN and C_DATAIN
301
-- The state machine will decide which will be used for Compression/Decompression
302
U_DATAIN_bit <= to_bitvector (U_DATAIN_reg);
303
C_DATAIN_bit <= to_bitvector (C_DATAIN_reg);
304
 
305
U_DATAIN_PROCESS : process (clk_CODMU, clr_CODMU, FIFO_read_signal)
306
begin
307
if (clr_CODMU = '0') then
308
        U_DATAIN_reg <= x"00000000";
309
elsif ((clk_CODMU'event) and (clk_CODMU = '1')) then
310
        if (rst_HOST = '0') then
311
                U_DATAIN_reg <= x"00000000";
312
        elsif (FIFO_read_signal = '1') then
313
                U_DATAIN_reg <= FIFO_data_out;
314
        else
315
                U_DATAIN_reg <= U_DATAIN_reg;
316
        end if;
317
end if;
318
end process U_DATAIN_PROCESS;
319
 
320
C_DATAIN_PROCESS : process (clk_CODMU, clr_CODMU, FIFO_read_signal)
321
begin
322
if (clr_CODMU = '0') then
323
        C_DATAIN_reg <= x"00000000";
324
elsif ((clk_CODMU'event) and (clk_CODMU = '1')) then
325
        if (rst_HOST = '0') then
326
                C_DATAIN_reg <= x"00000000";
327
        elsif (FIFO_read_signal = '1') then
328
                C_DATAIN_reg <= FIFO_data_out;
329
        else
330
                C_DATAIN_reg <= C_DATAIN_reg;
331
        end if;
332
end if;
333
end process C_DATAIN_PROCESS;
334
 
335
-- Acknowledgement bus from Compressor and Decompressor
336
-- CU is from Compressor to compress from Uncompressed
337
BUS_ACKNOWLEDGE_CU_PROCESS: process (clk_CODMU, clr_CODMU) is
338
begin
339
if (clr_CODMU = '0') then
340
        BUS_ACKNOWLEDGE_CU_bit <= '1';
341
elsif ((clk_CODMU'event) and (clk_CODMU = '1')) then
342
        if (BUS_REQUEST_CU_bit = '1') then
343
      BUS_ACKNOWLEDGE_CU_bit            <= '1';
344
        else
345
      BUS_ACKNOWLEDGE_CU_bit            <= '0';
346
  end if;
347
 end if;
348
end process BUS_ACKNOWLEDGE_CU_PROCESS;
349
 
350
BUS_ACKNOWLEDGE_DC_PROCESS: process (clk_CODMU, clr_CODMU) is
351
begin
352
if (clr_CODMU = '0') then
353
        BUS_ACKNOWLEDGE_DC_bit <= '1';
354
elsif ((clk_CODMU'event) and (clk_CODMU = '1')) then
355
        if (BUS_REQUEST_DC_bit = '1') then
356
      BUS_ACKNOWLEDGE_DC_bit            <= '1';
357
        else
358
      BUS_ACKNOWLEDGE_DC_bit            <= '0';
359
  end if;
360
 end if;
361
end process BUS_ACKNOWLEDGE_DC_PROCESS;
362
 
363
-- CC is from Compressor to compress becomes Compressed
364
-- DC is from Decompressor to decompress from Compressed
365
-- DU is from Decompressor to decompress becomes Uncompressed
366
--BUS_ACKNOWLEDGE_CU_bit <= BUS_REQUEST_CU_bit;
367
BUS_ACKNOWLEDGE_CC_bit <= BUS_REQUEST_CC_bit;
368
BUS_ACKNOWLEDGE_DU_bit <= BUS_REQUEST_DU_bit;
369
 
370
COMMAND_CR_PROCESS: process (clk_CODMU, clr_CODMU, command_CR_HOST) is
371
begin
372
if (clr_CODMU = '0') then
373
        reg_ADDRESS     <= (others => '0');
374
        reg_CONTROL     <= (others => '0');
375
        reg_THRESHOLD   <= (others => '0');
376
        reg_BLOCKSIZE   <= (others => '0');
377
        reg_FILESIZE    <= (others => '0');
378
elsif ((clk_CODMU'event) and (clk_CODMU = '1')) then
379
        case (command_CR_HOST(29 downto 28)) is
380
                when "01" => -- If the controller receive compress/decompress request, then save these 4 CR informations into registers
381
                        reg_ADDRESS     <= command_CR_HOST(31 downto 28);
382
                        reg_CONTROL     <= command_CR_HOST(27 downto 24);
383
                        reg_THRESHOLD   <= command_CR_HOST(23 downto 16);
384
                        reg_BLOCKSIZE   <= command_CR_HOST(15 downto  0);
385
                        reg_FILESIZE    <= (others => '0');
386
                when "10" => -- in C language, use bitwise OR operation | with 0x20000000 for filesize with optimized-compression, max filesize: 512 MB
387
                        reg_FILESIZE    <= command_CR_HOST(28 downto 0);
388
                when "11" => -- in C language, use bitwise OR operation | with 0x30000000 for filesize without optimized-compression, maxfilesize: 2^28 = 256 MB
389
                        reg_FILESIZE    <= '0' & command_CR_HOST(27 downto 0);
390
                when others =>
391
                        reg_ADDRESS     <= reg_ADDRESS;
392
                        reg_CONTROL     <= reg_CONTROL;
393
                        reg_THRESHOLD   <= reg_THRESHOLD;
394
                        reg_BLOCKSIZE   <= reg_BLOCKSIZE;
395
                        reg_FILESIZE    <= reg_FILESIZE;
396
        end case;
397
 end if;
398
end process COMMAND_CR_PROCESS;
399
 
400
COUNTER_BLOCKSIZE_PROCESS: process (clk_CODMU, clr_CODMU, cur_state, FIFO_read_signal, U_DATAIN_reg) is
401
begin
402
        if ((clk_CODMU'event) and (clk_CODMU = '1')) then
403
                if FIFO_read_signal = '1' and U_DATAIN_reg /= x"00000000" then
404
                        counter_BLOCKSIZE <= counter_BLOCKSIZE - 4;
405
                elsif (cur_state = COMPRESS_INIT_BLOCKSIZE) then -- if either Compress or Decompress
406
                        counter_BLOCKSIZE <= reg_BLOCKSIZE; -- blocksize
407
                else
408
                        counter_BLOCKSIZE <= counter_BLOCKSIZE;
409
                end if;
410
        end if;
411
end process COUNTER_BLOCKSIZE_PROCESS;
412
 
413
-- State machine sequence (synchronous process)
414
SM_SEQ: process (clk_CODMU, rst_HOST) is
415
begin
416
  if clk_CODMU'event and clk_CODMU = '1' then
417
    if rst_HOST = '0' then
418
      cur_state                         <= IDLE;
419
    else
420
      cur_state                         <= next_state;
421
    end if;
422
  end if;
423
end process SM_SEQ;
424
 
425
-- State machine (combinatorial process)
426
SM_COMB: process (cur_state, reg_ADDRESS, reg_FILESIZE, counter_BLOCKSIZE,
427
                                                BUS_REQUEST_CU_bit, FINISHED_C_bit, U_DATAIN_reg,
428
                                                BUS_REQUEST_DC_bit, FINISHED_D_bit, C_DATAIN_reg,
429
                                                wr_en_HOST, empty_CODMU, INTERRUPT_REQUEST_bit,
430
                                                COMPRESSING_bit, DECOMPRESSING_bit) is
431
begin
432
next_state                                              <= cur_state;           -- default remain current state          
433
CS_bit                                                  <= '1';
434
RW_bit                                                  <= '1';
435
ADDRESS_bit                                             <= "0011";                      -- "0011" is an unused Address which not be used by Compressor/Decompressor
436
CONTROL_std                                             <= x"00000000";
437
WAIT_CU_bit                                     <= '0';
438
WAIT_CC_bit                                     <= '1';
439
WAIT_DC_bit                                     <= '0';
440
WAIT_DU_bit                                     <= '1';
441
INTERUPT_ACKNWLDGE_bit          <= '1';
442
FIFO_read_signal                                <= '0';
443
clr_CODMU                                               <= '1';
444
CLR_XMATCH_C                                    <= '1';
445
CLR_XMATCH_D                                    <= '1';
446
reg_STATUS_CDI                          <= x"00000001";
447
 
448
case cur_state is
449
 
450
        when IDLE =>
451
                reg_STATUS_CDI <= x"00000002";
452
                case (reg_ADDRESS) is
453
                        when "1101" => next_state <=   COMPRESS_START;
454
                        when "1001" => next_state <= DECOMPRESS_START;
455
                        when others => next_state <= IDLE;
456
                end case;
457
 
458
        when COMPRESS_START =>
459
                CLR_XMATCH_C <= '0';
460
                next_state <=   COMPRESS_START1;
461
 
462
        when COMPRESS_START1 =>
463
                next_state <=   COMPRESS_START2;
464
 
465
        when COMPRESS_START2 =>
466
                next_state <=   COMPRESS_INIT_BLOCKSIZE;
467
 
468
        when COMPRESS_INIT_BLOCKSIZE =>
469
                reg_STATUS_CDI <= x"00000003";
470
                RW_bit                                                  <= '0';
471
                CS_bit                                                  <= '0';
472
                ADDRESS_bit                                             <= to_bitvector (reg_ADDRESS);
473
                CONTROL_std                                             <= x"0000" & reg_BLOCKSIZE;
474
                next_state                                              <= COMPRESS_INIT_COMMAND;
475
 
476
        when COMPRESS_INIT_COMMAND =>
477
                reg_STATUS_CDI <= x"00000004";
478
                RW_bit                                                  <= '0';
479
                CS_bit                                                  <= '0';
480
                ADDRESS_bit                                             <= to_bitvector (reg_CONTROL);
481
                CONTROL_std                                             <= "0000000000000000" & "0100" & reg_THRESHOLD & "0000";
482
                next_state                                              <= COMPRESS_WAIT_FILESIZE;
483
 
484
        when COMPRESS_WAIT_FILESIZE =>
485
                reg_STATUS_CDI <= x"00000009";
486
                if reg_FILESIZE /= x"00000000" then -- if controller has not received the filesize information yet
487
                        next_state                      <= COMPRESS_WAIT;
488
                else
489
                        next_state                      <= COMPRESS_WAIT_FILESIZE;
490
                end if;
491
 
492
        -- Compression wait if bus request CU is ready, and the FIFO of CoDMU is not empty (has data)
493
        when COMPRESS_WAIT =>
494
                reg_STATUS_CDI <= x"00000005";
495
                if BUS_REQUEST_CU_bit = '0' and empty_CODMU = '0' then
496
                        next_state                      <= COMPRESS_WAIT_BUS_ACK_CU;
497
                else
498
                        next_state                      <= COMPRESS_WAIT;
499
                end if;
500
 
501
        -- Wait for 1 clock cycle of Bus Ack CU
502
        when COMPRESS_WAIT_BUS_ACK_CU =>
503
                next_state                      <= COMPRESS_WAIT_SEND;
504
 
505
        -- FIFO read signal has one delay clock cycle, before Wait CU is asserted
506
        when COMPRESS_WAIT_SEND =>
507
                if U_DATAIN_reg /= x"00000000" then
508
                        WAIT_CU_bit <= '1'; -- the WAIT_CU will not be triggered if the first word is 0, due to absence of First Word Fall Through FIFO
509
                end if;
510
                FIFO_read_signal <= '1';
511
                next_state <= COMPRESS_SEND_DATA;
512
 
513
        -- Send data from FIFO to Xmatch
514
        when COMPRESS_SEND_DATA =>
515
                --WAIT_CU_bit <= '1';
516
                if U_DATAIN_reg /= x"00000000" then
517
                        WAIT_CU_bit <= '1'; -- the WAIT_CU will not be triggered if the first word is 0, due to absence of First Word Fall Through FIFO
518
                end if;
519
                if counter_BLOCKSIZE = x"0000" then
520
                        next_state <= COMPRESS_WAIT_REQ_CU;
521
                elsif BUS_REQUEST_CU_bit = '1' then
522
                        next_state <= COMPRESS_WAIT_REQ_CU;
523
                else
524
                        FIFO_read_signal <= '1';
525
                        next_state <= COMPRESS_SEND_DATA;
526
                end if;
527
 
528
        -- Wait if Bus Request CU is availabe (0) again
529
        when COMPRESS_WAIT_REQ_CU =>
530
                WAIT_CU_bit <= '1';
531
                if BUS_REQUEST_CU_bit = '0' then
532
                        next_state                      <= COMPRESS_WAIT_CU_SEND;
533
                elsif FINISHED_C_bit = '0' then
534
                        next_state                      <= COMPRESS_WAIT_INTERRUPT_REQUEST;
535
                else
536
                        next_state                      <= COMPRESS_WAIT_REQ_CU;
537
                end if;
538
 
539
        -- Read the first data goes out before read from FIFO again
540
        when COMPRESS_WAIT_CU_SEND =>
541
                WAIT_CU_bit <= '1';
542
                next_state      <= COMPRESS_SEND_DATA;
543
 
544
        when COMPRESS_WAIT_INTERRUPT_REQUEST =>
545
                if INTERRUPT_REQUEST_bit = '0' then
546
                        INTERUPT_ACKNWLDGE_bit <= '0';
547
                        clr_CODMU               <= '0';
548
                        next_state              <= IDLE;
549
                else
550
                        next_state              <= COMPRESS_WAIT_NEXT_PACKET;
551
                end if;
552
 
553
        when COMPRESS_WAIT_NEXT_PACKET =>
554
                if empty_CODMU = '0' then -- check if any packet left
555
                        CLR_XMATCH_C <= '0';
556
                        next_state <= COMPRESS_START; -- it will automatically starts Compressor Mode because there is still data available
557
                else
558
                        clr_CODMU       <= '0';
559
                        next_state <= IDLE;
560
                end if;
561
 
562
        when DECOMPRESS_START =>
563
                CLR_XMATCH_D <= '0';
564
                next_state <=   DECOMPRESS_START1;
565
 
566
        when DECOMPRESS_START1 =>
567
                next_state <=   DECOMPRESS_START2;
568
 
569
        when DECOMPRESS_START2 =>
570
                next_state <=   DECOMPRESS_INIT_BLOCKSIZE;
571
 
572
        when DECOMPRESS_INIT_BLOCKSIZE =>
573
                reg_STATUS_CDI <= x"00000006";
574
                RW_bit                                                  <= '0';
575
                CS_bit                                                  <= '0';
576
                ADDRESS_bit                                             <= to_bitvector (reg_ADDRESS);
577
                CONTROL_std                                             <= x"0000" & reg_BLOCKSIZE;
578
                next_state                                              <= DECOMPRESS_INIT_COMMAND;
579
 
580
        when DECOMPRESS_INIT_COMMAND =>
581
                reg_STATUS_CDI <= x"00000007";
582
                RW_bit                                                  <= '0';
583
                CS_bit                                                  <= '0';
584
                ADDRESS_bit                                             <= to_bitvector (reg_CONTROL);
585
                CONTROL_std                                             <= "0000000000000000" & "0100" & reg_THRESHOLD & "0000";
586
                next_state                                              <= DECOMPRESS_WAIT;
587
 
588
        -- Deompression wait if bus request DC is ready, and the FIFO of CoDMU is not empty (has data)
589
        when DECOMPRESS_WAIT =>
590
                reg_STATUS_CDI <= x"00000008";
591
                if BUS_REQUEST_DC_bit = '0' and empty_CODMU = '0' then
592
                        FIFO_read_signal <= '1';
593
                        next_state                      <= DECOMPRESS_WAIT_BUS_ACK_DC;
594
                else
595
                        next_state                      <= DECOMPRESS_WAIT;
596
                end if;
597
 
598
        -- Wait for 1 clock cycle of Bus Ack CU
599
        when DECOMPRESS_WAIT_BUS_ACK_DC =>
600
                next_state                      <= DECOMPRESS_WAIT_SEND;
601
 
602
        -- FIFO read signal has one delay clock cycle, before Wait DC is asserted
603
        when DECOMPRESS_WAIT_SEND =>
604
                if C_DATAIN_reg /= x"00000000" then
605
                        WAIT_DC_bit <= '1'; -- the WAIT_DC will not be triggered if the first word is 0
606
                end if;
607
                FIFO_read_signal <= '1';
608
                next_state <= DECOMPRESS_SEND_DATA;
609
 
610
        -- Send data from FIFO to Xmatch
611
        when DECOMPRESS_SEND_DATA =>
612
                WAIT_DC_bit <= '1';
613
                if C_DATAIN_reg = x"00000000" then
614
                        next_state <= DECOMPRESS_WAIT_FINISH_DC;
615
                elsif BUS_REQUEST_DC_bit = '1' then
616
                        next_state <= DECOMPRESS_WAIT_REQ_DC;
617
                else
618
                        FIFO_read_signal <= '1';
619
                        next_state <= DECOMPRESS_SEND_DATA;
620
                end if;
621
 
622
        -- Wait if Bus Request DC is availabe (0) again
623
        when DECOMPRESS_WAIT_REQ_DC =>
624
                if FINISHED_D_bit = '0' then
625
                        next_state                      <= DECOMPRESS_WAIT_INTERRUPT_REQUEST;
626
                elsif BUS_REQUEST_DC_bit = '0' then
627
                        next_state                      <= DECOMPRESS_WAIT_DC_SEND;
628
                else
629
                        next_state                      <= DECOMPRESS_WAIT_REQ_DC;
630
                end if;
631
 
632
        -- Read the first data goes out before read from FIFO again
633
        when DECOMPRESS_WAIT_DC_SEND =>
634
                WAIT_DC_bit <= '1';
635
                next_state      <= DECOMPRESS_SEND_DATA;
636
 
637
        -- The last tail was x"00000000", so WAIT_DC is asserted (with final compressed data) until BUS REQ DC has completed it's job
638
        when DECOMPRESS_WAIT_FINISH_DC =>
639
                WAIT_DC_bit <= '1';
640
                if BUS_REQUEST_DC_bit = '1' then
641
                        next_state <= DECOMPRESS_WAIT_REQ_DC;
642
                else
643
                        next_state <= DECOMPRESS_WAIT_FINISH_DC;
644
                end if;
645
 
646
        when DECOMPRESS_WAIT_INTERRUPT_REQUEST =>
647
                if INTERRUPT_REQUEST_bit = '0' then
648
                        INTERUPT_ACKNWLDGE_bit <= '0';
649
                        next_state              <= DECOMPRESS_WAIT_NEXT_PACKET;
650
--                      clr_CODMU               <= '0';
651
--                      next_state              <= IDLE;
652
                else
653
                        next_state              <= DECOMPRESS_WAIT_INTERRUPT_REQUEST;
654
                end if;
655
 
656
        when DECOMPRESS_WAIT_NEXT_PACKET =>
657
                if empty_CODMU = '0' then -- check if any packet left
658
                        CLR_XMATCH_D <= '0';
659
                        next_state <= DECOMPRESS_START; -- it will automatically starts Compressor Mode because there is still data available
660
                else
661
                        clr_CODMU       <= '0';
662
                        next_state <= IDLE;
663
                end if;
664
 
665
        when END_STATE =>
666
                if INTERRUPT_REQUEST_bit = '0' then
667
                        clr_CODMU               <= '0';
668
                        next_state              <= IDLE;
669
                else
670
                        next_state              <= END_STATE;
671
                end if;
672
 
673
  end case;
674
 
675
end process SM_COMB;
676
 
677
-- write compressed/decompressed data to write_buffer
678
write_C_D_buffer: process (clk_CODMU, C_DATA_VALID_bit, U_DATA_VALID_bit, cur_state) is
679
begin
680
        if (clk_CODMU'event) and (clk_CODMU = '1') then
681
                if cur_state = COMPRESS_WAIT_NEXT_PACKET then
682
                        FIFO_write_signal <= '1';
683
                        FIFO_data_in            <= x"00000000";
684
                elsif C_DATA_VALID_bit = '0' then
685
                        FIFO_write_signal <= '1';
686
                        FIFO_data_in            <= C_DATAOUT_std;
687
                elsif U_DATA_VALID_bit = '0' then
688
                        FIFO_write_signal <= '1';
689
                        FIFO_data_in            <= U_DATAOUT_std;
690
                else
691
                        FIFO_write_signal <= '0';
692
                        FIFO_data_in            <= x"00000000";
693
                end if;
694
        end if;
695
end process write_C_D_buffer;
696
 
697
end Behavioral;
698
 

powered by: WebSVN 2.1.0

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