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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [rtl/] [aux/] [busdelay.v] - Blame information for rev 195

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

Line No. Rev Author Line
1 195 dgisselq
////////////////////////////////////////////////////////////////////////////////
2 2 dgisselq
//
3
// Filename:    busdelay.v
4
//
5
// Project:     Zip CPU -- a small, lightweight, RISC CPU soft core
6
//
7
// Purpose:     Delay any access to the wishbone bus by a single clock.
8
//
9
//      When the first Zip System would not meet the timing requirements of
10
//      the board it was placed upon, this bus delay was added to help out.
11
//      It may no longer be necessary, having cleaned some other problems up
12
//      first, but it will remain here as a means of alleviating timing
13
//      problems.
14
//
15
//      The specific problem takes place on the stall line: a wishbone master
16
//      *must* know on the first clock whether or not the bus will stall.
17
//
18
//
19 195 dgisselq
//      After a period of time, I started a new design where the timing
20
//      associated with this original bus clock just wasn't ... fast enough.
21
//      I needed to delay the stall line as well.  A new busdelay was then
22
//      written and debugged whcih delays the stall line.  (I know, you aren't
23
//      supposed to delay the stall line--but what if you *have* to in order
24
//      to meet timing?)  This new logic has been merged in with the old,
25
//      and the DELAY_STALL line can be set to non-zero to use it instead
26
//      of the original logic.  Don't use it if you don't need it: it will
27
//      consume resources and slow your bus down more, but if you do need
28
//      it--don't be afraid to use it.  
29 2 dgisselq
//
30 195 dgisselq
//      Both versions of the bus delay will maintain a single access per
31
//      clock when pipelined, they only delay the time between the strobe
32
//      going high and the actual command being accomplished.
33 2 dgisselq
//
34 195 dgisselq
//
35 2 dgisselq
// Creator:     Dan Gisselquist, Ph.D.
36 69 dgisselq
//              Gisselquist Technology, LLC
37 2 dgisselq
//
38 195 dgisselq
////////////////////////////////////////////////////////////////////////////////
39 2 dgisselq
//
40 195 dgisselq
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
41 2 dgisselq
//
42
// This program is free software (firmware): you can redistribute it and/or
43
// modify it under the terms of  the GNU General Public License as published
44
// by the Free Software Foundation, either version 3 of the License, or (at
45
// your option) any later version.
46
//
47
// This program is distributed in the hope that it will be useful, but WITHOUT
48
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
49
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
50
// for more details.
51
//
52
// License:     GPL, v3, as defined and found on www.gnu.org,
53
//              http://www.gnu.org/licenses/gpl.html
54
//
55
//
56 195 dgisselq
////////////////////////////////////////////////////////////////////////////////
57 2 dgisselq
//
58
module  busdelay(i_clk,
59
                // The input bus
60
                i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data,
61 36 dgisselq
                        o_wb_ack, o_wb_stall, o_wb_data, o_wb_err,
62 2 dgisselq
                // The delayed bus
63
                o_dly_cyc, o_dly_stb, o_dly_we, o_dly_addr, o_dly_data,
64 36 dgisselq
                        i_dly_ack, i_dly_stall, i_dly_data, i_dly_err);
65 195 dgisselq
        parameter       AW=32, DW=32, DELAY_STALL = 0;
66 2 dgisselq
        input   i_clk;
67
        // Input/master bus
68
        input                           i_wb_cyc, i_wb_stb, i_wb_we;
69
        input           [(AW-1):0]       i_wb_addr;
70
        input           [(DW-1):0]       i_wb_data;
71
        output  reg                     o_wb_ack;
72
        output  wire                    o_wb_stall;
73
        output  reg     [(DW-1):0]       o_wb_data;
74 36 dgisselq
        output  wire                    o_wb_err;
75 2 dgisselq
        // Delayed bus
76
        output  reg                     o_dly_cyc, o_dly_stb, o_dly_we;
77
        output  reg     [(AW-1):0]       o_dly_addr;
78
        output  reg     [(DW-1):0]       o_dly_data;
79
        input                           i_dly_ack;
80
        input                           i_dly_stall;
81
        input           [(DW-1):0]       i_dly_data;
82 36 dgisselq
        input                           i_dly_err;
83 2 dgisselq
 
84 195 dgisselq
        generate
85
        if (DELAY_STALL != 0)
86
        begin
87
                reg     r_stb, r_we, r_rtn_stall, r_rtn_err;
88
                reg     [(DW-1):0]       r_data;
89
                reg     [(AW-1):0]       r_addr;
90 2 dgisselq
 
91 195 dgisselq
                initial o_dly_cyc  = 1'b0;
92
                initial r_rtn_stall= 1'b0;
93
                initial r_stb      = 1'b0;
94
                always @(posedge i_clk)
95
                begin
96
                        o_dly_cyc <= (i_wb_cyc);
97
 
98
                        if (!i_dly_stall)
99
                        begin
100
                                r_we   <= i_wb_we;
101
                                r_addr <= i_wb_addr;
102
                                r_data <= i_wb_data;
103 2 dgisselq
 
104 195 dgisselq
                                if (r_stb)
105
                                begin
106
                                        o_dly_we   <= r_we;
107
                                        o_dly_addr <= r_addr;
108
                                        o_dly_data <= r_data;
109
                                        o_dly_stb  <= 1'b1;
110
                                        r_rtn_stall <= 1'b0;
111
                                        r_stb <= 1'b0;
112
                                end else begin
113
                                        o_dly_we   <= i_wb_we;
114
                                        o_dly_addr <= i_wb_addr;
115
                                        o_dly_data <= i_wb_data;
116
                                        o_dly_stb  <= i_wb_stb;
117
                                        r_stb <= 1'b0;
118
                                        r_rtn_stall <= 1'b0;
119
                                end
120
                        end else if ((!r_stb)&&(!o_wb_stall))
121
                        begin
122
                                r_we   <= i_wb_we;
123
                                r_addr <= i_wb_addr;
124
                                r_data <= i_wb_data;
125
                                r_stb  <= i_wb_stb;
126 2 dgisselq
 
127 195 dgisselq
                                r_rtn_stall <= i_wb_stb;
128
                        end
129
 
130
                        if (!i_wb_cyc)
131
                        begin
132
                                o_dly_stb <= 1'b0;
133
                                r_stb <= 1'b0;
134
                                r_rtn_stall <= 1'b0;
135
                        end
136
 
137
                        o_wb_ack  <= (i_dly_ack)&&(i_wb_cyc)&&(o_dly_cyc);
138
                        o_wb_data <= i_dly_data;
139
                        r_rtn_err <= (i_dly_err)&&(i_wb_cyc)&&(o_dly_cyc);
140
                end
141
 
142
                assign  o_wb_stall = r_rtn_stall;
143
                assign  o_wb_err   = r_rtn_err;
144
 
145
        end else begin
146
 
147
                initial o_dly_cyc = 1'b0;
148
                initial o_dly_stb = 1'b0;
149
 
150
                always @(posedge i_clk)
151
                        o_dly_cyc <= i_wb_cyc;
152
                // Add the i_wb_cyc criteria here, so we can simplify the
153
                // o_wb_stall criteria below, which would otherwise *and*
154
                // these two.
155
                always @(posedge i_clk)
156
                        if (~o_wb_stall)
157
                                o_dly_stb <= ((i_wb_cyc)&&(i_wb_stb));
158
                always @(posedge i_clk)
159
                        if (~o_wb_stall)
160
                                o_dly_we  <= i_wb_we;
161
                always @(posedge i_clk)
162
                        if (~o_wb_stall)
163
                                o_dly_addr<= i_wb_addr;
164
                always @(posedge i_clk)
165
                        if (~o_wb_stall)
166
                                o_dly_data <= i_wb_data;
167
                always @(posedge i_clk)
168
                        o_wb_ack  <= (i_dly_ack)&&(o_dly_cyc)&&(i_wb_cyc);
169
                always @(posedge i_clk)
170
                        o_wb_data <= i_dly_data;
171
 
172
                // Our only non-delayed line, yet still really delayed.  Perhaps
173
                // there's a way to register this?
174
                // o_wb_stall <= (i_wb_cyc)&&(i_wb_stb) ... or some such?
175
                // assign o_wb_stall=((i_wb_cyc)&&(i_dly_stall)&&(o_dly_stb));//&&o_cyc
176
                assign  o_wb_stall = ((i_dly_stall)&&(o_dly_stb));//&&o_cyc
177
                assign  o_wb_err   = i_dly_err;
178
        end endgenerate
179
 
180 2 dgisselq
endmodule

powered by: WebSVN 2.1.0

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