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

Subversion Repositories xucpu

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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