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

Subversion Repositories bw_tiff_compression

[/] [bw_tiff_compression/] [trunk/] [var_width_RAM.vhd] - Blame information for rev 11

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

Line No. Rev Author Line
1 2 amulder
----------------------------------------------------------------------------------
2
-- Company:        
3
-- Engineer:       Aart Mulder
4
-- 
5
-- Create Date:    15:02:11 12/13/2012 
6
-- Design Name:    Tiff compression and transmission
7
-- Module Name:    var_width_RAM - Behavioral 
8
-- Project Name:   CCITT4
9
--
10
-- Revision: 
11
-- Revision 0.01 - File Created
12
--
13
----------------------------------------------------------------------------------
14
library IEEE;
15
use IEEE.STD_LOGIC_1164.ALL;
16
use IEEE.NUMERIC_STD.ALL;
17
 
18
entity var_width_RAM is
19
        Generic (
20
                MEM_SIZE_G        : integer := 1024;
21
                MEM_INDEX_WIDTH_G : integer := 10;
22
                DATA_WIDTH_G     : integer := 8
23
        );
24
        Port (
25
                reset_i   : in  STD_LOGIC;
26
                clk_i     : in  STD_LOGIC;
27
                d1_i      : in  STD_LOGIC_VECTOR (DATA_WIDTH_G-1 downto 0);
28
                wr1_i   : in  STD_LOGIC;
29
                d2_i      : in  STD_LOGIC_VECTOR (DATA_WIDTH_G-1 downto 0);
30
                wr2_i   : in  STD_LOGIC;
31
                d3_i      : in  STD_LOGIC_VECTOR (DATA_WIDTH_G-1 downto 0);
32
                wr3_i   : in  STD_LOGIC;
33
                d4_i      : in  STD_LOGIC_VECTOR (DATA_WIDTH_G-1 downto 0);
34
                wr4_i   : in  STD_LOGIC;
35
                rd_addr_i : in  STD_LOGIC_VECTOR (MEM_INDEX_WIDTH_G-1 downto 0);
36
                d_o       : out STD_LOGIC_VECTOR (DATA_WIDTH_G-1 downto 0);
37
                used_o    : out unsigned (MEM_INDEX_WIDTH_G-1 downto 0)
38
        );
39
end var_width_RAM;
40
 
41
architecture Behavioral of var_width_RAM is
42
        signal rd1, rd2, rd3, rd4, wr1, wr2, wr3, wr4 : std_logic := '0';
43
        signal rd_addr1, rd_addr2, rd_addr3, rd_addr4, wr_addr1, wr_addr2, wr_addr3, wr_addr4 : std_logic_vector(MEM_INDEX_WIDTH_G-3 downto 0) := (others => '0');
44
        signal d1_in, d2_in, d3_in, d4_in, d1_out, d2_out, d3_out, d4_out : std_logic_vector(DATA_WIDTH_G-1 downto 0) := (others => '0');
45
        signal mux_sel : unsigned(1 downto 0) := (others => '0');
46
begin
47
        RAM_ins1 : entity work.MyRAM
48
        generic map(
49
                DATA_WIDTH_G => DATA_WIDTH_G,
50
                MEMORY_SIZE_G => MEM_SIZE_G/4,
51
                MEMORY_ADDRESS_WIDTH_G  => MEM_INDEX_WIDTH_G-2,
52
                BUFFER_OUTPUT_G => true
53
        )
54
        port map(
55
                clk => clk_i,
56
                en => '1',
57
                rd => rd1,
58
                wr => wr1,
59
                rd_addr => rd_addr1,
60
                wr_addr => wr_addr1,
61
                Data_in => d1_in,
62
                Data_out => d1_out
63
        );
64
        rd_addr1 <= rd_addr_i(MEM_INDEX_WIDTH_G-1 downto 2);
65
        rd1 <= (not rd_addr_i(1)) and (not rd_addr_i(0));
66
 
67
        RAM_ins2 : entity work.MyRAM
68
        generic map(
69
                DATA_WIDTH_G => DATA_WIDTH_G,
70
                MEMORY_SIZE_G => MEM_SIZE_G/4,
71
                MEMORY_ADDRESS_WIDTH_G  => MEM_INDEX_WIDTH_G-2,
72
                BUFFER_OUTPUT_G => true
73
        )
74
        port map(
75
                clk => clk_i,
76
                en => '1',
77
                rd => rd2,
78
                wr => wr2,
79
                rd_addr => rd_addr2,
80
                wr_addr => wr_addr2,
81
                Data_in => d2_in,
82
                Data_out => d2_out
83
        );
84
        rd_addr2 <= rd_addr_i(MEM_INDEX_WIDTH_G-1 downto 2);
85
        rd2 <= (not rd_addr_i(1)) and (rd_addr_i(0));
86
 
87
        RAM_ins3 : entity work.MyRAM
88
        generic map(
89
                DATA_WIDTH_G => DATA_WIDTH_G,
90
                MEMORY_SIZE_G => MEM_SIZE_G/4,
91
                MEMORY_ADDRESS_WIDTH_G  => MEM_INDEX_WIDTH_G-2,
92
                BUFFER_OUTPUT_G => true
93
        )
94
        port map(
95
                clk => clk_i,
96
                en => '1',
97
                rd => rd3,
98
                wr => wr3,
99
                rd_addr => rd_addr3,
100
                wr_addr => wr_addr3,
101
                Data_in => d3_in,
102
                Data_out => d3_out
103
        );
104
        rd_addr3 <= rd_addr_i(MEM_INDEX_WIDTH_G-1 downto 2);
105
        rd3 <= (rd_addr_i(1)) and (not rd_addr_i(0));
106
 
107
        RAM_ins4 : entity work.MyRAM
108
        generic map(
109
                DATA_WIDTH_G => DATA_WIDTH_G,
110
                MEMORY_SIZE_G => MEM_SIZE_G/4,
111
                MEMORY_ADDRESS_WIDTH_G  => MEM_INDEX_WIDTH_G-2,
112
                BUFFER_OUTPUT_G => true
113
        )
114
        port map(
115
                clk => clk_i,
116
                en => '1',
117
                rd => rd4,
118
                wr => wr4,
119
                rd_addr => rd_addr4,
120
                wr_addr => wr_addr4,
121
                Data_in => d4_in,
122
                Data_out => d4_out
123
        );
124
        rd_addr4 <= rd_addr_i(MEM_INDEX_WIDTH_G-1 downto 2);
125
        rd4 <= (rd_addr_i(1)) and (rd_addr_i(0));
126
 
127
        --Multiplexer that selects the RAM output data
128
        d_o <= d1_out when rd_addr_i(1 downto 0) = "00"
129
                        else d2_out when rd_addr_i(1 downto 0) = "01"
130
                        else d3_out when rd_addr_i(1 downto 0) = "10"
131
                        else d4_out when rd_addr_i(1 downto 0) = "11";
132
 
133
        --The multiplexer selection counter
134
        mux_sel_cnt_process : process(clk_i)
135
        begin
136
                if clk_i'event and clk_i = '0' then
137
                        -- "0000" => 0
138
                        -- "0001" => 1
139
                        -- "0011" => 2 
140
                        -- "0111" => 3
141
                        -- "1111" => 4 = 0
142
 
143
                        if reset_i = '1' then
144
                                mux_sel <= (others => '0');
145
--                      if    wr4_i = '0' and wr3_i = '0' and wr2_i = '0' and wr1_i = '0' then
146
--                              mux_sel <= mux_sel - to_unsigned(0,2);
147
                        elsif    wr4_i = '0' and wr3_i = '0' and wr2_i = '0' and wr1_i = '1' then
148
                                mux_sel <= mux_sel - to_unsigned(1,2);
149
                        elsif wr4_i = '0' and wr3_i = '0' and wr2_i = '1' and wr1_i = '1' then
150
                                mux_sel <= mux_sel - to_unsigned(2,2);
151
                        elsif wr4_i = '0' and wr3_i = '1' and wr2_i = '1' and wr1_i = '1' then
152
                                mux_sel <= mux_sel - to_unsigned(3,2);
153
--                      elsif wr4_i = '1' and wr3_i = '1' and wr2_i = '1' and wr1_i = '1' then
154
--                              mux_sel <= mux_sel - to_unsigned(4,2);
155
                        else
156
                                mux_sel <= mux_sel - to_unsigned(0,2);
157
                        end if;
158
                end if;
159
        end process mux_sel_cnt_process;
160
 
161
        --This process controls the read addresses, i.e. counting up and reseting.
162
        rd_addr_cnt_process : process(clk_i)
163
        begin
164
                if clk_i'event and clk_i = '1' then
165
                        if reset_i = '1' then
166
                                wr_addr1 <= (others => '0');
167
                                wr_addr2 <= (others => '0');
168
                                wr_addr3 <= (others => '0');
169
                                wr_addr4 <= (others => '0');
170
                        else
171
                                if wr1 = '1' then
172
                                        wr_addr1 <= std_logic_vector(unsigned(wr_addr1) + to_unsigned(1, MEM_INDEX_WIDTH_G - 3));
173
                                end if;
174
                                if wr2 = '1' then
175
                                        wr_addr2 <= std_logic_vector(unsigned(wr_addr2) + to_unsigned(1, MEM_INDEX_WIDTH_G - 3));
176
                                end if;
177
                                if wr3 = '1' then
178
                                        wr_addr3 <= std_logic_vector(unsigned(wr_addr3) + to_unsigned(1, MEM_INDEX_WIDTH_G - 3));
179
                                end if;
180
                                if wr4 = '1' then
181
                                        wr_addr4 <= std_logic_vector(unsigned(wr_addr4) + to_unsigned(1, MEM_INDEX_WIDTH_G - 3));
182
                                end if;
183
                        end if;
184
                end if;
185
        end process rd_addr_cnt_process;
186
 
187
        --Multiplexer 1(input to RAM 1)
188
        mux1_process : process(clk_i)
189
        begin
190
                if clk_i'event and clk_i = '0' then
191
                        if (mux_sel + to_unsigned(0,2)) = to_unsigned(0,2) then
192
                                wr1 <= wr1_i;
193
                                d1_in <= d1_i;
194
                        elsif (mux_sel + to_unsigned(0,2)) = to_unsigned(1,2) then
195
                                wr1 <= wr2_i;
196
                                d1_in <= d2_i;
197
                        elsif (mux_sel + to_unsigned(0,2)) = to_unsigned(2,2) then
198
                                wr1 <= wr3_i;
199
                                d1_in <= d3_i;
200
                        elsif (mux_sel + to_unsigned(0,2)) = to_unsigned(3,2) then
201
                                wr1 <= wr4_i;
202
                                d1_in <= d4_i;
203
                        end if;
204
                end if;
205
        end process mux1_process;
206
 
207
        --Multiplexer 2(input to RAM 2)
208
        mux2_process : process(clk_i)
209
        begin
210
                if clk_i'event and clk_i = '0' then
211
                        if (mux_sel + to_unsigned(1,2)) = to_unsigned(0,2) then
212
                                wr2 <= wr1_i;
213
                                d2_in <= d1_i;
214
                        elsif (mux_sel + to_unsigned(1,2)) = to_unsigned(1,2) then
215
                                wr2 <= wr2_i;
216
                                d2_in <= d2_i;
217
                        elsif (mux_sel + to_unsigned(1,2)) = to_unsigned(2,2) then
218
                                wr2 <= wr3_i;
219
                                d2_in <= d3_i;
220
                        elsif (mux_sel + to_unsigned(1,2)) = to_unsigned(3,2) then
221
                                wr2 <= wr4_i;
222
                                d2_in <= d4_i;
223
                        end if;
224
                end if;
225
        end process mux2_process;
226
 
227
        --Multiplexer 3(input to RAM 3)
228
        mux3_process : process(clk_i)
229
        begin
230
                if clk_i'event and clk_i = '0' then
231
                        if (mux_sel + to_unsigned(2,2)) = to_unsigned(0,2) then
232
                                wr3 <= wr1_i;
233
                                d3_in <= d1_i;
234
                        elsif (mux_sel + to_unsigned(2,2)) = to_unsigned(1,2) then
235
                                wr3 <= wr2_i;
236
                                d3_in <= d2_i;
237
                        elsif (mux_sel + to_unsigned(2,2)) = to_unsigned(2,2) then
238
                                wr3 <= wr3_i;
239
                                d3_in <= d3_i;
240
                        elsif (mux_sel + to_unsigned(2,2)) = to_unsigned(3,2) then
241
                                wr3 <= wr4_i;
242
                                d3_in <= d4_i;
243
                        end if;
244
                end if;
245
        end process mux3_process;
246
 
247
        --Multiplexer 4(input to RAM 4)
248
        mux4_process : process(clk_i)
249
        begin
250
                if clk_i'event and clk_i = '0' then
251
                        if (mux_sel + to_unsigned(3,2)) = to_unsigned(0,2) then
252
                                wr4 <= wr1_i;
253
                                d4_in <= d1_i;
254
                        elsif (mux_sel + to_unsigned(3,2)) = to_unsigned(1,2) then
255
                                wr4 <= wr2_i;
256
                                d4_in <= d2_i;
257
                        elsif (mux_sel + to_unsigned(3,2)) = to_unsigned(2,2) then
258
                                wr4 <= wr3_i;
259
                                d4_in <= d3_i;
260
                        elsif (mux_sel + to_unsigned(3,2)) = to_unsigned(3,2) then
261
                                wr4 <= wr4_i;
262
                                d4_in <= d4_i;
263
                        end if;
264
                end if;
265
        end process mux4_process;
266
 
267
        used_o <= ("00" & unsigned(wr_addr1)) + ("00" & unsigned(wr_addr2)) + ("00" & unsigned(wr_addr3)) + ("00" & unsigned(wr_addr4));
268
 
269
end Behavioral;

powered by: WebSVN 2.1.0

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