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

Subversion Repositories tinycpu

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

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 40 earlz
  signal BootMemAddress: std_logic_vector(15 downto 0);
92 39 earlz
  signal BootDataIn: std_logic_vector(15 downto 0);
93
  signal BootDataOut: std_logic_vector(15 downto 0);
94
  signal BootDone: std_logic;
95 40 earlz
  signal BootFirst: std_logic;
96 39 earlz
  constant ROMSIZE: integer := 64;
97
  signal counter: std_logic_vector(4 downto 0);
98 23 earlz
begin
99
  cpu: core port map (
100
    MemAddr => cpuaddr,
101
    MemWW => cpuww,
102
    MemWE => cpuwe,
103
    MemIn => cpumemin,
104
    MemOut => cpumemout,
105
    Clock => Clock,
106
    Reset => Reset,
107
    Hold => Hold,
108
    HoldAck => HoldAck,
109
    DebugIR => DebugIR,
110
    DebugIP => DebugIP,
111
    DebugCS => DebugCS,
112
    DebugTR => DebugTR,
113
    DebugR0 => DebugR0
114
  );
115
  mem: memory port map(
116
    Address => MemAddress,
117
    WriteWord => MemWriteWord,
118
    WriteEnable => MemWriteEnable,
119
    Clock => Clock,
120
    DataIn => MemDataIn,
121 37 earlz
    DataOut => MemDataOut,
122
    Port0 => Port0
123 23 earlz
  );
124 39 earlz
  rom: bootrom port map(
125
    clk => clock,
126
    EN => '1',
127
    Addr => BootAddress,
128
    Data => BootDataOut
129
  );
130 40 earlz
  MemAddress <= cpuaddr when (DMA='0' and Reset='0') else BootMemAddress when (Reset='1' and DMA='0') else Address;
131 39 earlz
  MemWriteWord <= cpuww when DMA='0' and Reset='0' else '1' when Reset='1'  and DMA='0' else '1';
132
  MemWriteEnable <= cpuwe when DMA='0' and Reset='0' else'1'  when Reset='1' and DMA='0' else WriteEnable;
133
  MemDataIn <= cpumemout when DMA='0' and Reset='0' else Data when WriteEnable='1' else BootDataIn when Reset='1' and DMA='0' else "ZZZZZZZZZZZZZZZZ";
134 23 earlz
  cpumemin <= MemDataOut;
135 39 earlz
  Data <= MemDataOut when DMA='1' and Reset='0' and WriteEnable='0' else "ZZZZZZZZZZZZZZZZ";
136
  bootload: process(Clock, Reset)
137
  begin
138
    if rising_edge(clock) then
139
      if Reset='0' then
140
        counter <= "00000";
141
        BootDone <= '0';
142 40 earlz
        BootAddress <= "00000";
143
        BootDataIn <= BootDataOut;
144
        BootFirst <= '1';
145
      elsif Reset='1' and BootFirst='1' then
146
        BootMemAddress <= "00000001000" & "00000";
147
        BootAddress <= "00001";
148
        --BootDataIn <= BootDataOut;
149
        counter <= "00001";
150
        BootFirst <= '0';
151 39 earlz
      elsif Reset='1' and BootDone='0' then
152 40 earlz
        BootMemAddress <= "0000000100" & std_logic_vector(unsigned(counter)-1) & "0";
153
        BootAddress <= std_logic_vector(unsigned(counter) + 1);
154 39 earlz
        BootDataIn <= BootDataOut;
155
        counter <= std_logic_vector(unsigned(counter) + 1);
156 40 earlz
        if to_integer(unsigned(counter))>=(ROMSIZE/2-2) then
157 39 earlz
          BootDone <= '1';
158
        end if;
159
      else
160
 
161
      end if;
162
    end if;
163
  end process;
164 23 earlz
end Behavioral;

powered by: WebSVN 2.1.0

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