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

Subversion Repositories hf-risc

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

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, exception_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)
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
        end process;
51
 
52
        -- reset synchronizer
53
        process (clock, reset_in)
54
        begin
55
                if (reset_in = '1') then
56
                        rff1 <= '1';
57
                        reset <= '1';
58
                elsif (clock'event and clock = '1') then
59
                        rff1 <= '0';
60
                        reset <= rff1;
61
                end if;
62
        end process;
63
 
64
        process (reset, clock, ext_irq, ram_enable_n, ram_data)
65
        begin
66
                if reset = '1' then
67
                        data_read_ram <= (others => '0');
68
                        ram_dly <= '0';
69
                        ext_irq <= x"00";
70
                elsif clock'event and clock = '1' then
71
                        data_read_ram <= ram_data;
72
                        ram_dly <= not ram_enable_n;
73
                        ext_irq <= "0000000" & int_in;
74
                end if;
75
        end process;
76
 
77
        stall <= '0';
78
        boot_enable <= '1' when address(31 downto 28) = "0000" else '0';
79
        data_read <= data_read_boot when address(31 downto 28) = "0000" and ram_dly = '0' else data_read_ram;
80
 
81
        -- HF-RISCV core
82
        core: entity work.datapath
83
        port map(       clock => clock,
84
                        reset => reset,
85
                        stall => stall_cpu,
86
                        busy => busy_cpu,
87
                        irq_vector => irq_vector_cpu,
88
                        irq => irq_cpu,
89
                        irq_ack => irq_ack_cpu,
90
                        exception => exception_cpu,
91
                        inst_addr => inst_addr_cpu,
92
                        inst_in => inst_in_cpu,
93
                        data_addr => data_addr_cpu,
94
                        data_in => data_in_cpu,
95
                        data_out => data_out_cpu,
96
                        data_w => data_w_cpu,
97
                        data_access => data_access_cpu
98
        );
99
 
100
        -- peripherals / busmux logic
101
        peripherals_busmux: entity work.busmux
102
        generic map(
103
                uart_support => uart_support
104
        )
105
        port map(
106
                clock => clock,
107
                reset => reset,
108
 
109
                stall => stall,
110
 
111
                stall_cpu => stall_cpu,
112
                busy_cpu => busy_cpu,
113
                irq_vector_cpu => irq_vector_cpu,
114
                irq_cpu => irq_cpu,
115
                irq_ack_cpu => irq_ack_cpu,
116
                exception_cpu => exception_cpu,
117
                inst_addr_cpu => inst_addr_cpu,
118
                inst_in_cpu => inst_in_cpu,
119
                data_addr_cpu => data_addr_cpu,
120
                data_in_cpu => data_in_cpu,
121
                data_out_cpu => data_out_cpu,
122
                data_w_cpu => data_w_cpu,
123
                data_access_cpu => data_access_cpu,
124
 
125
                addr_mem => address,
126
                data_read_mem => data_read,
127
                data_write_mem => data_write,
128
                data_we_mem => data_we,
129
                extio_in => ext_irq,
130
                extio_out => open,
131
                uart_read => uart_read,
132
                uart_write => uart_write
133
        );
134
 
135
        -- instruction and data memory (boot RAM)
136
        boot_ram: entity work.ram
137
        generic map (memory_type => "DEFAULT")
138
        port map (
139
                clk                     => clock,
140
                enable                  => boot_enable,
141
                write_byte_enable       => "0000",
142
                address                 => address(31 downto 2),
143
                data_write              => (others => '0'),
144
                data_read               => data_read_boot
145
        );
146
 
147
        -- instruction and data memory (external SRAM)
148
        -- very simple SRAM memory controller using both IS61LV25616AL chips.
149
        -- these SRAMs have 16-bit words, so we use both chips and access each using low and
150
        -- high banks. using this arrangement, we have byte addressable 32-bit words.
151
        -- the address bus is controlled directly by the CPU.
152
        ram_enable_n <= '0' when address(31 downto 28) = "0100" else '1';
153
        ram_address <= address(31 downto 2);
154
 
155
        ram_control:
156
        process(clock, ram_enable_n, data_we, data_write)
157
        begin
158
                if ram_enable_n = '0' then                       --SRAM
159
                        ram_ce1_n <= '0';
160
                        ram_ce2_n <= '0';
161
                        if data_we = "0000" then                -- read
162
                                ram_data  <= (others => 'Z');
163
                                ram_ub1_n <= '0';
164
                                ram_lb1_n <= '0';
165
                                ram_ub2_n <= '0';
166
                                ram_lb2_n <= '0';
167
                                ram_we_n <= '1';
168
                                ram_oe_n  <= '0';
169
                        else                                    -- write
170
                                ram_data <= data_write;
171
                                ram_ub1_n <= not data_we(3);
172
                                ram_lb1_n <= not data_we(2);
173
                                ram_ub2_n <= not data_we(1);
174
                                ram_lb2_n <= not data_we(0);
175
                                if clock = '0' then
176
                                        ram_we_n <= '0';
177
                                else
178
                                        ram_we_n <= '1';
179
                                end if;
180
                                ram_oe_n  <= '1';
181
                        end if;
182
                else
183
                        ram_data <= (others => 'Z');
184
                        ram_ce1_n <= '1';
185
                        ram_ub1_n <= '1';
186
                        ram_lb1_n <= '1';
187
                        ram_ce2_n <= '1';
188
                        ram_ub2_n <= '1';
189
                        ram_lb2_n <= '1';
190
                        ram_we_n <= '1';
191
                        ram_oe_n  <= '1';
192
                end if;
193
        end process;
194
 
195
end interface;
196
 

powered by: WebSVN 2.1.0

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