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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [rtl/] [core/] [pipemem.v] - Blame information for rev 130

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

Line No. Rev Author Line
1 49 dgisselq
///////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    pipemem.v
4
//
5
// Project:     Zip CPU -- a small, lightweight, RISC CPU soft core
6
//
7
// Purpose:     A memory unit to support a CPU, this time one supporting
8
//              pipelined wishbone memory accesses.  The goal is to be able
9
//      to issue one pipelined wishbone access per clock, and (given the memory
10
//      is fast enough) to be able to read the results back at one access per
11
//      clock.  This renders on-chip memory fast enough to handle single cycle
12
//      (pipelined) access.
13
//
14
//
15
// Creator:     Dan Gisselquist, Ph.D.
16 69 dgisselq
//              Gisselquist Technology, LLC
17 49 dgisselq
//
18
///////////////////////////////////////////////////////////////////////////
19
//
20
// Copyright (C) 2015, Gisselquist Technology, LLC
21
//
22
// This program is free software (firmware): you can redistribute it and/or
23
// modify it under the terms of  the GNU General Public License as published
24
// by the Free Software Foundation, either version 3 of the License, or (at
25
// your option) any later version.
26
//
27
// This program is distributed in the hope that it will be useful, but WITHOUT
28
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
29
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
30
// for more details.
31
//
32
// License:     GPL, v3, as defined and found on www.gnu.org,
33
//              http://www.gnu.org/licenses/gpl.html
34
//
35
//
36
///////////////////////////////////////////////////////////////////////////
37
//
38 69 dgisselq
module  pipemem(i_clk, i_rst, i_pipe_stb, i_lock,
39 49 dgisselq
                i_op, i_addr, i_data, i_oreg,
40
                        o_busy, o_pipe_stalled, o_valid, o_err, o_wreg, o_result,
41
                o_wb_cyc_gbl, o_wb_cyc_lcl,
42
                        o_wb_stb_gbl, o_wb_stb_lcl,
43
                        o_wb_we, o_wb_addr, o_wb_data,
44
                i_wb_ack, i_wb_stall, i_wb_err, i_wb_data);
45 69 dgisselq
        parameter       ADDRESS_WIDTH=24, IMPLEMENT_LOCK=0, AW=ADDRESS_WIDTH;
46 49 dgisselq
        input                   i_clk, i_rst;
47 69 dgisselq
        input                   i_pipe_stb, i_lock;
48 49 dgisselq
        // CPU interface
49
        input                   i_op;
50
        input           [31:0]   i_addr;
51
        input           [31:0]   i_data;
52
        input           [4:0]    i_oreg;
53
        // CPU outputs
54
        output  wire            o_busy;
55
        output  wire            o_pipe_stalled;
56
        output  reg             o_valid;
57
        output  reg             o_err;
58
        output  reg     [4:0]    o_wreg;
59
        output  reg     [31:0]   o_result;
60
        // Wishbone outputs
61 69 dgisselq
        output  wire            o_wb_cyc_gbl;
62
        output  reg             o_wb_stb_gbl;
63
        output  wire            o_wb_cyc_lcl;
64
        output  reg             o_wb_stb_lcl, o_wb_we;
65 49 dgisselq
        output  reg     [(AW-1):0]       o_wb_addr;
66
        output  reg     [31:0]   o_wb_data;
67
        // Wishbone inputs
68
        input                   i_wb_ack, i_wb_stall, i_wb_err;
69
        input           [31:0]   i_wb_data;
70
 
71 69 dgisselq
        reg                     r_wb_cyc_gbl, r_wb_cyc_lcl;
72 49 dgisselq
        reg     [3:0]            rdaddr, wraddr;
73
        wire    [3:0]            nxt_rdaddr;
74
        reg     [(5-1):0]        fifo_oreg [0:15];
75
        initial rdaddr = 0;
76
        initial wraddr = 0;
77
        always @(posedge i_clk)
78
                fifo_oreg[wraddr] <= i_oreg;
79
        always @(posedge i_clk)
80
                if ((i_rst)||(i_wb_err))
81
                        wraddr <= 0;
82
                else if (i_pipe_stb)
83 56 dgisselq
                        wraddr <= wraddr + 4'h1;
84 49 dgisselq
        always @(posedge i_clk)
85
                if ((i_rst)||(i_wb_err))
86
                        rdaddr <= 0;
87 56 dgisselq
                else if ((i_wb_ack)&&(cyc))
88
                        rdaddr <= rdaddr + 4'h1;
89
        assign  nxt_rdaddr = rdaddr + 4'h1;
90 49 dgisselq
 
91 56 dgisselq
        reg     cyc;
92 49 dgisselq
        wire    gbl_stb, lcl_stb;
93
        assign  lcl_stb = (i_addr[31:8]==24'hc00000)&&(i_addr[7:5]==3'h0);
94 56 dgisselq
        assign  gbl_stb = (~lcl_stb);
95
                        //= ((i_addr[31:8]!=24'hc00000)||(i_addr[7:5]!=3'h0));
96 49 dgisselq
 
97 56 dgisselq
        initial cyc = 0;
98 69 dgisselq
        initial r_wb_cyc_lcl = 0;
99
        initial r_wb_cyc_gbl = 0;
100 49 dgisselq
        always @(posedge i_clk)
101
                if (i_rst)
102
                begin
103 69 dgisselq
                        r_wb_cyc_gbl <= 1'b0;
104
                        r_wb_cyc_lcl <= 1'b0;
105 49 dgisselq
                        o_wb_stb_gbl <= 1'b0;
106
                        o_wb_stb_lcl <= 1'b0;
107 56 dgisselq
                        cyc <= 1'b0;
108
                end else if (cyc)
109 49 dgisselq
                begin
110
                        if ((~i_wb_stall)&&(~i_pipe_stb))
111
                        begin
112
                                o_wb_stb_gbl <= 1'b0;
113
                                o_wb_stb_lcl <= 1'b0;
114 63 dgisselq
                        // end else if ((i_pipe_stb)&&(~i_wb_stall))
115
                        // begin
116 56 dgisselq
                                // o_wb_addr <= i_addr[(AW-1):0];
117
                                // o_wb_data <= i_data;
118 49 dgisselq
                        end
119
 
120
                        if (((i_wb_ack)&&(nxt_rdaddr == wraddr))||(i_wb_err))
121
                        begin
122 69 dgisselq
                                r_wb_cyc_gbl <= 1'b0;
123
                                r_wb_cyc_lcl <= 1'b0;
124 56 dgisselq
                                cyc <= 1'b0;
125 49 dgisselq
                        end
126
                end else if (i_pipe_stb) // New memory operation
127
                begin // Grab the wishbone
128 69 dgisselq
                        r_wb_cyc_lcl <= lcl_stb;
129
                        r_wb_cyc_gbl <= gbl_stb;
130 49 dgisselq
                        o_wb_stb_lcl <= lcl_stb;
131
                        o_wb_stb_gbl <= gbl_stb;
132 56 dgisselq
                        cyc <= 1'b1;
133
                        // o_wb_addr <= i_addr[(AW-1):0];
134
                        // o_wb_data <= i_data;
135
                        // o_wb_we <= i_op
136
                end
137
        always @(posedge i_clk)
138
                if ((cyc)&&(i_pipe_stb)&&(~i_wb_stall))
139
                begin
140 49 dgisselq
                        o_wb_addr <= i_addr[(AW-1):0];
141
                        o_wb_data <= i_data;
142 56 dgisselq
                end else if ((~cyc)&&(i_pipe_stb))
143
                begin
144
                        o_wb_addr <= i_addr[(AW-1):0];
145
                        o_wb_data <= i_data;
146 49 dgisselq
                end
147 56 dgisselq
 
148 49 dgisselq
        always @(posedge i_clk)
149 56 dgisselq
                if ((i_pipe_stb)&&(~cyc))
150 49 dgisselq
                        o_wb_we   <= i_op;
151
 
152
        initial o_valid = 1'b0;
153
        always @(posedge i_clk)
154 56 dgisselq
                o_valid <= (cyc)&&(i_wb_ack)&&(~o_wb_we);
155 49 dgisselq
        initial o_err = 1'b0;
156
        always @(posedge i_clk)
157 56 dgisselq
                o_err <= (cyc)&&(i_wb_err);
158
        assign  o_busy = cyc;
159 49 dgisselq
 
160
        always @(posedge i_clk)
161
                o_wreg <= fifo_oreg[rdaddr];
162
        always @(posedge i_clk)
163
                if (i_wb_ack)
164
                        o_result <= i_wb_data;
165
 
166 56 dgisselq
        assign  o_pipe_stalled = (cyc)
167 49 dgisselq
                        &&((i_wb_stall)||((~o_wb_stb_lcl)&&(~o_wb_stb_gbl)));
168 69 dgisselq
 
169
        generate
170
        if (IMPLEMENT_LOCK != 0)
171
        begin
172
                reg     lock_gbl, lock_lcl;
173
 
174
                initial lock_gbl = 1'b0;
175
                initial lock_lcl = 1'b0;
176
                always @(posedge i_clk)
177
                begin
178
                        lock_gbl <= (i_lock)&&((r_wb_cyc_gbl)||(lock_gbl));
179
                        lock_lcl <= (i_lock)&&((r_wb_cyc_lcl)||(lock_gbl));
180
                end
181
 
182
                assign  o_wb_cyc_gbl = (r_wb_cyc_gbl)||(lock_gbl);
183
                assign  o_wb_cyc_lcl = (r_wb_cyc_lcl)||(lock_lcl);
184
 
185
        end else begin
186
                assign  o_wb_cyc_gbl = (r_wb_cyc_gbl);
187
                assign  o_wb_cyc_lcl = (r_wb_cyc_lcl);
188
        end endgenerate
189
 
190 49 dgisselq
endmodule

powered by: WebSVN 2.1.0

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