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

Subversion Repositories simpcon

[/] [simpcon/] [trunk/] [vhdl/] [sc_sram32.vhd] - Blame information for rev 26

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 martin
--
2
--      sc_sram32.vhd
3
--
4
--      SimpCon compliant external memory interface
5 10 martin
--      for 32-bit SRAM (e.g. Cyclone board, Spartan-3 Starter Kit)
6 4 martin
--
7
--      Connection between mem_sc and the external memory bus
8
--
9
--      memory mapping
10
--      
11
--              000000-x7ffff   external SRAM (w mirror)        max. 512 kW (4*4 MBit)
12
--
13
--      RAM: 32 bit word
14
--
15
--
16
--      2005-11-22      first version
17 18 martin
--      2007-03-17      changed SimpCon to records
18 4 martin
--
19
 
20
Library IEEE;
21
use IEEE.std_logic_1164.all;
22
use ieee.numeric_std.all;
23
 
24
use work.jop_types.all;
25 18 martin
use work.sc_pack.all;
26 4 martin
 
27
entity sc_mem_if is
28 11 martin
generic (ram_ws : integer; addr_bits : integer);
29 4 martin
 
30
port (
31
 
32
        clk, reset      : in std_logic;
33
 
34 18 martin
--
35
--      SimpCon memory interface
36
--
37
        sc_mem_out              : in sc_mem_out_type;
38
        sc_mem_in               : out sc_in_type;
39 4 martin
 
40
-- memory interface
41
 
42 11 martin
        ram_addr        : out std_logic_vector(addr_bits-1 downto 0);
43 4 martin
        ram_dout        : out std_logic_vector(31 downto 0);
44
        ram_din         : in std_logic_vector(31 downto 0);
45
        ram_dout_en     : out std_logic;
46
        ram_ncs         : out std_logic;
47
        ram_noe         : out std_logic;
48 10 martin
        ram_nwe         : out std_logic
49 4 martin
 
50
);
51
end sc_mem_if;
52
 
53
architecture rtl of sc_mem_if is
54
 
55
--
56
--      signals for mem interface
57
--
58
        type state_type         is (
59
                                                        idl, rd1, rd2,
60
                                                        wr1
61
                                                );
62
        signal state            : state_type;
63
        signal next_state       : state_type;
64
 
65
        signal nwr_int          : std_logic;
66
        signal wait_state       : unsigned(3 downto 0);
67
        signal cnt                      : unsigned(1 downto 0);
68
 
69
        signal dout_ena         : std_logic;
70
        signal rd_data_ena      : std_logic;
71
 
72
begin
73
 
74 18 martin
        assert MEM_ADDR_SIZE>=addr_bits report "Too less address bits";
75 4 martin
        ram_dout_en <= dout_ena;
76
 
77 18 martin
        sc_mem_in.rdy_cnt <= cnt;
78 4 martin
 
79
--
80
--      Register memory address, write data and read data
81
--
82
process(clk, reset)
83
begin
84
        if reset='1' then
85
 
86
                ram_addr <= (others => '0');
87
                ram_dout <= (others => '0');
88 18 martin
                sc_mem_in.rd_data <= (others => '0');
89 4 martin
 
90
        elsif rising_edge(clk) then
91
 
92 18 martin
                if sc_mem_out.rd='1' or sc_mem_out.wr='1' then
93
                        ram_addr <= sc_mem_out.address(addr_bits-1 downto 0);
94 4 martin
                end if;
95 18 martin
                if sc_mem_out.wr='1' then
96
                        ram_dout <= sc_mem_out.wr_data;
97 4 martin
                end if;
98
                if rd_data_ena='1' then
99 18 martin
                        sc_mem_in.rd_data <= ram_din;
100 4 martin
                end if;
101
 
102
        end if;
103
end process;
104
 
105
--
106
--      'delay' nwe 1/2 cycle -> change on falling edge
107
--
108
process(clk, reset)
109
 
110
begin
111
        if (reset='1') then
112
                ram_nwe <= '1';
113
        elsif falling_edge(clk) then
114
                ram_nwe <= nwr_int;
115
        end if;
116
 
117
end process;
118
 
119
 
120
--
121
--      next state logic
122
--
123 18 martin
process(state, sc_mem_out.rd, sc_mem_out.wr, wait_state)
124 4 martin
 
125
begin
126
 
127
        next_state <= state;
128
 
129
 
130
        case state is
131
 
132
                when idl =>
133 18 martin
                        if sc_mem_out.rd='1' then
134 4 martin
                                if ram_ws=0 then
135
                                        -- then we omit state rd1!
136
                                        next_state <= rd2;
137
                                else
138
                                        next_state <= rd1;
139
                                end if;
140 18 martin
                        elsif sc_mem_out.wr='1' then
141 4 martin
                                next_state <= wr1;
142
                        end if;
143
 
144
                -- the WS state
145
                when rd1 =>
146
                        if wait_state=2 then
147
                                next_state <= rd2;
148
                        end if;
149
 
150
                -- last read state
151
                when rd2 =>
152
                        next_state <= idl;
153
                        -- This should do to give us a pipeline
154 11 martin
                        -- level of 2 for read
155 18 martin
                        if sc_mem_out.rd='1' then
156 4 martin
                                if ram_ws=0 then
157
                                        -- then we omit state rd1!
158
                                        next_state <= rd2;
159
                                else
160
                                        next_state <= rd1;
161
                                end if;
162 18 martin
                        elsif sc_mem_out.wr='1' then
163 4 martin
                                next_state <= wr1;
164
                        end if;
165
 
166
                -- the WS state
167
                when wr1 =>
168
-- TODO: check what happens on ram_ws=0
169
-- TODO: do we need a write pipelining?
170
--      not at the moment, but parhaps later when
171
--      we write the stack content to main memory
172
                        if wait_state=1 then
173
                                next_state <= idl;
174
                        end if;
175
 
176
        end case;
177
 
178
end process;
179
 
180
--
181
--      state machine register
182
--      output register
183
--
184
process(clk, reset)
185
 
186
begin
187
        if (reset='1') then
188
                state <= idl;
189
                dout_ena <= '0';
190
                ram_ncs <= '1';
191
                ram_noe <= '1';
192
                rd_data_ena <= '0';
193
        elsif rising_edge(clk) then
194
 
195
                state <= next_state;
196
                dout_ena <= '0';
197
                ram_ncs <= '1';
198
                ram_noe <= '1';
199
                rd_data_ena <= '0';
200
 
201
                case next_state is
202
 
203
                        when idl =>
204
 
205
                        -- the wait state
206
                        when rd1 =>
207
                                ram_ncs <= '0';
208
                                ram_noe <= '0';
209
 
210
                        -- last read state
211
                        when rd2 =>
212
                                ram_ncs <= '0';
213
                                ram_noe <= '0';
214
                                rd_data_ena <= '1';
215
 
216
 
217
                        -- the WS state
218
                        when wr1 =>
219
                                ram_ncs <= '0';
220
                                dout_ena <= '1';
221
 
222
                end case;
223
 
224
        end if;
225
end process;
226
 
227
--
228
--      nwr combinatorial processing
229
--      for the negativ edge
230
--
231
process(next_state, state)
232
begin
233
 
234
        nwr_int <= '1';
235
        if next_state=wr1 then
236
                nwr_int <= '0';
237
        end if;
238
 
239
end process;
240
 
241
--
242
-- wait_state processing
243
-- cs delay, dout enable
244
--
245
process(clk, reset)
246
begin
247
        if (reset='1') then
248
                wait_state <= (others => '1');
249
                cnt <= "00";
250
        elsif rising_edge(clk) then
251
 
252
                wait_state <= wait_state-1;
253
 
254
                cnt <= "11";
255
                if next_state=idl then
256
                        cnt <= "00";
257
                -- if wait_state<4 then
258
                elsif wait_state(3 downto 2)="00" then
259
                        cnt <= wait_state(1 downto 0)-1;
260
                end if;
261
 
262 18 martin
                if sc_mem_out.rd='1' or sc_mem_out.wr='1' then
263 4 martin
                        wait_state <= to_unsigned(ram_ws+1, 4);
264
                        if ram_ws<3 then
265
                                cnt <= to_unsigned(ram_ws+1, 2);
266
                        else
267
                                cnt <= "11";
268
                        end if;
269
                end if;
270
 
271
        end if;
272
end process;
273
 
274
end rtl;

powered by: WebSVN 2.1.0

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