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

Subversion Repositories tinycpu

[/] [tinycpu/] [trunk/] [src/] [blockram.vhd] - Blame information for rev 22

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

Line No. Rev Author Line
1 8 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
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
entity blockram is
15
  port(
16 10 earlz
    Address: in std_logic_vector(7 downto 0); --memory address
17 9 earlz
    WriteEnable: in std_logic_vector(1 downto 0); --write 1 byte at a time option
18 8 earlz
    Enable: in std_logic;
19
    Clock: in std_logic;
20
    DataIn: in std_logic_vector(15 downto 0);
21
    DataOut: out std_logic_vector(15 downto 0)
22
  );
23
end blockram;
24
 
25
architecture Behavioral of blockram is
26 11 earlz
    type ram_type is array (255 downto 0) of std_logic_vector (7 downto 0);
27
    signal RAM0: ram_type; --Spartan 3Es don't natively support byte-wide write enables, so we'll just emulate it with 2 banks of RAM
28
    signal RAM1: ram_type;
29 10 earlz
    signal di0, di1: std_logic_vector(7 downto 0);
30
    signal do : std_logic_vector(15 downto 0);
31 8 earlz
begin
32 10 earlz
  di0 <= DataIn(7 downto 0) when WriteEnable(0)='1' else do(7 downto 0);
33
    di1 <= DataIn(15 downto 8) when WriteEnable(1)='1' else do(15 downto 8);
34 8 earlz
  process (Clock)
35
  begin
36
    if rising_edge(Clock) then
37
      if Enable = '1' then
38 11 earlz
        if WriteEnable(0)='1' then
39
          RAM0(conv_integer(Address)) <= di0;
40 10 earlz
        else
41 11 earlz
          do(7 downto 0) <= RAM0(conv_integer(Address)) ;
42 10 earlz
        end if;
43 11 earlz
        if WriteEnable(1)='1' then
44
          RAM1(conv_integer(Address)) <= di1;
45
        else
46
          do(15 downto 8) <= RAM1(conv_integer(Address));
47
        end if;
48 8 earlz
      end if;
49
    end if;
50
  end process;
51 10 earlz
  DataOut <= do;
52 8 earlz
end Behavioral;

powered by: WebSVN 2.1.0

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