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

Subversion Repositories xmatchpro

[/] [xmatchpro/] [trunk/] [xmw4-comdec/] [xmatch_sim7/] [fifo_test.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 is port
78
(
79
    rst : IN STD_LOGIC;
80
    wr_clk : IN STD_LOGIC;
81
    rd_clk : IN STD_LOGIC;
82
    din : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
83
    wr_en : IN STD_LOGIC;
84
    rd_en : IN STD_LOGIC;
85
    dout : OUT STD_LOGIC_VECTOR(31 DOWNTO 0);
86
    full : OUT STD_LOGIC;
87
         almost_full : OUT STD_LOGIC;
88
    empty : OUT STD_LOGIC
89
  );
90
end component;
91
 
92
-- All signals to convert from std_logic to bit
93
signal CS_bit                                           : bit;
94
signal RW_bit                                           : bit;
95
signal ADDRESS_bit                              : bit_vector (3 downto 0);
96
signal CONTROL_std                              : std_logic_vector (31 downto 0);
97
signal CLK_bit                                  : bit;
98
signal CLEAR_bit                                        : bit;
99
signal BUS_ACKNOWLEDGE_CC_bit   : bit := '1';
100
signal BUS_ACKNOWLEDGE_CU_bit   : bit := '1';
101
signal BUS_ACKNOWLEDGE_DC_bit   : bit := '1';
102
signal BUS_ACKNOWLEDGE_DU_bit : bit := '1';
103
signal WAIT_CU_bit                              : bit;
104
signal WAIT_CC_bit                              : bit;
105
signal WAIT_DC_bit                              : bit;
106
signal WAIT_DU_bit                              : bit;
107
signal U_DATAIN_bit                             : bit_vector (31 downto 0);
108
signal C_DATAIN_bit                             : bit_vector (31 downto 0);
109
signal C_DATAOUT_std                            : std_logic_vector (31 downto 0);
110
signal U_DATAOUT_std                            : std_logic_vector (31 downto 0);
111
signal FINISHED_C_bit                   : bit;
112
signal FINISHED_D_bit                   : bit;
113
signal U_DATA_VALID_bit                 : bit;
114
signal C_DATA_VALID_bit                 : bit;
115
signal INTERUPT_ACKNWLDGE_bit : bit;
116
signal BUS_REQUEST_CC_bit               : bit;
117
signal BUS_REQUEST_CU_bit               : bit;
118
signal BUS_REQUEST_DC_bit               : bit;
119
signal BUS_REQUEST_DU_bit               : bit;
120
signal COMPRESSING_bit                  : bit;
121
signal FLUSHING_C_bit                   : bit;
122
signal FLUSHING_D_bit                   : bit;
123
signal DECOMPRESSING_bit                : bit;
124
signal DECODING_OVERFLOW_bit    : bit;
125
signal CODING_OVERFLOW_bit      : bit;
126
signal CRC_ERROR_bit                            : bit;
127
signal INTERRUPT_REQUEST_bit    : bit;
128
 
129
signal U_DATAIN_reg                             : std_logic_vector(31 downto 0):= (others => '0');
130
signal C_DATAIN_reg                             : std_logic_vector(31 downto 0):= (others => '0');
131
 
132
-- Signals used for FIFO
133
signal FIFO_read_signal                 : std_logic := '0';
134
signal FIFO_data_out                            : std_logic_vector(31 downto 0);
135
signal FIFO_write_signal                : std_logic := '0';
136
signal FIFO_data_in                             : std_logic_vector(31 downto 0);
137
 
138
-- State machine
139
type states is  (       IDLE,
140
                                                COMPRESS_START,
141
                                                COMPRESS_START1,
142
                                                COMPRESS_START2,
143
                                                COMPRESS_INIT_BLOCKSIZE,
144
                                                COMPRESS_INIT_COMMAND,
145
                                                COMPRESS_WAIT_FILESIZE,
146
                                                COMPRESS_WAIT,
147
                                                COMPRESS_WAIT_BUS_ACK_CU,
148
                                                COMPRESS_WAIT_SEND,
149
                                                COMPRESS_SEND_DATA,
150
                                                COMPRESS_WAIT_REQ_CU,
151
                                                COMPRESS_WAIT_CU_SEND,
152
                                                COMPRESS_WAIT_INTERRUPT_REQUEST,
153
                                                COMPRESS_WAIT_NEXT_PACKET,
154
                                                COMPRESS_WAIT_EMPTY_HOST,
155
                                                DECOMPRESS_START,
156
                                                DECOMPRESS_START1,
157
                                                DECOMPRESS_START2,
158
                                                DECOMPRESS_INIT_BLOCKSIZE,
159
                                                DECOMPRESS_INIT_COMMAND,
160
                                                DECOMPRESS_WAIT,
161
                                                DECOMPRESS_WAIT_BUS_ACK_DC,
162
                                                DECOMPRESS_WAIT_SEND,
163
                                                DECOMPRESS_SEND_DATA,
164
                                                DECOMPRESS_WAIT_REQ_DC,
165
                                                DECOMPRESS_WAIT_DC_SEND,
166
                                                DECOMPRESS_WAIT_FINISH_DC,
167
                                                DECOMPRESS_WAIT_INTERRUPT_REQUEST,
168
                                                DECOMPRESS_WAIT_NEXT_PACKET,
169
                                                END_STATE);
170
signal cur_state     : states;
171
signal next_state    : states;
172
 
173
type fifo_din_states is (
174
                IDLE,
175
                S1,
176
                S2,
177
                S3,
178
                S4,
179
                S5,
180
                S6,
181
                S7,
182
                S8,S9,S10,S11
183
);
184
signal FIFO_DIN_c_state : fifo_din_states; -- current state
185
signal FIFO_DIN_n_state : fifo_din_states; -- next state
186
 
187
 
188
signal reg_ADDRESS              :  std_logic_vector(3 downto 0);
189
signal reg_CONTROL              :  std_logic_vector(3 downto 0);
190
signal reg_THRESHOLD            :  std_logic_vector(7 downto 0);
191
signal reg_BLOCKSIZE            :  std_logic_vector(31 downto 0) := (others => '0');
192
 
193
signal full_CODMU               :  STD_LOGIC;
194
signal empty_CODMU              :  STD_LOGIC;
195
 
196
signal clr_CODMU                        :  STD_LOGIC;
197
 
198
signal CLR_XMATCH_C             :  STD_LOGIC := '1';
199
signal CLR_XMATCH_D             :  STD_LOGIC := '1';
200
 
201
signal reg_FILESIZE : std_logic_vector(28 downto 0) := (others => '0');
202
 
203
signal counter_BLOCKSIZE : std_logic_vector(31 downto 0) := (others => '0'); -- used for checking purposes if the uncompressed file almost reach 0
204
 
205
signal FINISHED_C_all   :  STD_LOGIC := '0';
206
signal FINISHED_D_all   :  STD_LOGIC := '0';
207
 
208
signal status_2 : std_logic_vector(15 downto 0):= (others => '0');
209
signal status_1 : std_logic_vector(7 downto 0):= (others => '0');
210
signal status_0 : std_logic_vector(7 downto 0):= (others => '0');
211
 
212
signal full_HOST_reg            :  std_logic;
213
signal empty_CODMU_reg  :  std_logic;
214
signal full_CODMU_reg   :  std_logic;
215
signal empty_HOST_reg   :  std_logic;
216
 
217
signal bitvec_xmatch : bit_vector(13 downto 0);
218
signal stdvec_xmatch : std_logic_vector(13 downto 0);
219
 
220
signal reg_TEMP : std_logic_vector(31 downto 0);
221
 
222
begin
223
 
224
 
225
assert (C_DATAOUT_std /= "01001001110000000111111010001001")
226
  report "Value  appeared on signal"
227
  severity note;
228
 
229
status_2 <= full_HOST_reg & empty_CODMU_reg & full_CODMU_reg & empty_HOST_reg & counter_BLOCKSIZE(13 downto 2);
230
status_1 <= stdvec_xmatch(7 downto 0);
231
status_0 <= FINISHED_C_all & stdvec_xmatch(13) & FINISHED_D_all & stdvec_xmatch(12) & stdvec_xmatch(11 downto 8);
232
 
233
bitvec_xmatch <= FINISHED_C_bit & FINISHED_D_bit & CODING_OVERFLOW_bit & DECODING_OVERFLOW_bit & CRC_ERROR_bit & INTERRUPT_REQUEST_bit
234
                                        & FLUSHING_C_bit & COMPRESSING_bit & FLUSHING_D_bit & DECOMPRESSING_bit
235
                                        & BUS_REQUEST_CC_bit & BUS_REQUEST_CU_bit & BUS_REQUEST_DC_bit & BUS_REQUEST_DU_bit;
236
stdvec_xmatch <= to_stdlogicvector(bitvec_xmatch);
237
 
238
status_CDI_HOST <= status_2 & status_1 & status_0;
239
 
240
xmatchpro : level1r
241
port map (
242
        CS                                                      => CS_bit,
243
        RW                                                      => RW_bit,
244
        ADDRESS                                                 => ADDRESS_bit,
245
        CONTROL_IN                                      => CONTROL_std,
246
        CONTROL_OUT_C                           => open,
247
        CONTROL_OUT_D                           => open,
248
        CLK                                                     => CLK_bit,
249
        CLEAR                                           => CLEAR_bit,
250
        BUS_ACKNOWLEDGE_CC              => BUS_ACKNOWLEDGE_CC_bit,
251
        BUS_ACKNOWLEDGE_CU              => BUS_ACKNOWLEDGE_CU_bit,
252
        BUS_ACKNOWLEDGE_DC              => BUS_ACKNOWLEDGE_DC_bit,
253
        BUS_ACKNOWLEDGE_DU              => BUS_ACKNOWLEDGE_DU_bit,
254
        WAIT_CU                                                 => WAIT_CU_bit,
255
   WAIT_CC                                              => WAIT_CC_bit,
256
   WAIT_DC                                              => WAIT_DC_bit,
257
        WAIT_DU                                                 => WAIT_DU_bit,
258
        U_DATAIN                                        => U_DATAIN_bit,
259
        C_DATAIN                                        => C_DATAIN_bit,
260
        U_DATAOUT                                       => U_DATAOUT_std,
261
        C_DATAOUT                                       => C_DATAOUT_std,
262
        FINISHED_C                                      => FINISHED_C_bit,
263
        FINISHED_D                                      => FINISHED_D_bit,
264
        COMPRESSING                             => COMPRESSING_bit,
265
        FLUSHING_C                                      => FLUSHING_C_bit,
266
        FLUSHING_D                                      => FLUSHING_D_bit,
267
        DECOMPRESSING                           => DECOMPRESSING_bit,
268
        U_DATA_VALID                            => U_DATA_VALID_bit,
269
        C_DATA_VALID                            => C_DATA_VALID_bit,
270
        DECODING_OVERFLOW               => DECODING_OVERFLOW_bit,
271
        CODING_OVERFLOW                         => CODING_OVERFLOW_bit,
272
        CRC_ERROR                                       => CRC_ERROR_bit,
273
        INTERRUPT_REQUEST               => INTERRUPT_REQUEST_bit,
274
        INTERRUPT_ACKNOWLEDGE   => INTERUPT_ACKNWLDGE_bit,
275
        BUS_REQUEST_CC                  => BUS_REQUEST_CC_bit,
276
        BUS_REQUEST_CU                  => BUS_REQUEST_CU_bit,
277
        BUS_REQUEST_DC                  => BUS_REQUEST_DC_bit,
278
        BUS_REQUEST_DU                  => BUS_REQUEST_DU_bit
279
 
280
);
281
 
282
FIFO_HOST2CODMU : fifo_32x512
283
  PORT MAP (
284
    rst => not rst_HOST,
285
         wr_clk => clk_HOST,
286
         rd_clk => clk_CODMU,
287
    din => din_HOST,
288
    wr_en => wr_en_HOST,
289
    rd_en => FIFO_read_signal,
290
    dout => FIFO_data_out,
291
    full => full_HOST_reg,
292
         almost_full => open,
293
    empty => empty_CODMU_reg
294
  );
295
 
296
full_HOST <= full_HOST_reg;
297
empty_CODMU <= empty_CODMU_reg;
298
 
299
-- rst_CODMU was replaced with rst_HOST in FIFO_CODMU2HOST
300
FIFO_CODMU2HOST : fifo_32x512
301
  PORT MAP (
302
    rst => not rst_HOST,
303
         wr_clk => clk_CODMU,
304
         rd_clk => clk_HOST,
305
    din => FIFO_data_in,
306
    wr_en => FIFO_write_signal,
307
    rd_en => rd_en_HOST,
308
    dout => dout_HOST,
309
    full => open,
310
         almost_full => full_CODMU_reg,
311
    empty => empty_HOST_reg
312
  );
313
 
314
full_CODMU <= full_CODMU_reg;
315
empty_HOST <= empty_HOST_reg;
316
 
317
-- Clock and Reset Declaration, convert from std_logic to bit to be used in Xmatch
318
CLK_bit         <= to_bit (clk_CODMU);
319
CLEAR_bit       <= (to_bit (rst_CODMU)) and ((to_bit (CLR_XMATCH_C)) xor (to_bit (not CLR_XMATCH_D)));
320
--CLEAR_bit     <= (to_bit (CLR_XMATCH_C)) xor (to_bit (not CLR_XMATCH_D));
321
 
322
-- Note: This is bit mapping of Bus2IP_Data example
323
-- Bus2IP_Data <= "1101 1100 00001000 0000000000100000";
324
-- 1101 is the Compression Channel at R1C Register called Uncompressed Block Size Register for ADDRESS
325
-- 1100 is the Compression Channel at R0C Register called Command Register for CONTROL
326
-- 00001000 is equivalent to 8 for THRESHOLD
327
-- 0000000000100000 is equivalent to 32 which means 32 Bytes size
328
 
329
-- The IP Core read from source address and send in both U_DATAIN and C_DATAIN
330
-- The state machine will decide which will be used for Compression/Decompression
331
U_DATAIN_bit <= to_bitvector (U_DATAIN_reg);
332
C_DATAIN_bit <= to_bitvector (C_DATAIN_reg);
333
 
334
U_DATAIN_PROCESS : process (clk_CODMU, clr_CODMU, FIFO_read_signal)
335
begin
336
if (clr_CODMU = '0') then
337
        U_DATAIN_reg <= x"00000000";
338
elsif ((clk_CODMU'event) and (clk_CODMU = '1')) then
339
        if (rst_HOST = '0') then
340
                U_DATAIN_reg <= x"00000000";
341
        elsif (FIFO_read_signal = '1') then
342
                U_DATAIN_reg <= FIFO_data_out;
343
        else
344
                U_DATAIN_reg <= U_DATAIN_reg;
345
        end if;
346
        else
347
                U_DATAIN_reg <= U_DATAIN_reg;
348
end if;
349
end process U_DATAIN_PROCESS;
350
 
351
C_DATAIN_PROCESS : process (clk_CODMU, clr_CODMU, FIFO_read_signal)
352
begin
353
if (clr_CODMU = '0') then
354
        C_DATAIN_reg <= x"00000000";
355
elsif ((clk_CODMU'event) and (clk_CODMU = '1')) then
356
        if (rst_HOST = '0') then
357
                C_DATAIN_reg <= x"00000000";
358
        elsif (FIFO_read_signal = '1') then
359
                C_DATAIN_reg <= FIFO_data_out;
360
        else
361
                C_DATAIN_reg <= C_DATAIN_reg;
362
        end if;
363
else
364
        C_DATAIN_reg <= C_DATAIN_reg;
365
end if;
366
end process C_DATAIN_PROCESS;
367
 
368
-- Acknowledgement bus from Compressor and Decompressor
369
-- CU is from Compressor to compress from Uncompressed
370
BUS_ACKNOWLEDGE_CU_PROCESS: process (clk_CODMU, clr_CODMU) is
371
begin
372
if (clr_CODMU = '0') then
373
        BUS_ACKNOWLEDGE_CU_bit <= '1';
374
elsif ((clk_CODMU'event) and (clk_CODMU = '1')) then
375
        if (BUS_REQUEST_CU_bit = '1') then
376
      BUS_ACKNOWLEDGE_CU_bit            <= '1';
377
        else
378
      BUS_ACKNOWLEDGE_CU_bit            <= '0';
379
  end if;
380
 else
381
   BUS_ACKNOWLEDGE_CU_bit <= BUS_ACKNOWLEDGE_CU_bit;
382
 end if;
383
end process BUS_ACKNOWLEDGE_CU_PROCESS;
384
 
385
BUS_ACKNOWLEDGE_DC_PROCESS: process (clk_CODMU, clr_CODMU) is
386
begin
387
if (clr_CODMU = '0') then
388
        BUS_ACKNOWLEDGE_DC_bit <= '1';
389
elsif ((clk_CODMU'event) and (clk_CODMU = '1')) then
390
        if (BUS_REQUEST_DC_bit = '1') then
391
      BUS_ACKNOWLEDGE_DC_bit            <= '1';
392
        else
393
      BUS_ACKNOWLEDGE_DC_bit            <= '0';
394
  end if;
395
 else
396
        BUS_ACKNOWLEDGE_DC_bit <= BUS_ACKNOWLEDGE_DC_bit;
397
 end if;
398
end process BUS_ACKNOWLEDGE_DC_PROCESS;
399
 
400
BUS_ACKNOWLEDGE_CC_PROCESS: process (clk_CODMU, clr_CODMU) is
401
begin
402
if (clr_CODMU = '0') then
403
        BUS_ACKNOWLEDGE_CC_bit <= '1';
404
elsif ((clk_CODMU'event) and (clk_CODMU = '1')) then
405
        if (BUS_REQUEST_CC_bit = '1') then
406
      BUS_ACKNOWLEDGE_CC_bit            <= '1';
407
        else
408
      BUS_ACKNOWLEDGE_CC_bit            <= '0';
409
  end if;
410
 else
411
   BUS_ACKNOWLEDGE_CC_bit <= BUS_ACKNOWLEDGE_CC_bit;
412
 end if;
413
end process BUS_ACKNOWLEDGE_CC_PROCESS;
414
 
415
BUS_ACKNOWLEDGE_DU_PROCESS: process (clk_CODMU, clr_CODMU) is
416
begin
417
if (clr_CODMU = '0') then
418
        BUS_ACKNOWLEDGE_DU_bit <= '1';
419
elsif ((clk_CODMU'event) and (clk_CODMU = '1')) then
420
        if (BUS_REQUEST_DU_bit = '1') then
421
      BUS_ACKNOWLEDGE_DU_bit            <= '1';
422
        else
423
      BUS_ACKNOWLEDGE_DU_bit            <= '0';
424
  end if;
425
 else
426
        BUS_ACKNOWLEDGE_DU_bit <= BUS_ACKNOWLEDGE_DU_bit;
427
 end if;
428
end process BUS_ACKNOWLEDGE_DU_PROCESS;
429
 
430
 
431
 
432
 
433
 
434
-- CC is from Compressor to compress becomes Compressed
435
-- DC is from Decompressor to decompress from Compressed
436
-- DU is from Decompressor to decompress becomes Uncompressed
437
--BUS_ACKNOWLEDGE_CU_bit <= BUS_REQUEST_CU_bit;
438
--BUS_ACKNOWLEDGE_CC_bit <= BUS_REQUEST_CC_bit;
439
--BUS_ACKNOWLEDGE_DU_bit <= BUS_REQUEST_DU_bit;
440
 
441
--COMMAND_CR_PROCESS: process (clk_CODMU, clr_CODMU, command_CR_HOST) is
442
--begin
443
--if (clr_CODMU = '0') then
444
--      reg_ADDRESS     <= (others => '0');
445
--      reg_CONTROL     <= (others => '0');
446
--      reg_THRESHOLD   <= (others => '0');
447
--      reg_BLOCKSIZE   <= (others => '0');
448
--      reg_FILESIZE    <= (others => '0');
449
--elsif ((clk_CODMU'event) and (clk_CODMU = '1')) then
450
--      case (command_CR_HOST(29 downto 28)) is
451
--              when "01" => -- If the controller receive compress/decompress request, then save these 4 CR informations into registers
452
--                      reg_ADDRESS     <= command_CR_HOST(31 downto 28);
453
--                      reg_CONTROL     <= command_CR_HOST(27 downto 24);
454
--                      reg_THRESHOLD   <= command_CR_HOST(23 downto 16);
455
--                      reg_BLOCKSIZE   <= command_CR_HOST(15 downto  0);
456
--                      reg_FILESIZE    <= (others => '0');
457
--              when "10" => -- in C language, use bitwise OR operation | with 0x20000000 for filesize with optimized-compression, max filesize: 512 MB
458
--                      reg_FILESIZE    <= command_CR_HOST(28 downto 0);
459
--              when "11" => -- in C language, use bitwise OR operation | with 0x30000000 for filesize without optimized-compression, maxfilesize: 2^28 = 256 MB
460
--                      reg_FILESIZE    <= '0' & command_CR_HOST(27 downto 0);
461
--              when others =>
462
--                      reg_ADDRESS     <= reg_ADDRESS;
463
--                      reg_CONTROL     <= reg_CONTROL;
464
--                      reg_THRESHOLD   <= reg_THRESHOLD;
465
--                      reg_BLOCKSIZE   <= reg_BLOCKSIZE;
466
--                      reg_FILESIZE    <= reg_FILESIZE;
467
--      end case;       
468
-- else
469
--                      reg_ADDRESS     <= reg_ADDRESS;
470
--                      reg_CONTROL     <= reg_CONTROL;
471
--                      reg_THRESHOLD   <= reg_THRESHOLD;
472
--                      reg_BLOCKSIZE   <= reg_BLOCKSIZE;
473
--                      reg_FILESIZE    <= reg_FILESIZE;
474
-- end if;
475
--end process COMMAND_CR_PROCESS;
476
 
477
COUNTER_BLOCKSIZE_PROCESS: process (clk_CODMU, clr_CODMU, cur_state, FIFO_read_signal, U_DATAIN_reg) is
478
begin
479
        if ((clk_CODMU'event) and (clk_CODMU = '1')) then
480
                if FIFO_read_signal = '1' and U_DATAIN_reg /= x"00000000" then
481
                        counter_BLOCKSIZE <= counter_BLOCKSIZE - 4;
482
                elsif (cur_state = COMPRESS_INIT_BLOCKSIZE) then -- if either Compress or Decompress
483
                        counter_BLOCKSIZE <= reg_BLOCKSIZE; -- blocksize
484
                else
485
                        counter_BLOCKSIZE <= counter_BLOCKSIZE;
486
                end if;
487
        else
488
                counter_BLOCKSIZE <= counter_BLOCKSIZE;
489
        end if;
490
end process COUNTER_BLOCKSIZE_PROCESS;
491
 
492
---- State machine sequence (synchronous process)
493
--SM_SEQ: process (clk_CODMU, rst_HOST) is
494
--begin
495
--  if clk_CODMU'event and clk_CODMU = '1' then
496
--    if rst_HOST = '0' then
497
--      cur_state                       <= IDLE;
498
--    else
499
--      cur_state                       <= next_state;
500
--    end if;
501
--  else
502
--    cur_state                         <= cur_state;
503
--  end if;
504
--end process SM_SEQ;
505
 
506
-- State machine sequence (synchronous process)
507
SM_SEQ: process (clk_CODMU, rst_HOST) is
508
begin
509
  if clk_CODMU'event and clk_CODMU = '1' then
510
    if rst_HOST = '0' then
511
      cur_state                         <= IDLE;
512
                FIFO_DIN_c_state        <= IDLE;
513
    else
514
      cur_state                         <= next_state;
515
                FIFO_DIN_c_state        <= FIFO_DIN_n_state;
516
    end if;
517
        else
518
        cur_state                       <= cur_state;
519
        FIFO_DIN_c_state        <= FIFO_DIN_c_state;
520
  end if;
521
end process SM_SEQ;
522
 
523
-- State machine (combinatorial process)
524
SM_COMB: process (cur_state, reg_ADDRESS, reg_FILESIZE, counter_BLOCKSIZE, command_CR_HOST,
525
                                                BUS_REQUEST_CU_bit, FINISHED_C_bit, U_DATAIN_reg,
526
                                                BUS_REQUEST_DC_bit, FINISHED_D_bit, C_DATAIN_reg,
527
                                                wr_en_HOST, empty_CODMU, INTERRUPT_REQUEST_bit, empty_HOST_reg,
528
                                                COMPRESSING_bit, DECOMPRESSING_bit) is
529
begin
530
next_state                                              <= cur_state;           -- default remain current state          
531
CS_bit                                                  <= '1';
532
RW_bit                                                  <= '1';
533
ADDRESS_bit                                             <= "0011";                      -- "0011" is an unused Address which not be used by Compressor/Decompressor
534
CONTROL_std                                             <= x"00000000";
535
WAIT_CU_bit                                     <= '0';
536
WAIT_DC_bit                                     <= '0';
537
INTERUPT_ACKNWLDGE_bit          <= '1';
538
FIFO_read_signal                                <= '0';
539
clr_CODMU                                               <= '1';
540
CLR_XMATCH_C                                    <= '1';
541
CLR_XMATCH_D                                    <= '1';
542
FINISHED_C_all                          <= '0';
543
FINISHED_D_all                          <= '0';
544
 
545
case cur_state is
546
 
547
        when IDLE =>
548
                -- command_CR_HOST(31 downto 28) is the ADDRESS register of XMatch
549
                case (command_CR_HOST(31 downto 28)) is
550
                        when "1101" => next_state <=   COMPRESS_START;
551
                        when "1001" => next_state <= DECOMPRESS_START;
552
                        when others => next_state <= IDLE;
553
                end case;
554
 
555
        when COMPRESS_START =>
556
                CLR_XMATCH_C <= '0';
557
                next_state <=   COMPRESS_START1;
558
 
559
        when COMPRESS_START1 =>
560
                reg_ADDRESS <= command_CR_HOST(31 downto 28);
561
                reg_CONTROL <= command_CR_HOST(27 downto 24);
562
                reg_THRESHOLD <= command_CR_HOST(23 downto 16);
563
                reg_TEMP <= command_CR_HOST; -- a temporary register to hold the previous value of command_CR
564
                next_state <=   COMPRESS_START2;
565
 
566
        when COMPRESS_START2 =>
567
                if (command_CR_HOST = reg_TEMP) then
568
                        next_state <=   COMPRESS_START2;
569
                else
570
                        reg_BLOCKSIZE <= command_CR_HOST;
571
                        next_state <=   COMPRESS_INIT_BLOCKSIZE;
572
                end if;
573
 
574
        when COMPRESS_INIT_BLOCKSIZE =>
575
                RW_bit                                                  <= '0';
576
                CS_bit                                                  <= '0';
577
                ADDRESS_bit                                             <= to_bitvector (reg_ADDRESS);
578
                --CONTROL_std                                           <= x"0000" & reg_BLOCKSIZE;
579
                CONTROL_std                                             <= reg_BLOCKSIZE;
580
                next_state                                              <= COMPRESS_INIT_COMMAND;
581
 
582
        when COMPRESS_INIT_COMMAND =>
583
                RW_bit                                                  <= '0';
584
                CS_bit                                                  <= '0';
585
                ADDRESS_bit                                             <= to_bitvector (reg_CONTROL);
586
                CONTROL_std                                             <= "0000000000000000" & "0100" & reg_THRESHOLD & "0000";
587
                next_state                                              <= COMPRESS_WAIT; -- skip COMPRESS_WAIT_FILESIZE
588
 
589
        when COMPRESS_WAIT_FILESIZE =>
590
                if reg_FILESIZE /= x"00000000" then -- if controller has not received the filesize information yet
591
                        next_state                      <= COMPRESS_WAIT;
592
                else
593
                        next_state                      <= COMPRESS_WAIT_FILESIZE;
594
                end if;
595
 
596
        -- Compression wait if bus request CU is ready, and the FIFO of CoDMU is not empty (has data)
597
        when COMPRESS_WAIT =>
598
                if BUS_REQUEST_CU_bit = '0' and empty_CODMU = '0' then
599
                        next_state                      <= COMPRESS_WAIT_BUS_ACK_CU;
600
                else
601
                        next_state                      <= COMPRESS_WAIT;
602
                end if;
603
 
604
        -- Wait for 1 clock cycle of Bus Ack CU
605
        when COMPRESS_WAIT_BUS_ACK_CU =>
606
                next_state                      <= COMPRESS_WAIT_SEND;
607
 
608
        -- FIFO read signal has one delay clock cycle, before Wait CU is asserted
609
        when COMPRESS_WAIT_SEND =>
610
                if U_DATAIN_reg /= x"00000000" then
611
                        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
612
                else
613
                        WAIT_CU_bit <= '0';
614
                end if;
615
                FIFO_read_signal <= '1';
616
                next_state <= COMPRESS_SEND_DATA;
617
 
618
        -- Send data from FIFO to Xmatch
619
        when COMPRESS_SEND_DATA =>
620
                --WAIT_CU_bit <= '1';
621
                if U_DATAIN_reg /= x"00000000" then
622
                        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
623
                else
624
                        WAIT_CU_bit <= '0';
625
                end if;
626
                if counter_BLOCKSIZE = x"0000" then
627
                        next_state <= COMPRESS_WAIT_REQ_CU;
628
                elsif BUS_REQUEST_CU_bit = '1' then
629
                        WAIT_CU_bit <= '0';
630
                        next_state <= COMPRESS_WAIT_REQ_CU;
631
                else
632
                        FIFO_read_signal <= '1';
633
                        next_state <= COMPRESS_SEND_DATA;
634
                end if;
635
 
636
        -- Wait if Bus Request CU is availabe (0) again
637
        when COMPRESS_WAIT_REQ_CU =>
638
--              WAIT_CU_bit <= '1';
639
                if BUS_REQUEST_CU_bit = '0' then
640
                        next_state                      <= COMPRESS_WAIT_CU_SEND;
641
                elsif FINISHED_C_bit = '0' then
642
                        next_state                      <= COMPRESS_WAIT_NEXT_PACKET;
643
                else
644
                        next_state                      <= COMPRESS_WAIT_REQ_CU;
645
                end if;
646
 
647
        -- Read the first data goes out before read from FIFO again
648
        when COMPRESS_WAIT_CU_SEND =>
649
                --WAIT_CU_bit <= '1';
650
                next_state      <= COMPRESS_SEND_DATA;
651
 
652
        when COMPRESS_WAIT_INTERRUPT_REQUEST =>
653
                if INTERRUPT_REQUEST_bit = '0' then
654
                        INTERUPT_ACKNWLDGE_bit <= '0';
655
                        clr_CODMU               <= '0';
656
                        next_state              <= COMPRESS_WAIT_EMPTY_HOST;
657
                else
658
                        next_state              <= COMPRESS_WAIT_INTERRUPT_REQUEST;
659
                end if;
660
 
661
        when COMPRESS_WAIT_NEXT_PACKET =>
662
                if empty_CODMU = '0' then -- check if any packet left
663
                        CLR_XMATCH_C <= '0';
664
                        next_state <= COMPRESS_START; -- it will automatically starts Compressor Mode because there is still data available
665
                else
666
--                      
667
--                      clr_CODMU       <= '0';
668
                        next_state <= COMPRESS_WAIT_INTERRUPT_REQUEST;
669
                end if;
670
 
671
        when COMPRESS_WAIT_EMPTY_HOST =>
672
                if empty_HOST_reg = '1' then
673
                        FINISHED_C_all <= '1';
674
                        next_state              <= IDLE;
675
                else
676
                        next_state              <= COMPRESS_WAIT_EMPTY_HOST;
677
                end if;
678
 
679
--      when COMPRESS_START1 =>
680
--              reg_ADDRESS <= command_CR_HOST(31 downto 28);
681
--              reg_CONTROL <= command_CR_HOST(27 downto 24);
682
--              reg_THRESHOLD <= command_CR_HOST(23 downto 16);
683
--              reg_TEMP <= command_CR_HOST; -- a temporary register to hold the previous value of command_CR
684
--              next_state <=   COMPRESS_START2;
685
--
686
--      when COMPRESS_START2 =>
687
--              if (command_CR_HOST = reg_TEMP) then
688
--                      next_state <=   COMPRESS_START2;        
689
--              else
690
--                      reg_BLOCKSIZE <= command_CR_HOST;
691
--                      next_state <=   COMPRESS_INIT_BLOCKSIZE;        
692
--              end if;
693
 
694
        when DECOMPRESS_START =>
695
                CLR_XMATCH_D <= '0';
696
                next_state <=   DECOMPRESS_START1;
697
 
698
        when DECOMPRESS_START1 =>
699
                reg_ADDRESS <= command_CR_HOST(31 downto 28);
700
                reg_CONTROL <= command_CR_HOST(27 downto 24);
701
                reg_THRESHOLD <= command_CR_HOST(23 downto 16);
702
                reg_TEMP <= command_CR_HOST; -- a temporary register to hold the previous value of command_CR
703
                next_state <=   DECOMPRESS_START2;
704
 
705
        when DECOMPRESS_START2 =>
706
                if (command_CR_HOST = reg_TEMP) then
707
                        next_state <=   DECOMPRESS_START2;
708
                else
709
                        reg_BLOCKSIZE <= command_CR_HOST;
710
                        next_state <=   DECOMPRESS_INIT_BLOCKSIZE;
711
                end if;
712
 
713
 
714
        when DECOMPRESS_INIT_BLOCKSIZE =>
715
                RW_bit                                                  <= '0';
716
                CS_bit                                                  <= '0';
717
                ADDRESS_bit                                             <= to_bitvector (reg_ADDRESS);
718
                --CONTROL_std                                           <= x"0000" & reg_BLOCKSIZE;
719
                CONTROL_std                                             <= reg_BLOCKSIZE;
720
                next_state                                              <= DECOMPRESS_INIT_COMMAND;
721
 
722
        when DECOMPRESS_INIT_COMMAND =>
723
                RW_bit                                                  <= '0';
724
                CS_bit                                                  <= '0';
725
                ADDRESS_bit                                             <= to_bitvector (reg_CONTROL);
726
                CONTROL_std                                             <= "0000000000000000" & "0100" & reg_THRESHOLD & "0000";
727
                next_state                                              <= DECOMPRESS_WAIT;
728
 
729
        -- Deompression wait if bus request DC is ready, and the FIFO of CoDMU is not empty (has data)
730
        when DECOMPRESS_WAIT =>
731
                if BUS_REQUEST_DC_bit = '0' and empty_CODMU = '0' then
732
                        FIFO_read_signal <= '1';
733
                        next_state                      <= DECOMPRESS_WAIT_BUS_ACK_DC;
734
                else
735
                        next_state                      <= DECOMPRESS_WAIT;
736
                end if;
737
 
738
        -- Wait for 1 clock cycle of Bus Ack CU
739
        when DECOMPRESS_WAIT_BUS_ACK_DC =>
740
                next_state                      <= DECOMPRESS_WAIT_SEND;
741
 
742
        -- FIFO read signal has one delay clock cycle, before Wait DC is asserted
743
        when DECOMPRESS_WAIT_SEND =>
744
                if C_DATAIN_reg /= x"00000000" then
745
                        WAIT_DC_bit <= '1'; -- the WAIT_DC will not be triggered if the first word is 0
746
                else
747
                        WAIT_DC_bit <= '0';
748
                end if;
749
                FIFO_read_signal <= '1';
750
                next_state <= DECOMPRESS_SEND_DATA;
751
 
752
        -- Send data from FIFO to Xmatch
753
        when DECOMPRESS_SEND_DATA =>
754
 
755
                if C_DATAIN_reg = x"00000000" then
756
                        next_state <= DECOMPRESS_WAIT_FINISH_DC;
757
                elsif BUS_REQUEST_DC_bit = '1' then
758
                        next_state <= DECOMPRESS_WAIT_REQ_DC;
759
                else
760
                        WAIT_DC_bit <= '1';
761
                        FIFO_read_signal <= '1';
762
                        next_state <= DECOMPRESS_SEND_DATA;
763
                end if;
764
 
765
        -- Wait if Bus Request DC is availabe (0) again
766
        when DECOMPRESS_WAIT_REQ_DC =>
767
                if FINISHED_D_bit = '0' then
768
                        next_state                      <= DECOMPRESS_WAIT_INTERRUPT_REQUEST;
769
                elsif BUS_REQUEST_DC_bit = '0' then
770
                        next_state                      <= DECOMPRESS_WAIT_DC_SEND;
771
                else
772
                        next_state                      <= DECOMPRESS_WAIT_REQ_DC;
773
                end if;
774
 
775
        -- Read the first data goes out before read from FIFO again
776
        when DECOMPRESS_WAIT_DC_SEND =>
777
                next_state      <= DECOMPRESS_SEND_DATA;
778
 
779
        -- The last tail was x"00000000", so WAIT_DC is asserted (with final compressed data) until BUS REQ DC has completed it's job
780
        when DECOMPRESS_WAIT_FINISH_DC =>
781
                WAIT_DC_bit <= '1';
782
                if BUS_REQUEST_DC_bit = '1' then
783
                        next_state <= DECOMPRESS_WAIT_REQ_DC;
784
                else
785
                        next_state <= DECOMPRESS_WAIT_FINISH_DC;
786
                end if;
787
 
788
        when DECOMPRESS_WAIT_INTERRUPT_REQUEST =>
789
                if INTERRUPT_REQUEST_bit = '0' then
790
                        INTERUPT_ACKNWLDGE_bit <= '0';
791
                        next_state              <= DECOMPRESS_WAIT_NEXT_PACKET;
792
--                      clr_CODMU               <= '0';
793
--                      next_state              <= IDLE;
794
                else
795
                        next_state              <= DECOMPRESS_WAIT_INTERRUPT_REQUEST;
796
                end if;
797
 
798
        when DECOMPRESS_WAIT_NEXT_PACKET =>
799
                if empty_CODMU = '0' then -- check if any packet left
800
                        CLR_XMATCH_D <= '0';
801
                        next_state <= DECOMPRESS_START; -- it will automatically starts Compressor Mode because there is still data available
802
                else
803
                        FINISHED_D_all <= '1';
804
                        clr_CODMU       <= '0';
805
                        next_state <= IDLE;
806
                end if;
807
 
808
        when END_STATE =>
809
                if INTERRUPT_REQUEST_bit = '0' then
810
                        clr_CODMU               <= '0';
811
                        next_state              <= IDLE;
812
                else
813
                        next_state              <= END_STATE;
814
                end if;
815
 
816
        when others =>
817
 
818
  end case;
819
 
820
end process SM_COMB;
821
 
822
WAIT_DU_PROCESS: process (full_CODMU) is
823
begin
824
                if (full_CODMU = '0') then
825
                        WAIT_DU_bit             <= '1';
826
                else
827
                        WAIT_DU_bit             <= '0';
828
                end if;
829
end process WAIT_DU_PROCESS;
830
 
831
WAIT_CC_PROCESS: process (full_CODMU) is
832
begin
833
                if (full_CODMU = '0') then
834
                        WAIT_CC_bit             <= '1';
835
                else
836
                        WAIT_CC_bit             <= '0';
837
                end if;
838
end process WAIT_CC_PROCESS;
839
--
840
---- State machine (combinatorial process)
841
--SM_COMB1: process (   FIFO_DIN_c_state, reg_FILESIZE,
842
--                                                      empty_CODMU, full_CODMU, 
843
--                                                      C_DATAOUT_std, FLUSHING_C_bit, FINISHED_C_bit, C_DATA_VALID_bit,
844
--                                                      U_DATAOUT_std, FLUSHING_D_bit, FINISHED_D_bit, U_DATA_VALID_bit, BUS_REQUEST_DU_bit
845
--                                                      ) is
846
--begin
847
--
848
--FIFO_data_in <= x"00000000";
849
--FIFO_DIN_n_state      <= FIFO_DIN_c_state;
850
--FIFO_write_signal <= '0';
851
--WAIT_DU_bit           <= '1';
852
--WAIT_CC_bit           <= '1';
853
--
854
--case FIFO_DIN_c_state is   
855
--
856
--      when IDLE =>
857
--              if BUS_REQUEST_DU_bit = '0' then
858
--                      FIFO_DIN_n_state <= S1;
859
--              elsif BUS_REQUEST_CC_bit = '0' then
860
--                      FIFO_DIN_n_state <= S4;
861
--              else
862
--                      FIFO_DIN_n_state <= IDLE;
863
--              end if;
864
--
865
--      when S1 =>
866
--              if U_DATA_VALID_bit = '0' then
867
--                      FIFO_write_signal <= '1';
868
--                      FIFO_data_in            <= U_DATAOUT_std;
869
--              else
870
--                      FIFO_write_signal <= '0';
871
--                      FIFO_data_in            <= FIFO_data_in;
872
--              end if;
873
--              if full_CODMU = '1' then
874
--                      FIFO_DIN_n_state <= S3;
875
--              else
876
--                      FIFO_DIN_n_state <= S1;
877
--              end if;
878
--              
879
--      -- wait until it is not empty
880
--      when S2 =>
881
--              FIFO_DIN_n_state <= S1;
882
--      
883
--      when S3 =>
884
--              WAIT_DU_bit             <= '0';
885
----                    FIFO_write_signal <= '1';
886
----                    FIFO_data_in            <= U_DATAOUT_std;
887
--              if full_CODMU = '1' then
888
--                      FIFO_DIN_n_state <= S2;
889
--              else
890
--                      FIFO_DIN_n_state <= S1;
891
--              end if;
892
--              
893
--      when S4 =>
894
--              if C_DATA_VALID_bit = '0' then
895
--                      FIFO_write_signal <= '1';
896
--                      FIFO_data_in            <= C_DATAOUT_std;
897
--              else
898
--                      FIFO_write_signal <= '0';
899
--                      FIFO_data_in            <= FIFO_data_in;
900
--              end if;
901
--              if full_CODMU = '1' then
902
--                      FIFO_DIN_n_state <= S6;
903
--              else
904
--                      FIFO_DIN_n_state <= S4;
905
--              end if;
906
--      
907
--      when S5 =>
908
--              FIFO_DIN_n_state <= S4;
909
--      
910
--      when S6 =>
911
--              WAIT_CC_bit             <= '0';
912
----                    FIFO_write_signal <= '1';
913
----                    FIFO_data_in            <= U_DATAOUT_std;
914
--              if full_CODMU = '1' then
915
--                      FIFO_DIN_n_state <= S5;
916
--              else
917
--                      FIFO_DIN_n_state <= S4;
918
--              end if;
919
--              
920
--      when S7 =>
921
--
922
--      
923
--      when S8 =>
924
--
925
--              
926
--      when S9 =>
927
--
928
--      
929
--      when S10 =>
930
--
931
--      
932
--      when S11 =>
933
--
934
--              
935
--      when others =>
936
--              
937
--end case;
938
--  
939
--end process SM_COMB1;
940
 
941
-- write compressed/decompressed data to write_buffer
942
write_C_D_buffer: process (clk_CODMU, C_DATA_VALID_bit, U_DATA_VALID_bit, cur_state) is
943
begin
944
        if (clk_CODMU'event) and (clk_CODMU = '1') then
945
                if cur_state = COMPRESS_WAIT_NEXT_PACKET then
946
                        FIFO_write_signal <= '1';
947
                        FIFO_data_in            <= x"00000001";
948
                elsif C_DATA_VALID_bit = '0' then
949
                        FIFO_write_signal <= '1';
950
                        FIFO_data_in            <= C_DATAOUT_std;
951
                elsif U_DATA_VALID_bit = '0' then
952
                        FIFO_write_signal <= '1';
953
                        FIFO_data_in            <= U_DATAOUT_std;
954
                else
955
                        FIFO_write_signal <= '0';
956
                        FIFO_data_in            <= x"00000000";
957
                end if;
958
        end if;
959
end process write_C_D_buffer;
960
 
961
end Behavioral;
962
 

powered by: WebSVN 2.1.0

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