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

Subversion Repositories amber

[/] [amber/] [trunk/] [hw/] [vlog/] [amber23/] [a23_wishbone.v] - Blame information for rev 61

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

Line No. Rev Author Line
1 2 csantifort
//////////////////////////////////////////////////////////////////
2
//                                                              //
3
//  Wishbone master interface for the Amber core                //
4
//                                                              //
5
//  This file is part of the Amber project                      //
6
//  http://www.opencores.org/project,amber                      //
7
//                                                              //
8
//  Description                                                 //
9
//  Turns memory access requests from the execute stage and     //
10
//  cache into wishbone bus cycles. For 4-word read requests    //
11
//  from the cache and swap accesses ( read followed by write   //
12
//  to the same address) from the execute stage,                //
13
//  a block transfer is done. All other requests result in      //
14
//  single word transfers.                                      //
15
//                                                              //
16
//  Write accesses can be done in a single clock cycle on       //
17
//  the wishbone bus, is the destination allows it. The         //
18
//  next transfer will begin immediately on the                 //
19
//  next cycle on the bus. This looks like a block transfer     //
20
//  and does hold ownership of the wishbone bus, preventing     //
21
//  the other master ( the ethernet MAC) from gaining           //
22
//  ownership between those two cycles. But otherwise it would  //
23
//  be necessary to insert a wait cycle after every write,      //
24
//  slowing down the performance of the core by around 5 to     //
25
//  10%.                                                        //
26
//                                                              //
27
//  Author(s):                                                  //
28
//      - Conor Santifort, csantifort.amber@gmail.com           //
29
//                                                              //
30
//////////////////////////////////////////////////////////////////
31
//                                                              //
32
// Copyright (C) 2010 Authors and OPENCORES.ORG                 //
33
//                                                              //
34
// This source file may be used and distributed without         //
35
// restriction provided that this copyright statement is not    //
36
// removed from the file and that any derivative work contains  //
37
// the original copyright notice and the associated disclaimer. //
38
//                                                              //
39
// This source file is free software; you can redistribute it   //
40
// and/or modify it under the terms of the GNU Lesser General   //
41
// Public License as published by the Free Software Foundation; //
42
// either version 2.1 of the License, or (at your option) any   //
43
// later version.                                               //
44
//                                                              //
45
// This source is distributed in the hope that it will be       //
46
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
47
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
48
// PURPOSE.  See the GNU Lesser General Public License for more //
49
// details.                                                     //
50
//                                                              //
51
// You should have received a copy of the GNU Lesser General    //
52
// Public License along with this source; if not, download it   //
53
// from http://www.opencores.org/lgpl.shtml                     //
54
//                                                              //
55
//////////////////////////////////////////////////////////////////
56
 
57
 
58 15 csantifort
module a23_wishbone
59 2 csantifort
(
60
input                       i_clk,
61
 
62
// Core Accesses to Wishbone bus
63
input                       i_select,
64
input       [31:0]          i_write_data,
65
input                       i_write_enable,
66
input       [3:0]           i_byte_enable,    // valid for writes only
67
input                       i_data_access,
68
input                       i_exclusive,      // high for read part of swap access
69
input       [31:0]          i_address,
70
output                      o_stall,
71
 
72
// Cache Accesses to Wishbone bus
73
input                       i_cache_req,
74
 
75
// Wishbone Bus
76
output reg  [31:0]          o_wb_adr = 'd0,
77
output reg  [3:0]           o_wb_sel = 'd0,
78
output reg                  o_wb_we  = 'd0,
79
input       [31:0]          i_wb_dat,
80
output reg  [31:0]          o_wb_dat = 'd0,
81
output reg                  o_wb_cyc = 'd0,
82
output reg                  o_wb_stb = 'd0,
83
input                       i_wb_ack,
84
input                       i_wb_err
85
 
86
);
87
 
88
 
89
localparam [3:0] WB_IDLE            = 3'd0,
90
                 WB_BURST1          = 3'd1,
91
                 WB_BURST2          = 3'd2,
92
                 WB_BURST3          = 3'd3,
93
                 WB_WAIT_ACK        = 3'd4;
94
 
95
reg     [2:0]               wishbone_st = WB_IDLE;
96
 
97
wire                        core_read_request;
98
wire                        core_write_request;
99
wire                        cache_read_request;
100
wire                        cache_write_request;
101
wire                        start_access;
102
reg                         servicing_cache = 'd0;
103
wire    [3:0]               byte_enable;
104
reg                         exclusive_access = 'd0;
105
wire                        read_ack;
106
wire                        wait_write_ack;
107 42 csantifort
wire                        wb_wait;
108 2 csantifort
 
109 42 csantifort
// Write buffer
110
reg     [31:0]              wbuf_addr_r = 'd0;
111
reg     [3:0]               wbuf_sel_r  = 'd0;
112
reg                         wbuf_busy_r = 'd0;
113 2 csantifort
 
114
 
115
assign read_ack             = !o_wb_we && i_wb_ack;
116
assign o_stall              = ( core_read_request  && !read_ack )       ||
117
                              ( core_read_request  && servicing_cache ) ||
118 42 csantifort
                              ( core_write_request && servicing_cache ) ||
119
                              ( core_write_request && wishbone_st == WB_WAIT_ACK) ||
120
                              ( cache_write_request && wishbone_st == WB_WAIT_ACK) ||
121
                              wbuf_busy_r;
122 2 csantifort
 
123
                              // Don't stall on writes
124
                              // Wishbone is doing burst read so make core wait to execute the write
125
                              // ( core_write_request && !i_wb_ack )  ;
126
 
127
assign core_read_request    = i_select && !i_write_enable;
128
assign core_write_request   = i_select &&  i_write_enable;
129
 
130
assign cache_read_request   = i_cache_req && !i_write_enable;
131
assign cache_write_request  = i_cache_req &&  i_write_enable;
132
 
133 42 csantifort
assign wb_wait              = o_wb_stb && !i_wb_ack;
134
assign start_access         = (core_read_request || core_write_request || i_cache_req) && !wb_wait ;
135 2 csantifort
 
136
// For writes the byte enable is always 4'hf
137 42 csantifort
assign byte_enable          = wbuf_busy_r                                   ? wbuf_sel_r    :
138
                              ( core_write_request || cache_write_request ) ? i_byte_enable :
139
                                                                              4'hf          ;
140 2 csantifort
 
141
 
142 42 csantifort
 
143 2 csantifort
// ======================================
144 42 csantifort
// Write buffer
145
// ======================================
146
 
147
 
148
always @( posedge i_clk )
149
    if ( wb_wait && !wbuf_busy_r && (core_write_request || cache_write_request) )
150
        begin
151
        wbuf_addr_r <= i_address;
152
        wbuf_sel_r  <= i_byte_enable;
153
        wbuf_busy_r <= 1'd1;
154
        end
155
    else if (!o_wb_stb)
156
        wbuf_busy_r <= 1'd0;
157
 
158
// ======================================
159 2 csantifort
// Register Accesses
160
// ======================================
161
always @( posedge i_clk )
162
    if ( start_access )
163
        o_wb_dat <= i_write_data;
164
 
165
 
166
assign wait_write_ack = o_wb_stb && o_wb_we && !i_wb_ack;
167
 
168
 
169
always @( posedge i_clk )
170
    case ( wishbone_st )
171
        WB_IDLE :
172
            begin
173
 
174
            if ( start_access )
175
                begin
176
                o_wb_stb            <= 1'd1;
177
                o_wb_cyc            <= 1'd1;
178
                o_wb_sel            <= byte_enable;
179
                end
180
            else if ( !wait_write_ack )
181
                begin
182
                o_wb_stb            <= 1'd0;
183
 
184
                // Hold cyc high after an exclusive access
185
                // to hold ownership of the wishbone bus
186
                o_wb_cyc            <= exclusive_access;
187
                end
188
 
189
            // cache has priority over the core                     
190
            servicing_cache <= cache_read_request && !wait_write_ack;
191
 
192
            if ( wait_write_ack )
193
                begin
194
                // still waiting for last (write) access to complete
195
                wishbone_st      <= WB_WAIT_ACK;
196
                end
197
            // do a burst of 4 read to fill a cache line                   
198
            else if ( cache_read_request )
199
                begin
200 42 csantifort
                wishbone_st         <= WB_BURST1;
201 2 csantifort
                exclusive_access    <= 1'd0;
202
                end
203
            else if ( core_read_request )
204
                begin
205 42 csantifort
                wishbone_st         <= WB_WAIT_ACK;
206 2 csantifort
                exclusive_access    <= i_exclusive;
207
                end
208
           // The core does not currently issue exclusive write requests
209
           // but there's no reason why this might not be added some
210
           // time in the future so allow for it here
211
            else if ( core_write_request )
212
                exclusive_access <= i_exclusive;
213
 
214
 
215
            if ( start_access )
216
                begin
217 42 csantifort
                if (wbuf_busy_r)
218
                    begin
219
                    o_wb_we              <= 1'd1;
220
                    o_wb_adr[31:2]       <= wbuf_addr_r[31:2];
221
                    end
222
                else
223
                    begin
224
                    o_wb_we              <= core_write_request || cache_write_request;
225
                    // only update these on new wb access to make debug easier
226
                    o_wb_adr[31:2]       <= i_address[31:2];
227
                    end
228
 
229 2 csantifort
                o_wb_adr[1:0]        <= byte_enable == 4'b0001 ? 2'd0 :
230
                                        byte_enable == 4'b0010 ? 2'd1 :
231
                                        byte_enable == 4'b0100 ? 2'd2 :
232
                                        byte_enable == 4'b1000 ? 2'd3 :
233
 
234
                                        byte_enable == 4'b0011 ? 2'd0 :
235
                                        byte_enable == 4'b1100 ? 2'd2 :
236
 
237
                                                                 2'd0 ;
238
                end
239
            end
240
 
241
 
242
        // Read burst, wait for first ack
243
        WB_BURST1:
244
            if ( i_wb_ack )
245
                begin
246
                // burst of 4 that wraps
247
                o_wb_adr[3:2]   <= o_wb_adr[3:2] + 1'd1;
248
                wishbone_st     <= WB_BURST2;
249
                end
250
 
251
 
252
        // Read burst, wait for second ack
253
        WB_BURST2:
254
            if ( i_wb_ack )
255
                begin
256
                // burst of 4 that wraps
257
                o_wb_adr[3:2]   <= o_wb_adr[3:2] + 1'd1;
258
                wishbone_st     <= WB_BURST3;
259
                end
260
 
261
 
262
        // Read burst, wait for third ack
263
        WB_BURST3:
264
            if ( i_wb_ack )
265
                begin
266
                // burst of 4 that wraps
267
                o_wb_adr[3:2]   <= o_wb_adr[3:2] + 1'd1;
268
                wishbone_st     <= WB_WAIT_ACK;
269
                end
270
 
271
 
272
        // Wait for the wishbone ack to be asserted
273
        WB_WAIT_ACK:
274
            if ( i_wb_ack )
275
                begin
276
                wishbone_st         <= WB_IDLE;
277
                o_wb_stb            <= 1'd0;
278
                o_wb_cyc            <= exclusive_access;
279
                o_wb_we             <= 1'd0;
280
                servicing_cache     <= 1'd0;
281
                end
282
 
283
    endcase
284
 
285
 
286
 
287
// ========================================================
288
// Debug Wishbone bus - not synthesizable
289
// ========================================================
290
//synopsys translate_off
291
wire    [(14*8)-1:0]   xAS_STATE;
292
 
293
 
294
assign xAS_STATE  = wishbone_st == WB_IDLE       ? "WB_IDLE"       :
295
                    wishbone_st == WB_BURST1     ? "WB_BURST1"     :
296
                    wishbone_st == WB_BURST2     ? "WB_BURST2"     :
297
                    wishbone_st == WB_BURST3     ? "WB_BURST3"     :
298
                    wishbone_st == WB_WAIT_ACK   ? "WB_WAIT_ACK"   :
299
                                                      "UNKNOWN"       ;
300
 
301
//synopsys translate_on
302
 
303
endmodule
304
 

powered by: WebSVN 2.1.0

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