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

Subversion Repositories usimplez

[/] [usimplez/] [trunk/] [QuartusII/] [usimplez_cpu.vhd.bak] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 pas.
--//////////////////////////////////////////////////////////////////////
2
--////                                                                                                                          ////
3
--////                                                                                                                          ////
4
--////                                                                                                                          ////
5
--//// This file is part of the MicroSimplez project                            ////
6
--//// http://opencores.org/project,usimplez                                            ////
7
--////                                                                                                                          ////
8
--//// Description                                                                                                      ////
9
--//// Implementation of MicroSimplez IP core according to                      ////
10
--//// MicroSimplez IP core specification document.                             ////
11
--////                                                                                                                          ////
12
--//// To Do:                                                                                                           ////
13
--//// -                                                                                                                        ////
14
--////                                                                                                                          ////
15
--//// Author(s):                                                                                                       ////
16
--//// - Daniel Peralta, peraltahd@opencores.org, designer                      ////
17
--//// - Martin Montero, monteromrtn@opencores.org, designer            ////
18
--//// - Julian Castro, julyan@opencores.org, reviewer                          ////
19
--//// - Pablo A. Salvadeo,     pas.@opencores, manager                                 ////
20
--////                                                                                                                          ////
21
--//////////////////////////////////////////////////////////////////////
22
--////                                                                                                                          ////
23
--//// Copyright (C) 2011 Authors and OPENCORES.ORG                             ////
24
--////                                                                                                                          ////
25
--//// This source file may be used and distributed without             ////
26
--//// restriction provided that this copyright statement is not        ////
27
--//// removed from the file and that any derivative work contains      ////
28
--//// the original copyright notice and the associated disclaimer.     ////
29
--////                                                                                                                          ////
30
--//// This source file is free software; you can redistribute it       ////
31
--//// and/or modify it under the terms of the GNU Lesser General       ////
32
--//// Public License as published by the Free Software Foundation;     ////
33
--//// either version 2.1 of the License, or (at your option) any       ////
34
--//// later version.                                                                                           ////
35
--////                                                                                                                          ////
36
--//// This source is distributed in the hope that it will be           ////
37
--//// useful, but WITHOUT ANY WARRANTY; without even the implied       ////
38
--//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR          ////
39
--//// PURPOSE. See the GNU Lesser General Public License for more      ////
40
--//// details.                                                                                                         ////
41
--////                                                                                                                          ////
42
--//// You should have received a copy of the GNU Lesser General        ////
43
--//// Public License along with this source; if not, download it       ////
44
--//// from http://www.opencores.org/lgpl.shtml                                         ////
45
--////                                                                                                                          ////
46
--//////////////////////////////////////////////////////////////////////
47
 
48
library ieee;
49
use ieee.std_logic_1164.all;
50
use ieee.numeric_std.all;
51
 
52
entity usimplez_cpu is
53
 
54
        generic(
55
                WIDTH_WORD:     natural:=12;
56
                WIDTH_OPERATION_CODE: natural:=3;
57
                WIDTH_ADDRESS: natural:=9;
58
                --Instructions:
59
                ST:     unsigned:="000";
60
                LD:     unsigned:="001";
61
                ADD:    unsigned:="010";
62
                BR:     unsigned:="011";
63
                BZ:     unsigned:="100";
64
                CLR:    unsigned:="101";
65
                DEC:    unsigned:="110";
66
                HALT:   unsigned:="111"
67
                );
68
 
69
        port(
70
                clk_i: in std_logic;
71
                rst_i: in std_logic;
72
                data_bus_i: in std_logic_vector((WIDTH_WORD-1) downto 0);
73
                data_bus_o: out std_logic_vector((WIDTH_WORD-1) downto 0);
74
                addr_bus_o: out std_logic_vector((WIDTH_ADDRESS-1) downto 0);
75
                we_o: out std_logic;
76
                --To Debug:
77
                        In0_o: out std_logic;
78
                        In1_o: out std_logic;
79
                        Op0_o: out std_logic;
80
                        Op1_o: out std_logic
81
                --
82
                );
83
 
84
end usimplez_cpu;
85
 
86
architecture fsm of usimplez_cpu is
87
 
88
        type T_estado is (In0,In1,Op0,Op1);
89
        signal estado: T_estado;
90
        --Registros:
91
         --Acumulador (AC)
92
        signal ac_reg_s: unsigned((WIDTH_WORD-1) downto 0);
93
         --Codigo de Operacion (CO)
94
        signal co_reg_s: unsigned((WIDTH_OPERATION_CODE-1) downto 0);
95
         --Campo de Direccion (CD)
96
        signal cd_reg_s: unsigned((WIDTH_ADDRESS-1) downto 0);
97
         --Contador de Programa (CP)
98
        signal cp_reg_s: unsigned((WIDTH_ADDRESS-1) downto 0);
99
        --Buses:
100
        signal data_bus_s: unsigned((WIDTH_WORD-1) downto 0);
101
        signal addr_bus_s: unsigned((WIDTH_ADDRESS-1) downto 0);
102
 
103
begin
104
 
105
    process(clk_i,rst_i)
106
    begin
107
                if(rising_edge(clk_i)) then
108
                        if(rst_i='1') then
109
                                co_reg_s <= (others=>'0');
110
                                ac_reg_s <= (others=>'0');
111
                                cd_reg_s <= (others=>'0');
112
                                cp_reg_s <= (others=>'0');
113
                                addr_bus_o <= (others=>'1');
114
                                data_bus_o <= (others=>'0');
115
                                we_o<='0';
116
                                --
117
                                estado <= In0;
118
                                --
119
                        else
120
                                case estado is
121
                                        when In0 =>
122
                                                -- (MP[CD])->CO;
123
                                                co_reg_s<=unsigned(data_bus_i(11 downto 9));
124
                                                cd_reg_s<=unsigned(data_bus_i(8 downto 0));
125
                                                -- (CP)+1->CP
126
                                                cp_reg_s<=cp_reg_s+1;
127
                                                --
128
                                                        In0_o<='1';
129
                                                        In1_o<='0';
130
                                                        Op0_o<='0';
131
                                                        Op1_o<='0';
132
                                                --
133
                                                estado<=In1;
134
                                        when In1 =>
135
                                                --
136
                                                        In0_o<='0';
137
                                                        In1_o<='1';
138
                                                        Op0_o<='0';
139
                                                        Op1_o<='0';
140
                                                --
141
                                                case (co_reg_s) is
142
                                                        when CLR =>
143
                                                                -- 0->AC
144
                                                                ac_reg_s<=(others=>'0');
145
                                                                -- (CP)->CD
146
                                                                addr_bus_o<=std_logic_vector(cp_reg_s);
147
                                                                estado<=In0;
148
                                                        when DEC =>
149
                                                                -- (AC)-1 -> AC
150
                                                                ac_reg_s<=ac_reg_s-1;
151
                                                                -- (CP)->CD
152
                                                                addr_bus_o<=std_logic_vector(cp_reg_s);
153
                                                                estado<=In0;
154
                                                        when BR =>
155
                                                                -- (CD)->CP,CD
156
                                                                cp_reg_s<=cd_reg_s;
157
                                                                addr_bus_o<=std_logic_vector(cd_reg_s);
158
                                                                estado<=In0;
159
                                                        when BZ =>
160
                                                                --Si AC>0 igual BR
161
                                                                if(ac_reg_s=0) then
162
                                                                        cp_reg_s<=cp_reg_s;
163
                                                                        addr_bus_o<=std_logic_vector(cd_reg_s);
164
                                                                else
165
                                                                --Si no (CP)->CD
166
                                                                        addr_bus_o<=std_logic_vector(cp_reg_s);
167
                                                                end if;
168
                                                                estado<=In0;
169
                                                        when HALT =>
170
                                                                -- 0->CP
171
                                                                cp_reg_s<=(others=>'0');
172
                                                                estado<=In1; --In0
173
                                                        when LD =>
174
                                                                -- (CD)->CD
175
                                                                addr_bus_o<=std_logic_vector(cd_reg_s);
176
                                                                estado<=Op0;
177
                                                        when ST =>
178
                                                                addr_bus_o<=std_logic_vector(cd_reg_s);
179
                                                                estado<=Op0;
180
                                                        when ADD =>
181
                                                                addr_bus_o<=std_logic_vector(cd_reg_s);
182
                                                                estado<=Op0;
183
                                                        when others=>
184
                                                                estado<=In0;
185
                                                end case;
186
                                        when Op0 =>
187
                                                --
188
                                                        In0_o<='0';
189
                                                        In1_o<='0';
190
                                                        Op0_o<='1';
191
                                                        Op1_o<='0';
192
                                                --
193
                                                case (co_reg_s) is
194
                                                        when LD =>
195
                                                                -- (MP[CD])->AC
196
                                                                ac_reg_s<=unsigned(data_bus_i);
197
                                                                estado<=Op1;
198
                                                        when ST =>
199
                                                                -- (AC)->MP[CD]
200
                                                                data_bus_o<=std_logic_vector(ac_reg_s);
201
                                                                we_o<='1';
202
                                                                estado<=Op1;
203
                                                        when ADD =>
204
                                                                ac_reg_s<=ac_reg_s+unsigned(data_bus_i);
205
                                                                estado<=Op1;
206
                                                        when others =>
207
                                                                estado<=In0;
208
                                                end case;
209
                                        when OP1 =>
210
                                                -- (CP)->CD
211
                                                addr_bus_o<=std_logic_vector(cp_reg_s);
212
                                                we_o<='0';
213
                                                estado<=In0;
214
                                                --
215
                                                        In0_o<='0';
216
                                                        In1_o<='0';
217
                                                        Op0_o<='0';
218
                                                        Op1_o<='1';
219
                                                --
220
                                        when others =>
221
                                                estado<=In0;
222
                                end case;
223
                        end if;
224
                end if;
225
        end process;
226
 
227
end fsm;

powered by: WebSVN 2.1.0

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