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

Subversion Repositories tinycpu

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

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

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

powered by: WebSVN 2.1.0

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