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

Subversion Repositories tinycpu

[/] [tinycpu/] [trunk/] [src/] [top.vhd] - Blame information for rev 37

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

Line No. Rev Author Line
1 23 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
library IEEE;
7
use IEEE.STD_LOGIC_1164.ALL;
8
use IEEE.NUMERIC_STD.ALL;
9
 
10
 
11
 
12
entity top is
13
  port(
14
    Reset: in std_logic;
15
    Hold: in std_logic;
16
    HoldAck: out std_logic;
17
    Clock: in std_logic;
18
    DMA: in std_logic; --when high, Address, WriteEnable, and Data are connected to memory
19
    Address: in std_logic_vector(15 downto 0); --memory address (in bytes)
20
    WriteEnable: in std_logic;
21
    Data: inout std_logic_vector(15 downto 0);
22 37 earlz
    Port0: inout std_logic_vector(7 downto 0);
23 23 earlz
    --debug ports
24
    DebugR0: out std_logic_vector(7 downto 0)
25
  );
26
end top;
27
 
28
architecture Behavioral of top is
29
 
30
  component memory is
31
    port(
32
      Address: in std_logic_vector(15 downto 0); --memory address (in bytes)
33
      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)
34
      WriteEnable: in std_logic;
35
      Clock: in std_logic;
36
      DataIn: in std_logic_vector(15 downto 0);
37 37 earlz
      DataOut: out std_logic_vector(15 downto 0);
38
      Port0: inout std_logic_vector(7 downto 0)
39 23 earlz
    );
40
  end component;
41
 
42
  component core is
43
    port(
44
      --memory interface 
45
      MemAddr: out std_logic_vector(15 downto 0); --memory address (in bytes)
46
      MemWW: out std_logic; --memory writeword
47
      MemWE: out std_logic; --memory writeenable
48
      MemIn: in std_logic_vector(15 downto 0);
49
      MemOut: out std_logic_vector(15 downto 0);
50
      --general interface
51
      Clock: in std_logic;
52
      Reset: in std_logic; --When this is high, CPU will reset within 1 clock cycles. 
53
      --Enable: in std_logic; --When this is high, the CPU executes as normal, when low the CPU stops at the next clock cycle(maintaining all state)
54
      Hold: in std_logic; --when high, CPU pauses execution and places Memory interfaces into high impendance state so the memory can be used by other components
55
      HoldAck: out std_logic; --when high, CPU acknowledged hold and buses are in high Z
56
      --todo: port interface
57
 
58
      --debug ports:
59
      DebugIR: out std_logic_vector(15 downto 0); --current instruction
60
      DebugIP: out std_logic_vector(7 downto 0); --current IP
61
      DebugCS: out std_logic_vector(7 downto 0); --current code segment
62
      DebugTR: out std_logic; --current value of TR
63
      DebugR0: out std_logic_vector(7 downto 0)
64
    );
65
  end component;
66
  signal cpuaddr: std_logic_vector(15 downto 0);
67
  signal cpuww: std_logic;
68
  signal cpuwe: std_logic;
69
  signal cpumemin: std_logic_vector(15 downto 0);
70
  signal cpumemout: std_logic_vector(15 downto 0);
71
  signal debugir: std_logic_vector(15 downto 0);
72
  signal debugip: std_logic_vector(7 downto 0);
73
  signal debugcs: std_logic_vector(7 downto 0);
74
  signal debugtr: std_logic;
75
 
76
  signal MemAddress: std_logic_vector(15 downto 0); --memory address (in bytes)
77
  signal MemWriteWord: 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)
78
  signal MemWriteEnable: std_logic;
79
  signal MemDataIn: std_logic_vector(15 downto 0);
80
  signal MemDataOut: std_logic_vector(15 downto 0);
81
begin
82
  cpu: core port map (
83
    MemAddr => cpuaddr,
84
    MemWW => cpuww,
85
    MemWE => cpuwe,
86
    MemIn => cpumemin,
87
    MemOut => cpumemout,
88
    Clock => Clock,
89
    Reset => Reset,
90
    Hold => Hold,
91
    HoldAck => HoldAck,
92
    DebugIR => DebugIR,
93
    DebugIP => DebugIP,
94
    DebugCS => DebugCS,
95
    DebugTR => DebugTR,
96
    DebugR0 => DebugR0
97
  );
98
  mem: memory port map(
99
    Address => MemAddress,
100
    WriteWord => MemWriteWord,
101
    WriteEnable => MemWriteEnable,
102
    Clock => Clock,
103
    DataIn => MemDataIn,
104 37 earlz
    DataOut => MemDataOut,
105
    Port0 => Port0
106 23 earlz
  );
107
 
108
  MemAddress <= cpuaddr when DMA='0' else Address;
109
  MemWriteWord <= cpuww when DMA='0' else '1';
110
  MemWriteEnable <= cpuwe when DMA='0' else WriteEnable;
111
  MemDataIn <= cpumemout when DMA='0' else Data when WriteEnable='1' else "ZZZZZZZZZZZZZZZZ";
112
  cpumemin <= MemDataOut;
113
  Data <= MemDataOut when DMA='1' and WriteEnable='0' else "ZZZZZZZZZZZZZZZZ";
114
 
115
end Behavioral;

powered by: WebSVN 2.1.0

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