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

Subversion Repositories the_wizardry_project

[/] [the_wizardry_project/] [trunk/] [Wizardry/] [VHDL/] [Wizardry Top Level/] [Address Generation/] [JOP/] [sc_sram32.vhd] - Blame information for rev 22

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 22 mcwaccent
--
2
--
3
--  This file is a part of JOP, the Java Optimized Processor
4
--
5
--  Copyright (C) 2001-2008, Martin Schoeberl (martin@jopdesign.com)
6
--
7
--  This program is free software: you can redistribute it and/or modify
8
--  it under the terms of the GNU General Public License as published by
9
--  the Free Software Foundation, either version 3 of the License, or
10
--  (at your option) any later version.
11
--
12
--  This program is distributed in the hope that it will be useful,
13
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
--  GNU General Public License for more details.
16
--
17
--  You should have received a copy of the GNU General Public License
18
--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
--
20
 
21
 
22
--
23
--      sc_sram32.vhd
24
--
25
--      SimpCon compliant external memory interface
26
--      for 32-bit SRAM (e.g. Cyclone board, Spartan-3 Starter Kit)
27
--
28
--      Connection between mem_sc and the external memory bus
29
--
30
--      memory mapping
31
--      
32
--              000000-x7ffff   external SRAM (w mirror)        max. 512 kW (4*4 MBit)
33
--
34
--      RAM: 32 bit word
35
--
36
--
37
--      2005-11-22      first version
38
--      2007-03-17      changed SimpCon to records
39
--      2008-05-29      nwe on pos edge, additional wait state for write
40
--
41
 
42
Library IEEE;
43
use IEEE.std_logic_1164.all;
44
use ieee.numeric_std.all;
45
 
46
use work.jop_types.all;
47
use work.sc_pack.all;
48
 
49
entity sc_mem_if is
50
generic (ram_ws : integer; addr_bits : integer);
51
 
52
port (
53
 
54
        clk, reset      : in std_logic;
55
 
56
--
57
--      SimpCon memory interface
58
--
59
        sc_mem_out              : in sc_out_type;
60
        sc_mem_in               : out sc_in_type;
61
 
62
-- memory interface
63
 
64
        ram_addr        : out std_logic_vector(addr_bits-1 downto 0);
65
        ram_dout        : out std_logic_vector(31 downto 0);
66
        ram_din         : in std_logic_vector(31 downto 0);
67
        ram_dout_en     : out std_logic;
68
        ram_ncs         : out std_logic;
69
        ram_noe         : out std_logic;
70
        ram_nwe         : out std_logic
71
 
72
);
73
end sc_mem_if;
74
 
75
architecture rtl of sc_mem_if is
76
 
77
--
78
--      signals for mem interface
79
--
80
        type state_type         is (
81
                                                        idl, rd1, rd2,
82
                                                        wr1, wr2
83
                                                );
84
        signal state            : state_type;
85
        signal next_state       : state_type;
86
 
87
        signal wait_state       : unsigned(3 downto 0);
88
        signal cnt                      : unsigned(1 downto 0);
89
 
90
        signal dout_ena         : std_logic;
91
        signal rd_data_ena      : std_logic;
92
 
93
        signal ram_ws_wr        : integer;
94
 
95
begin
96
 
97
        ram_ws_wr <= ram_ws+1; -- additional wait state for SRAM
98
 
99
        assert SC_ADDR_SIZE>=addr_bits report "Too less address bits";
100
        ram_dout_en <= dout_ena;
101
 
102
        sc_mem_in.rdy_cnt <= cnt;
103
 
104
--
105
--      Register memory address, write data and read data
106
--
107
process(clk, reset)
108
begin
109
        if reset='1' then
110
 
111
                ram_addr <= (others => '0');
112
                ram_dout <= (others => '0');
113
                sc_mem_in.rd_data <= (others => '0');
114
 
115
        elsif rising_edge(clk) then
116
 
117
                if sc_mem_out.rd='1' or sc_mem_out.wr='1' then
118
                        ram_addr <= sc_mem_out.address(addr_bits-1 downto 0);
119
                end if;
120
                if sc_mem_out.wr='1' then
121
                        ram_dout <= sc_mem_out.wr_data;
122
                end if;
123
                if rd_data_ena='1' then
124
                        sc_mem_in.rd_data <= ram_din;
125
                end if;
126
 
127
        end if;
128
end process;
129
 
130
--
131
--      next state logic
132
--
133
process(state, sc_mem_out.rd, sc_mem_out.wr, wait_state)
134
 
135
begin
136
 
137
        next_state <= state;
138
 
139
 
140
        case state is
141
 
142
                when idl =>
143
                        if sc_mem_out.rd='1' then
144
                                if ram_ws=0 then
145
                                        -- then we omit state rd1!
146
                                        next_state <= rd2;
147
                                else
148
                                        next_state <= rd1;
149
                                end if;
150
                        elsif sc_mem_out.wr='1' then
151
                                next_state <= wr1;
152
                        end if;
153
 
154
                -- the WS state
155
                when rd1 =>
156
                        if wait_state=2 then
157
                                next_state <= rd2;
158
                        end if;
159
 
160
                -- last read state
161
                when rd2 =>
162
                        next_state <= idl;
163
                        -- This should do to give us a pipeline
164
                        -- level of 2 for read
165
                        if sc_mem_out.rd='1' then
166
                                if ram_ws=0 then
167
                                        -- then we omit state rd1!
168
                                        next_state <= rd2;
169
                                else
170
                                        next_state <= rd1;
171
                                end if;
172
                        elsif sc_mem_out.wr='1' then
173
                                next_state <= wr1;
174
                        end if;
175
 
176
                -- the WS state
177
                when wr1 =>
178
                        if wait_state=2 then
179
                                next_state <= wr2;
180
                        end if;
181
 
182
                -- last write state
183
                when wr2 =>
184
                        next_state <= idl;
185
 
186
        end case;
187
 
188
end process;
189
 
190
--
191
--      state machine register
192
--      output register
193
--
194
process(clk, reset)
195
 
196
begin
197
        if (reset='1') then
198
                state <= idl;
199
                dout_ena <= '0';
200
                ram_ncs <= '1';
201
                ram_noe <= '1';
202
                rd_data_ena <= '0';
203
                ram_nwe <= '1';
204
 
205
        elsif rising_edge(clk) then
206
 
207
                state <= next_state;
208
                dout_ena <= '0';
209
                ram_ncs <= '1';
210
                ram_noe <= '1';
211
                rd_data_ena <= '0';
212
                ram_nwe <= '1';
213
 
214
                case next_state is
215
 
216
                        when idl =>
217
 
218
                        -- the wait state
219
                        when rd1 =>
220
                                ram_ncs <= '0';
221
                                ram_noe <= '0';
222
 
223
                        -- last read state
224
                        when rd2 =>
225
                                ram_ncs <= '0';
226
                                ram_noe <= '0';
227
                                rd_data_ena <= '1';
228
 
229
                        -- the WS state
230
                        when wr1 =>
231
                                ram_nwe <= '0';
232
                                dout_ena <= '1';
233
                                ram_ncs <= '0';
234
 
235
                        -- last write state     
236
                        when wr2 =>
237
                                dout_ena <= '1';
238
                                ram_ncs <= '0';
239
 
240
                end case;
241
 
242
        end if;
243
end process;
244
 
245
--
246
-- wait_state processing
247
-- cs delay, dout enable
248
--
249
process(clk, reset)
250
begin
251
        if (reset='1') then
252
                wait_state <= (others => '1');
253
                cnt <= "00";
254
        elsif rising_edge(clk) then
255
 
256
                wait_state <= wait_state-1;
257
 
258
                cnt <= "11";
259
                if next_state=idl then
260
                        cnt <= "00";
261
                -- if wait_state<4 then
262
                elsif wait_state(3 downto 2)="00" then
263
                        cnt <= wait_state(1 downto 0)-1;
264
                end if;
265
 
266
                if sc_mem_out.rd='1' then
267
                        wait_state <= to_unsigned(ram_ws+1, 4);
268
                        if ram_ws<3 then
269
                                cnt <= to_unsigned(ram_ws+1, 2);
270
                        else
271
                                cnt <= "11";
272
                        end if;
273
                end if;
274
 
275
                if sc_mem_out.wr='1' then
276
                        wait_state <= to_unsigned(ram_ws_wr+1, 4);
277
                        if ram_ws_wr<3 then
278
                                cnt <= to_unsigned(ram_ws_wr+1, 2);
279
                        else
280
                                cnt <= "11";
281
                        end if;
282
                end if;
283
 
284
        end if;
285
end process;
286
 
287
end rtl;

powered by: WebSVN 2.1.0

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