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 18

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

powered by: WebSVN 2.1.0

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