1 |
2 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// WISHBONE revB.2 compliant Xgate Coprocessor - Slave Bus interface
|
4 |
|
|
//
|
5 |
|
|
// Author: Bob Hayes
|
6 |
|
|
// rehayes@opencores.org
|
7 |
|
|
//
|
8 |
|
|
// Downloaded from: http://www.opencores.org/projects/xgate.....
|
9 |
|
|
//
|
10 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
11 |
|
|
// Copyright (c) 2009, Robert Hayes
|
12 |
|
|
//
|
13 |
|
|
// This source file is free software: you can redistribute it and/or modify
|
14 |
|
|
// it under the terms of the GNU Lesser General Public License as published
|
15 |
|
|
// by the Free Software Foundation, either version 3 of the License, or
|
16 |
|
|
// (at your option) any later version.
|
17 |
|
|
//
|
18 |
|
|
// Supplemental terms.
|
19 |
|
|
// * Redistributions of source code must retain the above copyright
|
20 |
|
|
// notice, this list of conditions and the following disclaimer.
|
21 |
|
|
// * Neither the name of the <organization> nor the
|
22 |
|
|
// names of its contributors may be used to endorse or promote products
|
23 |
|
|
// derived from this software without specific prior written permission.
|
24 |
|
|
//
|
25 |
|
|
// THIS SOFTWARE IS PROVIDED BY Robert Hayes ''AS IS'' AND ANY
|
26 |
|
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
27 |
|
|
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
28 |
|
|
// DISCLAIMED. IN NO EVENT SHALL Robert Hayes BE LIABLE FOR ANY
|
29 |
|
|
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
30 |
|
|
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
31 |
|
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
32 |
|
|
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
33 |
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
34 |
|
|
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
35 |
|
|
//
|
36 |
|
|
// You should have received a copy of the GNU General Public License
|
37 |
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
38 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
39 |
|
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
40 |
|
|
|
41 |
|
|
module xgate_wbs_bus #(parameter ARST_LVL = 1'b0, // asynchronous reset level
|
42 |
|
|
parameter DWIDTH = 16,
|
43 |
|
|
parameter SINGLE_CYCLE = 1'b0)
|
44 |
|
|
(
|
45 |
|
|
// Wishbone Signals
|
46 |
|
|
output [DWIDTH-1:0] wbs_dat_o, // databus output
|
47 |
|
|
output wbs_ack_o, // bus cycle acknowledge output
|
48 |
|
|
input wbs_clk_i, // master clock input
|
49 |
|
|
input wbs_rst_i, // synchronous active high reset
|
50 |
|
|
input arst_i, // asynchronous reset
|
51 |
|
|
input [ 4:0] wbs_adr_i, // lower address bits
|
52 |
|
|
input [DWIDTH-1:0] wbs_dat_i, // databus input
|
53 |
|
|
input wbs_we_i, // write enable input
|
54 |
|
|
input wbs_stb_i, // stobe/core select signal
|
55 |
|
|
input wbs_cyc_i, // valid bus cycle input
|
56 |
|
|
input [1:0] wbs_sel_i, // Select byte in word bus transaction
|
57 |
|
|
// COP Control Signals
|
58 |
|
|
output reg write_xgmctl, // Write Strobe for XGMCTL register
|
59 |
|
|
output reg write_xgisp74,// Write Strobe for XGISP74 register
|
60 |
|
|
output reg write_xgisp30,// Write Strobe for XGISP30 register
|
61 |
|
|
output reg write_xgvbr, // Write Strobe for XGVBR register
|
62 |
|
|
output reg write_xgif_7, // Write Strobe for Interrupt Flag Register 7
|
63 |
|
|
output reg write_xgif_6, // Write Strobe for Interrupt Flag Register 6
|
64 |
|
|
output reg write_xgif_5, // Write Strobe for Interrupt Flag Register 5
|
65 |
|
|
output reg write_xgif_4, // Write Strobe for Interrupt Flag Register 4
|
66 |
|
|
output reg write_xgif_3, // Write Strobe for Interrupt Flag Register 3
|
67 |
|
|
output reg write_xgif_2, // Write Strobe for Interrupt Flag Register 2
|
68 |
|
|
output reg write_xgif_1, // Write Strobe for Interrupt Flag Register 1
|
69 |
|
|
output reg write_xgif_0, // Write Strobe for Interrupt Flag Register 0
|
70 |
|
|
output reg write_xgswt, // Write Strobe for XGSWT register
|
71 |
|
|
output reg write_xgsem, // Write Strobe for XGSEM register
|
72 |
|
|
output reg write_xgccr, // Write Strobe for XGATE Condition Code Register
|
73 |
|
|
output reg write_xgpc, // Write Strobe for XGATE Program Counter
|
74 |
|
|
output reg write_xgr7, // Write Strobe for XGATE Data Register R7
|
75 |
|
|
output reg write_xgr6, // Write Strobe for XGATE Data Register R6
|
76 |
|
|
output reg write_xgr5, // Write Strobe for XGATE Data Register R5
|
77 |
|
|
output reg write_xgr4, // Write Strobe for XGATE Data Register R4
|
78 |
|
|
output reg write_xgr3, // Write Strobe for XGATE Data Register R3
|
79 |
|
|
output reg write_xgr2, // Write Strobe for XGATE Data Register R2
|
80 |
|
|
output reg write_xgr1, // Write Strobe for XGATE Data Register R1
|
81 |
|
|
output async_rst_b, //
|
82 |
|
|
output sync_reset, //
|
83 |
|
|
input [415:0] read_regs // status register bits
|
84 |
|
|
);
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
// registers
|
88 |
|
|
reg bus_wait_state; // Holdoff wbs_ack_o for one clock to add wait state
|
89 |
|
|
reg [DWIDTH-1:0] rd_data_mux; // Pseudo Register, WISHBONE Read Data Mux
|
90 |
|
|
reg [DWIDTH-1:0] rd_data_reg; // Latch for WISHBONE Read Data
|
91 |
|
|
|
92 |
|
|
reg write_reserv; // Dummy Reg decode for Reserved address
|
93 |
|
|
|
94 |
|
|
// Wires
|
95 |
|
|
wire module_sel; // This module is selected for bus transaction
|
96 |
|
|
wire wbs_wacc; // WISHBONE Write Strobe (Clock gating signal)
|
97 |
|
|
wire wbs_racc; // WISHBONE Read Access (Clock gating signal)
|
98 |
|
|
|
99 |
|
|
//
|
100 |
|
|
// module body
|
101 |
|
|
//
|
102 |
|
|
|
103 |
|
|
// generate internal resets
|
104 |
|
|
assign async_rst_b = arst_i ^ ARST_LVL;
|
105 |
|
|
assign sync_reset = wbs_rst_i;
|
106 |
|
|
|
107 |
|
|
// generate wishbone signals
|
108 |
|
|
assign module_sel = wbs_cyc_i && wbs_stb_i;
|
109 |
|
|
assign wbs_wacc = module_sel && wbs_we_i && (wbs_ack_o || SINGLE_CYCLE);
|
110 |
|
|
assign wbs_racc = module_sel && !wbs_we_i;
|
111 |
|
|
assign wbs_ack_o = SINGLE_CYCLE ? module_sel : bus_wait_state;
|
112 |
|
|
assign wbs_dat_o = SINGLE_CYCLE ? rd_data_mux : rd_data_reg;
|
113 |
|
|
|
114 |
|
|
// generate acknowledge output signal, By using register all accesses takes two cycles.
|
115 |
|
|
// Accesses in back to back clock cycles are not possable.
|
116 |
|
|
always @(posedge wbs_clk_i or negedge async_rst_b)
|
117 |
|
|
if (!async_rst_b)
|
118 |
|
|
bus_wait_state <= 1'b0;
|
119 |
|
|
else if (sync_reset)
|
120 |
|
|
bus_wait_state <= 1'b0;
|
121 |
|
|
else
|
122 |
|
|
bus_wait_state <= module_sel && !bus_wait_state;
|
123 |
|
|
|
124 |
|
|
// assign data read bus -- DAT_O
|
125 |
|
|
always @(posedge wbs_clk_i)
|
126 |
|
|
if ( wbs_racc ) // Clock gate for power saving
|
127 |
|
|
rd_data_reg <= rd_data_mux;
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
// WISHBONE Read Data Mux
|
131 |
|
|
always @*
|
132 |
|
|
case (wbs_adr_i) // synopsys parallel_case
|
133 |
|
|
// 16 bit Bus, 16 bit Granularity
|
134 |
|
|
5'b0_0000: rd_data_mux = read_regs[ 15: 0];
|
135 |
|
|
5'b0_0001: rd_data_mux = read_regs[ 31: 16];
|
136 |
|
|
5'b0_0010: rd_data_mux = read_regs[ 47: 32];
|
137 |
|
|
5'b0_0011: rd_data_mux = read_regs[ 63: 48];
|
138 |
|
|
5'b0_0100: rd_data_mux = read_regs[ 79: 64];
|
139 |
|
|
5'b0_0101: rd_data_mux = read_regs[ 95: 80];
|
140 |
|
|
5'b0_0110: rd_data_mux = read_regs[111: 96];
|
141 |
|
|
5'b0_0111: rd_data_mux = read_regs[127:112];
|
142 |
|
|
5'b0_1000: rd_data_mux = read_regs[143:128];
|
143 |
|
|
5'b0_1001: rd_data_mux = read_regs[159:144];
|
144 |
|
|
5'b0_1010: rd_data_mux = read_regs[175:160];
|
145 |
|
|
5'b0_1011: rd_data_mux = read_regs[191:176];
|
146 |
|
|
5'b0_1100: rd_data_mux = read_regs[207:192];
|
147 |
|
|
5'b0_1101: rd_data_mux = read_regs[223:208];
|
148 |
|
|
5'b0_1110: rd_data_mux = read_regs[239:224];
|
149 |
|
|
5'b0_1111: rd_data_mux = read_regs[255:240];
|
150 |
|
|
5'b1_0000: rd_data_mux = read_regs[271:256];
|
151 |
|
|
5'b1_0001: rd_data_mux = read_regs[287:272];
|
152 |
|
|
5'b1_0010: rd_data_mux = read_regs[303:288];
|
153 |
|
|
5'b1_0011: rd_data_mux = read_regs[319:304];
|
154 |
|
|
5'b1_0100: rd_data_mux = read_regs[335:320];
|
155 |
|
|
5'b1_0101: rd_data_mux = read_regs[351:336];
|
156 |
|
|
5'b1_0110: rd_data_mux = read_regs[367:352];
|
157 |
|
|
5'b1_0111: rd_data_mux = read_regs[383:368];
|
158 |
|
|
5'b1_1000: rd_data_mux = read_regs[399:384];
|
159 |
|
|
5'b1_1001: rd_data_mux = read_regs[415:400];
|
160 |
|
|
default: rd_data_mux = 16'h0000;
|
161 |
|
|
endcase
|
162 |
|
|
|
163 |
|
|
// generate wishbone write register strobes
|
164 |
|
|
always @*
|
165 |
|
|
begin
|
166 |
|
|
write_reserv = 1'b0;
|
167 |
|
|
write_xgmctl = 1'b0;
|
168 |
|
|
write_xgisp74 = 1'b0;
|
169 |
|
|
write_xgisp30 = 1'b0;
|
170 |
|
|
write_xgvbr = 1'b0;
|
171 |
|
|
write_xgif_7 = 1'b0;
|
172 |
|
|
write_xgif_6 = 1'b0;
|
173 |
|
|
write_xgif_5 = 1'b0;
|
174 |
|
|
write_xgif_4 = 1'b0;
|
175 |
|
|
write_xgif_3 = 1'b0;
|
176 |
|
|
write_xgif_2 = 1'b0;
|
177 |
|
|
write_xgif_1 = 1'b0;
|
178 |
|
|
write_xgif_0 = 1'b0;
|
179 |
|
|
write_xgif_7 = 1'b0;
|
180 |
|
|
write_xgswt = 1'b0;
|
181 |
|
|
write_xgsem = 1'b0;
|
182 |
|
|
write_xgccr = 1'b0;
|
183 |
|
|
write_xgpc = 1'b0;
|
184 |
|
|
write_xgr7 = 1'b0;
|
185 |
|
|
write_xgr6 = 1'b0;
|
186 |
|
|
write_xgr5 = 1'b0;
|
187 |
|
|
write_xgr4 = 1'b0;
|
188 |
|
|
write_xgr3 = 1'b0;
|
189 |
|
|
write_xgr2 = 1'b0;
|
190 |
|
|
write_xgr1 = 1'b0;
|
191 |
|
|
if (wbs_wacc)
|
192 |
|
|
case (wbs_adr_i) // synopsys parallel_case
|
193 |
|
|
// 16 bit Bus, 16 bit Granularity
|
194 |
|
|
5'b0_0000 : write_xgmctl = 1'b1;
|
195 |
|
|
// 5'b0_0001 : write_xgchid = 1'b1;
|
196 |
|
|
5'b0_0010 : write_xgisp74 = 1'b1;
|
197 |
|
|
5'b0_0011 : write_xgisp30 = 1'b1;
|
198 |
|
|
5'b0_0100 : write_xgvbr = 1'b1;
|
199 |
|
|
5'b0_0101 : write_xgif_7 = 1'b1;
|
200 |
|
|
5'b0_0110 : write_xgif_6 = 1'b1;
|
201 |
|
|
5'b0_0111 : write_xgif_5 = 1'b1;
|
202 |
|
|
5'b0_1000 : write_xgif_4 = 1'b1;
|
203 |
|
|
5'b0_1001 : write_xgif_3 = 1'b1;
|
204 |
|
|
5'b0_1010 : write_xgif_2 = 1'b1;
|
205 |
|
|
5'b0_1011 : write_xgif_1 = 1'b1;
|
206 |
|
|
5'b0_1100 : write_xgif_0 = 1'b1;
|
207 |
|
|
5'b0_1101 : write_xgswt = 1'b1;
|
208 |
|
|
5'b0_1110 : write_xgsem = 1'b1;
|
209 |
|
|
5'b0_1111 : write_reserv = 1'b1;
|
210 |
|
|
5'b1_0000 : write_xgccr = 1'b1;
|
211 |
|
|
5'b1_0001 : write_xgpc = 1'b1;
|
212 |
|
|
5'b1_0010 : write_reserv = 1'b1;
|
213 |
|
|
5'b1_0011 : write_xgr1 = 1'b1;
|
214 |
|
|
5'b1_0100 : write_xgr2 = 1'b1;
|
215 |
|
|
5'b1_0101 : write_xgr3 = 1'b1;
|
216 |
|
|
5'b1_0110 : write_xgr4 = 1'b1;
|
217 |
|
|
5'b1_0111 : write_xgr5 = 1'b1;
|
218 |
|
|
5'b1_1000 : write_xgr6 = 1'b1;
|
219 |
|
|
5'b1_1001 : write_xgr7 = 1'b1;
|
220 |
|
|
default: ;
|
221 |
|
|
endcase
|
222 |
|
|
end
|
223 |
|
|
|
224 |
|
|
endmodule // xgate_wbs_bus
|