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.
20 -- Wishbone interface:
21 wb_adr_in : in std_logic_vector(log2(MEMORY_SIZE) - 1 downto 0);
22 wb_dat_in : in std_logic_vector(63 downto 0);
23 wb_dat_out : out std_logic_vector(63 downto 0);
24 wb_cyc_in : in std_logic;
25 wb_stb_in : in std_logic;
26 wb_sel_in : in std_logic_vector( 7 downto 0);
27 wb_we_in : in std_logic;
28 wb_ack_out : out std_logic
30 end entity pp_soc_memory;
32 architecture behaviour of pp_soc_memory is
33 type ram_t is array(0 to (MEMORY_SIZE / 8) - 1) of std_logic_vector(63 downto 0);
35 impure function init_ram(name : STRING) return ram_t is
36 file ram_file : text open read_mode is name;
37 variable ram_line : line;
38 variable temp_word : std_logic_vector(63 downto 0);
39 variable temp_ram : ram_t := (others => (others => '0'));
41 for i in 0 to (MEMORY_SIZE/8)-1 loop
42 exit when endfile(ram_file);
43 readline(ram_file, ram_line);
44 hread(ram_line, temp_word);
45 temp_ram(i) := temp_word;
51 signal memory : ram_t := init_ram("firmware.hex");
53 attribute ram_style : string;
54 attribute ram_style of memory : signal is "block";
56 attribute ram_decomp : string;
57 attribute ram_decomp of memory : signal is "power";
59 type state_type is (IDLE, ACK);
60 signal state : state_type;
62 signal read_ack : std_logic;
66 wb_ack_out <= read_ack and wb_stb_in;
70 if rising_edge(clk) then
75 if wb_cyc_in = '1' then
78 if wb_stb_in = '1' and wb_we_in = '1' then
80 if wb_sel_in(i) = '1' then
81 memory(to_integer(unsigned(wb_adr_in(wb_adr_in'left downto 3))))(((i + 1) * 8) - 1 downto i * 8)
82 <= wb_dat_in(((i + 1) * 8) - 1 downto i * 8);
87 elsif wb_stb_in = '1' then
88 wb_dat_out <= memory(to_integer(unsigned(wb_adr_in(wb_adr_in'left downto 3))));
93 if wb_stb_in = '0' then
106 end architecture behaviour;