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

Subversion Repositories uos_processor

[/] [vhdl/] [labcpu.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 droggen
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
use IEEE.STD_LOGIC_UNSIGNED.ALL;
4
 
5
entity main is
6
    Port (
7
                                clk : in STD_LOGIC;
8
                                btnU : in STD_LOGIC;
9
                                btnD : in STD_LOGIC;
10
                                btnL : in STD_LOGIC;
11
                                btnC : in STD_LOGIC;
12
                                btnR : in STD_LOGIC;
13
                                btnCpuReset : in STD_LOGIC;
14
                                sw : in STD_LOGIC_VECTOR (15 downto 0);
15
                                led : out       STD_LOGIC_VECTOR (15 downto 0);
16
                                seg : out STD_LOGIC_VECTOR(6 downto 0);
17
                                an : out STD_LOGIC_VECTOR(7 downto 0)
18
                          );
19
 
20
end main;
21
 
22
architecture Structural of main is
23
        signal reset : STD_LOGIC;
24
 
25
        -- clocks
26
        signal clkmain : STD_LOGIC;
27
        signal clkslow : STD_LOGIC;
28
 
29
 
30
 
31
 
32
 
33
        signal cpu_ram_we : STD_LOGIC;
34
        signal cpu_ram_address : STD_LOGIC_VECTOR(4 downto 0);
35
        signal cpu_ram_datawr : STD_LOGIC_VECTOR(7 downto 0);
36
        signal cpu_ram_datard : STD_LOGIC_VECTOR(7 downto 0);
37
 
38
        signal ramedit_address : STD_LOGIC_VECTOR(4 downto 0);
39
        signal ramedit_data : STD_LOGIC_VECTOR(7 downto 0);
40
        signal ramedit_enable : STD_LOGIC;
41
        signal ramedit_we : STD_LOGIC;
42
 
43
        -- Display signals
44
        signal display_d7 : STD_LOGIC_VECTOR(3 downto 0);
45
        signal display_d6 : STD_LOGIC_VECTOR(3 downto 0);
46
        signal display_d5 : STD_LOGIC_VECTOR(3 downto 0);
47
        signal display_d4 : STD_LOGIC_VECTOR(3 downto 0);
48
        signal display_d3 : STD_LOGIC_VECTOR(3 downto 0);
49
        signal display_d2 : STD_LOGIC_VECTOR(3 downto 0);
50
        signal display_d1 : STD_LOGIC_VECTOR(3 downto 0);
51
        signal display_d0 : STD_LOGIC_VECTOR(3 downto 0);
52
        signal display_blink : STD_LOGIC_VECTOR(7 downto 0);
53
        signal cpu_d0, cpu_d1, cpu_d2, cpu_d3, cpu_d4, cpu_d5, cpu_d6, cpu_d7 : STD_LOGIC_VECTOR(3 downto 0);
54
 
55
        -- RAM signals
56
        signal ramclk : STD_LOGIC;
57
        signal ram_address : STD_LOGIC_VECTOR(4 downto 0);
58
        signal ram_datain : STD_LOGIC_VECTOR(7 downto 0);
59
        signal ram_we : STD_LOGIC;
60
        signal ram_dataout : STD_LOGIC_VECTOR(7 downto 0);
61
 
62
        -- debouncing
63
        signal btnUd,btnDd,btnLd,btnCd,btnRd,btnCpuResetd : STD_LOGIC;
64
        signal sw15d,sw13d : STD_LOGIC;
65
        -- edge detect
66
        signal btnUde,btnDde,btnLde,btnRde : STD_LOGIC;
67
 
68
        -- Only for CPU debugging
69
        signal dbg_qa : STD_LOGIC_VECTOR(7 downto 0);
70
        signal dbg_qb : STD_LOGIC_VECTOR(7 downto 0);
71
        signal dbg_qc : STD_LOGIC_VECTOR(7 downto 0);
72
        signal dbg_qd : STD_LOGIC_VECTOR(7 downto 0);
73
        signal dbg_instr : STD_LOGIC_VECTOR(15 downto 0);
74
        signal dbg_seq : STD_LOGIC_VECTOR(1 downto 0);
75
        signal dbg_flags : STD_LOGIC_VECTOR(3 downto 0);
76
 
77
begin
78
        -- Debouncing
79
        comp_deb1 : entity work.debounce port map(clk=>clk,button=>btnC,result=>btnCd);
80
        comp_deb2 : entity work.debounce port map(clk=>clk,button=>btnU,result=>btnUd);
81
        comp_deb3 : entity work.debounce port map(clk=>clk,button=>btnD,result=>btnDd);
82
        comp_deb4 : entity work.debounce port map(clk=>clk,button=>btnL,result=>btnLd);
83
        comp_deb5 : entity work.debounce port map(clk=>clk,button=>btnR,result=>btnRd);
84
        comp_deb6 : entity work.debounce port map(clk=>clk,button=>btnCpuReset,result=>btnCpuResetd);
85
        comp_deb7 : entity work.debounce port map(clk=>clk,button=>sw(15),result=>sw15d);
86
        comp_deb8 : entity work.debounce port map(clk=>clk,button=>sw(13),result=>sw13d);
87
 
88
        -- Edge detectors on some buttons (for RAM editor)
89
        comp_edg1 : entity work.edgedetect port map(clk=>clk,din=>btnLd,dout=>btnLde);
90
        comp_edg2 : entity work.edgedetect port map(clk=>clk,din=>btnRd,dout=>btnRde);
91
        comp_edg3 : entity work.edgedetect port map(clk=>clk,din=>btnUd,dout=>btnUde);
92
        comp_edg4 : entity work.edgedetect port map(clk=>clk,din=>btnDd,dout=>btnDde);
93
 
94
        -- slow clock
95
        --
96
        comp_clk : entity work.clkdiv generic map(N=>25) port map(clkin=>clk,clkout=>clkslow);
97
 
98
        -- Reset
99
        --
100
        reset <= not btnCpuResetd;
101
 
102
        -- Toggle the RAM edit mode according to sw15d
103
        -- 
104
        ramedit_enable <= sw15d;
105
 
106
 
107
        -- Display debug status on LEDs
108
        --
109
        led(15) <= ramedit_enable;
110
        led(14) <= clkmain;
111
        led(13 downto 12) <= dbg_seq;
112
        led(11 downto 8) <= dbg_flags;
113
 
114
 
115
        -- Display multiplexers: toggle between ram edit and cpu mode
116
        display_blink <= "00"&ramedit_enable&ramedit_enable&ramedit_enable&ramedit_enable&ramedit_enable&ramedit_enable;
117
        display_d7 <= "0000" when ramedit_enable='1' else cpu_d7;
118
        display_d6 <= "0000" when ramedit_enable='1' else cpu_d6;
119
        display_d5 <= "000"&ram_address(4 downto 4) when ramedit_enable='1' else cpu_d5;
120
        display_d4 <= ram_address(3 downto 0) when ramedit_enable='1' else cpu_d4;
121
        display_d3 <=   sw(7 downto 4) when ramedit_enable='1' else cpu_d3;
122
        display_d2 <=   sw(3 downto 0) when ramedit_enable='1' else cpu_d2;
123
        display_d1 <=   ram_dataout(7 downto 4) when ramedit_enable='1' else  cpu_d1;
124
        display_d0 <=  ram_dataout(3 downto 0) when ramedit_enable='1' else cpu_d0;
125
 
126
        -- Display multiplexers: toggle cpu display modes
127
        cpu_d7 <= dbg_qa(7 downto 4);
128
        cpu_d6 <= dbg_qa(3 downto 0);
129
        cpu_d5 <= dbg_qb(7 downto 4) when sw(14)='1' else "000"&cpu_ram_address(4 downto 4);
130
        cpu_d4 <= dbg_qb(3 downto 0) when sw(14)='1' else cpu_ram_address(3 downto 0);
131
        cpu_d3 <= dbg_qc(7 downto 4) when sw(14)='1' else dbg_instr(15 downto 12);
132
        cpu_d2 <= dbg_qc(3 downto 0) when sw(14)='1' else dbg_instr(11 downto 8);
133
        cpu_d1 <= dbg_qd(7 downto 4) when sw(14)='1' else dbg_instr(7 downto 4);
134
        cpu_d0 <= dbg_qd(3 downto 0) when sw(14)='1' else dbg_instr(3 downto 0);
135
 
136
        -- Instantiate the 7-segment display
137
        --
138
        comp1: entity work.hexto7seg port map(  clk=>clk,
139
                                                                                                                                d7=>display_d7,
140
                                                                                                                                d6=>display_d6,
141
                                                                                                                                d5=>display_d5,
142
                                                                                                                                d4=>display_d4,
143
                                                                                                                                d3=>display_d3,
144
                                                                                                                                d2=>display_d2,
145
                                                                                                                                d1=>display_d1,
146
                                                                                                                                d0=>display_d0,
147
                                                                                                                                blink=>display_blink,
148
                                                                                                                                q=>seg,
149
                                                                                                                                active=>an);
150
 
151
        --comp2: entity work.clkdiv generic map (N   => 26) port map(   clkin=>clk,clkout=>clkmain );
152
        --led(15)<=clkmain;
153
        clkmain <= not ramedit_enable and( (btnCd and not sw13d) or (clkslow and sw13d));
154
 
155
 
156
 
157
 
158
        -- Instantiate RAM
159
        -- RAM clock is either board clock in edit mode, or manual clock
160
        ramclk <= clk when sw15d='1' else clkmain;
161
        comp3: entity work.ram generic map(N=>5) port map(clk=>ramclk,address=>ram_address,data=>ram_datain,we=>ram_we,q=>ram_dataout);
162
 
163
        -- Instantiate the RAM editor
164
        comp_ramedit:
165
        entity work.ramedit generic map(N=>5) port map(clk=>clk,rst=>reset,btnU=>btnUde,btnD=>btnDde,btnL=>btnLde,btnR=>btnRde,din=>sw,
166
                                                                we=>ramedit_we,address=>ramedit_address,data=>ramedit_data);
167
 
168
        -- Multiplex the editor and the CPU to the RAM
169
        --
170
        ram_we <= ramedit_we when ramedit_enable='1' else cpu_ram_we;
171
        ram_address <= ramedit_address when ramedit_enable='1' else cpu_ram_address;
172
        ram_datain <= ramedit_data when ramedit_enable='1' else cpu_ram_datawr;
173
 
174
 
175
 
176
        -- Instantiate the CPU
177
        comp_cpu:
178
        entity work.CPU generic map(N=>5)
179
                                                        port map(clk=>clkmain,rst=>reset,ext_in=>sw(7 downto 0),ext_out=>led(7 downto 0),
180
                                                                                ram_we=>cpu_ram_we,ram_address=>cpu_ram_address,ram_datawr=>cpu_ram_datawr,ram_datard=>ram_dataout,
181
                                                                                dbg_qa=>dbg_qa,dbg_qb=>dbg_qb,dbg_qc=>dbg_qc,dbg_qd=>dbg_qd,
182
                                                                                dbg_instr=>dbg_instr,dbg_seq=>dbg_seq,dbg_flags=>dbg_flags);
183
 
184
 
185
end Structural;
186
 

powered by: WebSVN 2.1.0

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