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

Subversion Repositories lattice6502

[/] [lattice6502/] [ispLeaver/] [Processor.vhd] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 stanley82
------------------------------------------------------------------
2
--      6502 Top module.
3
--
4
--      Copyright Ian Chapman October 28 2010
5 6 stanley82
--      email author@kool.kor
6
--      author  EQU     ichapman
7
--      kool    EQU     videotron
8
--      kor     EQU     ca
9
--      ******************************************************
10
--      Dec 12 2010
11
--      RAM increased to 2k 0 to $7ff for bigger test code
12
--      sta irq and sta nmi trigger interrupts
13
--      ******************************************************
14
--      This file is part of the Lattice 6502 project  
15 2 stanley82
--      It is used to compile with ispLeaver not Linux ghdl.
16
--      It is the address mapping and connecting the other modules.
17
--      It is replaced by Processor.vhd when running ispLeaver.
18
--
19 6 stanley82
 
20 2 stanley82
--      To do
21
--              This will be work in process or replaced whatever
22
--              project file is needed to control other modules.
23
--
24
--      *************************************************************
25
--      Distributed under the GNU Lesser General Public License.    *
26
--      This can be obtained from “www.gnu.org”.                    *
27
--      *************************************************************
28
--      This program is free software: you can redistribute it and/or modify
29
--      it under the terms of the GNU General Public License as published by
30
--      the Free Software Foundation, either version 3 of the License, or
31
--      (at your option) any later version.
32
--
33
--      This program is distributed in the hope that it will be useful,
34
--      but WITHOUT ANY WARRANTY; without even the implied warranty of
35
--      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
36
--      GNU General Public License for more details.
37
--
38
--      You should have received a copy of the GNU General Public License
39
--      along with this program.  If not, see <http://www.gnu.org/licenses/>
40
--
41
--      Processor.vhd
42
------------------------------------------------------------------
43 6 stanley82
--      Revision history
44
--      Nov 411, 2010
45
--      To facilitate testing of NMI and IRQ.
46
--      changed from I/O pins to signals
47
--      IRQ and NMI address decoded so as to initiated the inerupt from
48
------------------------------------------------------------------
49 2 stanley82
library IEEE;                   --Use standard IEEE libs as recommended by Tristan. 
50
use IEEE.STD_LOGIC_1164.ALL;
51
use IEEE.numeric_std.all;
52
 
53
entity Processor is
54
 
55
Port (
56
--      data_wr : inout unsigned(7 downto 0);
57
        clk_pin : in std_logic;
58
--      clk_out : out std_logic;
59
--      u802 : out std_logic;
60
--      u702 : out std_logic;
61
--      u602 : out std_logic;
62
--      u1101 : out std_logic;  
63
--      u801 : out std_logic;
64
--      u701 : out std_logic;
65
        u601 : out std_logic;
66
        rst_pin : in std_logic;
67 6 stanley82
--      irq_pin : in std_logic; --disabled to test interrupts on fpga
68
--      nmi_pin : in std_logic;
69 2 stanley82
        RX_pin  : in std_logic;
70
--      PG_pin  : in std_logic;
71
        TX_pin  : out std_logic;
72
        Pwr_on_pin : out std_logic
73
    );
74
end Processor;
75
 
76
architecture structure of Processor is
77
 
78
--      COMPONENT DECLARATIONS
79
 
80
component P65C02
81
port(
82
        data_rd: in unsigned(7 downto 0);
83
        data_wr: out unsigned(7 downto 0);
84
--      cycle_mark : out std_logic;                     --Used to signal the cycle usually cycle 0.
85
        address: inout unsigned(15 downto 0);
86
        proc_write : inout std_logic;
87
        reset, clock : in std_logic;
88
        irq : in std_logic;
89
        nmi : in std_logic);
90
end component;
91
 
92
component UART_RX is
93
port(
94
        PG, OSC_10MHz,RX,  csr_usart :in std_logic;
95
        RX_rdy : out std_logic;
96
        rx_reg : out unsigned(7 downto 0)
97
        );
98
end component;
99
 
100
component UART_TX is
101
port(
102
        OSC_10MHz, PG, csw_usart :in std_logic;
103
        tx_dat : in unsigned(7 downto 0);
104
        TX ,tx_rdy : out std_logic
105
        );
106
end component;
107
 
108
component Lattice_rom
109
port (
110
        OutClock: in  std_logic;
111
        OutClockEn: in  std_logic;
112
        Reset: in  std_logic;
113
        Address: in  std_logic_vector(9 downto 0);
114
        Q: out  std_logic_vector(7 downto 0));
115
end component;
116
 
117
component Lattice_ram
118
port (
119
        Clock: in  std_logic;
120
        ClockEn: in  std_logic;
121
        Reset: in  std_logic;
122
        WE: in  std_logic;
123 6 stanley82
        Address: in  std_logic_vector(10 downto 0);
124 2 stanley82
        Data: in  std_logic_vector(7 downto 0);
125
        Q: out  std_logic_vector(7 downto 0));
126
end component;
127
 
128
--component ghdl_rom
129
--port  (
130
--      rom_dat: out unsigned(7 downto 0);
131
--      wr, clk, rst: in std_logic;
132
--      address: in unsigned(15 downto 0)
133
--    );
134
--end component;
135
 
136
--component ghdl_ram
137
--port  (
138
--      ram_dat: out unsigned(7 downto 0);
139
--      data_wr : in unsigned(7 downto 0);
140
--      clk, wr, rst: in std_logic;
141
--      address: in unsigned(15 downto 0)
142
--      );
143
--end component;
144
 
145
 
146
------------------------------------------------------------------------
147
-- Signal Declarations
148
------------------------------------------------------------------------
149
signal address : unsigned(15 downto 0);
150
signal add : unsigned(15 downto 0);
151
signal proc_rd_dat, rom_dat, ram_dat, data_wr : unsigned(7 downto 0);
152
signal rx_dat : unsigned(7 downto 0);
153
signal proc_write : std_logic;
154
signal one, RX_rdy, csw_usart, csr_usart, tx_rdy : std_logic;
155
signal rst_bar : std_logic;
156
 
157
signal clk : std_logic;
158
--signal clk_pin : std_logic;
159
signal counter : unsigned(3 downto 0);
160
signal ram_write : std_logic;
161 6 stanley82
signal irq_pin, nmi_pin : std_logic;
162 2 stanley82
 
163
--      I/O ports
164 6 stanley82
--constant      led_port        : unsigned (15 downto 0) := x"4007";
165
constant        irq             : unsigned (15 downto 0) := X"4002";
166
constant        nmi             : unsigned (15 downto 0) := x"4003";
167 2 stanley82
constant        rs232_dat   : unsigned (15 downto 0) := x"4000"; --input and output
168
constant        uart_stat   : unsigned (15 downto 0) := x"4001"; --RX and TX state found here
169
constant        uart: unsigned (15 downto 0) := x"4000"; --starts the uart transmitting
170
 
171
begin
172
 
173
U1 : P65C02 port map(
174
        reset => rst_pin,
175
        Clock => clk_pin,
176
        data_rd => proc_rd_dat,
177
        data_wr => data_wr,
178
        address => address,
179
        proc_write => proc_write,
180
        irq => irq_pin,
181
--      cycle_mark => cycle_mark);
182
        nmi => nmi_pin);
183
 
184
 
185
U2 : UART_RX port map (
186
        PG => rst_pin,
187
        OSC_10MHz => clk_pin,
188
        RX => RX_pin,
189
        rx_reg =>  rx_dat,
190
        csr_usart => csr_usart,
191
        RX_rdy => RX_rdy);
192
 
193
U3 : UART_TX port map (
194
        PG => rst_pin,
195
        TX => TX_pin,
196
        tx_rdy => tx_rdy,
197
        OSC_10MHz => clk_pin,
198
        tx_dat => data_wr,
199
        csw_usart => csw_usart);
200
 
201
--R1 : ghdl_rom port map(
202
--      rom_dat=>rom_dat,
203
--      address=>address,
204
--      wr=>proc_write,
205
--      clk=>clk_pin,
206
--      rst=>rst_pin);
207
 
208
--R2 : ghdl_ram port map(
209
--      clk=>clk_pin,
210
--      rst=>rst_pin,
211
--      ram_dat=>ram_dat,
212
--      data_wr=>data_wr,
213
--      address=>address,
214
--      wr=>ram_write);
215
 
216
R3 : Lattice_rom port map(
217
        Reset => rst_bar,
218
        OutClock => clk_pin,
219
        (address(9 downto 0)) => std_logic_vector(Address(9 downto 0)),
220
        unsigned(Q)  => rom_dat,
221
        OutClockEn => one);
222
 
223
R4 : Lattice_ram port map(
224
        Reset => rst_bar,
225
        Clock => clk_pin,
226
        WE => ram_write,
227 6 stanley82
        address(10 downto 0) => std_logic_vector(Address(10 downto 0)),
228 2 stanley82
        Data => std_logic_vector(data_wr),
229
        unsigned(Q) => ram_dat, ClockEn => one);
230
 
231
--      address(9 downto 0) => (Address(9 downto 0)), 
232
--      Data => (data_wr),
233
--      (Q) => ram_dat, ClockEn => one);
234
 
235
one <= '1';
236
rst_bar <= not rst_pin;
237
one <= '1';
238 6 stanley82
--ram_write <= proc_write and not address(15) and not address(14) and not address(13) and not address(12) and not address(11) and not address(10);
239
--ram_write <= proc_write and not address(15) and not address(14);
240
--irq_pin <= '1';       --only used to test interrupts on fpga
241
--nmi_pin <= '1';
242 2 stanley82
--u601 <= cycle_mark;
243
 
244
 
245
 
246
mux_add : process(rst_pin, clk_pin)
247
begin
248
if rst_pin = '0' then
249
add <= (others => '0');
250
elsif rising_edge(clk_pin) then
251
        add <= address;
252
end if;
253
end process;
254
 
255
ram_address : process (proc_write, address(15 downto 14))
256
begin
257
        if proc_write = '1' and address(15 downto 14) = "00" then
258
                ram_write <= '1';
259
        else
260
                ram_write <= '0';
261
        end if;
262
end process;
263
 
264
 
265
--      ===================================================================
266
--      Updated muxer process
267
muxer : process (add(15 downto 14), rom_dat, ram_dat, rx_dat, tx_rdy, rx_rdy)
268
begin
269
if add(15 downto 14) = "11" then
270
        proc_rd_dat <= rom_dat;
271
end if;
272
if add(15 downto 14) = "00" then
273
        proc_rd_dat <= ram_dat;
274
end if;
275
if add(15 downto 0) = rs232_dat then
276
        proc_rd_dat <= rx_dat;
277
end if;
278
if add(15 downto 0) = uart_stat then
279
        proc_rd_dat <= tx_rdy & rx_rdy & "000000";
280
end if;
281
end process;
282
--      ===================================================================
283
 
284
rs232_cs : process (rst_pin, clk_pin, address, proc_write)
285
begin
286
if proc_write = '0' and address = uart then
287
        csr_usart <= '1';
288
else
289
        csr_usart <= '0';
290
end if;
291
 
292
if proc_write = '1' and address = uart then
293
        csw_usart <= '1';
294
else
295
        csw_usart <= '0';
296
end if;
297 6 stanley82
end process;
298
--      Only uded to test interrupts in the fpga
299
--      These two processe let the SW fire NMI and IRG
300
--      with a sta instruction.
301
irq : process (rst_pin, proc_write, address, data_wr(0), clk_pin)
302
begin
303
if rst_pin = '0' then
304
        irq_pin <= '1';
305
        elsif rising_edge(clk_pin) then
306
                if address = irq and proc_write = '1' then
307
                        irq_pin <= data_wr(0);   --set and hold bit 0
308
                end if;
309
end if;
310 2 stanley82
end process;
311
 
312 6 stanley82
nmi : process (rst_pin, proc_write, address, data_wr(0), clk_pin)
313 2 stanley82
begin
314
if rst_pin = '0' then
315 6 stanley82
        nmi_pin <= '1';
316
        elsif rising_edge(clk_pin) then
317
                if address = nmi and proc_write = '1' then
318
                        nmi_pin <= data_wr(0);   --set and hold bit 0
319
                end if;
320 2 stanley82
end if;
321
end process;
322
 
323 6 stanley82
--relay : process (rst_pin, proc_write, address, data_wr(7), clk_pin)
324
--begin
325
--if rst_pin = '0' then
326
--      Pwr_on_pin <= '0';
327
--      elsif rising_edge(clk_pin) and address = led_port  and proc_write = '1' then
328
--      Pwr_on_pin <= data_wr(7);
329
--end if;
330
--end process;
331 2 stanley82
 
332 6 stanley82
 
333 2 stanley82
end structure;

powered by: WebSVN 2.1.0

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