1 |
2 |
dgisselq |
///////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// Filename: busmaster.v
|
4 |
|
|
//
|
5 |
|
|
// Project: XuLA2 board
|
6 |
|
|
//
|
7 |
|
|
// Purpose: This is the highest level, Verilator simulatable, portion of
|
8 |
|
|
// the XuLA2 core. You should be able to successfully Verilate
|
9 |
|
|
// this file, and then build a test bench that tests and proves the
|
10 |
|
|
// capability of anything within here.
|
11 |
|
|
//
|
12 |
|
|
// In general, this means the file is little more than a wishbone
|
13 |
|
|
// interconnect that connects multiple devices together. User-JTAG
|
14 |
|
|
// commands come in via i_rx_stb and i_rx_data. These are converted into
|
15 |
|
|
// wishbone bus interactions, the results of which come back out via
|
16 |
|
|
// o_tx_data and o_tx_stb.
|
17 |
|
|
//
|
18 |
|
|
//
|
19 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
20 |
|
|
// Gisselquist Technology, LLC
|
21 |
|
|
//
|
22 |
|
|
///////////////////////////////////////////////////////////////////////////
|
23 |
|
|
//
|
24 |
|
|
// Copyright (C) 2015, Gisselquist Technology, LLC
|
25 |
|
|
//
|
26 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
27 |
|
|
// modify it under the terms of the GNU General Public License as published
|
28 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
29 |
|
|
// your option) any later version.
|
30 |
|
|
//
|
31 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
32 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
33 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
34 |
|
|
// for more details.
|
35 |
|
|
//
|
36 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
37 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
38 |
|
|
//
|
39 |
|
|
//
|
40 |
|
|
///////////////////////////////////////////////////////////////////////////
|
41 |
|
|
//
|
42 |
31 |
dgisselq |
// `define XULA25
|
43 |
|
|
|
44 |
2 |
dgisselq |
`define INCLUDE_ZIPCPU
|
45 |
|
|
// `define NO_ZIP_WBU_DELAY
|
46 |
|
|
`define IMPLEMENT_ONCHIP_RAM
|
47 |
31 |
dgisselq |
`ifndef VERILATOR
|
48 |
|
|
`ifndef XULA25
|
49 |
2 |
dgisselq |
`define FANCY_ICAP_ACCESS
|
50 |
31 |
dgisselq |
`endif
|
51 |
|
|
`endif
|
52 |
2 |
dgisselq |
`define FLASH_ACCESS
|
53 |
18 |
dgisselq |
// `define SDCARD_ACCESS // Not built yet ...
|
54 |
|
|
//
|
55 |
|
|
//
|
56 |
2 |
dgisselq |
// `define FLASH_SCOPE
|
57 |
18 |
dgisselq |
`ifdef FANCY_ICAP_ACCESS
|
58 |
9 |
dgisselq |
`define CFG_SCOPE
|
59 |
18 |
dgisselq |
`endif
|
60 |
9 |
dgisselq |
// `define SDRAM_SCOPE
|
61 |
31 |
dgisselq |
`ifdef XULA25
|
62 |
2 |
dgisselq |
`define ZIP_SCOPE
|
63 |
31 |
dgisselq |
`endif
|
64 |
|
|
|
65 |
2 |
dgisselq |
module busmaster(i_clk, i_rst,
|
66 |
|
|
i_rx_stb, i_rx_data, o_tx_stb, o_tx_data, i_tx_busy,
|
67 |
|
|
// The SPI Flash lines
|
68 |
|
|
o_sf_cs_n, o_sd_cs_n, o_spi_sck, o_spi_mosi, i_spi_miso,
|
69 |
|
|
// The SDRAM lines
|
70 |
|
|
o_ram_cs_n, o_ram_cke, o_ram_ras_n, o_ram_cas_n,
|
71 |
|
|
o_ram_we_n, o_ram_bs, o_ram_addr,
|
72 |
|
|
o_ram_drive_data, i_ram_data, o_ram_data,
|
73 |
|
|
o_ram_dqm,
|
74 |
|
|
// Generic GPIO
|
75 |
|
|
i_gpio, o_gpio, o_pwm,
|
76 |
|
|
i_rx_uart, o_tx_uart);
|
77 |
|
|
parameter ZIP_ADDRESS_WIDTH=24, NGPO=15, NGPI=15,
|
78 |
|
|
ZA=ZIP_ADDRESS_WIDTH;
|
79 |
|
|
input i_clk, i_rst;
|
80 |
|
|
// The bus commander, via an external JTAG port
|
81 |
|
|
input i_rx_stb;
|
82 |
|
|
input [7:0] i_rx_data;
|
83 |
|
|
output wire o_tx_stb;
|
84 |
|
|
output wire [7:0] o_tx_data;
|
85 |
|
|
input i_tx_busy;
|
86 |
|
|
// SPI flash control
|
87 |
|
|
output wire o_sf_cs_n, o_sd_cs_n;
|
88 |
|
|
output wire o_spi_sck, o_spi_mosi;
|
89 |
|
|
input i_spi_miso;
|
90 |
|
|
// SDRAM control
|
91 |
|
|
output wire o_ram_cs_n, o_ram_cke;
|
92 |
|
|
output wire o_ram_ras_n, o_ram_cas_n, o_ram_we_n;
|
93 |
|
|
output wire [12:0] o_ram_addr;
|
94 |
|
|
output wire [1:0] o_ram_bs;
|
95 |
|
|
output wire o_ram_drive_data;
|
96 |
|
|
input [15:0] i_ram_data;
|
97 |
|
|
output wire [15:0] o_ram_data;
|
98 |
|
|
output wire [1:0] o_ram_dqm;
|
99 |
|
|
input [(NGPI-1):0] i_gpio;
|
100 |
|
|
output wire [(NGPO-1):0] o_gpio;
|
101 |
|
|
output wire o_pwm;
|
102 |
|
|
input i_rx_uart;
|
103 |
|
|
output wire o_tx_uart;
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
//
|
107 |
|
|
//
|
108 |
|
|
// Master wishbone wires
|
109 |
|
|
//
|
110 |
|
|
//
|
111 |
|
|
wire wb_cyc, wb_stb, wb_we, wb_stall, wb_ack, wb_err;
|
112 |
|
|
wire [31:0] wb_data, wb_idata, wb_addr;
|
113 |
|
|
|
114 |
|
|
//
|
115 |
|
|
//
|
116 |
|
|
// First BUS master source: The JTAG
|
117 |
|
|
//
|
118 |
|
|
//
|
119 |
|
|
wire [31:0] dwb_idata;
|
120 |
|
|
|
121 |
|
|
// Wires going to devices
|
122 |
|
|
wire wbu_cyc, wbu_stb, wbu_we;
|
123 |
|
|
wire [31:0] wbu_addr, wbu_data;
|
124 |
|
|
// and then coming from devices
|
125 |
|
|
wire wbu_ack, wbu_stall, wbu_err;
|
126 |
|
|
wire [31:0] wbu_idata;
|
127 |
|
|
// And then headed back home
|
128 |
|
|
wire w_interrupt;
|
129 |
|
|
// Oh, and the debug control for the ZIP CPU
|
130 |
|
|
wire wbu_zip_sel, zip_dbg_ack, zip_dbg_stall;
|
131 |
9 |
dgisselq |
assign wbu_zip_sel =((wbu_cyc)&&(wbu_addr[24]));
|
132 |
2 |
dgisselq |
wire [31:0] zip_dbg_data;
|
133 |
|
|
wbubus genbus(i_clk, i_rx_stb, i_rx_data,
|
134 |
|
|
wbu_cyc, wbu_stb, wbu_we, wbu_addr, wbu_data,
|
135 |
|
|
`ifdef INCLUDE_ZIPCPU
|
136 |
|
|
((~wbu_zip_sel)&&(wbu_ack))
|
137 |
|
|
||((wbu_zip_sel)&&(zip_dbg_ack)),
|
138 |
|
|
((~wbu_zip_sel)&&(wbu_stall))
|
139 |
|
|
||((wbu_zip_sel)&&(zip_dbg_stall)),
|
140 |
|
|
wbu_err, (wbu_zip_sel)?zip_dbg_data:dwb_idata,
|
141 |
|
|
`else
|
142 |
|
|
wbu_ack, wbu_stall,
|
143 |
|
|
wbu_err, dwb_idata,
|
144 |
|
|
`endif
|
145 |
|
|
w_interrupt,
|
146 |
|
|
o_tx_stb, o_tx_data, i_tx_busy);
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
//
|
150 |
|
|
//
|
151 |
|
|
// Second BUS master source: The ZipCPU
|
152 |
|
|
//
|
153 |
|
|
//
|
154 |
|
|
wire zip_cyc, zip_stb, zip_we, zip_cpu_int;
|
155 |
|
|
wire [(ZA-1):0] w_zip_addr;
|
156 |
|
|
wire [31:0] zip_addr, zip_data;
|
157 |
|
|
// and then coming from devices
|
158 |
|
|
wire zip_ack, zip_stall, zip_err;
|
159 |
|
|
wire dwb_we, dwb_stb, dwb_cyc, dwb_ack, dwb_stall, dwb_err;
|
160 |
|
|
wire [31:0] dwb_addr, dwb_odata;
|
161 |
|
|
wire [7:0] w_ints_to_zip_cpu;
|
162 |
|
|
`ifdef INCLUDE_ZIPCPU
|
163 |
31 |
dgisselq |
`ifdef XULA25
|
164 |
2 |
dgisselq |
wire [31:0] zip_debug;
|
165 |
|
|
zipsystem #(24'h2000,ZA,8,1,8)
|
166 |
|
|
zippy(i_clk, 1'b0,
|
167 |
|
|
// Zippys wishbone interface
|
168 |
|
|
zip_cyc, zip_stb, zip_we, w_zip_addr, zip_data,
|
169 |
|
|
zip_ack, zip_stall, dwb_idata, zip_err,
|
170 |
|
|
w_ints_to_zip_cpu, zip_cpu_int,
|
171 |
|
|
// Debug wishbone interface
|
172 |
|
|
((wbu_cyc)&&(wbu_zip_sel)),
|
173 |
|
|
((wbu_stb)&&(wbu_zip_sel)),wbu_we, wbu_addr[0],
|
174 |
|
|
wbu_data,
|
175 |
|
|
zip_dbg_ack, zip_dbg_stall, zip_dbg_data,
|
176 |
|
|
zip_debug);
|
177 |
31 |
dgisselq |
`else
|
178 |
|
|
zipbones #(24'h2000,ZA,8,1)
|
179 |
|
|
zippy(i_clk, 1'b0,
|
180 |
|
|
// Zippys wishbone interface
|
181 |
|
|
zip_cyc, zip_stb, zip_we, w_zip_addr, zip_data,
|
182 |
|
|
zip_ack, zip_stall, dwb_idata, zip_err,
|
183 |
|
|
w_interrupt, zip_cpu_int,
|
184 |
|
|
// Debug wishbone interface
|
185 |
|
|
((wbu_cyc)&&(wbu_zip_sel)),
|
186 |
|
|
((wbu_stb)&&(wbu_zip_sel)),wbu_we, wbu_addr[0],
|
187 |
|
|
wbu_data,
|
188 |
|
|
zip_dbg_ack, zip_dbg_stall, zip_dbg_data);
|
189 |
|
|
`endif
|
190 |
2 |
dgisselq |
generate
|
191 |
|
|
if (ZA < 32)
|
192 |
|
|
assign zip_addr = { {(32-ZA){1'b0}}, w_zip_addr };
|
193 |
|
|
else
|
194 |
|
|
assign zip_addr = w_zip_addr;
|
195 |
|
|
endgenerate
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
//
|
199 |
|
|
//
|
200 |
|
|
// And an arbiter to decide who gets to access the bus
|
201 |
|
|
//
|
202 |
|
|
//
|
203 |
|
|
/*
|
204 |
|
|
wbarbiter #(32,32) wbu_zip_arbiter(i_clk, i_rst,
|
205 |
|
|
// The UART interface Master
|
206 |
|
|
wbu_addr, wbu_data, wbu_we, (wbu_stb)&&(~wbu_zip_sel),
|
207 |
|
|
(wbu_cyc)&&(~wbu_zip_sel), wbu_ack, wbu_stall, wbu_err,
|
208 |
|
|
// The ZIP CPU Master
|
209 |
|
|
zip_addr, zip_data, zip_we, zip_stb,
|
210 |
|
|
zip_cyc, zip_ack, zip_stall, zip_err,
|
211 |
|
|
// Common bus returns
|
212 |
|
|
dwb_addr,dwb_odata,dwb_we,dwb_stb, dwb_cyc, dwb_ack, dwb_stall, dwb_err);
|
213 |
|
|
*/
|
214 |
|
|
wbpriarbiter #(32,32) wbu_zip_arbiter(i_clk,
|
215 |
|
|
// The ZIP CPU Master -- gets priority in the arbiter
|
216 |
|
|
zip_cyc, zip_stb, zip_we, zip_addr, zip_data,
|
217 |
|
|
zip_ack, zip_stall, zip_err,
|
218 |
|
|
// The JTAG interface Master, secondary priority,
|
219 |
|
|
// will suffer a 1clk delay in arbitration
|
220 |
|
|
(wbu_cyc)&&(~wbu_zip_sel), (wbu_stb)&&(~wbu_zip_sel), wbu_we,
|
221 |
|
|
wbu_addr, wbu_data,
|
222 |
|
|
wbu_ack, wbu_stall, wbu_err,
|
223 |
|
|
// Common bus returns
|
224 |
|
|
dwb_cyc, dwb_stb, dwb_we, dwb_addr, dwb_odata,
|
225 |
|
|
dwb_ack, dwb_stall, dwb_err);
|
226 |
|
|
|
227 |
|
|
`else
|
228 |
|
|
assign zip_cyc = 1'b0;
|
229 |
|
|
assign zip_stb = 1'b0;
|
230 |
|
|
assign zip_we = 1'b0;
|
231 |
|
|
assign zip_cpu_int = 1'b0;
|
232 |
|
|
assign zip_addr = 32'h000;
|
233 |
|
|
assign zip_data = 32'h000;
|
234 |
|
|
|
235 |
|
|
reg r_zip_dbg_ack;
|
236 |
|
|
initial r_zip_dbg_ack = 1'b0;
|
237 |
|
|
always @(posedge i_clk)
|
238 |
|
|
r_zip_dbg_ack <= ((wbu_cyc)&&(wbu_zip_sel)&(wbu_stb));
|
239 |
|
|
assign zip_dbg_ack = r_zip_dbg_ack;
|
240 |
|
|
assign zip_dbg_stall = 1'b0;
|
241 |
|
|
assign zip_dbg_data = 32'h000;
|
242 |
|
|
|
243 |
|
|
assign dwb_addr = wbu_addr;
|
244 |
|
|
assign dwb_odata = wbu_data;
|
245 |
|
|
assign dwb_we = wbu_we;
|
246 |
|
|
assign dwb_stb = (wbu_stb);
|
247 |
|
|
assign dwb_cyc = (wbu_cyc);
|
248 |
|
|
assign wbu_ack = dwb_ack;
|
249 |
|
|
assign wbu_stall = dwb_stall;
|
250 |
|
|
assign dwb_idata = wb_idata;
|
251 |
|
|
assign wbu_err = dwb_err;
|
252 |
|
|
`endif
|
253 |
|
|
|
254 |
|
|
|
255 |
|
|
//
|
256 |
|
|
//
|
257 |
|
|
// And because the ZIP CPU and the Arbiter create an unacceptable
|
258 |
|
|
// delay, we fail timing. So we add in a delay cycle ...
|
259 |
|
|
//
|
260 |
|
|
//
|
261 |
|
|
`ifdef NO_ZIP_WBU_DELAY
|
262 |
|
|
assign wb_cyc = dwb_cyc;
|
263 |
|
|
assign wb_stb = dwb_stb;
|
264 |
|
|
assign wb_we = dwb_we;
|
265 |
|
|
assign wb_addr = dwb_addr;
|
266 |
|
|
assign wb_data = dwb_odata;
|
267 |
|
|
assign dwb_idata = wb_idata;
|
268 |
|
|
assign dwb_ack = wb_ack;
|
269 |
|
|
assign dwb_stall = wb_stall;
|
270 |
|
|
assign dwb_err = wb_err;
|
271 |
|
|
`else
|
272 |
|
|
busdelay wbu_zip_delay(i_clk,
|
273 |
|
|
dwb_cyc, dwb_stb, dwb_we, dwb_addr, dwb_odata,
|
274 |
|
|
dwb_ack, dwb_stall, dwb_idata, dwb_err,
|
275 |
|
|
wb_cyc, wb_stb, wb_we, wb_addr, wb_data,
|
276 |
|
|
wb_ack, wb_stall, wb_idata, wb_err);
|
277 |
|
|
`endif
|
278 |
|
|
|
279 |
|
|
|
280 |
|
|
|
281 |
|
|
wire io_sel, pwm_sel, uart_sel, flash_sel, flctl_sel, scop_sel,
|
282 |
|
|
cfg_sel, mem_sel, sdram_sel, sdcard_sel,
|
283 |
|
|
none_sel, many_sel, io_bank;
|
284 |
|
|
wire io_ack, flash_ack, scop_ack, cfg_ack, mem_ack,
|
285 |
|
|
sdram_ack, sdcard_ack, uart_ack, pwm_ack;
|
286 |
|
|
wire io_stall, flash_stall, scop_stall, cfg_stall, mem_stall,
|
287 |
|
|
sdram_stall, sdcard_stall, uart_stall, pwm_stall;
|
288 |
|
|
|
289 |
|
|
wire [31:0] io_data, flash_data, scop_data, cfg_data, mem_data,
|
290 |
|
|
sdram_data, sdcard_data, uart_data, pwm_data;
|
291 |
|
|
reg [31:0] bus_err_addr;
|
292 |
|
|
|
293 |
|
|
assign wb_ack = (wb_cyc)&&((io_ack)||(uart_ack)||(pwm_ack)
|
294 |
|
|
||(scop_ack)||(cfg_ack)
|
295 |
|
|
||(mem_ack)||(flash_ack)||(sdram_ack)
|
296 |
|
|
||(sdcard_ack)
|
297 |
|
|
||((none_sel)&&(1'b1)));
|
298 |
|
|
assign wb_stall = ((io_sel)&&(io_stall))
|
299 |
|
|
||((uart_sel)&&(uart_stall))
|
300 |
|
|
||((pwm_sel)&&(pwm_stall))
|
301 |
|
|
||((scop_sel)&&(scop_stall))
|
302 |
|
|
||((cfg_sel)&&(cfg_stall))
|
303 |
|
|
||((mem_sel)&&(mem_stall))
|
304 |
|
|
||((sdram_sel)&&(sdram_stall))
|
305 |
|
|
||((sdcard_sel)&&(sdcard_stall))
|
306 |
|
|
||((flash_sel||flctl_sel)&&(flash_stall));
|
307 |
|
|
// (none_sel)&&(1'b0)
|
308 |
|
|
|
309 |
|
|
/*
|
310 |
|
|
assign wb_idata = (io_ack)?io_data
|
311 |
|
|
: ((scop_ack)?scop_data
|
312 |
|
|
: ((cfg_ack)?cfg_data
|
313 |
|
|
: ((mem_ack)?mem_data
|
314 |
|
|
: ((flash_ack)?flash_data
|
315 |
|
|
: 32'h00))));
|
316 |
|
|
*/
|
317 |
|
|
assign wb_idata = (io_ack|scop_ack)?((io_ack )? io_data : scop_data)
|
318 |
|
|
: ((uart_ack|pwm_ack)?((uart_ack)?uart_data: pwm_data)
|
319 |
|
|
: ((cfg_ack) ? cfg_data
|
320 |
|
|
: ((sdram_ack|sdcard_ack)
|
321 |
|
|
?((sdram_ack)? sdram_data : sdcard_data)
|
322 |
|
|
: ((mem_ack)?mem_data:flash_data)))); // if (flash_ack)
|
323 |
|
|
assign wb_err = ((wb_cyc)&&(wb_stb)&&(none_sel || many_sel)) || many_ack;
|
324 |
|
|
|
325 |
|
|
// Addresses ...
|
326 |
|
|
// 0000 xxxx configuration/control registers
|
327 |
|
|
// 001x xxxx Down-sampler taps (64 taps, 2 at a time)
|
328 |
|
|
// 1xxx xxxx Up-sampler taps
|
329 |
|
|
// 1 xxxx xxxx xxxx xxxx xxxx Up-sampler taps
|
330 |
31 |
dgisselq |
|
331 |
|
|
`ifndef SPEEDY_IO
|
332 |
|
|
|
333 |
|
|
wire pre_io, pre_pwm, pre_uart, pre_flctl, pre_scop;
|
334 |
2 |
dgisselq |
assign io_bank = (wb_cyc)&&(wb_addr[31:5] == 27'h8);
|
335 |
31 |
dgisselq |
assign pre_io = (~pre_flctl)&&(~pre_pwm)&&(~pre_uart)&&(~pre_scop);
|
336 |
|
|
assign io_sel = (io_bank)&&(pre_io);
|
337 |
|
|
assign pre_pwm = (wb_addr[4: 1]== 4'h4);
|
338 |
|
|
assign pwm_sel = (io_bank)&&(pre_pwm);
|
339 |
|
|
assign pre_uart = (wb_addr[4: 1]== 4'h5)||(wb_addr[4:0]==5'h7);
|
340 |
|
|
assign uart_sel = (io_bank)&&(pre_uart);
|
341 |
|
|
assign pre_flctl= (wb_addr[4: 2]== 3'h3);
|
342 |
|
|
assign flctl_sel= (io_bank)&&(pre_flctl);
|
343 |
|
|
assign pre_scop = (wb_addr[4: 3]== 2'h3);
|
344 |
|
|
assign scop_sel = (io_bank)&&(pre_scop);
|
345 |
2 |
dgisselq |
assign cfg_sel =((wb_cyc)&&(wb_addr[31: 6]== 26'h05));
|
346 |
|
|
// zip_sel is not on the bus at this point
|
347 |
|
|
assign mem_sel =((wb_cyc)&&(wb_addr[31:13]== 19'h01));
|
348 |
|
|
assign flash_sel=((wb_cyc)&&(wb_addr[31:18]== 14'h01));
|
349 |
|
|
assign sdcard_sel=1'b0;
|
350 |
|
|
assign sdram_sel=((wb_cyc)&&(wb_addr[31:23]== 9'h01));
|
351 |
31 |
dgisselq |
`else
|
352 |
|
|
assign iovec = { wb_addr[23],wb_addr[18],wb_addr[15:13] }
|
353 |
|
|
|
354 |
|
|
assign sdram_sel =((wb_cyc)&&(io_vec[4]));
|
355 |
|
|
assign flash_sel =((wb_cyc)&&(io_vec[4:3]==2'b01));
|
356 |
|
|
assign mem_sel =((wb_cyc)&&(io_vec[4:0]==5'h07));
|
357 |
|
|
assign cfg_sel =((wb_cyc)&&(io_vec[4:0]==5'h06));
|
358 |
|
|
assign sdcard_sel=((wb_cyc)&&(io_vec[4:0]==5'h05));
|
359 |
|
|
assign scop_sel =((wb_cyc)&&(io_vec[4:0]==5'h04));
|
360 |
|
|
assign rtc_sel =((wb_cyc)&&(io_vec[4:0]==5'h03));
|
361 |
|
|
assign rtc_sel =((wb_cyc)&&(io_vec[4:0]==5'h03));
|
362 |
|
|
assign puf_sel =((wb_cyc)&&(io_vec[4:0]==5'h02));
|
363 |
|
|
assign io_sel =((wb_cyc)&&(io_vec[4:0]==5'h01));
|
364 |
|
|
assign wb_err =((wb_cyc)&&(io_vec[4:0]==5'h00));
|
365 |
|
|
assign flctl_sel = (puf_sel)&&(wb_addr[2]);
|
366 |
|
|
assign pwm_sel = (puf_sel)&&(wb_addr[2:1]==2'b01);
|
367 |
|
|
assign sdcard_sel=1'b0;//((wb_cyc)&&({wb_addr[23],wb_addr[18]}==2'b01));
|
368 |
|
|
`endif
|
369 |
|
|
|
370 |
|
|
assign none_sel =((wb_cyc)&&(wb_stb)&&(~
|
371 |
|
|
(io_sel
|
372 |
|
|
||uart_sel
|
373 |
|
|
||pwm_sel
|
374 |
|
|
||flctl_sel
|
375 |
|
|
||scop_sel
|
376 |
|
|
||cfg_sel
|
377 |
|
|
||mem_sel
|
378 |
|
|
||sdram_sel
|
379 |
|
|
||sdcard_sel
|
380 |
|
|
||flash_sel)));
|
381 |
2 |
dgisselq |
assign many_sel =((wb_cyc)&&(wb_stb)&&(
|
382 |
|
|
{3'h0, io_sel}
|
383 |
|
|
+{3'h0, uart_sel}
|
384 |
|
|
+{3'h0, pwm_sel}
|
385 |
|
|
+{3'h0, flctl_sel}
|
386 |
|
|
+{3'h0, scop_sel}
|
387 |
|
|
+{3'h0, cfg_sel}
|
388 |
|
|
+{3'h0, mem_sel}
|
389 |
|
|
+{3'h0, sdram_sel}
|
390 |
|
|
+{3'h0, sdcard_sel}
|
391 |
|
|
+{3'h0, flash_sel} > 1));
|
392 |
|
|
|
393 |
|
|
wire many_ack;
|
394 |
|
|
assign many_ack =((wb_cyc)&&(
|
395 |
|
|
{3'h0, io_ack}
|
396 |
|
|
+{3'h0, uart_ack}
|
397 |
|
|
+{3'h0, pwm_ack}
|
398 |
31 |
dgisselq |
// FLCTL acks through the flash, so one less check here
|
399 |
2 |
dgisselq |
+{3'h0, scop_ack}
|
400 |
|
|
+{3'h0, cfg_ack}
|
401 |
|
|
+{3'h0, mem_ack}
|
402 |
|
|
+{3'h0, sdram_ack}
|
403 |
|
|
+{3'h0, sdcard_ack}
|
404 |
|
|
+{3'h0, flash_ack} > 1));
|
405 |
|
|
|
406 |
|
|
always @(posedge i_clk)
|
407 |
|
|
if (wb_err)
|
408 |
|
|
bus_err_addr <= wb_addr;
|
409 |
|
|
|
410 |
|
|
wire flash_interrupt, scop_interrupt,
|
411 |
|
|
uart_rx_int, uart_tx_int, pwm_int;
|
412 |
|
|
// The I/O processor, herein called an ioslave
|
413 |
|
|
ioslave #(NGPO, NGPI) runio(i_clk,
|
414 |
|
|
wb_cyc, (io_sel)&&(wb_stb), wb_we, wb_addr[4:0],
|
415 |
|
|
wb_data, io_ack, io_stall, io_data,
|
416 |
|
|
i_gpio, o_gpio,
|
417 |
|
|
bus_err_addr,
|
418 |
|
|
{ uart_tx_int, uart_rx_int, pwm_int, scop_interrupt,
|
419 |
31 |
dgisselq |
flash_interrupt,
|
420 |
|
|
`ifdef XULA25
|
421 |
|
|
zip_cpu_int
|
422 |
|
|
`else
|
423 |
|
|
1'b0
|
424 |
|
|
`endif
|
425 |
|
|
},
|
426 |
2 |
dgisselq |
w_ints_to_zip_cpu,
|
427 |
|
|
w_interrupt);
|
428 |
|
|
// 8684
|
429 |
|
|
// 1'bx, 4'h0, scop_sel, scop_ack, ~scop_stall,
|
430 |
|
|
// wb_err, ~vga_interrupt, 2'b00, flash_interrupt
|
431 |
|
|
//
|
432 |
|
|
|
433 |
|
|
//
|
434 |
|
|
// UART device
|
435 |
|
|
//
|
436 |
|
|
uartdev serialport(i_clk, i_rx_uart, o_tx_uart,
|
437 |
|
|
wb_cyc, (wb_stb)&&(uart_sel), wb_we,
|
438 |
9 |
dgisselq |
{ ~wb_addr[2], wb_addr[0]}, wb_data,
|
439 |
|
|
uart_ack, uart_stall, uart_data,
|
440 |
2 |
dgisselq |
uart_rx_int, uart_tx_int);
|
441 |
|
|
|
442 |
|
|
//
|
443 |
|
|
// PWM (audio) device
|
444 |
|
|
//
|
445 |
|
|
wbpwmaudio pwmdev(i_clk,
|
446 |
|
|
wb_cyc, (wb_stb)&&(pwm_sel), wb_we, wb_addr[0],
|
447 |
|
|
wb_data, pwm_ack, pwm_stall, pwm_data, o_pwm, pwm_int);
|
448 |
|
|
|
449 |
|
|
|
450 |
|
|
//
|
451 |
|
|
// FLASH MEMORY CONFIGURATION ACCESS
|
452 |
|
|
//
|
453 |
|
|
wire flash_cs_n, flash_sck, flash_mosi;
|
454 |
|
|
`ifdef FLASH_ACCESS
|
455 |
|
|
wbspiflash flashmem(i_clk,
|
456 |
|
|
wb_cyc,(wb_stb&&flash_sel),(wb_stb)&&(flctl_sel),wb_we,
|
457 |
|
|
wb_addr[17:0], wb_data,
|
458 |
|
|
flash_ack, flash_stall, flash_data,
|
459 |
|
|
flash_sck, flash_cs_n, o_sf_cs_n, flash_mosi, i_spi_miso,
|
460 |
|
|
flash_interrupt);
|
461 |
|
|
`else
|
462 |
|
|
reg r_flash_ack;
|
463 |
|
|
initial r_flash_ack = 1'b0;
|
464 |
|
|
always @(posedge i_clk)
|
465 |
|
|
r_flash_ack <= (wb_cyc)&&(wb_stb)&&((flash_sel)||(flctl_sel));
|
466 |
|
|
|
467 |
|
|
assign flash_ack = r_flash_ack;
|
468 |
|
|
assign flash_stall = 1'b0;
|
469 |
|
|
assign flash_data = 32'h0000;
|
470 |
|
|
assign flash_interrupt = 1'b0;
|
471 |
|
|
|
472 |
|
|
assign flash_cs_n = 1'b1;
|
473 |
|
|
assign flash_sck = 1'b1;
|
474 |
|
|
assign flash_mosi = 1'b1;
|
475 |
|
|
|
476 |
|
|
This is an error
|
477 |
|
|
`endif
|
478 |
|
|
|
479 |
|
|
`ifdef FLASH_ACCESS
|
480 |
|
|
`ifdef SDCARD_ACCESS
|
481 |
|
|
spiarbiter spichk(i_clk,
|
482 |
|
|
flash_cs_n, flash_sck, flash_mosi,
|
483 |
|
|
sdcard_cs_n, sdcard_sck, sdcard_mosi,
|
484 |
|
|
o_sf_cs_n, o_sd_cs_n, o_spi_sck, o_spi_mosi);
|
485 |
|
|
This is an error
|
486 |
|
|
`else
|
487 |
|
|
// Flash access, but no SD card access
|
488 |
|
|
assign o_sf_cs_n = flash_cs_n;
|
489 |
|
|
assign o_sd_cs_n = 1'b1;
|
490 |
|
|
assign o_spi_sck = flash_sck;
|
491 |
|
|
assign o_spi_mosi = flash_mosi;
|
492 |
|
|
`endif // SDCARD_ACCESS && FLASH_ACCESS
|
493 |
|
|
`else // FLASH_ACCESS
|
494 |
|
|
`ifdef SDCARD_ACCESS
|
495 |
|
|
// SDCard access, but no flash access
|
496 |
|
|
assign o_sf_cs_n = 1'b1;
|
497 |
|
|
assign o_sd_cs_n = sdcard_cs_n;
|
498 |
|
|
assign o_spi_sck = sdcard_sck;
|
499 |
|
|
assign o_spi_mosi = sdcard_mosi;
|
500 |
|
|
`else
|
501 |
|
|
// No SPI access ...
|
502 |
|
|
assign o_sf_cs_n = 1'b1;
|
503 |
|
|
assign o_sd_cs_n = 1'b1;
|
504 |
|
|
assign o_spi_sck = 1'b1;
|
505 |
|
|
assign o_spi_mosi = 1'b1;
|
506 |
|
|
`endif // SDCARD_ACCESS, w/o FLASH_ACCESS
|
507 |
|
|
`endif // !FLASH_ACCESS
|
508 |
|
|
|
509 |
|
|
|
510 |
|
|
//
|
511 |
|
|
// MULTIBOOT/ICAPE2 CONFIGURATION ACCESS
|
512 |
|
|
//
|
513 |
|
|
wire [31:0] cfg_scope;
|
514 |
|
|
`ifdef FANCY_ICAP_ACCESS
|
515 |
|
|
wbicape6 fpga_cfg(i_clk, wb_cyc,(cfg_sel)&&(wb_stb), wb_we,
|
516 |
|
|
wb_addr[5:0], wb_data,
|
517 |
|
|
cfg_ack, cfg_stall, cfg_data,
|
518 |
|
|
cfg_scope);
|
519 |
|
|
`else
|
520 |
|
|
assign cfg_scope = 32'h0000;
|
521 |
|
|
reg r_cfg_ack;
|
522 |
|
|
initial r_cfg_ack = 1'b0;
|
523 |
|
|
always @(posedge i_clk)
|
524 |
|
|
r_cfg_ack <= ((wb_cyc)&&(cfg_sel)&&(wb_stb)&&(~cfg_stall));
|
525 |
|
|
assign cfg_ack = r_cfg_ack;
|
526 |
|
|
assign cfg_stall = 1'b0;
|
527 |
|
|
assign cfg_data = 32'h0000;
|
528 |
|
|
`endif
|
529 |
|
|
|
530 |
|
|
|
531 |
|
|
//
|
532 |
|
|
// RAM MEMORY ACCESS
|
533 |
|
|
//
|
534 |
|
|
`ifdef IMPLEMENT_ONCHIP_RAM
|
535 |
|
|
memdev #(13) ram(i_clk, wb_cyc, (wb_stb)&&(mem_sel), wb_we,
|
536 |
|
|
wb_addr[12:0], wb_data, mem_ack, mem_stall, mem_data);
|
537 |
|
|
`else
|
538 |
|
|
reg r_mem_ack;
|
539 |
|
|
always @(posedge i_clk)
|
540 |
|
|
r_mem_ack = (wb_cyc)&&(wb_stb)&&(mem_sel);
|
541 |
|
|
assign mem_data = 32'h000;
|
542 |
|
|
assign mem_stall = 1'b0;
|
543 |
|
|
assign mem_ack = r_mem_ack;
|
544 |
|
|
`endif
|
545 |
|
|
|
546 |
|
|
|
547 |
|
|
//
|
548 |
|
|
// SDRAM Memory Access
|
549 |
|
|
//
|
550 |
|
|
wire [31:0] sdram_debug;
|
551 |
|
|
`ifndef BYPASS_SDRAM_ACCESS
|
552 |
|
|
wbsdram sdram(i_clk,
|
553 |
|
|
wb_cyc, (wb_stb)&&(sdram_sel),
|
554 |
|
|
wb_we, wb_addr[22:0], wb_data,
|
555 |
|
|
sdram_ack, sdram_stall, sdram_data,
|
556 |
|
|
o_ram_cs_n, o_ram_cke, o_ram_ras_n, o_ram_cas_n, o_ram_we_n,
|
557 |
|
|
o_ram_bs, o_ram_addr,
|
558 |
|
|
o_ram_drive_data, i_ram_data, o_ram_data, o_ram_dqm,
|
559 |
|
|
sdram_debug);
|
560 |
|
|
`else
|
561 |
|
|
reg r_sdram_ack;
|
562 |
|
|
initial r_sdram_ack = 1'b0;
|
563 |
|
|
always @(posedge i_clk)
|
564 |
|
|
r_sdram_ack <= (wb_cyc)&&(wb_stb)&&(sdram_sel);
|
565 |
|
|
assign sdram_ack = r_sdram_ack;
|
566 |
|
|
assign sdram_stall = 1'b0;
|
567 |
|
|
assign sdram_data = 32'h0000;
|
568 |
|
|
|
569 |
|
|
assign o_ram_ce_n = 1'b1;
|
570 |
|
|
assign o_ram_ras_n = 1'b1;
|
571 |
|
|
assign o_ram_cas_n = 1'b1;
|
572 |
|
|
assign o_ram_we_n = 1'b1;
|
573 |
|
|
|
574 |
|
|
assign sdram_debug = 32'h0000;
|
575 |
|
|
`endif
|
576 |
|
|
|
577 |
|
|
//
|
578 |
|
|
//
|
579 |
|
|
// WISHBONE SCOPES
|
580 |
|
|
//
|
581 |
|
|
//
|
582 |
|
|
//
|
583 |
|
|
//
|
584 |
|
|
`ifdef FLASH_SCOPE
|
585 |
|
|
reg [31:0] r_flash_debug, last_flash_debug;
|
586 |
|
|
wire [31:0] scop_flash_data;
|
587 |
|
|
wire scop_flash_ack, scop_flash_stall, scop_flash_interrupt;
|
588 |
|
|
always @(posedge i_clk)
|
589 |
|
|
r_flash_debug <= flash_debug;
|
590 |
|
|
always @(posedge i_clk)
|
591 |
|
|
last_flash_debug <= r_flash_debug;
|
592 |
|
|
wbscope spiscope(i_clk, 1'b1, (~o_spi_cs_n), r_flash_debug,
|
593 |
|
|
// Wishbone interface
|
594 |
|
|
i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b00)), wb_we, wb_addr[0],
|
595 |
|
|
wb_data,
|
596 |
|
|
scop_flash_ack, scop_flash_stall, scop_flash_data,
|
597 |
|
|
scop_flash_interrupt);
|
598 |
|
|
`else
|
599 |
|
|
wire [31:0] scop_flash_data;
|
600 |
|
|
wire scop_flash_ack, scop_flash_stall, scop_flash_interrupt;
|
601 |
|
|
assign scop_flash_data = 32'h00;
|
602 |
|
|
assign scop_flash_ack = (wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b00);
|
603 |
|
|
assign scop_flash_stall = 1'b0;
|
604 |
|
|
assign scop_flash_interrupt = 1'b0;
|
605 |
|
|
`endif
|
606 |
|
|
|
607 |
|
|
|
608 |
|
|
wire [31:0] scop_cfg_data;
|
609 |
|
|
wire scop_cfg_ack, scop_cfg_stall, scop_cfg_interrupt;
|
610 |
|
|
`ifdef CFG_SCOPE
|
611 |
|
|
wire scop_cfg_trigger;
|
612 |
|
|
assign scop_cfg_trigger = (wb_cyc)&&(wb_stb)&&(cfg_sel);
|
613 |
18 |
dgisselq |
wbscope #(5'h7) wbcfgscope(i_clk, 1'b1, scop_cfg_trigger, cfg_scope,
|
614 |
2 |
dgisselq |
// Wishbone interface
|
615 |
|
|
i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b01)),
|
616 |
|
|
wb_we, wb_addr[0], wb_data,
|
617 |
|
|
scop_cfg_ack, scop_cfg_stall, scop_cfg_data,
|
618 |
|
|
scop_cfg_interrupt);
|
619 |
|
|
`else
|
620 |
|
|
assign scop_cfg_data = 32'h00;
|
621 |
|
|
assign scop_cfg_ack = (wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b01);
|
622 |
|
|
assign scop_cfg_stall = 1'b0;
|
623 |
|
|
assign scop_cfg_interrupt = 1'b0;
|
624 |
|
|
`endif
|
625 |
|
|
|
626 |
|
|
wire [31:0] scop_ram_data;
|
627 |
|
|
wire scop_ram_ack, scop_ram_stall, scop_ram_interrupt;
|
628 |
|
|
`ifdef SDRAM_SCOPE
|
629 |
|
|
wire sdram_trigger;
|
630 |
|
|
assign sdram_trigger = sdram_sel;
|
631 |
|
|
// assign sdram_trigger = ((wbu_cyc)&&(wbu_zip_sel)&&(wbu_stb)&&(~wbu_addr[0])),
|
632 |
|
|
wire sdram_write;
|
633 |
|
|
assign sdram_write = ((wb_cyc)&&(sdram_sel)&&(wb_stb)&&(wb_we)&&(~sdram_stall));
|
634 |
|
|
/*
|
635 |
|
|
reg r_trigger;
|
636 |
|
|
reg [31:0] last_data;
|
637 |
|
|
always @(posedge i_clk)
|
638 |
|
|
if (sdram_write)
|
639 |
|
|
last_data <= wb_data;
|
640 |
|
|
initial r_trigger = 1'b0;
|
641 |
|
|
always @(posedge i_clk)
|
642 |
|
|
if ((sdram_write)&&(last_data == wb_data))
|
643 |
|
|
r_trigger <= 1'b1;
|
644 |
|
|
else
|
645 |
|
|
r_trigger <= 1'b0;
|
646 |
|
|
*/
|
647 |
|
|
|
648 |
9 |
dgisselq |
wbscope #(5'ha) sdramscope(i_clk, 1'b1, sdram_trigger,
|
649 |
2 |
dgisselq |
sdram_debug,
|
650 |
|
|
// zip_debug,
|
651 |
|
|
// Wishbone interface
|
652 |
|
|
i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b10)), wb_we, wb_addr[0],
|
653 |
|
|
wb_data,
|
654 |
|
|
scop_ram_ack, scop_ram_stall, scop_ram_data,
|
655 |
|
|
scop_ram_interrupt);
|
656 |
|
|
`else
|
657 |
|
|
assign scop_ram_data = 32'h00;
|
658 |
|
|
assign scop_ram_ack = (wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b10);
|
659 |
|
|
assign scop_ram_stall = 1'b0;
|
660 |
|
|
assign scop_ram_interrupt = 1'b0;
|
661 |
|
|
`endif
|
662 |
|
|
|
663 |
|
|
wire [31:0] scop_zip_data;
|
664 |
|
|
wire scop_zip_ack, scop_zip_stall, scop_zip_interrupt;
|
665 |
|
|
`ifdef ZIP_SCOPE
|
666 |
|
|
wire zip_trigger;
|
667 |
|
|
assign zip_trigger=(wbu_zip_sel)&&(wbu_we)&&(wbu_stb)&&(~wbu_addr[0]);
|
668 |
9 |
dgisselq |
wbscope #(5'ha) zipscope(i_clk, 1'b1, zip_trigger,
|
669 |
2 |
dgisselq |
zip_debug,
|
670 |
|
|
// Wishbone interface
|
671 |
|
|
i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b11)), wb_we, wb_addr[0],
|
672 |
|
|
wb_data,
|
673 |
|
|
scop_zip_ack, scop_zip_stall, scop_zip_data,
|
674 |
|
|
scop_zip_interrupt);
|
675 |
|
|
`else
|
676 |
|
|
assign scop_zip_data = 32'h00;
|
677 |
|
|
assign scop_zip_ack = (wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b11);
|
678 |
|
|
assign scop_zip_stall = 1'b0;
|
679 |
|
|
assign scop_zip_interrupt = 1'b0;
|
680 |
|
|
`endif
|
681 |
|
|
|
682 |
|
|
|
683 |
|
|
assign scop_interrupt = scop_flash_interrupt || scop_cfg_interrupt
|
684 |
|
|
|| scop_ram_interrupt || scop_zip_interrupt;
|
685 |
|
|
assign scop_ack = scop_cfg_ack | scop_flash_ack | scop_ram_ack | scop_zip_ack;
|
686 |
|
|
assign scop_stall = ((~wb_addr[2])?
|
687 |
|
|
((wb_addr[1])?scop_flash_stall:scop_cfg_stall)
|
688 |
|
|
: ((wb_addr[1])?scop_ram_stall:scop_zip_stall));
|
689 |
|
|
assign scop_data = ((scop_cfg_ack)?scop_cfg_data
|
690 |
|
|
: ((scop_flash_ack) ? scop_flash_data
|
691 |
|
|
: ((scop_ram_ack) ? scop_ram_data
|
692 |
|
|
: scop_zip_data)));
|
693 |
|
|
|
694 |
|
|
|
695 |
|
|
reg r_sdcard_ack;
|
696 |
|
|
initial r_sdcard_ack = 1'b0;
|
697 |
|
|
always @(posedge i_clk)
|
698 |
|
|
r_sdcard_ack <= (wb_cyc)&&(wb_stb)&&(sdcard_sel);
|
699 |
|
|
assign sdcard_stall = 1'b0;
|
700 |
|
|
assign sdcard_ack = r_sdcard_ack;
|
701 |
|
|
assign sdcard_data = 32'h0000;
|
702 |
|
|
endmodule
|
703 |
|
|
|
704 |
|
|
// 0x8684 interrupts ...???
|