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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [rtl/] [zipbones.v] - Blame information for rev 201

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

Line No. Rev Author Line
1 201 dgisselq
////////////////////////////////////////////////////////////////////////////////
2 38 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 69 dgisselq
//              Gisselquist Technology, LLC
13 38 dgisselq
//
14 201 dgisselq
////////////////////////////////////////////////////////////////////////////////
15 38 dgisselq
//
16 201 dgisselq
// Copyright (C) 2015, 2017, Gisselquist Technology, LLC
17 38 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 201 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 38 dgisselq
// License:     GPL, v3, as defined and found on www.gnu.org,
34
//              http://www.gnu.org/licenses/gpl.html
35
//
36
//
37 201 dgisselq
////////////////////////////////////////////////////////////////////////////////
38 38 dgisselq
//
39 201 dgisselq
//
40 105 dgisselq
`include "cpudefs.v"
41
//
42 38 dgisselq
module  zipbones(i_clk, i_rst,
43
                // Wishbone master interface from the CPU
44 201 dgisselq
                o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data, o_wb_sel,
45 38 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 66 dgisselq
                        o_dbg_ack, o_dbg_stall, o_dbg_data
53
`ifdef  DEBUG_SCOPE
54
                , o_zip_debug
55
`endif
56
                );
57 201 dgisselq
        parameter       RESET_ADDRESS=32'h0100000, ADDRESS_WIDTH=30,
58
                        LGICACHE=8, START_HALTED=0;
59
        localparam      AW=ADDRESS_WIDTH;
60 38 dgisselq
        input   i_clk, i_rst;
61
        // Wishbone master
62
        output  wire            o_wb_cyc, o_wb_stb, o_wb_we;
63 48 dgisselq
        output  wire    [(AW-1):0]       o_wb_addr;
64 38 dgisselq
        output  wire    [31:0]   o_wb_data;
65 201 dgisselq
        output  wire    [3:0]    o_wb_sel;
66 38 dgisselq
        input                   i_wb_ack, i_wb_stall;
67
        input           [31:0]   i_wb_data;
68
        input                   i_wb_err;
69
        // Incoming interrupts
70 48 dgisselq
        input                   i_ext_int;
71 38 dgisselq
        // 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 56 dgisselq
        //
80 66 dgisselq
`ifdef  DEBUG_SCOPE
81 56 dgisselq
        output  wire    [31:0]   o_zip_debug;
82 66 dgisselq
`endif
83 38 dgisselq
 
84
        // 
85
        //
86
        //
87
        wire    sys_cyc, sys_stb, sys_we;
88
        wire    [4:0]    sys_addr;
89 48 dgisselq
        wire    [(AW-1):0]       cpu_addr;
90 38 dgisselq
        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 56 dgisselq
        wire    [3:0]    cpu_dbg_cc;
110 38 dgisselq
        assign  dbg_cmd_write = (i_dbg_cyc)&&(i_dbg_stb)&&(i_dbg_we)&&(~i_dbg_addr);
111
        //
112 91 dgisselq
        // Always start us off with an initial reset
113
        //
114 38 dgisselq
        initial cmd_reset = 1'b1;
115
        always @(posedge i_clk)
116
                cmd_reset <= ((dbg_cmd_write)&&(i_dbg_data[6]));
117
        //
118 69 dgisselq
        initial cmd_halt  = START_HALTED;
119 38 dgisselq
        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 91 dgisselq
        initial cmd_clear_pf_cache = 1'b0;
128 38 dgisselq
        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 91 dgisselq
        initial cmd_addr = 5'h0;
141 38 dgisselq
        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 48 dgisselq
        assign  cmd_data = { 7'h00, 8'h00, i_ext_int,
163 56 dgisselq
                        cpu_dbg_cc,
164 38 dgisselq
                        1'b0, cmd_halt, (~cpu_dbg_stall), 1'b0,
165 56 dgisselq
                        1'b0, cpu_reset, 1'b0, cmd_addr };
166 38 dgisselq
 
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 56 dgisselq
        wire    [31:0]   cpu_data;
174 38 dgisselq
        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 201 dgisselq
        zipcpu  #(.RESET_ADDRESS(RESET_ADDRESS),
178
                        .ADDRESS_WIDTH(ADDRESS_WIDTH),
179
                        .LGICACHE(LGICACHE),
180
                        .WITH_LOCAL_BUS(0))
181 48 dgisselq
                thecpu(i_clk, cpu_reset, i_ext_int,
182 38 dgisselq
                        cpu_halt, cmd_clear_pf_cache, cmd_addr[4:0], cpu_dbg_we,
183
                                i_dbg_data, cpu_dbg_stall, cpu_dbg_data,
184
                                cpu_dbg_cc, cpu_break,
185
                        o_wb_cyc, o_wb_stb,
186
                                cpu_lcl_cyc, cpu_lcl_stb,
187 201 dgisselq
                                o_wb_we, o_wb_addr, o_wb_data, o_wb_sel,
188 56 dgisselq
                                i_wb_ack, i_wb_stall, i_wb_data,
189 201 dgisselq
                                (i_wb_err)||(cpu_lcl_cyc),
190 66 dgisselq
                        cpu_op_stall, cpu_pf_stall, cpu_i_count
191
`ifdef  DEBUG_SCOPE
192
                        , o_zip_debug
193
`endif
194
                        );
195 38 dgisselq
 
196
        // Return debug response values
197
        assign  o_dbg_data = (~i_dbg_addr)?cmd_data :cpu_dbg_data;
198
        initial o_dbg_ack = 1'b0;
199
        always @(posedge i_clk)
200
                o_dbg_ack <= (i_dbg_cyc)&&((~i_dbg_addr)||(~o_dbg_stall));
201
        assign  o_dbg_stall=(i_dbg_cyc)&&(cpu_dbg_stall)&&(i_dbg_addr);
202
 
203 56 dgisselq
        assign  o_ext_int = (cmd_halt) && (~i_wb_stall);
204 38 dgisselq
 
205
endmodule

powered by: WebSVN 2.1.0

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