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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [rtl/] [cpu/] [zipbones.v] - Blame information for rev 50

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 50 dgisselq
////////////////////////////////////////////////////////////////////////////////
2 3 dgisselq
//
3
// Filename:    zipbones.v
4
//
5
// Project:     Zip CPU -- a small, lightweight, RISC CPU soft core
6
//
7
// Purpose:     In the spirit of keeping the Zip CPU small, this implements a
8
//              Zip System with no peripherals: Any peripherals you wish will
9
//              need to be implemented off-module.
10
//
11
// Creator:     Dan Gisselquist, Ph.D.
12
//              Gisselquist Technology, LLC
13
//
14 50 dgisselq
////////////////////////////////////////////////////////////////////////////////
15 3 dgisselq
//
16 50 dgisselq
// Copyright (C) 2015, 2017, Gisselquist Technology, LLC
17 3 dgisselq
//
18
// This program is free software (firmware): you can redistribute it and/or
19
// modify it under the terms of  the GNU General Public License as published
20
// by the Free Software Foundation, either version 3 of the License, or (at
21
// your option) any later version.
22
//
23
// This program is distributed in the hope that it will be useful, but WITHOUT
24
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
25
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26
// for more details.
27
//
28 50 dgisselq
// You should have received a copy of the GNU General Public License along
29
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
30
// target there if the PDF file isn't present.)  If not, see
31
// <http://www.gnu.org/licenses/> for a copy.
32
//
33 3 dgisselq
// License:     GPL, v3, as defined and found on www.gnu.org,
34
//              http://www.gnu.org/licenses/gpl.html
35
//
36
//
37 50 dgisselq
////////////////////////////////////////////////////////////////////////////////
38 3 dgisselq
//
39 50 dgisselq
//
40 3 dgisselq
`include "cpudefs.v"
41
//
42
module  zipbones(i_clk, i_rst,
43
                // Wishbone master interface from the CPU
44 50 dgisselq
                o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data, o_wb_sel,
45 3 dgisselq
                        i_wb_ack, i_wb_stall, i_wb_data, i_wb_err,
46
                // Incoming interrupts
47
                i_ext_int,
48
                // Our one outgoing interrupt
49
                o_ext_int,
50
                // Wishbone slave interface for debugging purposes
51
                i_dbg_cyc, i_dbg_stb, i_dbg_we, i_dbg_addr, i_dbg_data,
52
                        o_dbg_ack, o_dbg_stall, o_dbg_data
53
`ifdef  DEBUG_SCOPE
54
                , o_zip_debug
55
`endif
56
                );
57 50 dgisselq
        parameter       RESET_ADDRESS=32'h0100000, ADDRESS_WIDTH=30,
58
                        LGICACHE=8, START_HALTED=0;
59
        localparam      AW=ADDRESS_WIDTH;
60 3 dgisselq
        input   i_clk, i_rst;
61
        // Wishbone master
62
        output  wire            o_wb_cyc, o_wb_stb, o_wb_we;
63
        output  wire    [(AW-1):0]       o_wb_addr;
64
        output  wire    [31:0]   o_wb_data;
65 50 dgisselq
        output  wire    [3:0]    o_wb_sel;
66 3 dgisselq
        input                   i_wb_ack, i_wb_stall;
67
        input           [31:0]   i_wb_data;
68
        input                   i_wb_err;
69
        // Incoming interrupts
70
        input                   i_ext_int;
71
        // Outgoing interrupt
72
        output  wire            o_ext_int;
73
        // Wishbone slave
74
        input                   i_dbg_cyc, i_dbg_stb, i_dbg_we, i_dbg_addr;
75
        input           [31:0]   i_dbg_data;
76
        output  reg             o_dbg_ack;
77
        output  wire            o_dbg_stall;
78
        output  wire    [31:0]   o_dbg_data;
79
        //
80
`ifdef  DEBUG_SCOPE
81
        output  wire    [31:0]   o_zip_debug;
82
`endif
83
 
84
        // 
85
        //
86
        //
87
        wire    sys_cyc, sys_stb, sys_we;
88
        wire    [4:0]    sys_addr;
89
        wire    [(AW-1):0]       cpu_addr;
90
        wire    [31:0]   sys_data;
91
        wire            sys_ack, sys_stall;
92
 
93
        //
94
        // The external debug interface
95
        //
96
        // We offer only a limited interface here, requiring a pre-register
97
        // write to set the local address.  This interface allows access to
98
        // the Zip System on a debug basis only, and not to the rest of the
99
        // wishbone bus.  Further, to access these registers, the control
100
        // register must first be accessed to both stop the CPU and to 
101
        // set the following address in question.  Hence all accesses require
102
        // two accesses: write the address to the control register (and halt
103
        // the CPU if not halted), then read/write the data from the data
104
        // register.
105
        //
106
        wire            cpu_break, dbg_cmd_write;
107
        reg             cmd_reset, cmd_halt, cmd_step, cmd_clear_pf_cache;
108
        reg     [4:0]    cmd_addr;
109
        wire    [3:0]    cpu_dbg_cc;
110
        assign  dbg_cmd_write = (i_dbg_cyc)&&(i_dbg_stb)&&(i_dbg_we)&&(~i_dbg_addr);
111
        //
112
        // Always start us off with an initial reset
113
        //
114
        initial cmd_reset = 1'b1;
115
        always @(posedge i_clk)
116
                cmd_reset <= ((dbg_cmd_write)&&(i_dbg_data[6]));
117
        //
118
        initial cmd_halt  = START_HALTED;
119
        always @(posedge i_clk)
120
                if (i_rst)
121
                        cmd_halt <= (START_HALTED == 1)? 1'b1 : 1'b0;
122
                else if (dbg_cmd_write)
123
                        cmd_halt <= ((i_dbg_data[10])||(i_dbg_data[8]));
124
                else if ((cmd_step)||(cpu_break))
125
                        cmd_halt  <= 1'b1;
126
 
127
        initial cmd_clear_pf_cache = 1'b0;
128
        always @(posedge i_clk)
129
                if (i_rst)
130
                        cmd_clear_pf_cache <= 1'b0;
131
                else if (dbg_cmd_write)
132
                        cmd_clear_pf_cache <= i_dbg_data[11];
133
                else
134
                        cmd_clear_pf_cache <= 1'b0;
135
        //
136
        initial cmd_step  = 1'b0;
137
        always @(posedge i_clk)
138
                cmd_step <= (dbg_cmd_write)&&(i_dbg_data[8]);
139
        //
140
        initial cmd_addr = 5'h0;
141
        always @(posedge i_clk)
142
                if (dbg_cmd_write)
143
                        cmd_addr <= i_dbg_data[4:0];
144
 
145
        wire    cpu_reset;
146
        assign  cpu_reset = (cmd_reset)||(i_rst);
147
 
148
        wire    cpu_halt, cpu_dbg_stall;
149
        assign  cpu_halt = (i_rst)||((cmd_halt)&&(~cmd_step));
150
        wire    [31:0]   cmd_data;
151
        // Values:
152
        //      0x0003f -> cmd_addr mask
153
        //      0x00040 -> reset
154
        //      0x00080 -> PIC interrrupts enabled
155
        //      0x00100 -> cmd_step
156
        //      0x00200 -> cmd_stall
157
        //      0x00400 -> cmd_halt
158
        //      0x00800 -> cmd_clear_pf_cache
159
        //      0x01000 -> cc.sleep
160
        //      0x02000 -> cc.gie
161
        //      0x10000 -> External interrupt line is high
162
        assign  cmd_data = { 7'h00, 8'h00, i_ext_int,
163
                        cpu_dbg_cc,
164
                        1'b0, cmd_halt, (~cpu_dbg_stall), 1'b0,
165
                        1'b0, cpu_reset, 1'b0, cmd_addr };
166
 
167
        //
168
        // The CPU itself
169
        //
170
        wire            cpu_gbl_stb, cpu_lcl_cyc, cpu_lcl_stb,
171
                        cpu_we, cpu_dbg_we,
172
                        cpu_op_stall, cpu_pf_stall, cpu_i_count;
173
        wire    [31:0]   cpu_data;
174
        wire    [31:0]   cpu_dbg_data;
175
        assign cpu_dbg_we = ((i_dbg_cyc)&&(i_dbg_stb)
176
                                        &&(i_dbg_we)&&(i_dbg_addr));
177
        generate
178
        if (HIGHSPEED_CPU==0)
179
        begin
180 50 dgisselq
        zipcpu  #(.RESET_ADDRESS(RESET_ADDRESS),
181
                        .ADDRESS_WIDTH(ADDRESS_WIDTH),
182
                        .LGICACHE(LGICACHE),
183
                        .WITH_LOCAL_BUS(0))
184 3 dgisselq
                thecpu(i_clk, cpu_reset, i_ext_int,
185
                        cpu_halt, cmd_clear_pf_cache, cmd_addr[4:0], cpu_dbg_we,
186
                                i_dbg_data, cpu_dbg_stall, cpu_dbg_data,
187
                                cpu_dbg_cc, cpu_break,
188
                        o_wb_cyc, o_wb_stb,
189
                                cpu_lcl_cyc, cpu_lcl_stb,
190 50 dgisselq
                                o_wb_we, o_wb_addr, o_wb_data, o_wb_sel,
191 3 dgisselq
                                i_wb_ack, i_wb_stall, i_wb_data,
192 32 dgisselq
                                (i_wb_err)||(cpu_lcl_cyc),
193 3 dgisselq
                        cpu_op_stall, cpu_pf_stall, cpu_i_count
194
`ifdef  DEBUG_SCOPE
195
                        , o_zip_debug
196
`endif
197
                        );
198
        end else begin
199 50 dgisselq
        zipcpu  #(.RESET_ADDRESS(RESET_ADDRESS),
200
                        .ADDRESS_WIDTH(ADDRESS_WIDTH),
201
                        .LGICACHE(LGICACHE),
202
                        .WITH_LOCAL_BUS(0))
203 3 dgisselq
                thecpu(i_clk, cpu_reset, i_ext_int,
204
                        cpu_halt, cmd_clear_pf_cache, cmd_addr[4:0], cpu_dbg_we,
205
                                i_dbg_data, cpu_dbg_stall, cpu_dbg_data,
206
                                cpu_dbg_cc, cpu_break,
207
                        o_wb_cyc, o_wb_stb,
208
                                cpu_lcl_cyc, cpu_lcl_stb,
209 50 dgisselq
                                o_wb_we, o_wb_addr, o_wb_data, o_wb_sel,
210 3 dgisselq
                                i_wb_ack, i_wb_stall, i_wb_data,
211
                                (i_wb_err)||((cpu_lcl_cyc)&&(cpu_lcl_stb)),
212
                        cpu_op_stall, cpu_pf_stall, cpu_i_count
213
`ifdef  DEBUG_SCOPE
214
                        , o_zip_debug
215
`endif
216
                        );
217
        end endgenerate
218
 
219
        // Return debug response values
220
        assign  o_dbg_data = (~i_dbg_addr)?cmd_data :cpu_dbg_data;
221
        initial o_dbg_ack = 1'b0;
222
        always @(posedge i_clk)
223
                o_dbg_ack <= (i_dbg_cyc)&&((~i_dbg_addr)||(~o_dbg_stall));
224 32 dgisselq
        assign  o_dbg_stall= 1'b0; //(i_dbg_cyc)&&(cpu_dbg_stall)&&(i_dbg_addr);
225 3 dgisselq
 
226
        assign  o_ext_int = (cmd_halt) && (~i_wb_stall);
227
 
228
endmodule

powered by: WebSVN 2.1.0

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