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

Subversion Repositories tinycpu

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

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 7 earlz
  constant BUSSIZE : integer := 8;
30
  type memorytype is array(0 to integer((2**BUSSIZE))) of std_logic_vector(7 downto 0);
31 4 earlz
  signal mem: memorytype;
32
begin
33
 
34
  writemem: process(Reset,Write, Address, UseTopBits, Clock)
35 7 earlz
    variable addr: integer range 0 to (2**BUSSIZE)-1 := 0;
36 4 earlz
  begin
37 7 earlz
    addr := conv_integer(Address(BUSSIZE-1 downto 0));
38 6 earlz
    if(rising_edge(Clock)) then
39
      if(Reset ='1') then
40 7 earlz
        --mem <= (others => "00000000");
41 6 earlz
      elsif( Write='1') then
42 7 earlz
        mem(addr) <= DataIn(7 downto 0);
43 4 earlz
        if(UseTopBits='1') then
44 7 earlz
          mem(addr+1) <= DataIn(15 downto 8);
45 4 earlz
        end if;
46
      end if;
47
    end if;
48
  end process;
49
  readmem: process(Reset,Address,Write,Clock)
50 7 earlz
    variable addr: integer range 0 to (2**BUSSIZE)-1 := 0;
51
    variable addr2: integer range 0 to (2**BUSSIZE)-1 := 0; -- for second part
52 4 earlz
  begin
53 7 earlz
    addr := conv_integer(Address(BUSSIZE-1 downto 0));
54
    addr2 := conv_integer(Address(BUSSIZE-1 downto 0));
55 4 earlz
    if(Reset='1') then
56
      DataOut <= (others => '0');
57
    elsif(Write='0') then
58 7 earlz
      DataOut <= mem(addr+1) & mem(addr);
59 4 earlz
    else
60
      DataOut <= (others => '0');
61
    end if;
62
  end process;
63
end Behavioral;

powered by: WebSVN 2.1.0

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