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

Subversion Repositories xucpu

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

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 10 lcdsgmtr
 
111 8 lcdsgmtr
  -- Clock generator with selectable speed and reset
112 10 lcdsgmtr
  --CLOCK1 : clock_gen
113
  --  PORT MAP (
114
  --    CLK_IN    => CLOCK,
115
  --    RESET     => RESET,
116
  --    CLK_VALID => CLK_VAL,
117
  --    CLK_OUT   => CLK);
118 8 lcdsgmtr
 
119
  -- Synchronous reset
120 10 lcdsgmtr
  --RST1 : sync_reset
121
  --  PORT MAP (
122
  --    ASYNC_RST => RESET,
123
  --    CLK       => CLK,
124
  --    CLK_VALID => CLK_VAL,
125
  --    RST       => RST);
126 8 lcdsgmtr
 
127 10 lcdsgmtr
  CLK <= CLOCK;
128
  RST <= RESET;
129
 
130 8 lcdsgmtr
  PC_TO_REG <= '0' & PC_OUT;
131
 
132
  -- Input multiplexer to register file
133
  REG_MUX : mux8to1
134
    PORT MAP (
135
      SEL => REG_SRC,
136
      S0  => ALU_OUT,                   -- "000"
137
      S1  => DATABUS_READ,              -- "001"
138
      S2  => IMMED,                     -- "010"
139
      S3  => PC_TO_REG,                 -- "011"
140
      S4  => A_OUT,                     -- "100"
141
      S5  => STD_LOGIC_VECTOR(TO_UNSIGNED(0, w_data)),
142
      S6  => STD_LOGIC_VECTOR(TO_UNSIGNED(0, w_data)),
143
      S7  => STD_LOGIC_VECTOR(TO_UNSIGNED(0, w_data)),
144
      Y   => REG_BUS);
145
 
146
  -- True if A output of register file is zero
147
  Z1 : zerof
148
    PORT MAP (
149
      A    => A_OUT,
150
      zero => I_ZERO);
151
 
152
  PROCESS(CLK)
153
  BEGIN
154
    IF rising_edge(CLK) THEN
155
      ZERO <= I_ZERO;
156
    END IF;
157
  END PROCESS;
158
 
159
  -- 16-register register file
160
  RF1 : regf
161
    PORT MAP (
162
      CLK => CLK,
163
      we  => REG_WR,
164
      a1  => RFA_A,
165
      a2  => RFA_B,
166
      d   => REG_BUS,
167
      q1  => A_OUT,
168
      q2  => B_OUT);
169
 
170
  -- Memory address register from B output
171
  MAR : data_reg
172
    GENERIC MAP (
173
      w_data => 15)
174
    PORT MAP (
175
      RST => RST,
176
      CLK => CLK,
177
      ENA => LD_MAR,
178
      D   => B_OUT(14 DOWNTO 0),
179
      Q   => DATA_ADDRESS);
180
 
181
  -- Memory data register from A output
182
  MDR : data_reg
183
    PORT MAP (
184
      RST => RST,
185
      CLK => CLK,
186
      ENA => LD_MDR,
187
      D   => A_OUT,
188
      Q   => DATABUS_WRITE);
189
 
190
  -- 16 function A output
191
  ALU1 : alu
192
    PORT MAP (
193
      clk => CLK,
194
      op  => ALU_OP,
195
      A   => A_OUT,
196
      B   => B_OUT,
197
      Y   => ALU_OUT);
198
 
199
-- Multiplexer for program counter input
200
  PC_MUX : mux8to1
201
    GENERIC MAP (
202
      w_data => 15)
203
    PORT MAP (
204
      SEL => PC_SRC,
205
      S0  => A_OUT(14 DOWNTO 0),                           -- "000"
206
      S1  => PC_INC,                                       -- "001"
207
      S2  => IMMED(14 DOWNTO 0),                           -- "010"
208
      S3  => PC_OUT,                                       -- "011"
209
      S4  => STD_LOGIC_VECTOR(TO_UNSIGNED(16#7FF0#, 15)),  -- "100"
210
      S5  => STD_LOGIC_VECTOR(TO_UNSIGNED(16#0000#, 15)),  -- "101"
211
      S6  => STD_LOGIC_VECTOR(TO_UNSIGNED(16#0000#, 15)),  -- "110"
212
      S7  => INSO4(14 DOWNTO 0),                           -- "111"
213
      Y   => PC_NEXT);
214
 
215
-- Program counter
216
  PC : data_reg
217
    GENERIC MAP (
218
      w_data      => 15)
219
    PORT MAP (
220
      RST => RST,
221
      CLK => CLK,
222
      ENA => LD_PC,
223
      D   => PC_NEXT,
224
      Q   => PC_OUT);
225
 
226
-- Incrementer for program counter
227
  PC_INC1 : incr
228
    GENERIC MAP (
229
      w_data => 15)
230
    PORT MAP (
231
      A => PC_OUT,
232
      Y => PC_INC);
233
 
234
  CTRL1 : uctrl
235
    PORT MAP (
236
      CLK      => CLK,
237
      RST      => RST,
238
      PC_SRC   => PC_SRC,
239
      LD_PC    => LD_PC,
240
      LD_IR    => LD_IR,
241
      LD_DP    => LD_DP,
242
      REG_SRC  => REG_SRC,
243
      RFA_A    => RFA_A,
244
      RFA_B    => RFA_B,
245
      REG_WR   => REG_WR,
246
      LD_MAR   => LD_MAR,
247
      LD_MDR   => LD_MDR,
248
      MEM_WR   => MEM_WR,
249
      ALU_OP   => ALU_OP,
250
      INT      => INT,
251
      ZERO     => ZERO,
252
      IR_IN    => INSTR);
253
 
254
-- Decoder for IO
255
  IO_DEC : decoder
256
    PORT MAP (
257
      clk     => CLK,
258
      ena     => LD_MAR,
259
      a1      => B_OUT(14 DOWNTO 0),
260
      gpio_1  => EOUT1,
261
      gpio_2  => EIN1,
262
      gpio_3  => EIN2,
263
      bus_sel => DOSEL);
264
 
265
-- Simple output register for LED output port
266
  OUT1 : gpio_out
267
    GENERIC MAP (
268
      w_port => 8)
269
    PORT MAP (
270
      RST      => RST,
271
      CLK      => CLK,
272
      ena      => EOUT1,
273
      we       => MEM_WR,
274
      D        => DATABUS_WRITE,
275
      Q        => DO1,
276
      port_out => led_out);
277
 
278
-- Simple input register for switches
279
  IN1 : gpio_in
280
    GENERIC MAP (
281
      w_port => 8)
282
    PORT MAP (
283
      RST     => RST,
284
      CLK     => CLK,
285
      ena     => EIN1,
286
      Q       => DO2,
287
      port_in => switch_in);
288
 
289
-- Simple input register for push buttons
290
  IN2 : gpio_in
291
    GENERIC MAP (
292
      w_port => 5)
293
    PORT MAP (
294
      RST     => RST,
295
      CLK     => CLK,
296
      ena     => EIN2,
297
      Q       => DO3,
298
      port_in => pushb_in);
299
 
300
-- 1kx16 two port RAM
301
  MEM1 : generic_ram
302
    GENERIC MAP (
303
      filename => "input_data.txt",
304
      w_addr   => 10)
305
    PORT MAP (
306
      CLK => CLK,
307
      we  => MEM_WR,
308
      a1  => B_OUT(9 DOWNTO 0),
309
      a2  => PC_NEXT(9 DOWNTO 0),
310
      d1  => A_OUT,
311
      q1  => MEMO4,                     -- Data memory output
312
      q2  => INSO4);                    -- Instruction memory output
313
 
314
  IR : data_reg
315
    PORT MAP (
316
      RST => RST,
317
      CLK => CLK,
318
      ENA => LD_IR,
319
      D   => INSO4,
320
      Q   => INSTR);
321
 
322
  DR : data_reg
323
    PORT MAP (
324
      RST => RST,
325
      CLK => CLK,
326
      ENA => LD_DP,
327
      D   => INSO4,
328
      Q   => IMMED);
329
 
330
-- RAM/input device READ multiplexer
331
  BUS_MUX : mux8to1
332
    PORT MAP (
333
      SEL => DOSEL,
334
      S0  => DO1,
335
      S1  => DO2,
336
      S2  => DO3,
337
      S3  => STD_LOGIC_VECTOR(TO_UNSIGNED(0, w_data)),
338
      S4  => STD_LOGIC_VECTOR(TO_UNSIGNED(0, w_data)),
339
      S5  => STD_LOGIC_VECTOR(TO_UNSIGNED(0, w_data)),
340
      S6  => STD_LOGIC_VECTOR(TO_UNSIGNED(0, w_data)),
341
      S7  => MEMO4,
342
      Y   => DATABUS_OUT);
343
 
344
  BUSR : data_reg_2 PORT MAP (
345
    CLK => CLK,
346
    D   => DATABUS_OUT,
347
    Q   => DATABUS_READ);
348
 
349
END Structural;

powered by: WebSVN 2.1.0

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