| 1 |
35 |
csantifort |
//////////////////////////////////////////////////////////////////
|
| 2 |
|
|
// //
|
| 3 |
|
|
// Wishbone master interface port buffer //
|
| 4 |
|
|
// //
|
| 5 |
|
|
// This file is part of the Amber project //
|
| 6 |
|
|
// http://www.opencores.org/project,amber //
|
| 7 |
|
|
// //
|
| 8 |
|
|
// Description //
|
| 9 |
|
|
// This is a sub-module of the Amber wishbone master //
|
| 10 |
|
|
// interface. The wishbone master interface connects a number //
|
| 11 |
|
|
// of internal amber ports to the wishbone bus. The ports //
|
| 12 |
|
|
// are; //
|
| 13 |
|
|
// instruction cache read accesses //
|
| 14 |
|
|
// data cache read and write accesses (cached) //
|
| 15 |
|
|
// data cache read and write accesses (uncached) //
|
| 16 |
|
|
// //
|
| 17 |
|
|
// The buffer module buffers a single port. For write //
|
| 18 |
|
|
// requests, this allows the processor core to continue //
|
| 19 |
|
|
// executing withont having to wait for the wishbone write //
|
| 20 |
|
|
// operation to complete. //
|
| 21 |
|
|
// //
|
| 22 |
|
|
// Author(s): //
|
| 23 |
|
|
// - Conor Santifort, csantifort.amber@gmail.com //
|
| 24 |
|
|
// //
|
| 25 |
|
|
//////////////////////////////////////////////////////////////////
|
| 26 |
|
|
// //
|
| 27 |
|
|
// Copyright (C) 2011 Authors and OPENCORES.ORG //
|
| 28 |
|
|
// //
|
| 29 |
|
|
// This source file may be used and distributed without //
|
| 30 |
|
|
// restriction provided that this copyright statement is not //
|
| 31 |
|
|
// removed from the file and that any derivative work contains //
|
| 32 |
|
|
// the original copyright notice and the associated disclaimer. //
|
| 33 |
|
|
// //
|
| 34 |
|
|
// This source file is free software; you can redistribute it //
|
| 35 |
|
|
// and/or modify it under the terms of the GNU Lesser General //
|
| 36 |
|
|
// Public License as published by the Free Software Foundation; //
|
| 37 |
|
|
// either version 2.1 of the License, or (at your option) any //
|
| 38 |
|
|
// later version. //
|
| 39 |
|
|
// //
|
| 40 |
|
|
// This source is distributed in the hope that it will be //
|
| 41 |
|
|
// useful, but WITHOUT ANY WARRANTY; without even the implied //
|
| 42 |
|
|
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
|
| 43 |
|
|
// PURPOSE. See the GNU Lesser General Public License for more //
|
| 44 |
|
|
// details. //
|
| 45 |
|
|
// //
|
| 46 |
|
|
// You should have received a copy of the GNU Lesser General //
|
| 47 |
|
|
// Public License along with this source; if not, download it //
|
| 48 |
|
|
// from http://www.opencores.org/lgpl.shtml //
|
| 49 |
|
|
// //
|
| 50 |
|
|
//////////////////////////////////////////////////////////////////
|
| 51 |
|
|
|
| 52 |
|
|
module a25_wishbone_buf (
|
| 53 |
|
|
input i_clk,
|
| 54 |
|
|
|
| 55 |
|
|
// Core side
|
| 56 |
|
|
input i_req,
|
| 57 |
|
|
input i_write,
|
| 58 |
|
|
input [127:0] i_wdata,
|
| 59 |
|
|
input [15:0] i_be,
|
| 60 |
|
|
input [31:0] i_addr,
|
| 61 |
|
|
output [127:0] o_rdata,
|
| 62 |
|
|
output o_ready,
|
| 63 |
|
|
|
| 64 |
|
|
// Wishbone side
|
| 65 |
|
|
output o_valid,
|
| 66 |
|
|
input i_accepted,
|
| 67 |
|
|
output o_write,
|
| 68 |
|
|
output [127:0] o_wdata,
|
| 69 |
|
|
output [15:0] o_be,
|
| 70 |
|
|
output [31:0] o_addr,
|
| 71 |
|
|
input [127:0] i_rdata,
|
| 72 |
|
|
input i_rdata_valid
|
| 73 |
|
|
);
|
| 74 |
|
|
|
| 75 |
|
|
|
| 76 |
|
|
// ----------------------------------------------------
|
| 77 |
|
|
// Signals
|
| 78 |
|
|
// ----------------------------------------------------
|
| 79 |
|
|
reg wbuf_used_r = 'd0;
|
| 80 |
|
|
reg [127:0] wbuf_wdata_r;
|
| 81 |
|
|
reg [31:0] wbuf_addr_r;
|
| 82 |
|
|
reg [15:0] wbuf_be_r;
|
| 83 |
|
|
reg wbuf_write_r = 'd0;
|
| 84 |
|
|
wire in_wreq = i_req && i_write;
|
| 85 |
|
|
reg busy_reading_r = 'd0;
|
| 86 |
|
|
|
| 87 |
|
|
|
| 88 |
|
|
// ----------------------------------------------------
|
| 89 |
|
|
// Access Buffer
|
| 90 |
|
|
// ----------------------------------------------------
|
| 91 |
|
|
always @(posedge i_clk)
|
| 92 |
36 |
csantifort |
if (i_req && !wbuf_used_r)
|
| 93 |
35 |
csantifort |
begin
|
| 94 |
|
|
wbuf_used_r <= !i_accepted;
|
| 95 |
|
|
wbuf_wdata_r <= i_wdata;
|
| 96 |
|
|
wbuf_addr_r <= i_addr;
|
| 97 |
|
|
wbuf_be_r <= i_write ? i_be : 16'hffff;
|
| 98 |
|
|
wbuf_write_r <= i_write;
|
| 99 |
|
|
end
|
| 100 |
36 |
csantifort |
else if ( i_req && wbuf_used_r && o_valid && i_accepted)
|
| 101 |
|
|
begin
|
| 102 |
|
|
wbuf_used_r <= 1'd1;
|
| 103 |
|
|
wbuf_wdata_r <= i_wdata;
|
| 104 |
|
|
wbuf_addr_r <= i_addr;
|
| 105 |
|
|
wbuf_be_r <= i_write ? i_be : 16'hffff;
|
| 106 |
|
|
wbuf_write_r <= i_write;
|
| 107 |
|
|
end
|
| 108 |
35 |
csantifort |
else if (o_valid && i_accepted && wbuf_write_r)
|
| 109 |
|
|
wbuf_used_r <= 1'd0;
|
| 110 |
|
|
else if (i_rdata_valid && !wbuf_write_r)
|
| 111 |
|
|
wbuf_used_r <= 1'd0;
|
| 112 |
|
|
|
| 113 |
|
|
|
| 114 |
|
|
// ----------------------------------------------------
|
| 115 |
|
|
// Output logic
|
| 116 |
|
|
// ----------------------------------------------------
|
| 117 |
|
|
assign o_wdata = wbuf_used_r ? wbuf_wdata_r : i_wdata;
|
| 118 |
|
|
assign o_write = wbuf_used_r ? wbuf_write_r : i_write;
|
| 119 |
|
|
assign o_addr = wbuf_used_r ? wbuf_addr_r : i_addr;
|
| 120 |
|
|
assign o_be = wbuf_used_r ? wbuf_be_r : i_write ? i_be : 16'hffff;
|
| 121 |
|
|
|
| 122 |
|
|
assign o_valid = (wbuf_used_r || i_req) && !busy_reading_r;
|
| 123 |
|
|
|
| 124 |
|
|
assign o_rdata = i_rdata;
|
| 125 |
|
|
assign o_ready = in_wreq ? (!wbuf_used_r || i_accepted) : i_rdata_valid;
|
| 126 |
|
|
|
| 127 |
|
|
|
| 128 |
|
|
always@(posedge i_clk)
|
| 129 |
|
|
if (o_valid && !o_write && i_accepted)
|
| 130 |
|
|
busy_reading_r <= 1'd1;
|
| 131 |
|
|
else if (i_rdata_valid)
|
| 132 |
|
|
busy_reading_r <= 1'd0;
|
| 133 |
|
|
|
| 134 |
|
|
|
| 135 |
|
|
|
| 136 |
|
|
endmodule
|
| 137 |
|
|
|
| 138 |
|
|
|
| 139 |
|
|
|
| 140 |
|
|
|