1 -- The Potato Processor - A simple processor for FPGAs
2 -- (c) Kristian Klomsten Skordal 2014 - 2015 <kristian.skordal@wafflemail.net>
5 use ieee.std_logic_1164.all;
6 use ieee.numeric_std.all;
9 use work.pp_utilities.all;
11 --! @brief Simple memory module for use in Wishbone-based systems.
12 entity pp_soc_memory is
14 MEMORY_SIZE : natural := 4096; --! Memory size in bytes.
15 RAM_INIT_FILE : string
21 -- Wishbone interface:
22 wb_adr_in : in std_logic_vector(log2(MEMORY_SIZE) - 1 downto 0);
23 wb_dat_in : in std_logic_vector(63 downto 0);
24 wb_dat_out : out std_logic_vector(63 downto 0);
25 wb_cyc_in : in std_logic;
26 wb_stb_in : in std_logic;
27 wb_sel_in : in std_logic_vector( 7 downto 0);
28 wb_we_in : in std_logic;
29 wb_ack_out : out std_logic
31 end entity pp_soc_memory;
33 architecture behaviour of pp_soc_memory is
34 type ram_t is array(0 to (MEMORY_SIZE / 8) - 1) of std_logic_vector(63 downto 0);
36 impure function init_ram(name : STRING) return ram_t is
37 file ram_file : text open read_mode is name;
38 variable ram_line : line;
39 variable temp_word : std_logic_vector(63 downto 0);
40 variable temp_ram : ram_t := (others => (others => '0'));
42 for i in 0 to (MEMORY_SIZE/8)-1 loop
43 exit when endfile(ram_file);
44 readline(ram_file, ram_line);
45 hread(ram_line, temp_word);
46 temp_ram(i) := temp_word;
52 signal memory : ram_t := init_ram(RAM_INIT_FILE);
54 attribute ram_style : string;
55 attribute ram_style of memory : signal is "block";
57 attribute ram_decomp : string;
58 attribute ram_decomp of memory : signal is "power";
60 type state_type is (IDLE, ACK);
61 signal state : state_type;
63 signal read_ack : std_logic;
67 wb_ack_out <= read_ack and wb_stb_in;
71 if rising_edge(clk) then
76 if wb_cyc_in = '1' then
79 if wb_stb_in = '1' and wb_we_in = '1' then
81 if wb_sel_in(i) = '1' then
82 memory(to_integer(unsigned(wb_adr_in(wb_adr_in'left downto 3))))(((i + 1) * 8) - 1 downto i * 8)
83 <= wb_dat_in(((i + 1) * 8) - 1 downto i * 8);
88 elsif wb_stb_in = '1' then
89 wb_dat_out <= memory(to_integer(unsigned(wb_adr_in(wb_adr_in'left downto 3))));
94 if wb_stb_in = '0' then
107 end architecture behaviour;