OpenCores
URL https://opencores.org/ocsvn/lzrw1-compressor-core/lzrw1-compressor-core/trunk

Subversion Repositories lzrw1-compressor-core

[/] [lzrw1-compressor-core/] [trunk/] [hw/] [HDL/] [history.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 habicht
--/**************************************************************************************************************
2
--*
3
--*    L Z R W 1   E N C O D E R   C O R E
4
--*
5
--*  A high throughput loss less data compression core.
6
--* 
7
--* Copyright 2012-2013   Lukas Schrittwieser (LS)
8
--*
9
--*    This program is free software: you can redistribute it and/or modify
10
--*    it under the terms of the GNU General Public License as published by
11
--*    the Free Software Foundation, either version 2 of the License, or
12
--*    (at your option) any later version.
13
--*
14
--*    This program is distributed in the hope that it will be useful,
15
--*    but WITHOUT ANY WARRANTY; without even the implied warranty of
16
--*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
--*    GNU General Public License for more details.
18
--*
19
--*    You should have received a copy of the GNU General Public License
20
--*    along with this program; if not, write to the Free Software
21
--*    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
22
--*    Or see <http://www.gnu.org/licenses/>
23
--*
24
--***************************************************************************************************************
25
--*
26
--* Change Log:
27
--*
28
--* Version 1.0 - 2012/6/21 - LS
29
--*   started file
30
--*
31
--* Version 1.0 - 2013/04/05 - LS
32
--*   release
33
--*
34
--***************************************************************************************************************
35
--*
36
--* Naming convention:  http://dz.ee.ethz.ch/en/information/hdl-help/vhdl-naming-conventions.html
37
--*
38
--***************************************************************************************************************
39
--*
40
--* 
41
--*
42
--***************************************************************************************************************
43
 
44
library IEEE;
45
use IEEE.STD_LOGIC_1164.all;
46
use IEEE.NUMERIC_STD.all;
47
 
48
library UNISIM;
49
use UNISIM.VComponents.all;
50
 
51
entity historyBuffer is
52
 
53
 
54
  port (
55
    ClkxCI          : in  std_logic;
56
    RstxRI          : in  std_logic;
57
    WriteInxDI      : in  std_logic_vector(7 downto 0);
58
    WExSI           : in  std_logic;
59
    NextWrAdrxDO    : out std_logic_vector(11 downto 0);  -- memory address at which the next byte will be written
60
    RExSI           : in  std_logic;    -- initiate a memory read back
61
    ReadBackAdrxDI  : in  std_logic_vector(11 downto 2);  -- for speed up read back is only word adressable
62
    ReadBackxDO     : out std_logic_vector(16*8-1 downto 0);
63
    ReadBackDonexSO : out std_logic);  -- indicates that requested read back data is available
64
 
65
end historyBuffer;
66
 
67
 
68
architecture Behavioral of historyBuffer is
69
 
70
  signal WrPtrxDN, WrPtrxDP                     : std_logic_vector(11 downto 0) := (others => '0');
71
  signal Ram0RdAdrAxD, Ram0RdAdrBxD             : std_logic_vector(13 downto 0);
72
  signal Ram1RdAdrAxD, Ram1RdAdrBxD             : std_logic_vector(13 downto 0);
73
  signal Ram0AdrAxD, Ram1AdrAxD                 : std_logic_vector(13 downto 0);
74
  signal RamWrDataxD                            : std_logic_vector(31 downto 0);
75
  signal Ram0OutAxD, Ram0OutBxD                 : std_logic_vector(31 downto 0);
76
  signal Ram1OutAxD, Ram1OutBxD                 : std_logic_vector(31 downto 0);
77
  signal Ram0WExS, Ram1WExS                     : std_logic_vector(3 downto 0);
78
  signal Ram0EnAxS, Ram1EnAxS                   : std_logic;
79
  signal RdAdrIntxD                             : integer;  -- to split up long expressions (type casts)
80
  signal Ram0RdAdrBasexD, Ram1RdAdrBasexD       : integer;
81
  signal DataReadyxSN, DataReadyxSP             : std_logic;
82
  signal LastReadBackAdrxDN, LastReadBackAdrxDP : std_logic_vector(11 downto 2);
83
 
84
begin
85
 
86
-- Note: If the requested address is not a multiple of 8 (ie bit 2 is 1) the
87
-- first word (4 bytes) we read is in ram 1. Therefore the adress for ram 0 has
88
-- to be incremented by 1. 
89
  RdAdrIntxD      <= to_integer(unsigned(ReadBackAdrxDI(11 downto 3)));
90
  Ram0RdAdrBasexD <= RdAdrIntxD   when ReadBackAdrxDI(2) = '0' else (RdAdrIntxD+1);
91
  Ram1RdAdrBasexD <= RdAdrIntxD;
92
  Ram0RdAdrAxD    <= std_logic_vector(to_unsigned(Ram0RdAdrBasexD, 9)) & "00000";
93
  Ram0RdAdrBxD    <= std_logic_vector(to_unsigned(Ram0RdAdrBasexD+1, 9)) & "00000";
94
  Ram1RdAdrAxD    <= std_logic_vector(to_unsigned(Ram1RdAdrBasexD, 9)) & "00000";
95
  Ram1RdAdrBxD    <= std_logic_vector(to_unsigned(Ram1RdAdrBasexD+1, 9)) & "00000";
96
  -- select port A address based on read/write mode
97
  Ram0AdrAxD      <= Ram0RdAdrAxD when WExSI = '0' else (WrPtrxDP(11 downto 3)& "00000");
98
  Ram1AdrAxD      <= Ram1RdAdrAxD when WExSI = '0' else (WrPtrxDP(11 downto 3) & "00000");
99
--  Ram0AdrAxD      <= Ram0RdAdrAxD when WExSI = '0' else (WrAdrxDI(11 downto 3)& "00000");
100
--  Ram1AdrAxD      <= Ram1RdAdrAxD when WExSI = '0' else (WrAdrxDI(11 downto 3) & "00000");
101
 
102
 
103
  RamWrDataxD <= WriteInxDI & WriteInxDI & WriteInxDI & WriteInxDI;
104
 
105
  -- The memory behaves like a register -> save requested adress for output decoder
106
  LastReadBackAdrxDN <= ReadBackAdrxDI;
107
 
108
  -- the read back value is reordered depending on wether the requested address
109
-- is a multiple of 8 or not. See comment above.
110
  ReadBackxDO <= (Ram1OutBxD & Ram0OutBxD & Ram1OutAxD & Ram0OutAxD) when LastReadBackAdrxDP(2) = '0' else (Ram0OutBxD & Ram1OutBxD & Ram0OutAxD & Ram1OutAxD);
111
 
112
  Ram0EnAxS <= WExSI or RExSI;
113
  Ram1EnAxS <= WExSI or RExSI;
114
 
115
  -- implement a write address counter
116
  wrCntPrcs : process (WExSI, WrPtrxDP)
117
  begin
118
    WrPtrxDN <= WrPtrxDP;
119
    Ram0WExS <= "0000";
120
    Ram1WExS <= "0000";
121
    if WExSI = '1' then
122
      if WrPtrxDP = x"fff" then
123
        WrPtrxDN <= x"000";
124
      else
125
        WrPtrxDN <= std_logic_vector(to_unsigned(to_integer(unsigned(WrPtrxDP))+1, 12));
126
      end if;
127
      -- decode lower 3 bits to the 8 write enable lines
128
      if WrPtrxDP(2) = '0' then
129
        -- write to ram 0
130
        Ram0WExS(to_integer(unsigned(WrPtrxDP(1 downto 0)))) <= '1';
131
      else
132
        Ram1WExS(to_integer(unsigned(WrPtrxDP(1 downto 0)))) <= '1';
133
      end if;
134
--      if WrAdrxDI(2) = '0' then
135
--        -- write to ram 0
136
--        Ram0WExS(to_integer(unsigned(WrAdrxDI(1 downto 0)))) <= '1';
137
--      else
138
--        Ram1WExS(to_integer(unsigned(WrAdrxDI(1 downto 0)))) <= '1';
139
--      end if;
140
 
141
    end if;
142
  end process wrCntPrcs;
143
 
144
  DataReadyxSN    <= RExSI;             -- it takes one clock cycle to read the
145
-- data, delay read enable for one cycle to create a output valid signal
146
  NextWrAdrxDO    <= WrPtrxDP;
147
  ReadBackDonexSO <= DataReadyxSP;
148
 
149
  process (ClkxCI, RstxRI)
150
  begin  -- process
151
    if RstxRI = '1' then
152
      LastReadBackAdrxDP <= (others => '0');
153
      WrPtrxDP           <= (others => '0');
154
      DataReadyxSP       <= '0';
155
    elsif ClkxCI'event and ClkxCI = '1' then  -- rising clock edge
156
      LastReadBackAdrxDP <= LastReadBackAdrxDN;
157
      WrPtrxDP           <= WrPtrxDN;
158
      DataReadyxSP       <= DataReadyxSN;
159
    end if;
160
  end process;
161
 
162
  -- port A is used to write and read (lower bytes) data, port B is for read only
163
  HistMem0Inst : RAMB16BWER
164
    generic map (
165
      -- DATA_WIDTH_A/DATA_WIDTH_B: 0, 1, 2, 4, 9, 18, or 36
166
      DATA_WIDTH_A        => 36,
167
      DATA_WIDTH_B        => 36,
168
      -- DOA_REG/DOB_REG: Optional output register (0 or 1)
169
      DOA_REG             => 0,
170
      DOB_REG             => 0,
171
      -- EN_RSTRAM_A/EN_RSTRAM_B: Enable/disable RST
172
      EN_RSTRAM_A         => true,
173
      EN_RSTRAM_B         => true,
174
      -- INIT_A/INIT_B: Initial values on output port
175
      INIT_A              => X"000000000",
176
      INIT_B              => X"000000000",
177
      -- INIT_FILE: Optional file used to specify initial RAM contents
178
      INIT_FILE           => "NONE",
179
      -- RSTTYPE: "SYNC" or "ASYNC" 
180
      RSTTYPE             => "SYNC",
181
      -- RST_PRIORITY_A/RST_PRIORITY_B: "CE" or "SR" 
182
      RST_PRIORITY_A      => "CE",
183
      RST_PRIORITY_B      => "CE",
184
      -- SIM_COLLISION_CHECK: Collision check enable "ALL", "WARNING_ONLY", "GENERATE_X_ONLY" or "NONE" 
185
      SIM_COLLISION_CHECK => "ALL",
186
      -- SIM_DEVICE: Must be set to "SPARTAN6" for proper simulation behavior
187
      SIM_DEVICE          => "SPARTAN6",
188
      -- SRVAL_A/SRVAL_B: Set/Reset value for RAM output
189
      SRVAL_A             => X"000000000",
190
      SRVAL_B             => X"000000000",
191
      -- WRITE_MODE_A/WRITE_MODE_B: "WRITE_FIRST", "READ_FIRST", or "NO_CHANGE" 
192
      WRITE_MODE_A        => "WRITE_FIRST",
193
      WRITE_MODE_B        => "WRITE_FIRST"
194
      )
195
    port map (
196
      -- Port A Data: 32-bit (each) Port A data
197
      DOA    => Ram0OutAxD,             -- 32-bit A port data output
198
      DOPA   => open,                   -- 4-bit A port parity output
199
      -- Port B Data: 32-bit (each) Port B data
200
      DOB    => Ram0OutBxD,
201
      DOPB   => open,
202
      -- Port A Address/Control Signals: 14-bit (each) Port A address and control signals
203
      ADDRA  => Ram0AdrAxD,             -- 14-bit A port address input
204
      CLKA   => ClkxCI,                 -- 1-bit A port clock input
205
      ENA    => Ram0EnAxS,              -- 1-bit A port enable input
206
      REGCEA => '1',           -- 1-bit A port register clock enable input
207
      RSTA   => RstxRI,        -- 1-bit A port register set/reset input
208
      WEA    => Ram0WExS,      -- 4-bit Port A byte-wide write enable input
209
      -- Port A Data: 32-bit (each) Port A data
210
      DIA    => RamWrDataxD,            -- 32-bit A port data input
211
      DIPA   => "0000",                 -- 4-bit A port parity input
212
      -- Port B Address/Control Signals: 14-bit (each) Port B address and control signals
213
      ADDRB  => Ram0RdAdrBxD,           -- 14-bit B port address input
214
      CLKB   => ClkxCI,                 -- 1-bit B port clock input
215
      ENB    => RExSI,                  -- 1-bit B port enable input
216
      REGCEB => '1',           -- 1-bit B port register clock enable input
217
      RSTB   => RstxRI,        -- 1-bit B port register set/reset input
218
      WEB    => x"0",          -- 4-bit Port B byte-wide write enable input
219
      -- Port B Data: 32-bit (each) Port B data
220
      DIB    => x"00000000",            -- 32-bit B port data input
221
      DIPB   => x"0"                    -- 4-bit B port parity input
222
      );
223
 
224
 
225
  -- RAM 1
226
  -- port A is used to write and read (lower bytes) data, port B is for read only
227
  HistMem1Inst : RAMB16BWER
228
    generic map (
229
      -- DATA_WIDTH_A/DATA_WIDTH_B: 0, 1, 2, 4, 9, 18, or 36
230
      DATA_WIDTH_A        => 36,
231
      DATA_WIDTH_B        => 36,
232
      -- DOA_REG/DOB_REG: Optional output register (0 or 1)
233
      DOA_REG             => 0,
234
      DOB_REG             => 0,
235
      -- EN_RSTRAM_A/EN_RSTRAM_B: Enable/disable RST
236
      EN_RSTRAM_A         => true,
237
      EN_RSTRAM_B         => true,
238
      -- INIT_A/INIT_B: Initial values on output port
239
      INIT_A              => X"000000000",
240
      INIT_B              => X"000000000",
241
      -- INIT_FILE: Optional file used to specify initial RAM contents
242
      INIT_FILE           => "NONE",
243
      -- RSTTYPE: "SYNC" or "ASYNC" 
244
      RSTTYPE             => "SYNC",
245
      -- RST_PRIORITY_A/RST_PRIORITY_B: "CE" or "SR" 
246
      RST_PRIORITY_A      => "CE",
247
      RST_PRIORITY_B      => "CE",
248
      -- SIM_COLLISION_CHECK: Collision check enable "ALL", "WARNING_ONLY", "GENERATE_X_ONLY" or "NONE" 
249
      SIM_COLLISION_CHECK => "ALL",
250
      -- SIM_DEVICE: Must be set to "SPARTAN6" for proper simulation behavior
251
      SIM_DEVICE          => "SPARTAN6",
252
      -- SRVAL_A/SRVAL_B: Set/Reset value for RAM output
253
      SRVAL_A             => X"000000000",
254
      SRVAL_B             => X"000000000",
255
      -- WRITE_MODE_A/WRITE_MODE_B: "WRITE_FIRST", "READ_FIRST", or "NO_CHANGE" 
256
      WRITE_MODE_A        => "WRITE_FIRST",
257
      WRITE_MODE_B        => "WRITE_FIRST"
258
      )
259
    port map (
260
      -- Port A Data: 32-bit (each) Port A data
261
      DOA    => Ram1OutAxD,             -- 32-bit A port data output
262
      DOPA   => open,                   -- 4-bit A port parity output
263
      -- Port B Data: 32-bit (each) Port B data
264
      DOB    => Ram1OutBxD,
265
      DOPB   => open,
266
      -- Port A Address/Control Signals: 14-bit (each) Port A address and control signals
267
      ADDRA  => Ram1AdrAxD,             -- 14-bit A port address input
268
      CLKA   => ClkxCI,                 -- 1-bit A port clock input
269
      ENA    => Ram1EnAxS,              -- 1-bit A port enable input
270
      REGCEA => '1',           -- 1-bit A port register clock enable input
271
      RSTA   => RstxRI,        -- 1-bit A port register set/reset input
272
      WEA    => Ram1WExS,      -- 4-bit Port A byte-wide write enable input
273
      -- Port A Data: 32-bit (each) Port A data
274
      DIA    => RamWrDataxD,            -- 32-bit A port data input
275
      DIPA   => "0000",                 -- 4-bit A port parity input
276
      -- Port B Address/Control Signals: 14-bit (each) Port B address and control signals
277
      ADDRB  => Ram1RdAdrBxD,           -- 14-bit B port address input
278
      CLKB   => ClkxCI,                 -- 1-bit B port clock input
279
      ENB    => RExSI,                  -- 1-bit B port enable input
280
      REGCEB => '1',           -- 1-bit B port register clock enable input
281
      RSTB   => RstxRI,        -- 1-bit B port register set/reset input
282
      WEB    => x"0",          -- 4-bit Port B byte-wide write enable input
283
      -- Port B Data: 32-bit (each) Port B data
284
      DIB    => x"00000000",            -- 32-bit B port data input
285
      DIPB   => x"0"                    -- 4-bit B port parity input
286
      );
287
 
288
end Behavioral;
289
 
290
 
291
 

powered by: WebSVN 2.1.0

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