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

Subversion Repositories zipcpu

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

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
//              Gisselquist Tecnology, 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,
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
        parameter       ADDRESS_WIDTH = 24, AW=ADDRESS_WIDTH;
46
        input                   i_clk, i_rst;
47
        input                   i_pipe_stb;
48
        // 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
        output  reg             o_wb_cyc_gbl, o_wb_stb_gbl;
62
        output  reg             o_wb_cyc_lcl, o_wb_stb_lcl, o_wb_we;
63
        output  reg     [(AW-1):0]       o_wb_addr;
64
        output  reg     [31:0]   o_wb_data;
65
        // Wishbone inputs
66
        input                   i_wb_ack, i_wb_stall, i_wb_err;
67
        input           [31:0]   i_wb_data;
68
 
69
        reg     [3:0]            rdaddr, wraddr;
70
        wire    [3:0]            nxt_rdaddr;
71
        reg     [(5-1):0]        fifo_oreg [0:15];
72
        initial rdaddr = 0;
73
        initial wraddr = 0;
74
        always @(posedge i_clk)
75
                fifo_oreg[wraddr] <= i_oreg;
76
        always @(posedge i_clk)
77
                if ((i_rst)||(i_wb_err))
78
                        wraddr <= 0;
79
                else if (i_pipe_stb)
80 56 dgisselq
                        wraddr <= wraddr + 4'h1;
81 49 dgisselq
        always @(posedge i_clk)
82
                if ((i_rst)||(i_wb_err))
83
                        rdaddr <= 0;
84 56 dgisselq
                else if ((i_wb_ack)&&(cyc))
85
                        rdaddr <= rdaddr + 4'h1;
86
        assign  nxt_rdaddr = rdaddr + 4'h1;
87 49 dgisselq
 
88 56 dgisselq
        reg     cyc;
89 49 dgisselq
        wire    gbl_stb, lcl_stb;
90
        assign  lcl_stb = (i_addr[31:8]==24'hc00000)&&(i_addr[7:5]==3'h0);
91 56 dgisselq
        assign  gbl_stb = (~lcl_stb);
92
                        //= ((i_addr[31:8]!=24'hc00000)||(i_addr[7:5]!=3'h0));
93 49 dgisselq
 
94 56 dgisselq
        initial cyc = 0;
95
        initial o_wb_cyc_lcl = 0;
96
        initial o_wb_cyc_gbl = 0;
97 49 dgisselq
        always @(posedge i_clk)
98
                if (i_rst)
99
                begin
100
                        o_wb_cyc_gbl <= 1'b0;
101
                        o_wb_cyc_lcl <= 1'b0;
102
                        o_wb_stb_gbl <= 1'b0;
103
                        o_wb_stb_lcl <= 1'b0;
104 56 dgisselq
                        cyc <= 1'b0;
105
                end else if (cyc)
106 49 dgisselq
                begin
107
                        if ((~i_wb_stall)&&(~i_pipe_stb))
108
                        begin
109
                                o_wb_stb_gbl <= 1'b0;
110
                                o_wb_stb_lcl <= 1'b0;
111 63 dgisselq
                        // end else if ((i_pipe_stb)&&(~i_wb_stall))
112
                        // begin
113 56 dgisselq
                                // o_wb_addr <= i_addr[(AW-1):0];
114
                                // o_wb_data <= i_data;
115 49 dgisselq
                        end
116
 
117
                        if (((i_wb_ack)&&(nxt_rdaddr == wraddr))||(i_wb_err))
118
                        begin
119
                                o_wb_cyc_gbl <= 1'b0;
120
                                o_wb_cyc_lcl <= 1'b0;
121 56 dgisselq
                                cyc <= 1'b0;
122 49 dgisselq
                        end
123
                end else if (i_pipe_stb) // New memory operation
124
                begin // Grab the wishbone
125
                        o_wb_cyc_lcl <= lcl_stb;
126
                        o_wb_cyc_gbl <= gbl_stb;
127
                        o_wb_stb_lcl <= lcl_stb;
128
                        o_wb_stb_gbl <= gbl_stb;
129 56 dgisselq
                        cyc <= 1'b1;
130
                        // o_wb_addr <= i_addr[(AW-1):0];
131
                        // o_wb_data <= i_data;
132
                        // o_wb_we <= i_op
133
                end
134
        always @(posedge i_clk)
135
                if ((cyc)&&(i_pipe_stb)&&(~i_wb_stall))
136
                begin
137 49 dgisselq
                        o_wb_addr <= i_addr[(AW-1):0];
138
                        o_wb_data <= i_data;
139 56 dgisselq
                end else if ((~cyc)&&(i_pipe_stb))
140
                begin
141
                        o_wb_addr <= i_addr[(AW-1):0];
142
                        o_wb_data <= i_data;
143 49 dgisselq
                end
144 56 dgisselq
 
145 49 dgisselq
        always @(posedge i_clk)
146 56 dgisselq
                if ((i_pipe_stb)&&(~cyc))
147 49 dgisselq
                        o_wb_we   <= i_op;
148
 
149
        initial o_valid = 1'b0;
150
        always @(posedge i_clk)
151 56 dgisselq
                o_valid <= (cyc)&&(i_wb_ack)&&(~o_wb_we);
152 49 dgisselq
        initial o_err = 1'b0;
153
        always @(posedge i_clk)
154 56 dgisselq
                o_err <= (cyc)&&(i_wb_err);
155
        assign  o_busy = cyc;
156 49 dgisselq
 
157
        always @(posedge i_clk)
158
                o_wreg <= fifo_oreg[rdaddr];
159
        always @(posedge i_clk)
160
                if (i_wb_ack)
161
                        o_result <= i_wb_data;
162
 
163 56 dgisselq
        assign  o_pipe_stalled = (cyc)
164 49 dgisselq
                        &&((i_wb_stall)||((~o_wb_stb_lcl)&&(~o_wb_stb_gbl)));
165
endmodule

powered by: WebSVN 2.1.0

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