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

Subversion Repositories amber

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

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
 
108
 
109
 
110
assign read_ack             = !o_wb_we && i_wb_ack;
111
assign o_stall              = ( core_read_request  && !read_ack )       ||
112
                              ( core_read_request  && servicing_cache ) ||
113
                              ( core_write_request && servicing_cache ) ;
114
 
115
                              // Don't stall on writes
116
                              // Wishbone is doing burst read so make core wait to execute the write
117
                              // ( core_write_request && !i_wb_ack )  ;
118
 
119
assign core_read_request    = i_select && !i_write_enable;
120
assign core_write_request   = i_select &&  i_write_enable;
121
 
122
assign cache_read_request   = i_cache_req && !i_write_enable;
123
assign cache_write_request  = i_cache_req &&  i_write_enable;
124
 
125
assign start_access         = core_read_request || core_write_request || i_cache_req ;
126
 
127
// For writes the byte enable is always 4'hf
128
assign byte_enable          = ( core_write_request || cache_write_request ) ? i_byte_enable : 4'hf;
129
 
130
 
131
// ======================================
132
// Register Accesses
133
// ======================================
134
always @( posedge i_clk )
135
    if ( start_access )
136
        o_wb_dat <= i_write_data;
137
 
138
 
139
assign wait_write_ack = o_wb_stb && o_wb_we && !i_wb_ack;
140
 
141
 
142
always @( posedge i_clk )
143
    case ( wishbone_st )
144
        WB_IDLE :
145
            begin
146
 
147
            if ( start_access )
148
                begin
149
                o_wb_stb            <= 1'd1;
150
                o_wb_cyc            <= 1'd1;
151
                o_wb_sel            <= byte_enable;
152
                end
153
            else if ( !wait_write_ack )
154
                begin
155
                o_wb_stb            <= 1'd0;
156
 
157
                // Hold cyc high after an exclusive access
158
                // to hold ownership of the wishbone bus
159
                o_wb_cyc            <= exclusive_access;
160
                end
161
 
162
            // cache has priority over the core                     
163
            servicing_cache <= cache_read_request && !wait_write_ack;
164
 
165
            if ( wait_write_ack )
166
                begin
167
                // still waiting for last (write) access to complete
168
                wishbone_st      <= WB_WAIT_ACK;
169
                end
170
            // do a burst of 4 read to fill a cache line                   
171
            else if ( cache_read_request )
172
                begin
173
                wishbone_st      <= WB_BURST1;
174
                exclusive_access    <= 1'd0;
175
                end
176
            else if ( core_read_request )
177
                begin
178
                wishbone_st      <= WB_WAIT_ACK;
179
                exclusive_access    <= i_exclusive;
180
                end
181
           // The core does not currently issue exclusive write requests
182
           // but there's no reason why this might not be added some
183
           // time in the future so allow for it here
184
            else if ( core_write_request )
185
                exclusive_access <= i_exclusive;
186
 
187
 
188
            if ( start_access )
189
                begin
190
                o_wb_we              <= core_write_request || cache_write_request;
191
                // only update these on new wb access to make debug easier
192
                o_wb_adr[31:2]       <= i_address[31:2];
193
                o_wb_adr[1:0]        <= byte_enable == 4'b0001 ? 2'd0 :
194
                                        byte_enable == 4'b0010 ? 2'd1 :
195
                                        byte_enable == 4'b0100 ? 2'd2 :
196
                                        byte_enable == 4'b1000 ? 2'd3 :
197
 
198
                                        byte_enable == 4'b0011 ? 2'd0 :
199
                                        byte_enable == 4'b1100 ? 2'd2 :
200
 
201
                                                                 2'd0 ;
202
                end
203
            end
204
 
205
 
206
        // Read burst, wait for first ack
207
        WB_BURST1:
208
            if ( i_wb_ack )
209
                begin
210
                // burst of 4 that wraps
211
                o_wb_adr[3:2]   <= o_wb_adr[3:2] + 1'd1;
212
                wishbone_st     <= WB_BURST2;
213
                end
214
 
215
 
216
        // Read burst, wait for second ack
217
        WB_BURST2:
218
            if ( i_wb_ack )
219
                begin
220
                // burst of 4 that wraps
221
                o_wb_adr[3:2]   <= o_wb_adr[3:2] + 1'd1;
222
                wishbone_st     <= WB_BURST3;
223
                end
224
 
225
 
226
        // Read burst, wait for third ack
227
        WB_BURST3:
228
            if ( i_wb_ack )
229
                begin
230
                // burst of 4 that wraps
231
                o_wb_adr[3:2]   <= o_wb_adr[3:2] + 1'd1;
232
                wishbone_st     <= WB_WAIT_ACK;
233
                end
234
 
235
 
236
        // Wait for the wishbone ack to be asserted
237
        WB_WAIT_ACK:
238
            if ( i_wb_ack )
239
                begin
240
                wishbone_st         <= WB_IDLE;
241
                o_wb_stb            <= 1'd0;
242
                o_wb_cyc            <= exclusive_access;
243
                o_wb_we             <= 1'd0;
244
                servicing_cache     <= 1'd0;
245
                end
246
 
247
    endcase
248
 
249
 
250
 
251
// ========================================================
252
// Debug Wishbone bus - not synthesizable
253
// ========================================================
254
//synopsys translate_off
255
wire    [(14*8)-1:0]   xAS_STATE;
256
 
257
 
258
assign xAS_STATE  = wishbone_st == WB_IDLE       ? "WB_IDLE"       :
259
                    wishbone_st == WB_BURST1     ? "WB_BURST1"     :
260
                    wishbone_st == WB_BURST2     ? "WB_BURST2"     :
261
                    wishbone_st == WB_BURST3     ? "WB_BURST3"     :
262
                    wishbone_st == WB_WAIT_ACK   ? "WB_WAIT_ACK"   :
263
                                                      "UNKNOWN"       ;
264
 
265
//synopsys translate_on
266
 
267
endmodule
268
 

powered by: WebSVN 2.1.0

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