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

Subversion Repositories ion

[/] [ion/] [trunk/] [vhdl/] [mips_cache_stub.vhdl] - Blame information for rev 42

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

Line No. Rev Author Line
1 42 ja_rd
--------------------------------------------------------------------------------
2
-- mips_cache_stub.vhdl -- cache module with no actual cache memory.
3
--
4
-- This module has the same interface as a real cache but has no cache memory.
5
-- It just interfaces the CPU to the following:
6
--
7
--  1.- Internal 32-bit-wide BRAM for read and write
8
--  2.- Internal 32-bit I/O bus
9
--  3.- External 16-bit wide SRAM
10
--
11
-- The SRAM memory interface signals are meant to connect directly to FPGA pins 
12
-- and all outputs are registered (tco should be minimal).
13
-- SRAM data inputs are NOT registered, though. They go through a couple muxes
14
-- before reaching the first register so watch out for tsetup.
15
-- The SRAM is assumed to be fast enough to read or write in a clock cycle.
16
--
17
-- Obviously this module provides no performance gain; on the contrary, by 
18
-- coupling the CPU to slow external memory (16 bit bus) it actually slows it
19
-- down. The purpose of this module is just to test the SRAM interface.
20
--
21
-- FIXME there HAS to be some explaination of the logic, it's not obvious!
22
--
23
--------------------------------------------------------------------------------
24
 
25
library ieee;
26
use ieee.std_logic_1164.all;
27
use ieee.std_logic_arith.all;
28
use ieee.std_logic_unsigned.all;
29
use work.mips_pkg.all;
30
 
31
entity mips_cache_stub is
32
    generic (
33
        BRAM_ADDR_SIZE : integer := 10;
34
        SRAM_ADDR_SIZE : integer := 17
35
    );
36
    port(
37
        clk             : in std_logic;
38
        reset           : in std_logic;
39
 
40
        -- Interface to CPU core
41
        data_rd_addr    : in std_logic_vector(31 downto 0);
42
        data_rd         : out std_logic_vector(31 downto 0);
43
        data_rd_vma     : in std_logic;
44
 
45
        code_rd_addr    : in std_logic_vector(31 downto 2);
46
        code_rd         : out std_logic_vector(31 downto 0);
47
        code_rd_vma     : in std_logic;
48
 
49
        data_wr_addr    : in std_logic_vector(31 downto 2);
50
        byte_we         : in std_logic_vector(3 downto 0);
51
        data_wr         : in std_logic_vector(31 downto 0);
52
 
53
        mem_wait        : out std_logic;
54
 
55
        -- interface to FPGA i/o devices
56
        io_rd_data      : in std_logic_vector(31 downto 0);
57
        io_rd_addr      : out std_logic_vector(31 downto 2);
58
        io_wr_addr      : out std_logic_vector(31 downto 2);
59
        io_wr_data      : out std_logic_vector(31 downto 0);
60
        io_rd_vma       : out std_logic;
61
        io_byte_we      : out std_logic_vector(3 downto 0);
62
 
63
        -- interface to synchronous 32-bit-wide FPGA BRAM (possibly used as ROM)
64
        bram_rd_data    : in std_logic_vector(31 downto 0);
65
        bram_wr_data    : out std_logic_vector(31 downto 0);
66
        bram_rd_addr    : out std_logic_vector(BRAM_ADDR_SIZE+1 downto 2);
67
        bram_wr_addr    : out std_logic_vector(BRAM_ADDR_SIZE+1 downto 2);
68
        bram_byte_we    : out std_logic_vector(3 downto 0);
69
 
70
        -- interface to asynchronous 16-bit-wide EXTERNAL SRAM
71
        sram_address    : out std_logic_vector(SRAM_ADDR_SIZE-1 downto 1);
72
        sram_databus    : inout std_logic_vector(15 downto 0);
73
        sram_byte_we_n  : out std_logic_vector(1 downto 0);
74
        sram_oe_n       : out std_logic
75
    );
76
end entity mips_cache_stub;
77
 
78
 
79
 
80
architecture stub of mips_cache_stub is
81
 
82
type t_cache_state is (
83
    idle,
84
 
85
    read_bram_data_0,
86
    read_bram_data_1,
87
 
88
    read_data_0,
89
    read_data_1,
90
 
91
    read_code_0,
92
    read_code_1,
93
 
94
    write_0,
95
    write_1
96
   );
97
 
98
signal ps, ns :             t_cache_state;
99
 
100
 
101
signal use_sram_wr :        std_logic;
102
signal use_sram_rd :        std_logic;
103
signal use_io_wr :          std_logic;
104
signal use_io_rd :          std_logic;
105
signal data_addr_reg :      std_logic_vector(SRAM_ADDR_SIZE-1 downto 2);
106
signal data_wr_reg :        std_logic_vector(31 downto 0);
107
signal data_input_reg :     std_logic_vector(15 downto 0);
108
signal bram_rd_data_reg :   std_logic_vector(31 downto 0);
109
signal byte_we_reg :        std_logic_vector(3 downto 0);
110
 
111
begin
112
 
113
 
114
cache_state_machine_reg:
115
process(clk)
116
begin
117
   if clk'event and clk='1' then
118
        if reset='1' then
119
            ps <= idle; --wait_idle;
120
        else
121
            ps <= ns;
122
        end if;
123
    end if;
124
end process cache_state_machine_reg;
125
 
126
 
127
 
128
cache_state_machine_transitions:
129
process(clk,ps)
130
begin
131
    case ps is
132
    when idle =>
133
        ns <= ps;
134
 
135
        if code_rd_vma='1' and use_sram_rd='1' then
136
            ns <= read_code_0;
137
        elsif data_rd_vma='1' and use_sram_rd='1' then
138
            ns <= read_data_0;
139
        elsif data_rd_vma='1' and use_sram_rd='0' then
140
            ns <= read_bram_data_0;
141
        elsif byte_we/="0000" and use_sram_wr='1' then
142
            ns <= write_0;
143
        else
144
            ns <= ps;
145
        end if;
146
 
147
    when read_bram_data_0 =>
148
        ns <= read_bram_data_1;
149
 
150
    when read_bram_data_1 =>
151
        ns <= idle;
152
 
153
    when read_code_0 =>
154
        ns <= read_code_1;
155
 
156
    when read_code_1 =>
157
        if data_rd_vma='1' and use_sram_rd='1' then
158
            ns <= read_data_0;
159
        elsif byte_we/="0000" and use_sram_wr='1' then
160
            ns <= write_0;
161
        else
162
            ns <= idle;
163
        end if;
164
 
165
    when read_data_0 =>
166
        ns <= read_data_1;
167
 
168
    when read_data_1 =>
169
        if byte_we/="0000" and use_sram_wr='1' then
170
            ns <= write_0;
171
        else
172
            ns <= idle;
173
        end if;
174
 
175
    when write_0 =>
176
        ns <= write_1;
177
 
178
    when write_1 =>
179
        ns <= idle;
180
 
181
    when others =>
182
        -- BUG: should raise some debug signal
183
        ns <= idle;
184
    end case;
185
end process cache_state_machine_transitions;
186
 
187
sram_address(sram_address'high downto 2) <=
188
                                data_addr_reg(sram_address'high downto 2);
189
 
190
 
191
with ps select sram_address(1) <=
192
    '0'     when read_data_0,
193
    '1'     when read_data_1,
194
    '0'     when read_code_0,
195
    '1'     when read_code_1,
196
    '0'     when write_0,
197
    '1'     when write_1,
198
    '0'     when others;
199
 
200
with ps select sram_oe_n <=
201
    '0'     when read_data_0,
202
    '0'     when read_data_1,
203
    '0'     when read_code_0,
204
    '0'     when read_code_1,
205
    '1'     when others;
206
 
207
with ps select sram_byte_we_n <=
208
    not byte_we_reg(3 downto 2)     when write_0,
209
    not byte_we_reg(1 downto 0)     when write_1,
210
    "11"                            when others;
211
 
212
with ps select sram_databus <=
213
    data_wr_reg(31 downto 16)   when write_0,
214
    data_wr_reg(15 downto  0)   when write_1,
215
    (others => 'Z')             when others;
216
 
217
sdram_address_register:
218
process(clk)
219
begin
220
    if clk'event and clk='1' then
221
        if reset='1' then
222
            data_addr_reg <= (others => '0');
223
        else
224
            if data_rd_vma='1' then
225
                data_addr_reg <= data_rd_addr(sram_address'high downto 2);
226
            elsif byte_we/="0000" then
227
                data_addr_reg <= data_wr_addr(sram_address'high downto 2);
228
            end if;
229
        end if;
230
    end if;
231
end process sdram_address_register;
232
 
233
 
234
data_input_register:
235
process(clk)
236
begin
237
    if clk'event and clk='1' then
238
        if reset='1' then
239
            data_input_reg <= (others => '0');
240
        else
241
            if ps=read_data_0 then
242
                data_input_reg <= sram_databus;
243
            end if;
244
            bram_rd_data_reg <= bram_rd_data;
245
            if byte_we/="0000" then
246
                byte_we_reg <= byte_we;
247
                data_wr_reg <= data_wr;
248
            end if;
249
        end if;
250
    end if;
251
end process data_input_register;
252
 
253
 
254
with ps select code_rd <=
255
    data_input_reg & sram_databus   when read_code_1,
256
    bram_rd_data                    when others;
257
 
258
 
259
data_rd <=
260
    data_input_reg & sram_databus when ps=read_data_1 else
261
    bram_rd_data_reg;
262
    -- FIXME IO RD data missing
263
    --io_rd_data      when (ps=idle and use_io_rd='1') else
264
 
265
mem_wait <= '1' when
266
    ps=read_bram_data_0 or
267
    ps=read_data_0 or
268
    ps=write_0 or
269
    (ps=idle and use_sram_wr='1' and byte_we/="0000")
270
    else '0';
271
 
272
use_sram_rd <= '1'
273
    when (addr_decode(data_rd_addr,ADDR_XRAM)='1' and data_rd_vma='1') or
274
         (addr_decode(code_rd_addr,ADDR_XRAM)='1' and code_rd_vma='1')
275
    else '0';
276
 
277
use_sram_wr <= '1'
278
    when addr_decode(data_wr_addr,ADDR_XRAM)='1'
279
    else '0';
280
 
281
use_io_rd <= '1'
282
    when addr_decode(data_rd_addr,ADDR_IO)='1' and data_rd_vma='1'
283
    else '0';
284
 
285
use_io_wr <= '1'
286
    when addr_decode(data_wr_addr,ADDR_IO)='1' and byte_we/="0000"
287
    else '0';
288
 
289
--------------------------------------------------------------------------------
290
 
291
bram_rd_addr <= data_rd_addr(bram_rd_addr'high downto 2) when
292
    (ps=idle and use_sram_rd='0' and data_rd_vma='1')
293
    else code_rd_addr(bram_rd_addr'high downto 2);
294
 
295
bram_wr_addr <= data_wr_addr(bram_wr_addr'high downto 2);
296
bram_byte_we <= byte_we when addr_decode(data_wr_addr,ADDR_BOOT)='1' else "0000";
297
 
298
 
299
io_wr_addr <= data_wr_addr;
300
io_rd_addr <= data_rd_addr(31  downto 2);
301
io_wr_data <= data_wr;
302
io_byte_we <= byte_we when addr_decode(data_wr_addr,ADDR_IO)='1' else "0000";
303
 
304
 
305
end architecture stub;

powered by: WebSVN 2.1.0

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