| 1 |
201 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
| 2 |
36 |
dgisselq |
//
|
| 3 |
|
|
// Filename: wbpriarbiter.v
|
| 4 |
|
|
//
|
| 5 |
|
|
// Project: Zip CPU -- a small, lightweight, RISC CPU soft core
|
| 6 |
|
|
//
|
| 7 |
|
|
// Purpose: This is a priority bus arbiter. It allows two separate wishbone
|
| 8 |
|
|
// masters to connect to the same bus, while also guaranteeing
|
| 9 |
|
|
// that one master can have the bus with no delay any time the
|
| 10 |
|
|
// other master is not using the bus. The goal is to eliminate
|
| 11 |
|
|
// the combinatorial logic required in the other wishbone
|
| 12 |
|
|
// arbiter, while still guarateeing access time for the priority
|
| 13 |
|
|
// channel.
|
| 14 |
|
|
//
|
| 15 |
|
|
// The core logic works like this:
|
| 16 |
|
|
//
|
| 17 |
|
|
// 1. When no one requests the bus, 'A' is granted the bus and
|
| 18 |
|
|
// guaranteed that any access will go right through.
|
| 19 |
|
|
// 2. If 'B' requests the bus (asserts cyc), and the bus is idle,
|
| 20 |
|
|
// then 'B' will be granted the bus.
|
| 21 |
|
|
// 3. Bus grants last as long as the 'cyc' line is high.
|
| 22 |
|
|
// 4. Once 'cyc' is dropped, the bus returns to 'A' as the owner.
|
| 23 |
|
|
//
|
| 24 |
|
|
//
|
| 25 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
| 26 |
69 |
dgisselq |
// Gisselquist Technology, LLC
|
| 27 |
36 |
dgisselq |
//
|
| 28 |
201 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
| 29 |
36 |
dgisselq |
//
|
| 30 |
201 |
dgisselq |
// Copyright (C) 2015,2017, Gisselquist Technology, LLC
|
| 31 |
36 |
dgisselq |
//
|
| 32 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
| 33 |
|
|
// modify it under the terms of the GNU General Public License as published
|
| 34 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
| 35 |
|
|
// your option) any later version.
|
| 36 |
|
|
//
|
| 37 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
| 38 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
| 39 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
| 40 |
|
|
// for more details.
|
| 41 |
|
|
//
|
| 42 |
201 |
dgisselq |
// You should have received a copy of the GNU General Public License along
|
| 43 |
|
|
// with this program. (It's in the $(ROOT)/doc directory. Run make with no
|
| 44 |
|
|
// target there if the PDF file isn't present.) If not, see
|
| 45 |
|
|
// <http://www.gnu.org/licenses/> for a copy.
|
| 46 |
|
|
//
|
| 47 |
36 |
dgisselq |
// License: GPL, v3, as defined and found on www.gnu.org,
|
| 48 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
| 49 |
|
|
//
|
| 50 |
|
|
//
|
| 51 |
201 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
| 52 |
36 |
dgisselq |
//
|
| 53 |
201 |
dgisselq |
//
|
| 54 |
|
|
module wbpriarbiter(i_clk,
|
| 55 |
36 |
dgisselq |
// Bus A
|
| 56 |
201 |
dgisselq |
i_a_cyc, i_a_stb, i_a_we, i_a_adr, i_a_dat, i_a_sel, o_a_ack, o_a_stall, o_a_err,
|
| 57 |
36 |
dgisselq |
// Bus B
|
| 58 |
201 |
dgisselq |
i_b_cyc, i_b_stb, i_b_we, i_b_adr, i_b_dat, i_b_sel, o_b_ack, o_b_stall, o_b_err,
|
| 59 |
36 |
dgisselq |
// Both buses
|
| 60 |
201 |
dgisselq |
o_cyc, o_stb, o_we, o_adr, o_dat, o_sel, i_ack, i_stall, i_err);
|
| 61 |
36 |
dgisselq |
parameter DW=32, AW=32;
|
| 62 |
56 |
dgisselq |
//
|
| 63 |
|
|
input i_clk;
|
| 64 |
36 |
dgisselq |
// Bus A
|
| 65 |
|
|
input i_a_cyc, i_a_stb, i_a_we;
|
| 66 |
|
|
input [(AW-1):0] i_a_adr;
|
| 67 |
|
|
input [(DW-1):0] i_a_dat;
|
| 68 |
201 |
dgisselq |
input [(DW/8-1):0] i_a_sel;
|
| 69 |
36 |
dgisselq |
output wire o_a_ack, o_a_stall, o_a_err;
|
| 70 |
|
|
// Bus B
|
| 71 |
|
|
input i_b_cyc, i_b_stb, i_b_we;
|
| 72 |
|
|
input [(AW-1):0] i_b_adr;
|
| 73 |
|
|
input [(DW-1):0] i_b_dat;
|
| 74 |
201 |
dgisselq |
input [(DW/8-1):0] i_b_sel;
|
| 75 |
36 |
dgisselq |
output wire o_b_ack, o_b_stall, o_b_err;
|
| 76 |
201 |
dgisselq |
//
|
| 77 |
36 |
dgisselq |
output wire o_cyc, o_stb, o_we;
|
| 78 |
|
|
output wire [(AW-1):0] o_adr;
|
| 79 |
|
|
output wire [(DW-1):0] o_dat;
|
| 80 |
201 |
dgisselq |
output wire [(DW/8-1):0] o_sel;
|
| 81 |
36 |
dgisselq |
input i_ack, i_stall, i_err;
|
| 82 |
|
|
|
| 83 |
|
|
// Go high immediately (new cycle) if ...
|
| 84 |
|
|
// Previous cycle was low and *someone* is requesting a bus cycle
|
| 85 |
|
|
// Go low immadiately if ...
|
| 86 |
|
|
// We were just high and the owner no longer wants the bus
|
| 87 |
|
|
// WISHBONE Spec recommends no logic between a FF and the o_cyc
|
| 88 |
|
|
// This violates that spec. (Rec 3.15, p35)
|
| 89 |
|
|
assign o_cyc = (r_a_owner) ? i_a_cyc : i_b_cyc;
|
| 90 |
|
|
reg r_a_owner;
|
| 91 |
|
|
initial r_a_owner = 1'b1;
|
| 92 |
|
|
always @(posedge i_clk)
|
| 93 |
|
|
if (~i_b_cyc)
|
| 94 |
|
|
r_a_owner <= 1'b1;
|
| 95 |
|
|
else if ((i_b_cyc)&&(~i_a_cyc))
|
| 96 |
|
|
r_a_owner <= 1'b0;
|
| 97 |
|
|
|
| 98 |
|
|
|
| 99 |
|
|
// Realistically, if neither master owns the bus, the output is a
|
| 100 |
|
|
// don't care. Thus we trigger off whether or not 'A' owns the bus.
|
| 101 |
201 |
dgisselq |
// If 'B' owns it all we care is that 'A' does not. Likewise, if
|
| 102 |
36 |
dgisselq |
// neither owns the bus than the values on the various lines are
|
| 103 |
|
|
// irrelevant.
|
| 104 |
201 |
dgisselq |
assign o_we = (r_a_owner) ? i_a_we : i_b_we;
|
| 105 |
|
|
`ifdef ZERO_ON_IDLE
|
| 106 |
|
|
//
|
| 107 |
|
|
// ZERO_ON_IDLE will use up more logic and may even slow down the master
|
| 108 |
|
|
// clock if set. However, it may also reduce the power used by the
|
| 109 |
|
|
// FPGA by preventing things from toggling when the bus isn't in use.
|
| 110 |
|
|
// The option is here because it also makes it a lot easier to look
|
| 111 |
|
|
// for when things happen on the bus via VERILATOR when timing and
|
| 112 |
|
|
// logic counts don't matter.
|
| 113 |
|
|
//
|
| 114 |
|
|
assign o_stb = (o_cyc)?((r_a_owner) ? i_a_stb : i_b_stb):0;
|
| 115 |
|
|
assign o_adr = (o_stb)?((r_a_owner) ? i_a_adr : i_b_adr):0;
|
| 116 |
|
|
assign o_dat = (o_stb)?((r_a_owner) ? i_a_dat : i_b_dat):0;
|
| 117 |
|
|
assign o_sel = (o_stb)?((r_a_owner) ? i_a_sel : i_b_sel):0;
|
| 118 |
|
|
assign o_a_ack = (o_cyc)&&( r_a_owner) ? i_ack : 1'b0;
|
| 119 |
|
|
assign o_b_ack = (o_cyc)&&(~r_a_owner) ? i_ack : 1'b0;
|
| 120 |
|
|
assign o_a_stall = (o_cyc)&&( r_a_owner) ? i_stall : 1'b1;
|
| 121 |
|
|
assign o_b_stall = (o_cyc)&&(~r_a_owner) ? i_stall : 1'b1;
|
| 122 |
|
|
assign o_a_err = (o_cyc)&&( r_a_owner) ? i_err : 1'b0;
|
| 123 |
|
|
assign o_b_err = (o_cyc)&&(~r_a_owner) ? i_err : 1'b0;
|
| 124 |
|
|
`else
|
| 125 |
36 |
dgisselq |
assign o_stb = (r_a_owner) ? i_a_stb : i_b_stb;
|
| 126 |
|
|
assign o_adr = (r_a_owner) ? i_a_adr : i_b_adr;
|
| 127 |
|
|
assign o_dat = (r_a_owner) ? i_a_dat : i_b_dat;
|
| 128 |
201 |
dgisselq |
assign o_sel = (r_a_owner) ? i_a_sel : i_b_sel;
|
| 129 |
36 |
dgisselq |
|
| 130 |
|
|
// We cannot allow the return acknowledgement to ever go high if
|
| 131 |
|
|
// the master in question does not own the bus. Hence we force it
|
| 132 |
|
|
// low if the particular master doesn't own the bus.
|
| 133 |
|
|
assign o_a_ack = ( r_a_owner) ? i_ack : 1'b0;
|
| 134 |
|
|
assign o_b_ack = (~r_a_owner) ? i_ack : 1'b0;
|
| 135 |
|
|
|
| 136 |
|
|
// Stall must be asserted on the same cycle the input master asserts
|
| 137 |
|
|
// the bus, if the bus isn't granted to him.
|
| 138 |
|
|
assign o_a_stall = ( r_a_owner) ? i_stall : 1'b1;
|
| 139 |
|
|
assign o_b_stall = (~r_a_owner) ? i_stall : 1'b1;
|
| 140 |
|
|
|
| 141 |
201 |
dgisselq |
//
|
| 142 |
|
|
//
|
| 143 |
36 |
dgisselq |
assign o_a_err = ( r_a_owner) ? i_err : 1'b0;
|
| 144 |
|
|
assign o_b_err = (~r_a_owner) ? i_err : 1'b0;
|
| 145 |
201 |
dgisselq |
`endif
|
| 146 |
36 |
dgisselq |
|
| 147 |
|
|
endmodule
|
| 148 |
|
|
|