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

Subversion Repositories potato

[/] [potato/] [trunk/] [soc/] [pp_soc_memory.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 skordal
-- The Potato Processor - A simple processor for FPGAs
2
-- (c) Kristian Klomsten Skordal 2014 - 2015 <kristian.skordal@wafflemail.net>
3 3 skordal
-- Report bugs and issues on <http://opencores.org/project,potato,bugtracker>
4 2 skordal
 
5
library ieee;
6
use ieee.std_logic_1164.all;
7
use ieee.numeric_std.all;
8
use ieee.std_logic_textio.all;
9
use std.textio.all;
10
 
11
use work.pp_utilities.all;
12
 
13
--! @brief Simple memory module for use in Wishbone-based systems.
14
entity pp_soc_memory is
15
        generic(
16
                MEMORY_SIZE : natural := 4096 --! Memory size in bytes.
17
        );
18
        port(
19
                clk : in std_logic;
20
                reset : in std_logic;
21
 
22
                -- Wishbone interface:
23
                wb_adr_in  : in  std_logic_vector(log2(MEMORY_SIZE) - 1 downto 0);
24
                wb_dat_in  : in  std_logic_vector(31 downto 0);
25
                wb_dat_out : out std_logic_vector(31 downto 0);
26
                wb_cyc_in  : in  std_logic;
27
                wb_stb_in  : in  std_logic;
28
                wb_sel_in  : in  std_logic_vector( 3 downto 0);
29
                wb_we_in   : in  std_logic;
30
                wb_ack_out : out std_logic
31
        );
32
end entity pp_soc_memory;
33
 
34
architecture behaviour of pp_soc_memory is
35
        type memory_array is array(0 to (MEMORY_SIZE / 4) - 1) of std_logic_vector(31 downto 0);
36
        signal memory : memory_array := (others => (others => '0'));
37
 
38
        attribute ram_style : string;
39
        attribute ram_style of memory : signal is "block";
40
 
41
        type state_type is (IDLE, ACK);
42
        signal state : state_type;
43
 
44
        signal read_ack : std_logic;
45
 
46
begin
47
 
48
        wb_ack_out <= read_ack and wb_stb_in;
49
 
50
        process(clk)
51
        begin
52
                if rising_edge(clk) then
53
                        if reset = '1' then
54
                                read_ack <= '0';
55
                                state <= IDLE;
56
                        else
57
                                if wb_cyc_in = '1' then
58
                                        case state is
59
                                                when IDLE =>
60
                                                        if wb_stb_in = '1' and wb_we_in = '1' then
61
                                                                 for i in 0 to 3 loop
62
                                                                        if wb_sel_in(i) = '1' then
63
                                                                                memory(to_integer(unsigned(wb_adr_in(wb_adr_in'left downto 2))))(((i + 1) * 8) - 1 downto i * 8)
64
                                                                                        <= wb_dat_in(((i + 1) * 8) - 1 downto i * 8);
65
                                                                        end if;
66
                                                                 end loop;
67
                                                                 read_ack <= '1';
68
                                                                 state <= ACK;
69
                                                        elsif wb_stb_in = '1' then
70
                                                                wb_dat_out <= memory(to_integer(unsigned(wb_adr_in(wb_adr_in'left downto 2))));
71
                                                                read_ack <= '1';
72
                                                                state <= ACK;
73
                                                        end if;
74
                                                when ACK =>
75
                                                        if wb_stb_in = '0' then
76
                                                                read_ack <= '0';
77
                                                                state <= IDLE;
78
                                                        end if;
79
                                        end case;
80
                                else
81
                                        state <= IDLE;
82
                                        read_ack <= '0';
83
                                end if;
84
                        end if;
85
                end if;
86
        end process clk;
87
 
88
end architecture behaviour;

powered by: WebSVN 2.1.0

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