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

Subversion Repositories tinycpu

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

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

Line No. Rev Author Line
1 18 earlz
--Memory management component
2
--By having this separate, it should be fairly easy to add RAMs or ROMs later
3
--This basically lets the CPU not have to worry about how memory "Really" works
4
--currently just one RAM. 1024 byte blockram.vhd mapped as 0 - 1023
5 6 earlz
 
6 4 earlz
library IEEE;
7
use IEEE.STD_LOGIC_1164.ALL;
8
use IEEE.NUMERIC_STD.ALL;
9
 
10 6 earlz
 
11
 
12 4 earlz
entity memory is
13
  port(
14 18 earlz
    Address: in std_logic_vector(15 downto 0); --memory address (in bytes)
15
    WriteWord: in std_logic; --if set, will write a full 16-bit word instead of a byte. Address must be aligned to 16-bit address. (bottom bit must be 0)
16
    WriteEnable: in std_logic;
17 4 earlz
    Clock: in std_logic;
18
    DataIn: in std_logic_vector(15 downto 0);
19 18 earlz
    DataOut: out std_logic_vector(15 downto 0)
20
--    Reset: in std_logic
21
 
22
    --RAM/ROM interface (RAMA is built in to here
23
    --RAMBDataIn: out std_logic_vector(15 downto 0);
24
    --RAMBDataOut: in std_logic_vector(15 downto 0);
25
    --RAMBAddress: out std_logic_vector(15 downto 0);
26
    --RAMBWriteEnable: out std_logic_vector(1 downto 0);
27 4 earlz
  );
28
end memory;
29
 
30
architecture Behavioral of memory is
31 18 earlz
 
32
  component blockram
33
    port(
34
      Address: in std_logic_vector(7 downto 0); --memory address
35
      WriteEnable: in std_logic_vector(1 downto 0); --write or read
36
      Enable: in std_logic;
37
      Clock: in std_logic;
38
      DataIn: in std_logic_vector(15 downto 0);
39
      DataOut: out std_logic_vector(15 downto 0)
40
    );
41
  end component;
42
 
43
  constant R1START: integer := 0;
44
  constant R1END: integer := 1023;
45
  signal addr: std_logic_vector(15 downto 0) := (others => '0');
46
  signal R1addr: std_logic_vector(7 downto 0);
47
  signal we: std_logic_vector(1 downto 0);
48
  signal datawrite: std_logic_vector(15 downto 0);
49
  signal dataread: std_logic_vector(15 downto 0);
50
  --signal en: std_logic;
51
  signal R1we: std_logic_vector(1 downto 0);
52
  signal R1en: std_logic;
53
  signal R1in: std_logic_vector(15 downto 0);
54
  signal R1out: std_logic_vector(15 downto 0);
55 4 earlz
begin
56 18 earlz
  R1: blockram port map (R1addr, R1we, R1en, Clock, R1in, R1out);
57
  addrwe: process(Address, WriteWord, WriteEnable, DataIn)
58 4 earlz
  begin
59 18 earlz
    addr <= Address(15 downto 1) & '0';
60
    if WriteEnable='1' then
61
      if WriteWord='1' then
62
        we <= "11";
63
        datawrite <= DataIn;
64
      else
65
        if Address(0)='0' then
66
          we <= "01";
67
          datawrite <= x"00" & DataIn(7 downto 0); --not really necessary
68
        else
69
          we <= "10";
70
          datawrite <= DataIn(7 downto 0) & x"00";
71 4 earlz
        end if;
72
      end if;
73 18 earlz
    else
74
      we <= "00";
75 4 earlz
    end if;
76
  end process;
77 18 earlz
 
78
  assignram: process (we, datawrite, addr, r1out)
79
  variable tmp: integer;
80
  variable found: boolean := false;
81 4 earlz
  begin
82 18 earlz
    tmp := to_integer(unsigned(addr));
83
    if tmp >= R1START and tmp <= R1END then
84
      --map all to R1
85
      found := true;
86
      R1en <= '1';
87
      R1we <= we;
88
      R1in <= datawrite;
89
      dataread <= R1out;
90
      R1addr <= addr(8 downto 1);
91
    else
92
      R1en <= '0';
93
      R1we <= "00";
94
      R1in <= x"0000";
95
      R1addr <= x"00";
96
      dataread <= x"0000";
97 4 earlz
    end if;
98
  end process;
99 18 earlz
 
100
  readdata: process(Address, dataread)
101
  begin
102
    if Address(0) = '0' then
103
      DataOut <= dataread;
104
    else
105
      DataOut <= x"00" & dataread(15 downto 8);
106
    end if;
107
  end process;
108
 
109 4 earlz
end Behavioral;

powered by: WebSVN 2.1.0

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