1 |
21 |
dgisselq |
///////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// Filename: wbdblpriarb.v
|
4 |
|
|
//
|
5 |
|
|
// Project: Zip CPU -- a small, lightweight, RISC CPU soft core
|
6 |
|
|
//
|
7 |
|
|
// Purpose: This should almost be identical to the priority arbiter, save
|
8 |
|
|
// for a simple diffence: it allows the arbitration of two
|
9 |
|
|
// separate wishbone buses. The purpose of this is to push the address
|
10 |
|
|
// resolution back one cycle, so that by the first clock visible to this
|
11 |
|
|
// core, it is known which of two parts of the bus the desired address
|
12 |
|
|
// will be on, save that we still use the arbiter since the underlying
|
13 |
|
|
// device doesn't know that there are two wishbone buses.
|
14 |
|
|
//
|
15 |
|
|
// So at this point we've deviated from the WB spec somewhat, by allowing
|
16 |
|
|
// two CYC and two STB lines. Everything else is the same. This allows
|
17 |
|
|
// (in this case the Zip CPU) to determine whether or not the access
|
18 |
|
|
// will be to the local ZipSystem bus or the external WB bus on the clock
|
19 |
|
|
// before the local bus access, otherwise peripherals were needing to do
|
20 |
|
|
// multiple device selection comparisons/test within a clock: 1) is this
|
21 |
|
|
// for the local or external bus, and 2) is this referencing me as a
|
22 |
|
|
// peripheral. This then caused the ZipCPU to fail all timing specs.
|
23 |
|
|
// By creating the two pairs of lines, CYC_A/STB_A and CYC_B/STB_B, the
|
24 |
|
|
// determination of local vs external can be made one clock earlier
|
25 |
|
|
// where there's still time for the logic, and the second comparison
|
26 |
|
|
// now has time to complete.
|
27 |
|
|
//
|
28 |
|
|
// So let me try to explain this again. To use this arbiter, one of the
|
29 |
|
|
// two masters sets CYC and STB before, only the master determines which
|
30 |
|
|
// of two address spaces the CYC and STB apply to before the clock and
|
31 |
|
|
// only sets the appropriate CYC and STB lines. Then, on the clock tick,
|
32 |
|
|
// the arbiter determines who gets *both* busses, as they both share every
|
33 |
|
|
// other WB line. Thus, only one of CYC_A and CYC_B going out will ever
|
34 |
|
|
// be high at a given time.
|
35 |
|
|
//
|
36 |
|
|
// Hopefully this makes more sense than it sounds. If not, check out the
|
37 |
|
|
// code below for a better explanation.
|
38 |
|
|
//
|
39 |
|
|
// 20150919 -- Added supported for the WB error signal.
|
40 |
|
|
//
|
41 |
|
|
//
|
42 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
43 |
|
|
// Gisselquist Technology, LLC
|
44 |
|
|
//
|
45 |
|
|
///////////////////////////////////////////////////////////////////////////
|
46 |
|
|
//
|
47 |
|
|
// Copyright (C) 2015, Gisselquist Technology, LLC
|
48 |
|
|
//
|
49 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
50 |
|
|
// modify it under the terms of the GNU General Public License as published
|
51 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
52 |
|
|
// your option) any later version.
|
53 |
|
|
//
|
54 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
55 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
56 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
57 |
|
|
// for more details.
|
58 |
|
|
//
|
59 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
60 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
61 |
|
|
//
|
62 |
|
|
//
|
63 |
|
|
///////////////////////////////////////////////////////////////////////////
|
64 |
|
|
//
|
65 |
|
|
module wbdblpriarb(i_clk, i_rst,
|
66 |
|
|
// Bus A
|
67 |
|
|
i_a_cyc_a,i_a_cyc_b,i_a_stb_a,i_a_stb_b,i_a_we,i_a_adr, i_a_dat, o_a_ack, o_a_stall, o_a_err,
|
68 |
|
|
// Bus B
|
69 |
|
|
i_b_cyc_a,i_b_cyc_b,i_b_stb_a,i_b_stb_b,i_b_we,i_b_adr, i_b_dat, o_b_ack, o_b_stall, o_b_err,
|
70 |
|
|
// Both buses
|
71 |
|
|
o_cyc_a, o_cyc_b, o_stb_a, o_stb_b, o_we, o_adr, o_dat,
|
72 |
|
|
i_ack, i_stall, i_err);
|
73 |
|
|
parameter DW=32, AW=32;
|
74 |
|
|
// Wishbone doesn't use an i_ce signal. While it could, they dislike
|
75 |
|
|
// what it would (might) do to the synchronous reset signal, i_rst.
|
76 |
|
|
input i_clk, i_rst;
|
77 |
|
|
// Bus A
|
78 |
|
|
input i_a_cyc_a, i_a_cyc_b, i_a_stb_a, i_a_stb_b, i_a_we;
|
79 |
|
|
input [(AW-1):0] i_a_adr;
|
80 |
|
|
input [(DW-1):0] i_a_dat;
|
81 |
|
|
output wire o_a_ack, o_a_stall, o_a_err;
|
82 |
|
|
// Bus B
|
83 |
|
|
input i_b_cyc_a, i_b_cyc_b, i_b_stb_a, i_b_stb_b, i_b_we;
|
84 |
|
|
input [(AW-1):0] i_b_adr;
|
85 |
|
|
input [(DW-1):0] i_b_dat;
|
86 |
|
|
output wire o_b_ack, o_b_stall, o_b_err;
|
87 |
|
|
//
|
88 |
|
|
output wire o_cyc_a,o_cyc_b, o_stb_a, o_stb_b, o_we;
|
89 |
|
|
output wire [(AW-1):0] o_adr;
|
90 |
|
|
output wire [(DW-1):0] o_dat;
|
91 |
|
|
input i_ack, i_stall, i_err;
|
92 |
|
|
|
93 |
|
|
// All of our logic is really captured in the 'r_a_owner' register.
|
94 |
|
|
// This register determines who owns the bus. If no one is requesting
|
95 |
|
|
// the bus, ownership goes to A on the next clock. Otherwise, if B is
|
96 |
|
|
// requesting the bus and A is not, then ownership goes to not A on
|
97 |
|
|
// the next clock. (Sounds simple ...)
|
98 |
|
|
//
|
99 |
|
|
// The CYC logic is here to make certain that, by the time we determine
|
100 |
|
|
// who the bus owner is, we can do so based upon determined criteria.
|
101 |
|
|
assign o_cyc_a = (~i_rst)&&((r_a_owner) ? i_a_cyc_a : i_b_cyc_a);
|
102 |
|
|
assign o_cyc_b = (~i_rst)&&((r_a_owner) ? i_a_cyc_b : i_b_cyc_b);
|
103 |
|
|
reg r_a_owner;
|
104 |
|
|
initial r_a_owner = 1'b1;
|
105 |
|
|
always @(posedge i_clk)
|
106 |
|
|
if (i_rst)
|
107 |
|
|
r_a_owner <= 1'b1;
|
108 |
|
|
else if ((~o_cyc_a)&&(~o_cyc_b))
|
109 |
|
|
r_a_owner <= ((i_b_cyc_a)||(i_b_cyc_b))? 1'b0:1'b1;
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
// Realistically, if neither master owns the bus, the output is a
|
113 |
|
|
// don't care. Thus we trigger off whether or not 'A' owns the bus.
|
114 |
|
|
// If 'B' owns it all we care is that 'A' does not. Likewise, if
|
115 |
|
|
// neither owns the bus than the values on these various lines are
|
116 |
|
|
// irrelevant.
|
117 |
|
|
assign o_stb_a = (r_a_owner) ? i_a_stb_a : i_b_stb_a;
|
118 |
|
|
assign o_stb_b = (r_a_owner) ? i_a_stb_b : i_b_stb_b;
|
119 |
|
|
assign o_we = (r_a_owner) ? i_a_we : i_b_we;
|
120 |
|
|
assign o_adr = (r_a_owner) ? i_a_adr : i_b_adr;
|
121 |
|
|
assign o_dat = (r_a_owner) ? i_a_dat : i_b_dat;
|
122 |
|
|
|
123 |
|
|
// We cannot allow the return acknowledgement to ever go high if
|
124 |
|
|
// the master in question does not own the bus. Hence we force it
|
125 |
|
|
// low if the particular master doesn't own the bus.
|
126 |
|
|
assign o_a_ack = ( r_a_owner) ? i_ack : 1'b0;
|
127 |
|
|
assign o_b_ack = (~r_a_owner) ? i_ack : 1'b0;
|
128 |
|
|
|
129 |
|
|
// Stall must be asserted on the same cycle the input master asserts
|
130 |
|
|
// the bus, if the bus isn't granted to him.
|
131 |
|
|
assign o_a_stall = ( r_a_owner) ? i_stall : 1'b1;
|
132 |
|
|
assign o_b_stall = (~r_a_owner) ? i_stall : 1'b1;
|
133 |
|
|
|
134 |
|
|
//
|
135 |
|
|
// These error lines will be implemented soon, as soon as the rest of
|
136 |
|
|
// the Zip CPU is ready to support them.
|
137 |
|
|
//
|
138 |
|
|
assign o_a_err = ( r_a_owner) ? i_err : 1'b0;
|
139 |
|
|
assign o_b_err = (~r_a_owner) ? i_err : 1'b0;
|
140 |
|
|
|
141 |
|
|
endmodule
|
142 |
|
|
|