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

Subversion Repositories xucpu

[/] [xucpu/] [trunk/] [src/] [system/] [1k/] [system.vhdl] - Blame information for rev 5

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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