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

Subversion Repositories zipcpu

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

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 194 dgisselq
        parameter       ADDRESS_WIDTH=32, 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 131 dgisselq
        reg     cyc;
72 69 dgisselq
        reg                     r_wb_cyc_gbl, r_wb_cyc_lcl;
73 49 dgisselq
        reg     [3:0]            rdaddr, wraddr;
74
        wire    [3:0]            nxt_rdaddr;
75
        reg     [(5-1):0]        fifo_oreg [0:15];
76
        initial rdaddr = 0;
77
        initial wraddr = 0;
78
        always @(posedge i_clk)
79
                fifo_oreg[wraddr] <= i_oreg;
80
        always @(posedge i_clk)
81
                if ((i_rst)||(i_wb_err))
82
                        wraddr <= 0;
83
                else if (i_pipe_stb)
84 56 dgisselq
                        wraddr <= wraddr + 4'h1;
85 49 dgisselq
        always @(posedge i_clk)
86
                if ((i_rst)||(i_wb_err))
87
                        rdaddr <= 0;
88 56 dgisselq
                else if ((i_wb_ack)&&(cyc))
89
                        rdaddr <= rdaddr + 4'h1;
90
        assign  nxt_rdaddr = rdaddr + 4'h1;
91 49 dgisselq
 
92
        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 160 dgisselq
                // if (i_wb_ack) isn't necessary, since o_valid won't be true
164
                // then either.
165
                o_result <= i_wb_data;
166 49 dgisselq
 
167 56 dgisselq
        assign  o_pipe_stalled = (cyc)
168 49 dgisselq
                        &&((i_wb_stall)||((~o_wb_stb_lcl)&&(~o_wb_stb_gbl)));
169 69 dgisselq
 
170
        generate
171
        if (IMPLEMENT_LOCK != 0)
172
        begin
173
                reg     lock_gbl, lock_lcl;
174
 
175
                initial lock_gbl = 1'b0;
176
                initial lock_lcl = 1'b0;
177
                always @(posedge i_clk)
178
                begin
179
                        lock_gbl <= (i_lock)&&((r_wb_cyc_gbl)||(lock_gbl));
180
                        lock_lcl <= (i_lock)&&((r_wb_cyc_lcl)||(lock_gbl));
181
                end
182
 
183
                assign  o_wb_cyc_gbl = (r_wb_cyc_gbl)||(lock_gbl);
184
                assign  o_wb_cyc_lcl = (r_wb_cyc_lcl)||(lock_lcl);
185
 
186
        end else begin
187
                assign  o_wb_cyc_gbl = (r_wb_cyc_gbl);
188
                assign  o_wb_cyc_lcl = (r_wb_cyc_lcl);
189
        end endgenerate
190
 
191 49 dgisselq
endmodule

powered by: WebSVN 2.1.0

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