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

Subversion Repositories zipcpu

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

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

Line No. Rev Author Line
1 38 dgisselq
///////////////////////////////////////////////////////////////////////////
2
//
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 Tecnology, LLC
13
//
14
///////////////////////////////////////////////////////////////////////////
15
//
16
// Copyright (C) 2015, Gisselquist Technology, LLC
17
//
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
// License:     GPL, v3, as defined and found on www.gnu.org,
29
//              http://www.gnu.org/licenses/gpl.html
30
//
31
//
32
///////////////////////////////////////////////////////////////////////////
33
//
34
module  zipbones(i_clk, i_rst,
35
                // Wishbone master interface from the CPU
36
                o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data,
37
                        i_wb_ack, i_wb_stall, i_wb_data, i_wb_err,
38
                // Incoming interrupts
39
                i_ext_int,
40
                // Our one outgoing interrupt
41
                o_ext_int,
42
                // Wishbone slave interface for debugging purposes
43
                i_dbg_cyc, i_dbg_stb, i_dbg_we, i_dbg_addr, i_dbg_data,
44
                        o_dbg_ack, o_dbg_stall, o_dbg_data);
45
        parameter       RESET_ADDRESS=32'h0100000, START_HALTED=1,
46
                        EXTERNAL_INTERRUPTS=1;
47
        input   i_clk, i_rst;
48
        // Wishbone master
49
        output  wire            o_wb_cyc, o_wb_stb, o_wb_we;
50
        output  wire    [31:0]   o_wb_addr;
51
        output  wire    [31:0]   o_wb_data;
52
        input                   i_wb_ack, i_wb_stall;
53
        input           [31:0]   i_wb_data;
54
        input                   i_wb_err;
55
        // Incoming interrupts
56
        input           [(EXTERNAL_INTERRUPTS-1):0]      i_ext_int;
57
        // Outgoing interrupt
58
        output  wire            o_ext_int;
59
        // Wishbone slave
60
        input                   i_dbg_cyc, i_dbg_stb, i_dbg_we, i_dbg_addr;
61
        input           [31:0]   i_dbg_data;
62
        output  reg             o_dbg_ack;
63
        output  wire            o_dbg_stall;
64
        output  wire    [31:0]   o_dbg_data;
65
 
66
        // 
67
        //
68
        //
69
        wire    sys_cyc, sys_stb, sys_we;
70
        wire    [4:0]    sys_addr;
71
        wire    [31:0]   cpu_addr;
72
        wire    [31:0]   sys_data;
73
        wire            sys_ack, sys_stall;
74
 
75
        //
76
        // The external debug interface
77
        //
78
        // We offer only a limited interface here, requiring a pre-register
79
        // write to set the local address.  This interface allows access to
80
        // the Zip System on a debug basis only, and not to the rest of the
81
        // wishbone bus.  Further, to access these registers, the control
82
        // register must first be accessed to both stop the CPU and to 
83
        // set the following address in question.  Hence all accesses require
84
        // two accesses: write the address to the control register (and halt
85
        // the CPU if not halted), then read/write the data from the data
86
        // register.
87
        //
88
        wire            cpu_break, dbg_cmd_write;
89
        reg             cmd_reset, cmd_halt, cmd_step, cmd_clear_pf_cache;
90
        reg     [4:0]    cmd_addr;
91
        wire    [1:0]    cpu_dbg_cc;
92
        assign  dbg_cmd_write = (i_dbg_cyc)&&(i_dbg_stb)&&(i_dbg_we)&&(~i_dbg_addr);
93
        //
94
        initial cmd_reset = 1'b1;
95
        always @(posedge i_clk)
96
                cmd_reset <= ((dbg_cmd_write)&&(i_dbg_data[6]));
97
        //
98
        initial cmd_halt  = 1'b1;
99
        always @(posedge i_clk)
100
                if (i_rst)
101
                        cmd_halt <= (START_HALTED == 1)? 1'b1 : 1'b0;
102
                else if (dbg_cmd_write)
103
                        cmd_halt <= ((i_dbg_data[10])||(i_dbg_data[8]));
104
                else if ((cmd_step)||(cpu_break))
105
                        cmd_halt  <= 1'b1;
106
 
107
        always @(posedge i_clk)
108
                if (i_rst)
109
                        cmd_clear_pf_cache <= 1'b0;
110
                else if (dbg_cmd_write)
111
                        cmd_clear_pf_cache <= i_dbg_data[11];
112
                else
113
                        cmd_clear_pf_cache <= 1'b0;
114
        //
115
        initial cmd_step  = 1'b0;
116
        always @(posedge i_clk)
117
                cmd_step <= (dbg_cmd_write)&&(i_dbg_data[8]);
118
        //
119
        always @(posedge i_clk)
120
                if (dbg_cmd_write)
121
                        cmd_addr <= i_dbg_data[4:0];
122
 
123
        wire    cpu_reset;
124
        assign  cpu_reset = (cmd_reset)||(i_rst);
125
 
126
        wire    cpu_halt, cpu_dbg_stall;
127
        assign  cpu_halt = (i_rst)||((cmd_halt)&&(~cmd_step));
128
        wire    [31:0]   pic_data;
129
        wire    [31:0]   cmd_data;
130
        // Values:
131
        //      0x0003f -> cmd_addr mask
132
        //      0x00040 -> reset
133
        //      0x00080 -> PIC interrrupts enabled
134
        //      0x00100 -> cmd_step
135
        //      0x00200 -> cmd_stall
136
        //      0x00400 -> cmd_halt
137
        //      0x00800 -> cmd_clear_pf_cache
138
        //      0x01000 -> cc.sleep
139
        //      0x02000 -> cc.gie
140
        //      0x10000 -> External interrupt line is high
141
        assign  cmd_data = { 7'h00, {(9-EXTERNAL_INTERRUPTS){1'b0}}, i_ext_int,
142
                        2'b00, cpu_dbg_cc,
143
                        1'b0, cmd_halt, (~cpu_dbg_stall), 1'b0,
144
                        pic_data[15], cpu_reset, 1'b0, cmd_addr };
145
        wire    cpu_gie;
146
        assign  cpu_gie = cpu_dbg_cc[1];
147
 
148
        //
149
        // The CPU itself
150
        //
151
        wire            cpu_gbl_stb, cpu_lcl_cyc, cpu_lcl_stb,
152
                        cpu_we, cpu_dbg_we,
153
                        cpu_op_stall, cpu_pf_stall, cpu_i_count;
154
        wire    [31:0]   cpu_data, wb_data;
155
        wire            cpu_ack, cpu_stall, cpu_err;
156
        wire    [31:0]   cpu_dbg_data;
157
        assign cpu_dbg_we = ((i_dbg_cyc)&&(i_dbg_stb)
158
                                        &&(i_dbg_we)&&(i_dbg_addr));
159
        zipcpu  #(RESET_ADDRESS) thecpu(i_clk, cpu_reset, i_ext_int,
160
                        cpu_halt, cmd_clear_pf_cache, cmd_addr[4:0], cpu_dbg_we,
161
                                i_dbg_data, cpu_dbg_stall, cpu_dbg_data,
162
                                cpu_dbg_cc, cpu_break,
163
                        o_wb_cyc, o_wb_stb,
164
                                cpu_lcl_cyc, cpu_lcl_stb,
165
                                o_wb_we, o_wb_addr, o_wb_data,
166
                                i_wb_ack, i_wb_stall, wb_data,
167
                                i_wb_err,
168
                        cpu_op_stall, cpu_pf_stall, cpu_i_count);
169
 
170
        // Return debug response values
171
        assign  o_dbg_data = (~i_dbg_addr)?cmd_data :cpu_dbg_data;
172
        initial o_dbg_ack = 1'b0;
173
        always @(posedge i_clk)
174
                o_dbg_ack <= (i_dbg_cyc)&&((~i_dbg_addr)||(~o_dbg_stall));
175
        assign  o_dbg_stall=(i_dbg_cyc)&&(cpu_dbg_stall)&&(i_dbg_addr);
176
 
177
        assign  o_ext_int = (cmd_halt) && (~cpu_stall);
178
 
179
endmodule

powered by: WebSVN 2.1.0

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