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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [rtl/] [cpu/] [pipemem.v] - Blame information for rev 118

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 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
//              Gisselquist Technology, LLC
17
//
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
module  pipemem(i_clk, i_rst, i_pipe_stb, i_lock,
39
                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 118 dgisselq
        parameter       ADDRESS_WIDTH=32, IMPLEMENT_LOCK=0;
46
        localparam      AW=ADDRESS_WIDTH;
47 21 dgisselq
        input                   i_clk, i_rst;
48
        input                   i_pipe_stb, i_lock;
49
        // CPU interface
50
        input                   i_op;
51
        input           [31:0]   i_addr;
52
        input           [31:0]   i_data;
53
        input           [4:0]    i_oreg;
54
        // CPU outputs
55
        output  wire            o_busy;
56
        output  wire            o_pipe_stalled;
57
        output  reg             o_valid;
58
        output  reg             o_err;
59
        output  reg     [4:0]    o_wreg;
60
        output  reg     [31:0]   o_result;
61
        // Wishbone outputs
62
        output  wire            o_wb_cyc_gbl;
63
        output  reg             o_wb_stb_gbl;
64
        output  wire            o_wb_cyc_lcl;
65
        output  reg             o_wb_stb_lcl, o_wb_we;
66
        output  reg     [(AW-1):0]       o_wb_addr;
67
        output  reg     [31:0]   o_wb_data;
68
        // Wishbone inputs
69
        input                   i_wb_ack, i_wb_stall, i_wb_err;
70
        input           [31:0]   i_wb_data;
71
 
72 52 dgisselq
        reg     cyc;
73 21 dgisselq
        reg                     r_wb_cyc_gbl, r_wb_cyc_lcl;
74
        reg     [3:0]            rdaddr, wraddr;
75
        wire    [3:0]            nxt_rdaddr;
76
        reg     [(5-1):0]        fifo_oreg [0:15];
77
        initial rdaddr = 0;
78
        initial wraddr = 0;
79
        always @(posedge i_clk)
80
                fifo_oreg[wraddr] <= i_oreg;
81
        always @(posedge i_clk)
82
                if ((i_rst)||(i_wb_err))
83
                        wraddr <= 0;
84
                else if (i_pipe_stb)
85
                        wraddr <= wraddr + 4'h1;
86
        always @(posedge i_clk)
87
                if ((i_rst)||(i_wb_err))
88
                        rdaddr <= 0;
89
                else if ((i_wb_ack)&&(cyc))
90
                        rdaddr <= rdaddr + 4'h1;
91
        assign  nxt_rdaddr = rdaddr + 4'h1;
92
 
93
        wire    gbl_stb, lcl_stb;
94
        assign  lcl_stb = (i_addr[31:8]==24'hc00000)&&(i_addr[7:5]==3'h0);
95
        assign  gbl_stb = (~lcl_stb);
96
                        //= ((i_addr[31:8]!=24'hc00000)||(i_addr[7:5]!=3'h0));
97
 
98
        initial cyc = 0;
99
        initial r_wb_cyc_lcl = 0;
100
        initial r_wb_cyc_gbl = 0;
101
        always @(posedge i_clk)
102
                if (i_rst)
103
                begin
104
                        r_wb_cyc_gbl <= 1'b0;
105
                        r_wb_cyc_lcl <= 1'b0;
106
                        o_wb_stb_gbl <= 1'b0;
107
                        o_wb_stb_lcl <= 1'b0;
108
                        cyc <= 1'b0;
109
                end else if (cyc)
110
                begin
111
                        if ((~i_wb_stall)&&(~i_pipe_stb))
112
                        begin
113
                                o_wb_stb_gbl <= 1'b0;
114
                                o_wb_stb_lcl <= 1'b0;
115
                        // end else if ((i_pipe_stb)&&(~i_wb_stall))
116
                        // begin
117
                                // o_wb_addr <= i_addr[(AW-1):0];
118
                                // o_wb_data <= i_data;
119
                        end
120
 
121
                        if (((i_wb_ack)&&(nxt_rdaddr == wraddr))||(i_wb_err))
122
                        begin
123
                                r_wb_cyc_gbl <= 1'b0;
124
                                r_wb_cyc_lcl <= 1'b0;
125
                                cyc <= 1'b0;
126
                        end
127
                end else if (i_pipe_stb) // New memory operation
128
                begin // Grab the wishbone
129
                        r_wb_cyc_lcl <= lcl_stb;
130
                        r_wb_cyc_gbl <= gbl_stb;
131
                        o_wb_stb_lcl <= lcl_stb;
132
                        o_wb_stb_gbl <= gbl_stb;
133
                        cyc <= 1'b1;
134
                        // o_wb_addr <= i_addr[(AW-1):0];
135
                        // o_wb_data <= i_data;
136
                        // o_wb_we <= i_op
137
                end
138
        always @(posedge i_clk)
139
                if ((cyc)&&(i_pipe_stb)&&(~i_wb_stall))
140
                begin
141
                        o_wb_addr <= i_addr[(AW-1):0];
142
                        o_wb_data <= i_data;
143
                end else if ((~cyc)&&(i_pipe_stb))
144
                begin
145
                        o_wb_addr <= i_addr[(AW-1):0];
146
                        o_wb_data <= i_data;
147
                end
148
 
149
        always @(posedge i_clk)
150
                if ((i_pipe_stb)&&(~cyc))
151
                        o_wb_we   <= i_op;
152
 
153
        initial o_valid = 1'b0;
154
        always @(posedge i_clk)
155
                o_valid <= (cyc)&&(i_wb_ack)&&(~o_wb_we);
156
        initial o_err = 1'b0;
157
        always @(posedge i_clk)
158
                o_err <= (cyc)&&(i_wb_err);
159
        assign  o_busy = cyc;
160
 
161
        always @(posedge i_clk)
162
                o_wreg <= fifo_oreg[rdaddr];
163
        always @(posedge i_clk)
164 66 dgisselq
                // if (i_wb_ack) isn't necessary, since o_valid won't be true
165
                // then either.
166
                o_result <= i_wb_data;
167 21 dgisselq
 
168
        assign  o_pipe_stalled = (cyc)
169
                        &&((i_wb_stall)||((~o_wb_stb_lcl)&&(~o_wb_stb_gbl)));
170
 
171
        generate
172
        if (IMPLEMENT_LOCK != 0)
173
        begin
174
                reg     lock_gbl, lock_lcl;
175
 
176
                initial lock_gbl = 1'b0;
177
                initial lock_lcl = 1'b0;
178
                always @(posedge i_clk)
179
                begin
180
                        lock_gbl <= (i_lock)&&((r_wb_cyc_gbl)||(lock_gbl));
181
                        lock_lcl <= (i_lock)&&((r_wb_cyc_lcl)||(lock_gbl));
182
                end
183
 
184
                assign  o_wb_cyc_gbl = (r_wb_cyc_gbl)||(lock_gbl);
185
                assign  o_wb_cyc_lcl = (r_wb_cyc_lcl)||(lock_lcl);
186
 
187
        end else begin
188
                assign  o_wb_cyc_gbl = (r_wb_cyc_gbl);
189
                assign  o_wb_cyc_lcl = (r_wb_cyc_lcl);
190
        end endgenerate
191
 
192
endmodule

powered by: WebSVN 2.1.0

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