OpenCores
URL https://opencores.org/ocsvn/hf-risc/hf-risc/trunk

Subversion Repositories hf-risc

[/] [hf-risc/] [trunk/] [hf-risc/] [platform/] [spartan3_starterkit/] [spartan3_SRAM.vhd] - Blame information for rev 13

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

Line No. Rev Author Line
1 13 serginhofr
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.std_logic_unsigned.all;
4
 
5
entity hellfire_cpu_if is
6
        generic(
7
                address_width: integer := 14;
8
                memory_file : string := "code.txt";
9
                uart_support : string := "yes"
10
        );
11
        port (  clk_in:         in std_logic;
12
                reset_in:       in std_logic;
13
                int_in:         in std_logic;
14
                uart_read:      in std_logic;
15
                uart_write:     out std_logic;
16
 
17
                ram_address:    out std_logic_vector(31 downto 2);
18
                ram_data:       inout std_logic_vector(31 downto 0);
19
                ram_ce1_n:      out std_logic;
20
                ram_ub1_n:      out std_logic;
21
                ram_lb1_n:      out std_logic;
22
                ram_ce2_n:      out std_logic;
23
                ram_ub2_n:      out std_logic;
24
                ram_lb2_n:      out std_logic;
25
                ram_we_n:       out std_logic;
26
                ram_oe_n:       out std_logic
27
        );
28
end hellfire_cpu_if;
29
 
30
architecture interface of hellfire_cpu_if is
31
        signal clock, boot_enable, ram_enable_n, stall, stall_cpu, busy_cpu, irq_cpu, irq_ack_cpu, data_access_cpu, ram_dly, rff1, reset: std_logic;
32
        signal address, data_read, data_write, data_read_boot, data_read_ram, irq_vector_cpu, inst_addr_cpu, inst_in_cpu, data_addr_cpu, data_in_cpu, data_out_cpu: std_logic_vector(31 downto 0);
33
        signal ext_irq: std_logic_vector(7 downto 0);
34
        signal data_we, data_w_cpu: std_logic_vector(3 downto 0);
35
 
36
        signal we_n_next    : std_logic;
37
        signal we_n_reg     : std_logic;
38
        signal data_reg     : std_logic_vector(31 downto 0);
39
begin
40
        -- clock divider (25MHz clock from 50MHz main clock for Spartan3 Starter Kit)
41
        process (reset_in, clk_in, clock, we_n_next)
42
        begin
43
                if reset_in = '1' then
44
                        clock <= '0';
45
                else
46
                        if clk_in'event and clk_in='1' then
47
                                clock <= not clock;
48
                        end if;
49
                end if;
50
 
51
                if reset_in = '1' then
52
                        we_n_reg <= '1';
53
                elsif rising_edge(clk_in) then
54
                        we_n_reg <= we_n_next or not clock;
55
                end if;
56
 
57
                if reset_in = '1' then
58
                        data_read_ram <= (others => '0');
59
                elsif rising_edge(clock) then
60
                        data_read_ram <= ram_data;
61
                end if;
62
        end process;
63
 
64
        -- reset synchronizer
65
        process (clock, reset_in)
66
        begin
67
                if (reset_in = '1') then
68
                        rff1 <= '1';
69
                        reset <= '1';
70
                elsif (clock'event and clock = '1') then
71
                        rff1 <= '0';
72
                        reset <= rff1;
73
                end if;
74
        end process;
75
 
76
 
77
        process (reset, clock, ext_irq, ram_enable_n)
78
        begin
79
                if reset = '1' then
80
                        ram_dly <= '0';
81
                        ext_irq <= x"00";
82
                elsif clock'event and clock = '1' then
83
                        ram_dly <= not ram_enable_n;
84
                        ext_irq <= "0000000" & int_in;
85
                end if;
86
        end process;
87
 
88
        stall <= '0';
89
        boot_enable <= '1' when address(31 downto 28) = "0000" else '0';
90
        data_read <= data_read_boot when address(31 downto 28) = "0000" and ram_dly = '0' else data_read_ram;
91
 
92
        -- HF-RISC core
93
        core: entity work.datapath
94
        port map(       clock => clock,
95
                        reset => reset,
96
                        stall => stall_cpu,
97
                        busy => busy_cpu,
98
                        irq_vector => irq_vector_cpu,
99
                        irq => irq_cpu,
100
                        irq_ack => irq_ack_cpu,
101
                        inst_addr => inst_addr_cpu,
102
                        inst_in => inst_in_cpu,
103
                        data_addr => data_addr_cpu,
104
                        data_in => data_in_cpu,
105
                        data_out => data_out_cpu,
106
                        data_w => data_w_cpu,
107
                        data_access => data_access_cpu
108
        );
109
 
110
        -- peripherals / busmux logic
111
        peripherals_busmux: entity work.busmux
112
        generic map(
113
                uart_support => uart_support
114
        )
115
        port map(
116
                clock => clock,
117
                reset => reset,
118
 
119
                stall => stall,
120
 
121
                stall_cpu => stall_cpu,
122
                busy_cpu => busy_cpu,
123
                irq_vector_cpu => irq_vector_cpu,
124
                irq_cpu => irq_cpu,
125
                irq_ack_cpu => irq_ack_cpu,
126
                inst_addr_cpu => inst_addr_cpu,
127
                inst_in_cpu => inst_in_cpu,
128
                data_addr_cpu => data_addr_cpu,
129
                data_in_cpu => data_in_cpu,
130
                data_out_cpu => data_out_cpu,
131
                data_w_cpu => data_w_cpu,
132
                data_access_cpu => data_access_cpu,
133
 
134
                addr_mem => address,
135
                data_read_mem => data_read,
136
                data_write_mem => data_write,
137
                data_we_mem => data_we,
138
                extio_in => ext_irq,
139
                extio_out => open,
140
                uart_read => uart_read,
141
                uart_write => uart_write
142
        );
143
 
144
        -- instruction and data memory (boot RAM)
145
        boot_ram: entity work.ram
146
        generic map (memory_type => "DEFAULT")
147
        port map (
148
                clk                     => clock,
149
                enable                  => boot_enable,
150
                write_byte_enable       => "0000",
151
                address                 => address(31 downto 2),
152
                data_write              => (others => '0'),
153
                data_read               => data_read_boot
154
        );
155
 
156
        -- instruction and data memory (external SRAM)
157
        -- very simple SRAM memory controller using both IS61LV25616AL chips.
158
        -- these SRAMs have 16-bit words, so we use both chips and access each using low and
159
        -- high banks. using this arrangement, we have byte addressable 32-bit words.
160
        -- the address bus is controlled directly by the CPU.
161
        ram_enable_n <= '0' when address(31 downto 28) = "0100" else '1';
162
        ram_address <= address(31 downto 2);
163
        ram_we_n <= we_n_reg;
164
 
165
        ram_control:
166
        process(clock, ram_enable_n, data_we, data_write)
167
        begin
168
                if ram_enable_n = '0' then                       --SRAM
169
                        ram_ce1_n <= '0';
170
                        ram_ce2_n <= '0';
171
                        if data_we = "0000" then                -- read
172
                                ram_data  <= (others => 'Z');
173
                                ram_ub1_n <= '0';
174
                                ram_lb1_n <= '0';
175
                                ram_ub2_n <= '0';
176
                                ram_lb2_n <= '0';
177
                                we_n_next <= '1';
178
                                ram_oe_n  <= '0';
179
                        else                                    -- write
180
                                if clock = '1' then
181
                                        ram_data <= (others => 'Z');
182
                                else
183
                                        ram_data <= data_write;
184
                                end if;
185
                                ram_ub1_n <= not data_we(3);
186
                                ram_lb1_n <= not data_we(2);
187
                                ram_ub2_n <= not data_we(1);
188
                                ram_lb2_n <= not data_we(0);
189
                                we_n_next <= '0';
190
                                ram_oe_n  <= '1';
191
                        end if;
192
                else
193
                        ram_data <= (others => 'Z');
194
                        ram_ce1_n <= '1';
195
                        ram_ub1_n <= '1';
196
                        ram_lb1_n <= '1';
197
                        ram_ce2_n <= '1';
198
                        ram_ub2_n <= '1';
199
                        ram_lb2_n <= '1';
200
                        we_n_next <= '1';
201
                        ram_oe_n  <= '1';
202
                end if;
203
        end process;
204
 
205
end interface;
206
 

powered by: WebSVN 2.1.0

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