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

Subversion Repositories amber

[/] [amber/] [trunk/] [hw/] [vlog/] [amber25/] [a25_wishbone.v] - Blame information for rev 79

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

Line No. Rev Author Line
1 16 csantifort
//////////////////////////////////////////////////////////////////
2
//                                                              //
3
//  Wishbone master interface for the Amber 25 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 17 csantifort
//  instruction and data caches into wishbone bus cycles.       //
11
//  For 4-word read requests from either cache and swap         //
12
//  accesses ( read followed by write to the same address)      //
13
//  from the execute stage, a block transfer is done.           //
14
//  All other requests result in single word transfers.         //
15 16 csantifort
//                                                              //
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) 2011 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 35 csantifort
// TODO add support for exclusive accesses
59
 
60 16 csantifort
module a25_wishbone
61
(
62
input                       i_clk,
63
 
64
 
65 35 csantifort
// Port 0 - dcache uncached
66
input                       i_port0_req,
67 39 csantifort
output                      o_port0_ack,
68 35 csantifort
input                       i_port0_write,
69
input       [127:0]         i_port0_wdata,
70
input       [15:0]          i_port0_be,
71
input       [31:0]          i_port0_addr,
72
output      [127:0]         o_port0_rdata,
73 16 csantifort
 
74 35 csantifort
// Port 1 - dcache cached
75
input                       i_port1_req,
76 39 csantifort
output                      o_port1_ack,
77 35 csantifort
input                       i_port1_write,
78
input       [127:0]         i_port1_wdata,
79
input       [15:0]          i_port1_be,
80
input       [31:0]          i_port1_addr,
81
output      [127:0]         o_port1_rdata,
82
 
83
// Port 2 - instruction cache accesses, read only
84
input                       i_port2_req,
85 39 csantifort
output                      o_port2_ack,
86 35 csantifort
input                       i_port2_write,
87
input       [127:0]         i_port2_wdata,
88
input       [15:0]          i_port2_be,
89
input       [31:0]          i_port2_addr,
90
output      [127:0]         o_port2_rdata,
91
 
92
 
93
// 128-bit Wishbone Bus
94 16 csantifort
output reg  [31:0]          o_wb_adr = 'd0,
95 35 csantifort
output reg  [15:0]          o_wb_sel = 'd0,
96 16 csantifort
output reg                  o_wb_we  = 'd0,
97 35 csantifort
output reg  [127:0]         o_wb_dat = 'd0,
98 16 csantifort
output reg                  o_wb_cyc = 'd0,
99
output reg                  o_wb_stb = 'd0,
100 35 csantifort
input       [127:0]         i_wb_dat,
101 16 csantifort
input                       i_wb_ack,
102
input                       i_wb_err
103
);
104
 
105
 
106 35 csantifort
// ----------------------------------------------------
107
// Parameters
108
// ----------------------------------------------------
109
localparam WBUF = 3;
110 16 csantifort
 
111
 
112 35 csantifort
// ----------------------------------------------------
113
// Signals
114
// ----------------------------------------------------
115
wire [0:0]                  wbuf_valid          [WBUF-1:0];
116
wire [0:0]                  wbuf_accepted       [WBUF-1:0];
117
wire [0:0]                  wbuf_write          [WBUF-1:0];
118
wire [127:0]                wbuf_wdata          [WBUF-1:0];
119
wire [15:0]                 wbuf_be             [WBUF-1:0];
120
wire [31:0]                 wbuf_addr           [WBUF-1:0];
121
wire [0:0]                  wbuf_rdata_valid    [WBUF-1:0];
122
wire                        new_access;
123
reg  [WBUF-1:0]             serving_port = 'd0;
124 16 csantifort
 
125
 
126 35 csantifort
// ----------------------------------------------------
127
// Instantiate the write buffers
128
// ----------------------------------------------------
129
a25_wishbone_buf u_a25_wishbone_buf_p0 (
130
    .i_clk          ( i_clk                 ),
131 16 csantifort
 
132 35 csantifort
    .i_req          ( i_port0_req           ),
133 39 csantifort
    .o_ack          ( o_port0_ack           ),
134 35 csantifort
    .i_write        ( i_port0_write         ),
135
    .i_wdata        ( i_port0_wdata         ),
136
    .i_be           ( i_port0_be            ),
137
    .i_addr         ( i_port0_addr          ),
138
    .o_rdata        ( o_port0_rdata         ),
139 16 csantifort
 
140 35 csantifort
    .o_valid        ( wbuf_valid       [0]  ),
141
    .i_accepted     ( wbuf_accepted    [0]  ),
142
    .o_write        ( wbuf_write       [0]  ),
143
    .o_wdata        ( wbuf_wdata       [0]  ),
144
    .o_be           ( wbuf_be          [0]  ),
145
    .o_addr         ( wbuf_addr        [0]  ),
146
    .i_rdata        ( i_wb_dat              ),
147
    .i_rdata_valid  ( wbuf_rdata_valid [0]  )
148
    );
149 16 csantifort
 
150
 
151 35 csantifort
a25_wishbone_buf u_a25_wishbone_buf_p1 (
152
    .i_clk          ( i_clk                 ),
153 30 csantifort
 
154 35 csantifort
    .i_req          ( i_port1_req           ),
155 39 csantifort
    .o_ack          ( o_port1_ack           ),
156 35 csantifort
    .i_write        ( i_port1_write         ),
157
    .i_wdata        ( i_port1_wdata         ),
158
    .i_be           ( i_port1_be            ),
159
    .i_addr         ( i_port1_addr          ),
160
    .o_rdata        ( o_port1_rdata         ),
161 16 csantifort
 
162 35 csantifort
    .o_valid        ( wbuf_valid        [1] ),
163
    .i_accepted     ( wbuf_accepted     [1] ),
164
    .o_write        ( wbuf_write        [1] ),
165
    .o_wdata        ( wbuf_wdata        [1] ),
166
    .o_be           ( wbuf_be           [1] ),
167
    .o_addr         ( wbuf_addr         [1] ),
168
    .i_rdata        ( i_wb_dat              ),
169
    .i_rdata_valid  ( wbuf_rdata_valid  [1] )
170
    );
171
 
172 16 csantifort
 
173 35 csantifort
a25_wishbone_buf u_a25_wishbone_buf_p2 (
174
    .i_clk          ( i_clk                 ),
175 16 csantifort
 
176 35 csantifort
    .i_req          ( i_port2_req           ),
177 39 csantifort
    .o_ack          ( o_port2_ack           ),
178 35 csantifort
    .i_write        ( i_port2_write         ),
179
    .i_wdata        ( i_port2_wdata         ),
180
    .i_be           ( i_port2_be            ),
181
    .i_addr         ( i_port2_addr          ),
182
    .o_rdata        ( o_port2_rdata         ),
183 16 csantifort
 
184 35 csantifort
    .o_valid        ( wbuf_valid        [2] ),
185
    .i_accepted     ( wbuf_accepted     [2] ),
186
    .o_write        ( wbuf_write        [2] ),
187
    .o_wdata        ( wbuf_wdata        [2] ),
188
    .o_be           ( wbuf_be           [2] ),
189
    .o_addr         ( wbuf_addr         [2] ),
190
    .i_rdata        ( i_wb_dat              ),
191
    .i_rdata_valid  ( wbuf_rdata_valid  [2] )
192
    );
193 16 csantifort
 
194
 
195 35 csantifort
assign new_access       = !o_wb_stb || i_wb_ack;
196
assign wbuf_accepted[0] = new_access &&  wbuf_valid[0];
197
assign wbuf_accepted[1] = new_access && !wbuf_valid[0] &&  wbuf_valid[1];
198
assign wbuf_accepted[2] = new_access && !wbuf_valid[0] && !wbuf_valid[1] && wbuf_valid[2];
199 16 csantifort
 
200
 
201 35 csantifort
always @(posedge i_clk)
202 16 csantifort
    begin
203 35 csantifort
    if (new_access)
204
        begin
205
        if (wbuf_valid[0])
206 30 csantifort
            begin
207 35 csantifort
            o_wb_adr        <= wbuf_addr [0];
208
            o_wb_sel        <= wbuf_be   [0];
209
            o_wb_we         <= wbuf_write[0];
210
            o_wb_dat        <= wbuf_wdata[0];
211
            o_wb_cyc        <= 1'd1;
212
            o_wb_stb        <= 1'd1;
213
            serving_port    <= 3'b001;
214 30 csantifort
            end
215 35 csantifort
        else if (wbuf_valid[1])
216 30 csantifort
            begin
217 35 csantifort
            o_wb_adr        <= wbuf_addr [1];
218
            o_wb_sel        <= wbuf_be   [1];
219
            o_wb_we         <= wbuf_write[1];
220
            o_wb_dat        <= wbuf_wdata[1];
221
            o_wb_cyc        <= 1'd1;
222
            o_wb_stb        <= 1'd1;
223
            serving_port    <= 3'b010;
224 30 csantifort
            end
225 35 csantifort
        else if (wbuf_valid[2])
226 30 csantifort
            begin
227 35 csantifort
            o_wb_adr        <= wbuf_addr [2];
228
            o_wb_sel        <= wbuf_be   [2];
229
            o_wb_we         <= wbuf_write[2];
230
            o_wb_dat        <= wbuf_wdata[2];
231
            o_wb_cyc        <= 1'd1;
232
            o_wb_stb        <= 1'd1;
233
            serving_port    <= 3'b100;
234 30 csantifort
            end
235 35 csantifort
        else
236
            begin
237
            o_wb_cyc        <= 1'd0;
238
            o_wb_stb        <= 1'd0;
239 30 csantifort
 
240 35 csantifort
            // Don't need to change these values because they are ignored
241
            // when stb is low, but it makes for a cleaner waveform, at the expense of a few gates
242
            o_wb_we         <= 1'd0;
243
            o_wb_adr        <= 'd0;
244
            o_wb_dat        <= 'd0;
245
 
246
            serving_port    <= 3'b000;
247
            end
248 16 csantifort
        end
249
    end
250
 
251
 
252 35 csantifort
assign {wbuf_rdata_valid[2], wbuf_rdata_valid[1], wbuf_rdata_valid[0]} = {3{i_wb_ack & ~ o_wb_we}} & serving_port;
253 16 csantifort
 
254
 
255
endmodule
256
 
257 35 csantifort
 

powered by: WebSVN 2.1.0

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