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

Subversion Repositories RISCMCU

[/] [RISCMCU/] [trunk/] [vhdl/] [v_riscmcu.vhd] - Blame information for rev 30

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 yapzihe
----------------------------------------------------------------------------
2
----                                                                    ----
3
---- WISHBONE RISCMCU IP Core                                           ----
4
----                                                                    ----
5
---- This file is part of the RISCMCU project                           ----
6
---- http://www.opencores.org/projects/riscmcu/                         ----
7
----                                                                    ----
8
---- Description                                                        ----
9
---- Implementation of a RISC Microcontroller based on Atmel AVR        ----
10
---- AT90S1200 instruction set and features with Altera Flex10k20 FPGA. ----
11
----                                                                    ----
12
---- Author(s):                                                         ----
13
----    - Yap Zi He, yapzihe@hotmail.com                                ----
14
----                                                                    ----
15
----------------------------------------------------------------------------
16
----                                                                    ----
17
---- Copyright (C) 2001 Authors and OPENCORES.ORG                       ----
18
----                                                                    ----
19
---- This source file may be used and distributed without               ----
20
---- restriction provided that this copyright statement is not          ----
21
---- removed from the file and that any derivative work contains        ----
22
---- the original copyright notice and the associated disclaimer.       ----
23
----                                                                    ----
24
---- This source file is free software; you can redistribute it         ----
25
---- and/or modify it under the terms of the GNU Lesser General         ----
26
---- Public License as published by the Free Software Foundation;       ----
27
---- either version 2.1 of the License, or (at your option) any         ----
28
---- later version.                                                     ----
29
----                                                                    ----
30
---- This source is distributed in the hope that it will be             ----
31
---- useful, but WITHOUT ANY WARRANTY; without even the implied         ----
32
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR            ----
33
---- PURPOSE. See the GNU Lesser General Public License for more        ----
34
---- details.                                                           ----
35
----                                                                    ----
36
---- You should have received a copy of the GNU Lesser General          ----
37
---- Public License along with this source; if not, download it         ----
38
---- from http://www.opencores.org/lgpl.shtml                           ----
39
----                                                                    ----
40
----------------------------------------------------------------------------
41
 
42
library ieee;
43
use ieee.std_logic_1164.all;
44
 
45
entity v_riscmcu is
46
        port (
47
                clock : in STD_LOGIC;
48
                reset : in STD_LOGIC;
49
                pinb : inout STD_LOGIC_VECTOR(7 downto 0);
50
                pinc : inout STD_LOGIC_VECTOR(7 downto 0);
51
                pind : inout STD_LOGIC_VECTOR(7 downto 0)
52
        );
53
end v_riscmcu;
54
 
55
architecture riscmcu of v_riscmcu is
56
 
57 19 yapzihe
signal ext_irq_pin, ext_timer_clk_pin : std_logic;
58 8 yapzihe
 
59
signal clk, clrn, div2, div4, div8, div16 : std_logic;
60
signal sr, reg_rd, reg_rr, c, addrbus: std_logic_vector(7 downto 0);
61
 
62
signal pc, offset : std_logic_vector(8 downto 0);
63
signal instruction, ir : std_logic_vector(15 downto 0);
64
 
65
signal skip, en, wr_reg : std_logic;
66
signal sren : std_logic_vector (6 downto 0);
67
signal c2a, c2b, add, subcp, logic, right, dir, pass_a : std_logic;
68
signal wcarry : std_logic;
69
signal logicsel : integer range 0 to 3;
70
signal rightsel : integer range 0 to 2;
71
signal dirsel : integer range 0 to 1;
72
signal addoffset, push, pull, cpse, skiptest : std_logic;
73
signal bclr,bset, bld, cbisbi : std_logic;
74
signal dest, rr, rd : integer range 0 to 15;
75
signal srsel : integer range 0 to 7;
76
signal imm_value : std_logic_vector(7 downto 0);
77
 
78
signal tosr : std_logic_vector (6 downto 0);
79
 
80
signal vec2, vec4, clr_i, set_i, clr_tov0, clr_intf, timerirq, extirq : std_logic;
81
 
82
signal rd_sreg,wr_sreg,rd_gimsk,wr_gimsk,rd_timsk, wr_timsk, rd_tifr,wr_tifr : std_logic;
83
signal rd_mcucr,wr_mcucr, rd_tccr0, wr_tccr0, rd_tcnt0,wr_tcnt0 : std_logic;
84
signal rd_portb,wr_portb,rd_ddrb,wr_ddrb,rd_pinb : std_logic;
85
signal rd_portc,wr_portc,rd_ddrc,wr_ddrc,rd_pinc : std_logic;
86
signal rd_portd,wr_portd,rd_ddrd,wr_ddrd,rd_pind : std_logic;
87
 
88
signal t_flag, c_flag : std_logic;
89
 
90
signal vcc, gnd : std_logic;
91
 
92
signal rd_ram, wr_ram, ld_mar, ld_mbr, inc_zp, dec_zp :std_logic;
93
 
94
signal bitsel : integer range 0 to 7;
95
signal set : std_logic;
96
 
97
signal asel : integer range 0 to 1;
98
signal bsel : integer range 0 to 3;
99
 
100 19 yapzihe
        -- Frequency Divider - Divide clock by 2(div2), 4(div4), 8(div8) and 16(div16)
101 8 yapzihe
        component v_freqdiv
102
        port (  clock : in std_logic;
103
                div2, div4, div8, div16 : buffer std_logic
104
        );
105
        end component;
106
 
107 19 yapzihe
        -- Program Counter (9 bit wide)
108 8 yapzihe
        component v_pc
109
        port (  offset : in std_logic_vector(8 downto 0);
110
                en, addoffset, push, pull, vec2, vec4 : in std_logic;
111
                clk, clrn : in std_logic;
112
                pc : buffer std_logic_vector(8 downto 0)
113
        );
114
        end component;
115
 
116 19 yapzihe
        -- Program ROM (512 words)
117 8 yapzihe
        component v_rom
118
        port (  pc : in std_logic_vector(8 downto 0);
119
                instruction : out std_logic_vector(15 downto 0)
120
        );
121
        end component;
122
 
123 19 yapzihe
        -- Instruction Register (16 bit wide)
124 8 yapzihe
        component v_ir
125
        port (  instruction : in std_logic_vector(15 downto 0);
126
                en, clk, clrn : in std_logic;
127
                ir : buffer std_logic_vector(15 downto 0);
128
                imm_value : out std_logic_vector(7 downto 0);
129
                rd, rr : out integer range 0 to 15
130
        );
131
        end component;
132
 
133 19 yapzihe
        -- Control Unit (with IO address decoder module inside)
134 8 yapzihe
        component v_controlunit
135
        port (  ir      : in std_logic_vector(15 downto 0);
136
                sr : in std_logic_vector(7 downto 0);
137
                clk, clrn : in std_logic;
138
                skip, extirq, timerirq : in std_logic;
139
 
140
                en : buffer std_logic;
141
                wr_reg : buffer std_logic;
142
                rd_ram, wr_ram, ld_mar, ld_mbr, inc_zp, dec_zp : out std_logic;
143
                sren : out std_logic_vector (6 downto 0);
144
 
145
                c2a,c2b : out std_logic;
146
                asel : out integer range 0 to 1;
147
                bsel : out integer range 0 to 3;
148
                bitsel : out integer range 0 to 7;
149
                set : out std_logic;
150
 
151
                add, subcp, logic, right, dir, pass_a : out std_logic;
152
 
153
                wcarry : out std_logic;
154
                logicsel : out integer range 0 to 3;
155
                rightsel : out integer range 0 to 2;
156
                dirsel : out integer range 0 to 1;
157
 
158
                addoffset : out std_logic;
159
                push, pull : out std_logic;
160
 
161
                cpse, skiptest : out std_logic;
162
 
163
                bclr,bset : out std_logic;
164
                bld : out std_logic;
165
 
166
                cbisbi : out std_logic;
167
 
168
                vec2, vec4 : buffer std_logic;
169
 
170
                dest : out integer range 0 to 15;
171
                srsel : out integer range 0 to 7;
172
                offset : out std_logic_vector(8 downto 0);
173
 
174
                clr_i, set_i, clr_intf, clr_tov0 : out std_logic;
175
 
176
                rd_sreg, wr_sreg : out std_logic;
177
                rd_gimsk, wr_gimsk, rd_timsk, wr_timsk, rd_tifr,wr_tifr : out std_logic;
178
                rd_mcucr,wr_mcucr, rd_tccr0, wr_tccr0, rd_tcnt0,wr_tcnt0 : out std_logic;
179
                rd_portb, wr_portb, rd_ddrb, wr_ddrb, rd_pinb : out std_logic;
180
                rd_portc, wr_portc, rd_ddrc, wr_ddrc, rd_pinc : out std_logic;
181
                rd_portd, wr_portd, rd_ddrd, wr_ddrd, rd_pind : out std_logic
182
        );
183
        end component;
184
 
185 19 yapzihe
        -- General Purpose Register (16 x 8bit)
186 8 yapzihe
        component v_gpr
187
        port (  c : in std_logic_vector(7 downto 0);
188
                wr_reg, inc_zp, dec_zp : in std_logic;
189
                rd, rr, dest : in integer range 0 to 15;
190
                clk, clrn : in std_logic;
191
                reg_rd, reg_rr, addrbus : out std_logic_vector(7 downto 0)
192
        );
193
        end component;
194
 
195 19 yapzihe
        -- ALU
196 8 yapzihe
        component v_alu
197
        port (  reg_rd, reg_rr, imm_value : in std_logic_vector(7 downto 0);
198
                c2a, c2b : in std_logic;
199
                asel : in integer range 0 to 1;
200
                bsel : in integer range 0 to 3;
201
 
202
                bitsel : in integer range 0 to 7;
203
                set : in std_logic;
204
                c_flag, t_flag : in std_logic;
205
 
206
                add, subcp, logic, right, dir, bld, cbisbi, pass_a : in std_logic;
207
                cpse, skiptest : in std_logic;
208
 
209
                wcarry : in std_logic;
210
                logicsel : in integer range 0 to 3;
211
                rightsel : in integer range 0 to 2;
212
                dirsel : in integer range 0 to 1;
213
 
214
                clk, clrn : in std_logic;
215
 
216
                c : buffer std_logic_vector(7 downto 0);
217
                tosr : buffer std_logic_vector (6 downto 0);
218
                skip : out std_logic
219
        );
220
        end component;
221
 
222 19 yapzihe
        -- Status Register (8 bit wide, flags are ITHSVNZC)
223 8 yapzihe
        component v_sr
224
        port (  clk,clrn: in std_logic;
225
                        sren,tosr : in std_logic_vector(6 downto 0);
226
                        srsel : in integer range 0 to 7;
227
                        clr_i,set_i,bset,bclr : in std_logic;
228
                        rd_sreg, wr_sreg : in std_logic;
229
                        c : inout std_logic_vector(7 downto 0);
230
                        sr : inout std_logic_vector(7 downto 0)
231
        );
232
        end component;
233
 
234 19 yapzihe
        -- Data RAM (128 bytes)
235 8 yapzihe
        component v_ram
236
        port (  addrbus : in std_logic_vector(7 downto 0);
237
                rd_ram, wr_ram, ld_mar, ld_mbr : in std_logic;
238
                clk, clrn : in std_logic;
239
                c : inout std_logic_vector(7 downto 0)
240
        );
241
        end component;
242
 
243 19 yapzihe
        -- Standard 8-bit I/O Port module (all ports share this same module)
244 8 yapzihe
        component v_port
245
        port (  rd_port, wr_port, rd_ddr, wr_ddr, rd_pin : in std_logic;
246
                clk, clrn : in std_logic;
247
                c : inout std_logic_vector(7 downto 0);
248
                pin : inout std_logic_vector(7 downto 0)
249
        );
250
        end component;
251
 
252 19 yapzihe
        -- 8-bit Timer with overflow interrupt request, can drive by external clock source
253 8 yapzihe
        component v_timer
254
        port (  extpin, clr_tov0 : in std_logic;
255
                rd_timsk, wr_timsk, rd_tifr, wr_tifr : in std_logic;
256
                rd_tccr0, wr_tccr0, rd_tcnt0, wr_tcnt0 : in std_logic;
257
                clk, clrn : in std_logic;
258
                c : inout std_logic_vector(7 downto 0);
259
                timerirq : out std_logic
260
        );
261
        end component;
262
 
263 19 yapzihe
        -- External Interrupt
264 8 yapzihe
        component v_extint
265
        port (  clk, clrn, extpin, clr_intf : in std_logic;
266
                rd_mcucr, wr_mcucr, rd_gimsk, wr_gimsk : in std_logic;
267
                extirq  : out std_logic;
268
                c : inout std_logic_vector(7 downto 0)
269
        );
270
        end component;
271
 
272
begin
273 19 yapzihe
        --U_v_freqdiv: v_freqdiv
274
        --      port map (clock, div2, div4, div8, div16);
275 8 yapzihe
 
276
        U_v_pc: v_pc
277
                port map (offset, en, addoffset, push, pull, vec2, vec4, clk, clrn, pc);
278
 
279
        U_v_rom: v_rom
280
                port map (pc, instruction);
281
 
282
        U_v_ir: v_ir
283
                port map (instruction, en, clk, clrn, ir, imm_value, rd, rr);
284
 
285
        U_v_controlunit: v_controlunit
286
                port map (ir, sr, clk, clrn, skip, extirq, timerirq, en, wr_reg, rd_ram, wr_ram, ld_mar, ld_mbr, inc_zp, dec_zp, sren, c2a, c2b, asel, bsel, bitsel, set, add, subcp, logic, right, dir, pass_a, wcarry, logicsel, rightsel, dirsel, addoffset, push, pull, cpse, skiptest, bclr, bset, bld, cbisbi, vec2, vec4, dest, srsel, offset, clr_i, set_i, clr_intf, clr_tov0, rd_sreg, wr_sreg, rd_gimsk, wr_gimsk, rd_timsk, wr_timsk, rd_tifr, wr_tifr, rd_mcucr, wr_mcucr, rd_tccr0, wr_tccr0, rd_tcnt0, wr_tcnt0, rd_portb, wr_portb, rd_ddrb, wr_ddrb, rd_pinb, rd_portc, wr_portc, rd_ddrc, wr_ddrc, rd_pinc, rd_portd, wr_portd, rd_ddrd, wr_ddrd, rd_pind);
287
 
288
        U_v_gpr: v_gpr
289
                port map (c, wr_reg, inc_zp, dec_zp, rd, rr, dest, clk, clrn, reg_rd, reg_rr, addrbus);
290
 
291
        U_v_alu: v_alu
292
                port map (reg_rd, reg_rr, imm_value, c2a, c2b, asel, bsel, bitsel, set, c_flag, t_flag, add, subcp, logic, right, dir, bld, cbisbi, pass_a, cpse, skiptest, wcarry, logicsel, rightsel, dirsel, clk, clrn, c, tosr, skip);
293
 
294
        U_v_sr: v_sr
295
                port map (clk, clrn, sren, tosr, srsel, clr_i, set_i, bset, bclr, rd_sreg, wr_sreg, c, sr);
296
 
297
        U_v_ram: v_ram
298
                port map (addrbus, rd_ram, wr_ram, ld_mar, ld_mbr, clk, clrn, c);
299
 
300
        U_v_timer: v_timer
301 19 yapzihe
                port map (ext_timer_clk_pin, clr_tov0, rd_timsk, wr_timsk, rd_tifr, wr_tifr, rd_tccr0, wr_tccr0, rd_tcnt0, wr_tcnt0, clk, clrn, c, timerirq);
302 8 yapzihe
 
303
        U_v_extint: v_extint
304 19 yapzihe
                port map (clk, clrn, ext_irq_pin, clr_intf, rd_mcucr, wr_mcucr, rd_gimsk, wr_gimsk, extirq, c);
305 8 yapzihe
 
306 19 yapzihe
        -- The same module v_port is used by 3 I/O ports, just the signals are different
307 8 yapzihe
        U_v_portB: v_port
308
                port map (rd_portb, wr_portb, rd_ddrb, wr_ddrb, rd_pinb, clk, clrn, c, pinb);
309
 
310
        U_v_portC: v_port
311
                port map (rd_portc, wr_portc, rd_ddrc, wr_ddrc, rd_pinc, clk, clrn, c, pinc);
312
 
313
        U_v_portD: v_port
314
                port map (rd_portd, wr_portd, rd_ddrd, wr_ddrd, rd_pind, clk, clrn, c, pind);
315
 
316 19 yapzihe
        -- Global reset, it resets ALL flip-flops and registers to the initial state (normally gnd)
317 8 yapzihe
        clrn <= reset;
318 19 yapzihe
 
319 8 yapzihe
        vcc <= '1';
320
        gnd <= '0';
321
        t_flag <= sr(6);
322
        c_flag <= sr(0);
323
 
324 19 yapzihe
        -- These are the external interrupt request pin and external timer clock source pin
325
        -- They share pins with the I/O ports
326
        -- TIPS: You can use any of the 24 I/O pins, I use pind(7) for my applications
327
        ext_irq_pin <= pind(2);
328
        ext_timer_clk_pin <= pind(4);
329
 
330
        -- When I use the UP1 board, the on-board 25 MHz clock is too fast and
331
        -- I need to divide it by 4 so that the MCU can run
332
        -- For waveform simulation, it does not require division (clk <= clock)
333
        -- TIPS: To have division, uncomment v_freqdiv module instantation on top of the page and 
334
        --       assign clk with div2, div4, div8 or div16
335
        clk <= clock;
336
 
337
 
338 8 yapzihe
end riscmcu;
339
 
340
 

powered by: WebSVN 2.1.0

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