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

Subversion Repositories xucpu

[/] [xucpu/] [trunk/] [src/] [system/] [system.vhdl] - Blame information for rev 9

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

Line No. Rev Author Line
1 8 lcdsgmtr
-- Copyright 2015, Jürgen Defurne
2
--
3
-- This file is part of the Experimental Unstable CPU System.
4
--
5
-- The Experimental Unstable CPU System Is free software: you can redistribute
6
-- it and/or modify it under the terms of the GNU Lesser General Public License
7
-- as published by the Free Software Foundation, either version 3 of the
8
-- License, or (at your option) any later version.
9
--
10
-- The Experimental Unstable CPU System is distributed in the hope that it will
11
-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
13
-- General Public License for more details.
14
--
15
-- You should have received a copy of the GNU Lesser General Public License
16
-- along with Experimental Unstable CPU System. If not, see
17
-- http://www.gnu.org/licenses/lgpl.txt.
18
 
19
 
20
LIBRARY IEEE;
21
USE IEEE.STD_LOGIC_1164.ALL;
22
USE IEEE.numeric_std.ALL;
23
USE work.components.ALL;
24
USE work.ram_parts.ALL;
25
USE work.mux_parts.ALL;
26
USE work.controllers.ALL;
27
 
28
-- LIBRARY unisim;
29
-- USE unisim.vcomponents.ALL;
30
 
31
ENTITY system IS
32
  PORT (
33
    clock     : IN  STD_LOGIC;
34
    reset     : IN  STD_LOGIC;
35
    led_out   : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
36
    switch_in : IN  STD_LOGIC_VECTOR(7 DOWNTO 0);
37
    pushb_in  : IN  STD_LOGIC_VECTOR(4 DOWNTO 0));
38
END system;
39
 
40
ARCHITECTURE Structural OF system IS
41
 
42
  CONSTANT w_data : POSITIVE := 16;
43
 
44
  SIGNAL CLK     : STD_LOGIC;           -- System clock
45
  SIGNAL CLK_VAL : STD_LOGIC;           -- System clock valid
46
  SIGNAL RST     : STD_LOGIC;           -- System synchronous reset
47
 
48
  -- All signals for the instruction and data processing
49
  -- Ordered in proper bundles per pipeline stage
50
 
51
  -- FiRST stage in the instruction pipeline is the program counter circuitry
52
  SIGNAL PC_SRC  : STD_LOGIC_VECTOR(2 DOWNTO 0)  := "000";
53
  SIGNAL LD_PC   : STD_LOGIC                     := '0';
54
  SIGNAL PC_INC  : STD_LOGIC_VECTOR(14 DOWNTO 0) := "000000000000000";
55
  SIGNAL PC_NEXT : STD_LOGIC_VECTOR(14 DOWNTO 0) := "000000000000000";
56
 
57
  -- The second stage in the instruction pipeline is the memory, followed by
58
  -- the instruction queue.
59
  SIGNAL LD_IR  : STD_LOGIC := '0';
60
  SIGNAL LD_DP  : STD_LOGIC := '0';
61
  SIGNAL LD_REG : STD_LOGIC := '0';
62
 
63
  SIGNAL RFA_A  : STD_LOGIC_VECTOR(3 DOWNTO 0) := "0000";
64
  SIGNAL RFA_B  : STD_LOGIC_VECTOR(3 DOWNTO 0) := "0000";
65
  SIGNAL ALU_OP : STD_LOGIC_VECTOR(3 DOWNTO 0) := "0000";
66
 
67
  SIGNAL REG_SRC      : STD_LOGIC_VECTOR(2 DOWNTO 0)  := "111";
68
  SIGNAL DATABUS_OUT : STD_LOGIC_VECTOR(15 DOWNTO 0);
69
  SIGNAL DATABUS_READ : STD_LOGIC_VECTOR(15 DOWNTO 0) := X"0000";
70
  SIGNAL INSTR_OUT    : STD_LOGIC_VECTOR(15 DOWNTO 0) := X"0000";
71
 
72
  SIGNAL REG_WR  : STD_LOGIC                     := '1';
73
  SIGNAL REG_BUS : STD_LOGIC_VECTOR(15 DOWNTO 0) := X"0000";
74
  SIGNAL A_OUT   : STD_LOGIC_VECTOR(15 DOWNTO 0) := X"0000";
75
  SIGNAL B_OUT   : STD_LOGIC_VECTOR(15 DOWNTO 0) := X"0000";
76
 
77
  SIGNAL LD_MAR   : STD_LOGIC;
78
  SIGNAL LD_MDR   : STD_LOGIC;
79
 
80
  SIGNAL QA      : STD_LOGIC_VECTOR(15 DOWNTO 0) := X"0000";
81
  SIGNAL QB      : STD_LOGIC_VECTOR(15 DOWNTO 0) := X"0000";
82
  SIGNAL ALU_OUT : STD_LOGIC_VECTOR(15 DOWNTO 0) := X"0000";
83
 
84
  SIGNAL DATA_ADDRESS  : STD_LOGIC_VECTOR(14 DOWNTO 0) := "000000000000000";
85
  SIGNAL DATABUS_WRITE : STD_LOGIC_VECTOR(15 DOWNTO 0) := X"0000";
86
 
87
  SIGNAL DOSEL : STD_LOGIC_VECTOR(2 DOWNTO 0) := "000";
88
  SIGNAL EOUT1 : STD_LOGIC;
89
  SIGNAL EIN1  : STD_LOGIC;
90
  SIGNAL EIN2  : STD_LOGIC;
91
 
92
  SIGNAL MEM_WR    : STD_LOGIC                     := '1';
93
  SIGNAL PC_OUT    : STD_LOGIC_VECTOR(14 DOWNTO 0) := "000000000000000";
94
  SIGNAL PC_TO_REG : STD_LOGIC_VECTOR(15 DOWNTO 0) := X"0000";
95
 
96
  SIGNAL DO1   : STD_LOGIC_VECTOR(15 DOWNTO 0) := X"0000";
97
  SIGNAL DO2   : STD_LOGIC_VECTOR(15 DOWNTO 0) := X"0000";
98
  SIGNAL DO3   : STD_LOGIC_VECTOR(15 DOWNTO 0) := X"0000";
99
  SIGNAL MEMO4 : STD_LOGIC_VECTOR(15 DOWNTO 0) := X"0000";
100
  SIGNAL INSO4 : STD_LOGIC_VECTOR(15 DOWNTO 0) := X"0000";
101
  SIGNAL INSTR : STD_LOGIC_VECTOR(15 DOWNTO 0) := X"0000";
102
  SIGNAL IMMED : STD_LOGIC_VECTOR(15 DOWNTO 0) := X"0000";
103
 
104
  SIGNAL I_ZERO : STD_LOGIC;
105
  SIGNAL ZERO   : STD_LOGIC;
106
  SIGNAL INT    : STD_LOGIC;
107
 
108
BEGIN
109
 
110
  -- Clock generator with selectable speed and reset
111
  CLOCK1 : clock_gen
112
    PORT MAP (
113
      CLK_IN    => CLOCK,
114
      RESET     => RESET,
115
      CLK_VALID => CLK_VAL,
116
      CLK_OUT   => CLK);
117
 
118
  -- Synchronous reset
119
  RST1 : sync_reset
120
    PORT MAP (
121
      ASYNC_RST => RESET,
122
      CLK       => CLK,
123
      CLK_VALID => CLK_VAL,
124
      RST       => RST);
125
 
126
  PC_TO_REG <= '0' & PC_OUT;
127
 
128
  -- Input multiplexer to register file
129
  REG_MUX : mux8to1
130
    PORT MAP (
131
      SEL => REG_SRC,
132
      S0  => ALU_OUT,                   -- "000"
133
      S1  => DATABUS_READ,              -- "001"
134
      S2  => IMMED,                     -- "010"
135
      S3  => PC_TO_REG,                 -- "011"
136
      S4  => A_OUT,                     -- "100"
137
      S5  => STD_LOGIC_VECTOR(TO_UNSIGNED(0, w_data)),
138
      S6  => STD_LOGIC_VECTOR(TO_UNSIGNED(0, w_data)),
139
      S7  => STD_LOGIC_VECTOR(TO_UNSIGNED(0, w_data)),
140
      Y   => REG_BUS);
141
 
142
  -- True if A output of register file is zero
143
  Z1 : zerof
144
    PORT MAP (
145
      A    => A_OUT,
146
      zero => I_ZERO);
147
 
148
  PROCESS(CLK)
149
  BEGIN
150
    IF rising_edge(CLK) THEN
151
      ZERO <= I_ZERO;
152
    END IF;
153
  END PROCESS;
154
 
155
  -- 16-register register file
156
  RF1 : regf
157
    PORT MAP (
158
      CLK => CLK,
159
      we  => REG_WR,
160
      a1  => RFA_A,
161
      a2  => RFA_B,
162
      d   => REG_BUS,
163
      q1  => A_OUT,
164
      q2  => B_OUT);
165
 
166
  -- Memory address register from B output
167
  MAR : data_reg
168
    GENERIC MAP (
169
      w_data => 15)
170
    PORT MAP (
171
      RST => RST,
172
      CLK => CLK,
173
      ENA => LD_MAR,
174
      D   => B_OUT(14 DOWNTO 0),
175
      Q   => DATA_ADDRESS);
176
 
177
  -- Memory data register from A output
178
  MDR : data_reg
179
    PORT MAP (
180
      RST => RST,
181
      CLK => CLK,
182
      ENA => LD_MDR,
183
      D   => A_OUT,
184
      Q   => DATABUS_WRITE);
185
 
186
  -- 16 function A output
187
  ALU1 : alu
188
    PORT MAP (
189
      clk => CLK,
190
      op  => ALU_OP,
191
      A   => A_OUT,
192
      B   => B_OUT,
193
      Y   => ALU_OUT);
194
 
195
-- Multiplexer for program counter input
196
  PC_MUX : mux8to1
197
    GENERIC MAP (
198
      w_data => 15)
199
    PORT MAP (
200
      SEL => PC_SRC,
201
      S0  => A_OUT(14 DOWNTO 0),                           -- "000"
202
      S1  => PC_INC,                                       -- "001"
203
      S2  => IMMED(14 DOWNTO 0),                           -- "010"
204
      S3  => PC_OUT,                                       -- "011"
205
      S4  => STD_LOGIC_VECTOR(TO_UNSIGNED(16#7FF0#, 15)),  -- "100"
206
      S5  => STD_LOGIC_VECTOR(TO_UNSIGNED(16#0000#, 15)),  -- "101"
207
      S6  => STD_LOGIC_VECTOR(TO_UNSIGNED(16#0000#, 15)),  -- "110"
208
      S7  => INSO4(14 DOWNTO 0),                           -- "111"
209
      Y   => PC_NEXT);
210
 
211
-- Program counter
212
  PC : data_reg
213
    GENERIC MAP (
214
      w_data      => 15)
215
    PORT MAP (
216
      RST => RST,
217
      CLK => CLK,
218
      ENA => LD_PC,
219
      D   => PC_NEXT,
220
      Q   => PC_OUT);
221
 
222
-- Incrementer for program counter
223
  PC_INC1 : incr
224
    GENERIC MAP (
225
      w_data => 15)
226
    PORT MAP (
227
      A => PC_OUT,
228
      Y => PC_INC);
229
 
230
  CTRL1 : uctrl
231
    PORT MAP (
232
      CLK      => CLK,
233
      RST      => RST,
234
      PC_SRC   => PC_SRC,
235
      LD_PC    => LD_PC,
236
      LD_IR    => LD_IR,
237
      LD_DP    => LD_DP,
238
      REG_SRC  => REG_SRC,
239
      RFA_A    => RFA_A,
240
      RFA_B    => RFA_B,
241
      REG_WR   => REG_WR,
242
      LD_MAR   => LD_MAR,
243
      LD_MDR   => LD_MDR,
244
      MEM_WR   => MEM_WR,
245
      ALU_OP   => ALU_OP,
246
      INT      => INT,
247
      ZERO     => ZERO,
248
      IR_IN    => INSTR);
249
 
250
-- Decoder for IO
251
  IO_DEC : decoder
252
    PORT MAP (
253
      clk     => CLK,
254
      ena     => LD_MAR,
255
      a1      => B_OUT(14 DOWNTO 0),
256
      gpio_1  => EOUT1,
257
      gpio_2  => EIN1,
258
      gpio_3  => EIN2,
259
      bus_sel => DOSEL);
260
 
261
-- Simple output register for LED output port
262
  OUT1 : gpio_out
263
    GENERIC MAP (
264
      w_port => 8)
265
    PORT MAP (
266
      RST      => RST,
267
      CLK      => CLK,
268
      ena      => EOUT1,
269
      we       => MEM_WR,
270
      D        => DATABUS_WRITE,
271
      Q        => DO1,
272
      port_out => led_out);
273
 
274
-- Simple input register for switches
275
  IN1 : gpio_in
276
    GENERIC MAP (
277
      w_port => 8)
278
    PORT MAP (
279
      RST     => RST,
280
      CLK     => CLK,
281
      ena     => EIN1,
282
      Q       => DO2,
283
      port_in => switch_in);
284
 
285
-- Simple input register for push buttons
286
  IN2 : gpio_in
287
    GENERIC MAP (
288
      w_port => 5)
289
    PORT MAP (
290
      RST     => RST,
291
      CLK     => CLK,
292
      ena     => EIN2,
293
      Q       => DO3,
294
      port_in => pushb_in);
295
 
296
-- 1kx16 two port RAM
297
  MEM1 : generic_ram
298
    GENERIC MAP (
299
      filename => "input_data.txt",
300
      w_addr   => 10)
301
    PORT MAP (
302
      CLK => CLK,
303
      we  => MEM_WR,
304
      a1  => B_OUT(9 DOWNTO 0),
305
      a2  => PC_NEXT(9 DOWNTO 0),
306
      d1  => A_OUT,
307
      q1  => MEMO4,                     -- Data memory output
308
      q2  => INSO4);                    -- Instruction memory output
309
 
310
  IR : data_reg
311
    PORT MAP (
312
      RST => RST,
313
      CLK => CLK,
314
      ENA => LD_IR,
315
      D   => INSO4,
316
      Q   => INSTR);
317
 
318
  DR : data_reg
319
    PORT MAP (
320
      RST => RST,
321
      CLK => CLK,
322
      ENA => LD_DP,
323
      D   => INSO4,
324
      Q   => IMMED);
325
 
326
-- RAM/input device READ multiplexer
327
  BUS_MUX : mux8to1
328
    PORT MAP (
329
      SEL => DOSEL,
330
      S0  => DO1,
331
      S1  => DO2,
332
      S2  => DO3,
333
      S3  => STD_LOGIC_VECTOR(TO_UNSIGNED(0, w_data)),
334
      S4  => STD_LOGIC_VECTOR(TO_UNSIGNED(0, w_data)),
335
      S5  => STD_LOGIC_VECTOR(TO_UNSIGNED(0, w_data)),
336
      S6  => STD_LOGIC_VECTOR(TO_UNSIGNED(0, w_data)),
337
      S7  => MEMO4,
338
      Y   => DATABUS_OUT);
339
 
340
  BUSR : data_reg_2 PORT MAP (
341
    CLK => CLK,
342
    D   => DATABUS_OUT,
343
    Q   => DATABUS_READ);
344
 
345
END Structural;

powered by: WebSVN 2.1.0

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