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

Subversion Repositories tinycpu

[/] [tinycpu/] [trunk/] [src/] [memory.vhd] - Blame information for rev 6

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 earlz
--RAM module
2
--4096*8 bit file
3
--simultaneous write/read support
4
--16 bit or 8 bit data bus
5
--16 bit address bus
6
--On Reset, will load a "default" RAM image
7
 
8 4 earlz
library IEEE;
9
use IEEE.STD_LOGIC_1164.ALL;
10
use ieee.std_logic_arith.all;
11
use IEEE.NUMERIC_STD.ALL;
12
use ieee.std_logic_unsigned.all;
13
 
14 6 earlz
 
15
 
16 4 earlz
entity memory is
17
  port(
18
    Address: in std_logic_vector(15 downto 0); --memory address
19
    Write: in std_logic; --write or read
20
    UseTopBits: in std_logic;  --if 1, top 8 bits of data is ignored and not written to memory
21
    Clock: in std_logic;
22
    DataIn: in std_logic_vector(15 downto 0);
23
    DataOut: out std_logic_vector(15 downto 0);
24
    Reset: in std_logic
25
  );
26
end memory;
27
 
28
architecture Behavioral of memory is
29
  constant SIZE : integer := 4096;
30
  type memorytype is array(0 to (size-1)) of std_logic_vector(7 downto 0);
31
  signal mem: memorytype;
32
 
33
begin
34
 
35
  writemem: process(Reset,Write, Address, UseTopBits, Clock)
36
    variable addr: integer;
37
  begin
38
    addr := conv_integer(Address);
39
    if(addr>size-1) then
40
      addr:=0;
41
    end if;
42 6 earlz
    if(rising_edge(Clock)) then
43
      if(Reset ='1') then
44
        mem <= (others => "00000000");
45
      elsif( Write='1') then
46 4 earlz
        mem(conv_integer(addr)) <= DataIn(7 downto 0);
47
        if(UseTopBits='1') then
48
          mem(conv_integer(addr)+1) <= DataIn(15 downto 8);
49
        end if;
50
      end if;
51
    end if;
52
  end process;
53
  readmem: process(Reset,Address,Write,Clock)
54
    variable addr: integer;
55
  begin
56
    addr := conv_integer(Address);
57
    if(addr>size-1) then
58
      addr:=0;
59
    end if;
60
    if(Reset='1') then
61
      DataOut <= (others => '0');
62
    elsif(Write='0') then
63
      DataOut <= mem(conv_integer(addr)+1) & mem(conv_integer(addr));
64
    else
65
      DataOut <= (others => '0');
66
    end if;
67
  end process;
68
end Behavioral;

powered by: WebSVN 2.1.0

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