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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [rtl/] [aux/] [wbdblpriarb.v] - Blame information for rev 201

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 201 dgisselq
////////////////////////////////////////////////////////////////////////////////
2 36 dgisselq
//
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 69 dgisselq
//              Gisselquist Technology, LLC
44 36 dgisselq
//
45 201 dgisselq
////////////////////////////////////////////////////////////////////////////////
46 36 dgisselq
//
47 201 dgisselq
// Copyright (C) 2015,2017, Gisselquist Technology, LLC
48 36 dgisselq
//
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 201 dgisselq
// You should have received a copy of the GNU General Public License along
60
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
61
// target there if the PDF file isn't present.)  If not, see
62
// <http://www.gnu.org/licenses/> for a copy.
63
//
64 36 dgisselq
// License:     GPL, v3, as defined and found on www.gnu.org,
65
//              http://www.gnu.org/licenses/gpl.html
66
//
67
//
68 201 dgisselq
////////////////////////////////////////////////////////////////////////////////
69 36 dgisselq
//
70 201 dgisselq
//
71
module  wbdblpriarb(i_clk, i_rst,
72 36 dgisselq
        // Bus A
73 201 dgisselq
        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, i_a_sel, o_a_ack, o_a_stall, o_a_err,
74 36 dgisselq
        // Bus B
75 201 dgisselq
        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, i_b_sel, o_b_ack, o_b_stall, o_b_err,
76 36 dgisselq
        // Both buses
77 201 dgisselq
        o_cyc_a, o_cyc_b, o_stb_a, o_stb_b, o_we, o_adr, o_dat, o_sel,
78 36 dgisselq
                i_ack, i_stall, i_err);
79
        parameter                       DW=32, AW=32;
80
        // Wishbone doesn't use an i_ce signal.  While it could, they dislike
81
        // what it would (might) do to the synchronous reset signal, i_rst.
82
        input                           i_clk, i_rst;
83
        // Bus A
84
        input                           i_a_cyc_a, i_a_cyc_b, i_a_stb_a, i_a_stb_b, i_a_we;
85
        input           [(AW-1):0]       i_a_adr;
86
        input           [(DW-1):0]       i_a_dat;
87 201 dgisselq
        input           [(DW/8-1):0]     i_a_sel;
88 36 dgisselq
        output  wire                    o_a_ack, o_a_stall, o_a_err;
89
        // Bus B
90
        input                           i_b_cyc_a, i_b_cyc_b, i_b_stb_a, i_b_stb_b, i_b_we;
91
        input           [(AW-1):0]       i_b_adr;
92
        input           [(DW-1):0]       i_b_dat;
93 201 dgisselq
        input           [(DW/8-1):0]     i_b_sel;
94 36 dgisselq
        output  wire                    o_b_ack, o_b_stall, o_b_err;
95 201 dgisselq
        //
96 36 dgisselq
        output  wire                    o_cyc_a,o_cyc_b, o_stb_a, o_stb_b, o_we;
97
        output  wire    [(AW-1):0]       o_adr;
98
        output  wire    [(DW-1):0]       o_dat;
99 201 dgisselq
        output  wire    [(DW/8-1):0]     o_sel;
100 36 dgisselq
        input                           i_ack, i_stall, i_err;
101
 
102
        // All of our logic is really captured in the 'r_a_owner' register.
103
        // This register determines who owns the bus.  If no one is requesting
104 201 dgisselq
        // the bus, ownership goes to A on the next clock.  Otherwise, if B is
105 36 dgisselq
        // requesting the bus and A is not, then ownership goes to not A on
106
        // the next clock.  (Sounds simple ...)
107
        //
108
        // The CYC logic is here to make certain that, by the time we determine
109
        // who the bus owner is, we can do so based upon determined criteria.
110 201 dgisselq
        assign o_cyc_a = ((r_a_owner) ? i_a_cyc_a : i_b_cyc_a);
111
        assign o_cyc_b = ((r_a_owner) ? i_a_cyc_b : i_b_cyc_b);
112 36 dgisselq
        reg     r_a_owner;
113
        initial r_a_owner = 1'b1;
114
        always @(posedge i_clk)
115
                if (i_rst)
116
                        r_a_owner <= 1'b1;
117
                else if ((~o_cyc_a)&&(~o_cyc_b))
118
                        r_a_owner <= ((i_b_cyc_a)||(i_b_cyc_b))? 1'b0:1'b1;
119
 
120
 
121 201 dgisselq
        assign o_we    = (r_a_owner) ? i_a_we    : i_b_we;
122
`ifdef  ZERO_ON_IDLE
123
        //
124
        // ZERO_ON_IDLE uses more logic than the alternative.  It should be
125
        // useful for reducing power, as these circuits tend to drive wires
126
        // all the way across the design, but it may also slow down the master
127
        // clock.  I've used it as an option when using VERILATOR, 'cause
128
        // zeroing things on idle can make them stand out all the more when
129
        // staring at wires and dumps and such.
130
        //
131
        wire    o_cyc, o_stb;
132
        assign  o_cyc = ((o_cyc_a)||(o_cyc_b));
133
        assign  o_stb = (o_cyc)&&((o_stb_a)||(o_stb_b));
134
        assign o_stb_a = (r_a_owner) ? (i_a_stb_a)&&(o_cyc_a) : (i_b_stb_a)&&(o_cyc_a);
135
        assign o_stb_b = (r_a_owner) ? (i_a_stb_b)&&(o_cyc_b) : (i_b_stb_b)&&(o_cyc_b);
136
        assign o_adr   = ((o_stb_a)|(o_stb_b))?((r_a_owner) ? i_a_adr   : i_b_adr):0;
137
        assign o_dat   = (o_stb)?((r_a_owner) ? i_a_dat   : i_b_dat):0;
138
        assign o_sel   = (o_stb)?((r_a_owner) ? i_a_sel   : i_b_sel):0;
139
        assign o_a_ack   = (o_cyc)&&( r_a_owner) ? i_ack   : 1'b0;
140
        assign o_b_ack   = (o_cyc)&&(~r_a_owner) ? i_ack   : 1'b0;
141
        assign  o_a_stall = (o_cyc)&&( r_a_owner) ? i_stall : 1'b1;
142
        assign  o_b_stall = (o_cyc)&&(~r_a_owner) ? i_stall : 1'b1;
143
        assign  o_a_err = (o_cyc)&&( r_a_owner) ? i_err : 1'b0;
144
        assign  o_b_err = (o_cyc)&&(~r_a_owner) ? i_err : 1'b0;
145
`else
146 36 dgisselq
        // Realistically, if neither master owns the bus, the output is a
147
        // don't care.  Thus we trigger off whether or not 'A' owns the bus.
148 201 dgisselq
        // If 'B' owns it all we care is that 'A' does not.  Likewise, if
149 36 dgisselq
        // neither owns the bus than the values on these various lines are
150
        // irrelevant.
151
        assign o_stb_a = (r_a_owner) ? i_a_stb_a : i_b_stb_a;
152
        assign o_stb_b = (r_a_owner) ? i_a_stb_b : i_b_stb_b;
153
        assign o_we    = (r_a_owner) ? i_a_we    : i_b_we;
154
        assign o_adr   = (r_a_owner) ? i_a_adr   : i_b_adr;
155
        assign o_dat   = (r_a_owner) ? i_a_dat   : i_b_dat;
156 201 dgisselq
        assign o_sel   = (r_a_owner) ? i_a_sel   : i_b_sel;
157 36 dgisselq
 
158
        // We cannot allow the return acknowledgement to ever go high if
159
        // the master in question does not own the bus.  Hence we force it
160
        // low if the particular master doesn't own the bus.
161
        assign  o_a_ack   = ( r_a_owner) ? i_ack   : 1'b0;
162
        assign  o_b_ack   = (~r_a_owner) ? i_ack   : 1'b0;
163
 
164
        // Stall must be asserted on the same cycle the input master asserts
165
        // the bus, if the bus isn't granted to him.
166
        assign  o_a_stall = ( r_a_owner) ? i_stall : 1'b1;
167
        assign  o_b_stall = (~r_a_owner) ? i_stall : 1'b1;
168
 
169
        //
170
        // These error lines will be implemented soon, as soon as the rest of
171
        // the Zip CPU is ready to support them.
172
        //
173
        assign  o_a_err = ( r_a_owner) ? i_err : 1'b0;
174
        assign  o_b_err = (~r_a_owner) ? i_err : 1'b0;
175 201 dgisselq
`endif
176 36 dgisselq
 
177
endmodule
178
 

powered by: WebSVN 2.1.0

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