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

Subversion Repositories tinycpu

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

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 39 earlz
  component bootrom is
67
    port(
68
        CLK : in std_logic;
69
        EN : in std_logic;
70
        ADDR : in std_logic_vector(4 downto 0);
71
        DATA : out std_logic_vector(15 downto 0)
72
    );
73
  end component;
74 23 earlz
  signal cpuaddr: std_logic_vector(15 downto 0);
75
  signal cpuww: std_logic;
76
  signal cpuwe: std_logic;
77
  signal cpumemin: std_logic_vector(15 downto 0);
78
  signal cpumemout: std_logic_vector(15 downto 0);
79
  signal debugir: std_logic_vector(15 downto 0);
80
  signal debugip: std_logic_vector(7 downto 0);
81
  signal debugcs: std_logic_vector(7 downto 0);
82
  signal debugtr: std_logic;
83
 
84
  signal MemAddress: std_logic_vector(15 downto 0); --memory address (in bytes)
85
  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)
86
  signal MemWriteEnable: std_logic;
87
  signal MemDataIn: std_logic_vector(15 downto 0);
88
  signal MemDataOut: std_logic_vector(15 downto 0);
89 39 earlz
 
90
  signal BootAddress: std_logic_vector(4 downto 0);
91
  signal BootDataIn: std_logic_vector(15 downto 0);
92
  signal BootDataOut: std_logic_vector(15 downto 0);
93
  signal BootDone: std_logic;
94
  constant ROMSIZE: integer := 64;
95
  signal counter: std_logic_vector(4 downto 0);
96 23 earlz
begin
97
  cpu: core port map (
98
    MemAddr => cpuaddr,
99
    MemWW => cpuww,
100
    MemWE => cpuwe,
101
    MemIn => cpumemin,
102
    MemOut => cpumemout,
103
    Clock => Clock,
104
    Reset => Reset,
105
    Hold => Hold,
106
    HoldAck => HoldAck,
107
    DebugIR => DebugIR,
108
    DebugIP => DebugIP,
109
    DebugCS => DebugCS,
110
    DebugTR => DebugTR,
111
    DebugR0 => DebugR0
112
  );
113
  mem: memory port map(
114
    Address => MemAddress,
115
    WriteWord => MemWriteWord,
116
    WriteEnable => MemWriteEnable,
117
    Clock => Clock,
118
    DataIn => MemDataIn,
119 37 earlz
    DataOut => MemDataOut,
120
    Port0 => Port0
121 23 earlz
  );
122 39 earlz
  rom: bootrom port map(
123
    clk => clock,
124
    EN => '1',
125
    Addr => BootAddress,
126
    Data => BootDataOut
127
  );
128
  MemAddress <= cpuaddr when (DMA='0' and Reset='0') else "00000001000" & BootAddress when (Reset='1' and DMA='0') else Address;
129
  MemWriteWord <= cpuww when DMA='0' and Reset='0' else '1' when Reset='1'  and DMA='0' else '1';
130
  MemWriteEnable <= cpuwe when DMA='0' and Reset='0' else'1'  when Reset='1' and DMA='0' else WriteEnable;
131
  MemDataIn <= cpumemout when DMA='0' and Reset='0' else Data when WriteEnable='1' else BootDataIn when Reset='1' and DMA='0' else "ZZZZZZZZZZZZZZZZ";
132 23 earlz
  cpumemin <= MemDataOut;
133 39 earlz
  Data <= MemDataOut when DMA='1' and Reset='0' and WriteEnable='0' else "ZZZZZZZZZZZZZZZZ";
134
 
135
  bootload: process(Clock, Reset)
136
  begin
137
    if rising_edge(clock) then
138
      if Reset='0' then
139
        counter <= "00000";
140
        BootDone <= '0';
141
      elsif Reset='1' and BootDone='0' then
142
        BootAddress <= counter;
143
        BootDataIn <= BootDataOut;
144
        counter <= std_logic_vector(unsigned(counter) + 1);
145
        if to_integer(unsigned(counter))>=(ROMSIZE/2-1) then
146
          BootDone <= '1';
147
        end if;
148
      else
149
 
150
      end if;
151
    end if;
152
  end process;
153 23 earlz
end Behavioral;

powered by: WebSVN 2.1.0

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