1 |
3 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// Filename: fastmaster.v
|
4 |
|
|
//
|
5 |
|
|
// Project: OpenArty, an entirely open SoC based upon the Arty platform
|
6 |
|
|
//
|
7 |
|
|
// Purpose: On other projects, this file would be called the "bus
|
8 |
|
|
// interconnect". This module connects all the devices on the
|
9 |
|
|
// Wishbone bus within this project together. It is created by hand, not
|
10 |
|
|
// automatically.
|
11 |
|
|
//
|
12 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
13 |
|
|
// Gisselquist Technology, LLC
|
14 |
|
|
//
|
15 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
16 |
|
|
//
|
17 |
|
|
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
|
18 |
|
|
//
|
19 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
20 |
|
|
// modify it under the terms of the GNU General Public License as published
|
21 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
22 |
|
|
// your option) any later version.
|
23 |
|
|
//
|
24 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
25 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
26 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
27 |
|
|
// for more details.
|
28 |
|
|
//
|
29 |
|
|
// You should have received a copy of the GNU General Public License along
|
30 |
|
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
31 |
|
|
// target there if the PDF file isn't present.) If not, see
|
32 |
|
|
// <http://www.gnu.org/licenses/> for a copy.
|
33 |
|
|
//
|
34 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
35 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
36 |
|
|
//
|
37 |
|
|
//
|
38 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
39 |
|
|
//
|
40 |
|
|
//
|
41 |
|
|
`define NO_ZIP_WBU_DELAY
|
42 |
|
|
// `define ZIPCPU
|
43 |
|
|
`ifdef ZIPCPU
|
44 |
|
|
//`define ZIP_SYSTEM
|
45 |
|
|
`ifndef ZIP_SYSTEM
|
46 |
|
|
`define ZIP_BONES
|
47 |
|
|
`endif // ZIP_SYSTEM
|
48 |
|
|
`endif // ZipCPU
|
49 |
|
|
//
|
50 |
|
|
//
|
51 |
|
|
`define SDCARD_ACCESS
|
52 |
|
|
`define ETHERNET_ACCESS
|
53 |
|
|
`ifndef VERILATOR
|
54 |
|
|
`define ICAPE_ACCESS
|
55 |
|
|
`endif
|
56 |
|
|
`define FLASH_ACCESS
|
57 |
|
|
//`define SDRAM_ACCESS
|
58 |
|
|
`define GPS_CLOCK
|
59 |
|
|
// UART_ACCESS and GPS_UART have both been placed within fastio
|
60 |
|
|
// `define UART_ACCESS
|
61 |
|
|
// `define GPS_UART
|
62 |
|
|
`define RTC_ACCESS
|
63 |
|
|
`define OLEDRGB_ACCESS
|
64 |
|
|
//
|
65 |
|
|
// `define CPU_SCOPE
|
66 |
|
|
// `define GPS_SCOPE
|
67 |
|
|
`define FLASH_SCOPE
|
68 |
|
|
// `define SDRAM_SCOPE
|
69 |
|
|
// `define ENET_SCOPE
|
70 |
|
|
//
|
71 |
|
|
//
|
72 |
|
|
module fastmaster(i_clk, i_rst,
|
73 |
|
|
// CNC
|
74 |
|
|
i_rx_stb, i_rx_data, o_tx_stb, o_tx_data, i_tx_busy,
|
75 |
|
|
// Boad I/O
|
76 |
|
|
i_sw, i_btn, o_led,
|
77 |
|
|
o_clr_led0, o_clr_led1, o_clr_led2, o_clr_led3,
|
78 |
|
|
// PMod I/O
|
79 |
|
|
i_aux_rx, o_aux_tx, o_aux_cts, i_gps_rx, o_gps_tx,
|
80 |
|
|
// The Quad SPI Flash
|
81 |
|
|
o_qspi_cs_n, o_qspi_sck, o_qspi_dat, i_qspi_dat, o_qspi_mod,
|
82 |
|
|
// The DDR3 SDRAM
|
83 |
|
|
o_ddr_reset_n, o_ddr_cke,
|
84 |
|
|
o_ddr_cs_n, o_ddr_ras_n, o_ddr_cas_n, o_ddr_we_n,
|
85 |
|
|
o_ddr_dqs, o_ddr_addr, o_ddr_ba, o_ddr_data, i_ddr_data,
|
86 |
|
|
// The SD Card
|
87 |
|
|
o_sd_sck, o_sd_cmd, o_sd_data, i_sd_cmd, i_sd_data, i_sd_detect,
|
88 |
|
|
// Ethernet control (MDIO) lines
|
89 |
|
|
o_mdclk, o_mdio, o_mdwe, i_mdio,
|
90 |
|
|
// OLED Control interface (roughly SPI)
|
91 |
|
|
o_oled_sck, o_oled_cs_n, o_oled_mosi, o_oled_dcn,
|
92 |
|
|
o_oled_reset_n, o_oled_vccen, o_oled_pmoden,
|
93 |
|
|
// The GPS PMod
|
94 |
|
|
i_gps_pps, i_gps_3df
|
95 |
|
|
);
|
96 |
|
|
parameter ZA=24, ZIPINTS=13;
|
97 |
|
|
input i_clk, i_rst;
|
98 |
|
|
// The bus commander, via an external uart port
|
99 |
|
|
input i_rx_stb;
|
100 |
|
|
input [7:0] i_rx_data;
|
101 |
|
|
output wire o_tx_stb;
|
102 |
|
|
output wire [7:0] o_tx_data;
|
103 |
|
|
input i_tx_busy;
|
104 |
|
|
// I/O to/from board level devices
|
105 |
|
|
input [3:0] i_sw; // 16 switch bus
|
106 |
|
|
input [3:0] i_btn; // 5 Buttons
|
107 |
|
|
output wire [3:0] o_led; // 16 wide LED's
|
108 |
|
|
output wire [2:0] o_clr_led0, o_clr_led1, o_clr_led2, o_clr_led3;
|
109 |
|
|
// PMod UARTs
|
110 |
|
|
input i_aux_rx;
|
111 |
|
|
output wire o_aux_tx, o_aux_cts;
|
112 |
|
|
input i_gps_rx;
|
113 |
|
|
output wire o_gps_tx;
|
114 |
|
|
// Quad-SPI flash control
|
115 |
|
|
output wire o_qspi_cs_n, o_qspi_sck;
|
116 |
|
|
output wire [3:0] o_qspi_dat;
|
117 |
|
|
input [3:0] i_qspi_dat;
|
118 |
|
|
output wire [1:0] o_qspi_mod;
|
119 |
|
|
// DDR3 RAM controller
|
120 |
|
|
output wire o_ddr_reset_n, o_ddr_cke,
|
121 |
|
|
o_ddr_cs_n, o_ddr_ras_n, o_ddr_cas_n,o_ddr_we_n;
|
122 |
|
|
output wire [2:0] o_ddr_dqs;
|
123 |
|
|
output wire [13:0] o_ddr_addr;
|
124 |
|
|
output wire [2:0] o_ddr_ba;
|
125 |
|
|
output wire [31:0] o_ddr_data;
|
126 |
|
|
input [31:0] i_ddr_data;
|
127 |
|
|
// The SD Card
|
128 |
|
|
output wire o_sd_sck;
|
129 |
|
|
output wire o_sd_cmd;
|
130 |
|
|
output wire [3:0] o_sd_data;
|
131 |
|
|
input i_sd_cmd;
|
132 |
|
|
input [3:0] i_sd_data;
|
133 |
|
|
input i_sd_detect;
|
134 |
|
|
// Ethernet control (MDIO)
|
135 |
|
|
output wire o_mdclk, o_mdio, o_mdwe;
|
136 |
|
|
input i_mdio;
|
137 |
|
|
// OLEDRGB interface
|
138 |
|
|
output wire o_oled_sck, o_oled_cs_n, o_oled_mosi,
|
139 |
|
|
o_oled_dcn, o_oled_reset_n, o_oled_vccen,
|
140 |
|
|
o_oled_pmoden;
|
141 |
|
|
// GPS PMod (GPS UART above)
|
142 |
|
|
input i_gps_pps;
|
143 |
|
|
input i_gps_3df;
|
144 |
|
|
|
145 |
|
|
//
|
146 |
|
|
//
|
147 |
|
|
// Master wishbone wires
|
148 |
|
|
//
|
149 |
|
|
//
|
150 |
|
|
wire wb_cyc, wb_stb, wb_we, wb_stall, wb_err;
|
151 |
|
|
wire [31:0] wb_data, wb_addr;
|
152 |
|
|
reg wb_ack;
|
153 |
|
|
reg [31:0] wb_idata;
|
154 |
|
|
|
155 |
|
|
// Interrupts
|
156 |
|
|
wire gpio_int, oled_int, flash_int, scop_int;
|
157 |
|
|
wire enet_tx_int, enet_rx_int, sdcard_int, rtc_int, rtc_pps,
|
158 |
|
|
auxrx_int, auxtx_int, gpsrx_int, sw_int, btn_int;
|
159 |
|
|
|
160 |
|
|
//
|
161 |
|
|
//
|
162 |
|
|
// First BUS master source: The UART
|
163 |
|
|
//
|
164 |
|
|
//
|
165 |
|
|
wire [31:0] dwb_idata;
|
166 |
|
|
|
167 |
|
|
// Wires going to devices
|
168 |
|
|
wire wbu_cyc, wbu_stb, wbu_we;
|
169 |
|
|
wire [31:0] wbu_addr, wbu_data;
|
170 |
|
|
// and then coming from devices
|
171 |
|
|
wire wbu_ack, wbu_stall, wbu_err;
|
172 |
|
|
wire [31:0] wbu_idata;
|
173 |
|
|
// And then headed back home
|
174 |
|
|
wire w_interrupt;
|
175 |
|
|
// Oh, and the debug control for the ZIP CPU
|
176 |
|
|
wire wbu_zip_sel, zip_dbg_ack, zip_dbg_stall;
|
177 |
|
|
wire [31:0] zip_dbg_data;
|
178 |
|
|
wbubus genbus(i_clk, i_rx_stb, i_rx_data,
|
179 |
|
|
wbu_cyc, wbu_stb, wbu_we, wbu_addr, wbu_data,
|
180 |
|
|
(wbu_zip_sel)?zip_dbg_ack:wbu_ack,
|
181 |
|
|
(wbu_zip_sel)?zip_dbg_stall:wbu_stall,
|
182 |
|
|
wbu_err,
|
183 |
|
|
(wbu_zip_sel)?zip_dbg_data:wbu_idata,
|
184 |
|
|
w_interrupt,
|
185 |
|
|
o_tx_stb, o_tx_data, i_tx_busy);
|
186 |
|
|
|
187 |
|
|
// assign o_dbg = (wbu_ack)&&(wbu_cyc);
|
188 |
|
|
|
189 |
|
|
wire zip_cpu_int; // True if the CPU suddenly halts
|
190 |
|
|
`ifdef ZIPCPU
|
191 |
|
|
// Are we trying to access the ZipCPU? Such accesses must be special,
|
192 |
|
|
// because they must succeed regardless of whether or not the ZipCPU
|
193 |
|
|
// is on the bus. Hence, we trap them here.
|
194 |
|
|
assign wbu_zip_sel = (wbu_addr[27]);
|
195 |
|
|
|
196 |
|
|
//
|
197 |
|
|
//
|
198 |
|
|
// Second BUS master source: The ZipCPU
|
199 |
|
|
//
|
200 |
|
|
//
|
201 |
|
|
wire zip_cyc, zip_stb, zip_we;
|
202 |
|
|
wire [(ZA-1):0] w_zip_addr;
|
203 |
|
|
wire [31:0] zip_data, zip_scope_data;
|
204 |
|
|
// and then coming from devices
|
205 |
|
|
wire zip_ack, zip_stall, zip_err;
|
206 |
|
|
|
207 |
|
|
`ifdef ZIP_SYSTEM
|
208 |
|
|
wire [(ZIPINTS-1):0] zip_interrupt_vec = {
|
209 |
|
|
// Lazy(ier) interrupts
|
210 |
|
|
oled_int, gpio_int, rtc_int, scop_int, flash_int, sw_int, btn_int,
|
211 |
|
|
// Fast interrupts
|
212 |
|
|
sdcard_int, auxtx_int, auxrx_int, enet_tx_int, enet_rx_int,
|
213 |
|
|
gpsrx_int, rtc_pps
|
214 |
|
|
};
|
215 |
|
|
|
216 |
|
|
zipsystem #( .RESET_ADDRESS(24'h08000),
|
217 |
|
|
.ADDRESS_WIDTH(ZA),
|
218 |
|
|
.LGICACHE(10),
|
219 |
|
|
.START_HALTED(1),
|
220 |
|
|
.EXTERNAL_INTERRUPTS(ZIPINTS),
|
221 |
|
|
.HIGHSPEED_CPU(1))
|
222 |
|
|
zippy(i_clk, i_rst,
|
223 |
|
|
// Zippys wishbone interface
|
224 |
|
|
zip_cyc, zip_stb, zip_we, w_zip_addr, zip_data,
|
225 |
|
|
zip_ack, zip_stall, dwb_idata, zip_err,
|
226 |
|
|
zip_interrupt_vec, zip_cpu_int,
|
227 |
|
|
// Debug wishbone interface
|
228 |
|
|
((wbu_cyc)&&(wbu_zip_sel)),
|
229 |
|
|
((wbu_stb)&&(wbu_zip_sel)),wbu_we, wbu_addr[0],
|
230 |
|
|
wbu_data,
|
231 |
|
|
zip_dbg_ack, zip_dbg_stall, zip_dbg_data
|
232 |
|
|
`ifdef CPU_DEBUG
|
233 |
|
|
, zip_scope_data
|
234 |
|
|
`endif
|
235 |
|
|
);
|
236 |
|
|
`else // ZIP_SYSTEM
|
237 |
|
|
wire w_zip_cpu_int_ignored;
|
238 |
|
|
zipbones #( .RESET_ADDRESS(24'h08000),
|
239 |
|
|
.ADDRESS_WIDTH(ZA),
|
240 |
|
|
.LGICACHE(10),
|
241 |
|
|
.START_HALTED(1),
|
242 |
|
|
.HIGHSPEED_CPU(1))
|
243 |
|
|
zippy(i_clk, i_rst,
|
244 |
|
|
// Zippys wishbone interface
|
245 |
|
|
zip_cyc, zip_stb, zip_we, w_zip_addr, zip_data,
|
246 |
|
|
zip_ack, zip_stall, dwb_idata, zip_err,
|
247 |
|
|
w_interrupt, w_zip_cpu_int_ignored,
|
248 |
|
|
// Debug wishbone interface
|
249 |
|
|
((wbu_cyc)&&(wbu_zip_sel)),
|
250 |
|
|
((wbu_stb)&&(wbu_zip_sel)),wbu_we, wbu_addr[0],
|
251 |
|
|
wbu_data,
|
252 |
|
|
zip_dbg_ack, zip_dbg_stall, zip_dbg_data
|
253 |
|
|
`ifdef CPU_DEBUG
|
254 |
|
|
, zip_scope_data
|
255 |
|
|
`endif
|
256 |
|
|
);
|
257 |
|
|
assign zip_cpu_int = 1'b0;
|
258 |
|
|
`endif // ZIP_SYSTEM v ZIP_BONES
|
259 |
|
|
|
260 |
|
|
wire [31:0] zip_addr;
|
261 |
|
|
generate
|
262 |
|
|
if (ZA < 32)
|
263 |
|
|
assign zip_addr = { {(32-ZA){1'b0}}, w_zip_addr};
|
264 |
|
|
else
|
265 |
|
|
assign zip_addr = w_zip_addr;
|
266 |
|
|
endgenerate
|
267 |
|
|
|
268 |
|
|
//
|
269 |
|
|
//
|
270 |
|
|
// And an arbiter to decide who gets to access the bus
|
271 |
|
|
//
|
272 |
|
|
//
|
273 |
|
|
wire dwb_we, dwb_stb, dwb_cyc, dwb_ack, dwb_stall, dwb_err;
|
274 |
|
|
wire [31:0] dwb_addr, dwb_odata;
|
275 |
|
|
wbpriarbiter #(32,32) wbu_zip_arbiter(i_clk,
|
276 |
|
|
// The ZIP CPU Master -- Gets the priority slot
|
277 |
|
|
zip_cyc, zip_stb, zip_we, zip_addr, zip_data,
|
278 |
|
|
zip_ack, zip_stall, zip_err,
|
279 |
|
|
// The UART interface Master
|
280 |
|
|
(wbu_cyc)&&(~wbu_zip_sel), (wbu_stb)&&(~wbu_zip_sel), wbu_we,
|
281 |
|
|
wbu_addr, wbu_data,
|
282 |
|
|
wbu_ack, wbu_stall, wbu_err,
|
283 |
|
|
// Common bus returns
|
284 |
|
|
dwb_cyc, dwb_stb, dwb_we, dwb_addr, dwb_odata,
|
285 |
|
|
dwb_ack, dwb_stall, dwb_err);
|
286 |
|
|
|
287 |
|
|
//
|
288 |
|
|
//
|
289 |
|
|
// And because the ZIP CPU and the Arbiter create an unacceptable
|
290 |
|
|
// delay, we fail timing. So we add in a delay cycle ...
|
291 |
|
|
//
|
292 |
|
|
//
|
293 |
|
|
assign wbu_idata = dwb_idata;
|
294 |
|
|
busdelay wbu_zip_delay(i_clk,
|
295 |
|
|
dwb_cyc, dwb_stb, dwb_we, dwb_addr, dwb_odata,
|
296 |
|
|
dwb_ack, dwb_stall, dwb_idata, dwb_err,
|
297 |
|
|
wb_cyc, wb_stb, wb_we, wb_addr, wb_data,
|
298 |
|
|
wb_ack, wb_stall, wb_idata, wb_err);
|
299 |
|
|
|
300 |
|
|
`else // ZIPCPU
|
301 |
|
|
assign zip_cpu_int = 1'b0; // No CPU here to halt
|
302 |
|
|
assign wbu_zip_sel = 1'b0;
|
303 |
|
|
|
304 |
|
|
// If there's no ZipCPU, there's no need for a Zip/WB-Uart bus delay.
|
305 |
|
|
// We can go directly from the WB-Uart master bus to the master bus
|
306 |
|
|
// itself.
|
307 |
|
|
assign wb_cyc = wbu_cyc;
|
308 |
|
|
assign wb_stb = wbu_stb;
|
309 |
|
|
assign wb_we = wbu_we;
|
310 |
|
|
assign wb_addr = wbu_addr;
|
311 |
|
|
assign wb_data = wbu_data;
|
312 |
|
|
assign wbu_idata = wb_idata;
|
313 |
|
|
assign wbu_ack = wb_ack;
|
314 |
|
|
assign wbu_stall = wb_stall;
|
315 |
|
|
assign wbu_err = wb_err;
|
316 |
|
|
|
317 |
|
|
// The CPU never halts if it doesn't exist, so set this interrupt to
|
318 |
|
|
// zero.
|
319 |
|
|
assign zip_cpu_int= 1'b0;
|
320 |
|
|
`endif // ZIPCPU
|
321 |
|
|
|
322 |
|
|
|
323 |
|
|
//
|
324 |
|
|
// Peripheral select lines.
|
325 |
|
|
//
|
326 |
|
|
// These lines will be true during any wishbone cycle whose address
|
327 |
|
|
// line selects the given I/O peripheral. The none_sel and many_sel
|
328 |
|
|
// lines are used to detect problems, such as when no device is
|
329 |
|
|
// selected or many devices are selected. Such problems will lead to
|
330 |
|
|
// bus errors (below).
|
331 |
|
|
//
|
332 |
|
|
wire io_sel, scop_sel, netb_sel,
|
333 |
|
|
flctl_sel, rtc_sel, sdcard_sel, netp_sel,
|
334 |
|
|
oled_sel, gps_sel, mio_sel, cfg_sel,
|
335 |
|
|
mem_sel, flash_sel, ram_sel,
|
336 |
|
|
none_sel, many_sel;
|
337 |
|
|
|
338 |
|
|
wire [4:0] skipaddr;
|
339 |
|
|
assign skipaddr = { wb_addr[26], wb_addr[22], wb_addr[15], wb_addr[11],
|
340 |
|
|
~wb_addr[8] };
|
341 |
|
|
assign ram_sel = (skipaddr[4]);
|
342 |
|
|
assign flash_sel = (skipaddr[4:3]==2'b01);
|
343 |
|
|
assign mem_sel = (skipaddr[4:2]==3'b001);
|
344 |
|
|
assign netb_sel = (skipaddr[4:1]==4'b0001);
|
345 |
|
|
assign io_sel = (~|skipaddr)&&(wb_addr[7:5]==3'b000);
|
346 |
|
|
assign scop_sel = (~|skipaddr)&&(wb_addr[7:3]==5'b00100);
|
347 |
|
|
assign rtc_sel = (~|skipaddr)&&(wb_addr[7:2]==6'b001010);
|
348 |
|
|
assign sdcard_sel= (~|skipaddr)&&(wb_addr[7:2]==6'b001011);
|
349 |
|
|
assign netp_sel = (~|skipaddr)&&(wb_addr[7:2]==6'b001101);
|
350 |
|
|
assign oled_sel = (~|skipaddr)&&(wb_addr[7:2]==6'b001110);
|
351 |
|
|
assign gps_sel = (~|skipaddr)&&( (wb_addr[7:2]==6'b001100)
|
352 |
|
|
|| (wb_addr[7:3]==5'b01000));
|
353 |
|
|
assign mio_sel = (~|skipaddr)&&(wb_addr[7:5]==3'b101);
|
354 |
|
|
assign flctl_sel = (~|skipaddr)&&(wb_addr[7:5]==3'b110);
|
355 |
|
|
assign cfg_sel = (~|skipaddr)&&(wb_addr[7:5]==3'b111);
|
356 |
|
|
|
357 |
|
|
wire skiperr;
|
358 |
|
|
assign skiperr = (|wb_addr[31:27])
|
359 |
|
|
||(~skipaddr[4])&&(|wb_addr[25:23])
|
360 |
|
|
||(skipaddr[4:3]==2'b00)&&(|wb_addr[21:16])
|
361 |
|
|
||(skipaddr[4:2]==3'b000)&&(|wb_addr[14:12])
|
362 |
|
|
||(skipaddr[4:1]==4'b0000)&&(|wb_addr[10:9]);
|
363 |
|
|
|
364 |
|
|
|
365 |
|
|
//
|
366 |
|
|
// Peripheral acknowledgement lines
|
367 |
|
|
//
|
368 |
|
|
// These are only a touch more confusing, since the flash device will
|
369 |
|
|
// ACK for both flctl_sel (the control line select), as well as the
|
370 |
|
|
// flash_sel (the memory line select). Hence we have one fewer ack
|
371 |
|
|
// line.
|
372 |
|
|
wire io_ack, oled_ack,
|
373 |
|
|
rtc_ack, sdcard_ack,
|
374 |
|
|
netp_ack, gps_ack, mio_ack, cfg_ack, netb_ack,
|
375 |
|
|
mem_ack, flash_ack, ram_ack;
|
376 |
|
|
reg many_ack, slow_many_ack;
|
377 |
|
|
reg slow_ack, scop_ack;
|
378 |
|
|
wire [4:0] ack_list;
|
379 |
|
|
assign ack_list = { ram_ack, flash_ack, mem_ack, netb_ack, cfg_ack };
|
380 |
|
|
initial many_ack = 1'b0;
|
381 |
|
|
always @(posedge i_clk)
|
382 |
|
|
many_ack <= ((ack_list != 5'h10)
|
383 |
|
|
&&(ack_list != 5'h8)
|
384 |
|
|
&&(ack_list != 5'h4)
|
385 |
|
|
&&(ack_list != 5'h2)
|
386 |
|
|
&&(ack_list != 5'h1)
|
387 |
|
|
&&(ack_list != 5'h0));
|
388 |
|
|
/*
|
389 |
|
|
assign many_ack = ( { 2'h0, ram_ack}
|
390 |
|
|
+{2'h0, flash_ack }
|
391 |
|
|
+{2'h0, mem_ack }
|
392 |
|
|
+{2'h0, netb_ack }
|
393 |
|
|
+{2'h0, slow_ack } > 3'h1 );
|
394 |
|
|
*/
|
395 |
|
|
|
396 |
|
|
wire [7:0] slow_ack_list;
|
397 |
|
|
assign slow_ack_list = { mio_ack, gps_ack, netp_ack,
|
398 |
|
|
sdcard_ack, rtc_ack, scop_ack, oled_ack, io_ack };
|
399 |
|
|
initial slow_many_ack = 1'b0;
|
400 |
|
|
always @(posedge i_clk)
|
401 |
|
|
slow_many_ack <= ((slow_ack_list != 8'h80)
|
402 |
|
|
&&(slow_ack_list != 8'h40)
|
403 |
|
|
&&(slow_ack_list != 8'h20)
|
404 |
|
|
&&(slow_ack_list != 8'h10)
|
405 |
|
|
&&(slow_ack_list != 8'h08)
|
406 |
|
|
&&(slow_ack_list != 8'h04)
|
407 |
|
|
&&(slow_ack_list != 8'h02)
|
408 |
|
|
&&(slow_ack_list != 8'h01)
|
409 |
|
|
&&(slow_ack_list != 8'h00));
|
410 |
|
|
|
411 |
|
|
always @(posedge i_clk)
|
412 |
|
|
wb_ack <= (wb_cyc)&&(|{ ram_ack, flash_ack, mem_ack,
|
413 |
|
|
netb_ack, cfg_ack, slow_ack });
|
414 |
|
|
always @(posedge i_clk)
|
415 |
|
|
slow_ack <= (wb_cyc)&&(|{oled_ack, mio_ack, gps_ack,
|
416 |
|
|
netp_ack, sdcard_ack, rtc_ack, scop_ack,
|
417 |
|
|
oled_ack, io_ack});
|
418 |
|
|
|
419 |
|
|
//
|
420 |
|
|
// Peripheral data lines
|
421 |
|
|
//
|
422 |
|
|
wire [31:0] io_data, oled_data,
|
423 |
|
|
rtc_data, sdcard_data,
|
424 |
|
|
netp_data, gps_data, mio_data, cfg_data, netb_data,
|
425 |
|
|
mem_data, flash_data, ram_data;
|
426 |
|
|
reg [31:0] slow_data, scop_data;
|
427 |
|
|
|
428 |
|
|
// 4 control lines, 5x32 data lines ...
|
429 |
|
|
always @(posedge i_clk)
|
430 |
|
|
if ((ram_ack)||(flash_ack))
|
431 |
|
|
wb_idata <= (ram_ack)?ram_data:flash_data;
|
432 |
|
|
else if ((mem_ack)||(netb_ack))
|
433 |
|
|
wb_idata <= (mem_ack)?mem_data:netb_data;
|
434 |
|
|
else
|
435 |
|
|
wb_idata <= slow_data;
|
436 |
|
|
|
437 |
|
|
// 7 control lines, 8x32 data lines
|
438 |
|
|
always @(posedge i_clk)
|
439 |
|
|
if ((cfg_ack)||(mio_ack))
|
440 |
|
|
slow_data <= (cfg_ack) ? cfg_data : mio_data;
|
441 |
|
|
else if ((gps_ack)||(netp_ack))
|
442 |
|
|
slow_data <= (gps_ack) ? gps_data : netp_data;
|
443 |
|
|
else if ((sdcard_ack)||(rtc_ack))
|
444 |
|
|
slow_data <= (sdcard_ack)?sdcard_data : rtc_data;
|
445 |
|
|
else if ((scop_ack)|(oled_ack))
|
446 |
|
|
slow_data <= (scop_ack)?scop_data:oled_data;
|
447 |
|
|
else
|
448 |
|
|
slow_data <= io_data;
|
449 |
|
|
|
450 |
|
|
//
|
451 |
|
|
// Peripheral stall lines
|
452 |
|
|
//
|
453 |
|
|
// As per the wishbone spec, these cannot be clocked or delayed. They
|
454 |
|
|
// *must* be done via combinatorial logic.
|
455 |
|
|
//
|
456 |
|
|
wire io_stall, scop_stall, oled_stall,
|
457 |
|
|
rtc_stall, sdcard_stall,
|
458 |
|
|
netp_stall, gps_stall, mio_stall, cfg_stall, netb_stall,
|
459 |
|
|
mem_stall, flash_stall, ram_stall,
|
460 |
|
|
many_stall;
|
461 |
|
|
assign wb_stall = (wb_cyc)&&(
|
462 |
|
|
((io_sel)&&(io_stall)) // Never stalls
|
463 |
|
|
||((scop_sel)&&(scop_stall)) // Never stalls
|
464 |
|
|
||((rtc_sel)&&(rtc_stall)) // Never stalls
|
465 |
|
|
||((sdcard_sel)&&(sdcard_stall))// Never stalls
|
466 |
|
|
||((netp_sel)&&(netp_stall))
|
467 |
|
|
||((gps_sel)&&(gps_stall)) //(maybe? never stalls?)
|
468 |
|
|
||((oled_sel)&&(oled_stall))
|
469 |
|
|
||((mio_sel)&&(mio_stall))
|
470 |
|
|
||((cfg_sel)&&(cfg_stall))
|
471 |
|
|
||((netb_sel)&&(netb_stall)) // Never stalls
|
472 |
|
|
||((mem_sel)&&(mem_stall)) // Never stalls
|
473 |
|
|
||((flash_sel|flctl_sel)&&(flash_stall))
|
474 |
|
|
||((ram_sel)&&(ram_stall)));
|
475 |
|
|
|
476 |
|
|
|
477 |
|
|
//
|
478 |
|
|
// Bus Error calculation(s)
|
479 |
|
|
//
|
480 |
|
|
|
481 |
|
|
// Selecting nothing is only an error if the strobe line is high as well
|
482 |
|
|
// as the cycle line. However, this is captured within the wb_err
|
483 |
|
|
// logic itself, so we can ignore it for a line or two.
|
484 |
|
|
assign none_sel = ( //(skiperr)||
|
485 |
|
|
(~|{ io_sel, scop_sel, flctl_sel, rtc_sel,
|
486 |
|
|
sdcard_sel, netp_sel, gps_sel,
|
487 |
|
|
oled_sel,
|
488 |
|
|
mio_sel, cfg_sel, netb_sel, mem_sel,
|
489 |
|
|
flash_sel,ram_sel }));
|
490 |
|
|
//
|
491 |
|
|
// Selecting multiple devices at once is a design flaw that should
|
492 |
|
|
// never happen. Hence, if this logic won't build, we won't include
|
493 |
|
|
// it. Still, having this logic in place has saved my tush more than
|
494 |
|
|
// once.
|
495 |
|
|
//
|
496 |
|
|
reg [31:0] sel_addr;
|
497 |
|
|
always @(posedge i_clk)
|
498 |
|
|
sel_addr <= wb_addr;
|
499 |
|
|
|
500 |
|
|
reg many_sel_a, many_sel_b, single_sel_a, single_sel_b, last_stb;
|
501 |
|
|
always @(posedge i_clk)
|
502 |
|
|
begin
|
503 |
|
|
last_stb <= wb_stb;
|
504 |
|
|
|
505 |
|
|
single_sel_a <= (wb_stb)&&((ram_sel)|(flash_sel)
|
506 |
|
|
|(mem_sel)|(netb_sel)|(cfg_sel));
|
507 |
|
|
many_sel_a <= 1'b0;
|
508 |
|
|
if ((ram_sel)&&((flash_sel)||(mem_sel)||(netb_sel)||cfg_sel))
|
509 |
|
|
many_sel_a <= 1'b1;
|
510 |
|
|
else if ((flash_sel)&&((mem_sel)||(netb_sel)||cfg_sel))
|
511 |
|
|
many_sel_a <= 1'b1;
|
512 |
|
|
else if ((mem_sel)&&((netb_sel)||cfg_sel))
|
513 |
|
|
many_sel_a <= 1'b1;
|
514 |
|
|
else if ((netb_sel)&&(cfg_sel))
|
515 |
|
|
many_sel_a <= 1'b1;
|
516 |
|
|
|
517 |
|
|
single_sel_b <= (wb_stb)&&((mio_sel)||(gps_sel)||(netp_sel)
|
518 |
|
|
||(sdcard_sel)||(rtc_sel)||(flctl_sel)
|
519 |
|
|
||(oled_sel)||(scop_sel)||(io_sel));
|
520 |
|
|
many_sel_b <= 1'b0;
|
521 |
|
|
if ((mio_sel)&&((gps_sel)||(netp_sel)||(sdcard_sel)||(rtc_sel)
|
522 |
|
|
||(flctl_sel)||(scop_sel)||(oled_sel)||(io_sel)))
|
523 |
|
|
many_sel_b <= 1'b1;
|
524 |
|
|
else if ((gps_sel)&&((netp_sel)||(sdcard_sel)||(rtc_sel)
|
525 |
|
|
||(flctl_sel)||(scop_sel)||(oled_sel)||(io_sel)))
|
526 |
|
|
many_sel_b <= 1'b1;
|
527 |
|
|
else if ((netp_sel)&&((sdcard_sel)||(rtc_sel)
|
528 |
|
|
||(flctl_sel)||(scop_sel)||(oled_sel)||(io_sel)))
|
529 |
|
|
many_sel_b <= 1'b1;
|
530 |
|
|
else if ((sdcard_sel)&&((rtc_sel)
|
531 |
|
|
||(flctl_sel)||(scop_sel)||(oled_sel)||(io_sel)))
|
532 |
|
|
many_sel_b <= 1'b1;
|
533 |
|
|
else if ((rtc_sel)&&((flctl_sel)||(scop_sel)||(oled_sel)||(io_sel)))
|
534 |
|
|
many_sel_b <= 1'b1;
|
535 |
|
|
else if ((flctl_sel)&&((scop_sel)||(oled_sel)||(io_sel)))
|
536 |
|
|
many_sel_b <= 1'b1;
|
537 |
|
|
else if ((scop_sel)&&((oled_sel)||(io_sel)))
|
538 |
|
|
many_sel_b <= 1'b1;
|
539 |
|
|
else if ((oled_sel)&&(io_sel))
|
540 |
|
|
many_sel_b <= 1'b1;
|
541 |
|
|
end
|
542 |
|
|
|
543 |
|
|
wire sel_err; // 5 inputs
|
544 |
|
|
assign sel_err = ( (last_stb)&&(~single_sel_a)&&(~single_sel_b))
|
545 |
|
|
||((single_sel_a)&&(single_sel_b))
|
546 |
|
|
||((single_sel_a)&&(many_sel_a))
|
547 |
|
|
||((single_sel_b)&&(many_sel_b));
|
548 |
|
|
assign wb_err = (wb_cyc)&&(sel_err || many_ack || slow_many_ack);
|
549 |
|
|
|
550 |
|
|
|
551 |
|
|
// Finally, if we ever encounter a bus error, knowing the address of
|
552 |
|
|
// the error will be important to figuring out how to fix it. Hence,
|
553 |
|
|
// we grab it here. Be aware, however, that this might not truly be
|
554 |
|
|
// the address that caused an error: in the case of none_sel it will
|
555 |
|
|
// be, but if many_ack or slow_many_ack are true then we might just be
|
556 |
|
|
// looking at an address on the bus that was nearby the one requested.
|
557 |
|
|
reg [31:0] bus_err_addr;
|
558 |
|
|
initial bus_err_addr = 32'h00;
|
559 |
|
|
always @(posedge i_clk)
|
560 |
|
|
if (wb_err)
|
561 |
|
|
bus_err_addr <= sel_addr;
|
562 |
|
|
|
563 |
|
|
//
|
564 |
|
|
// I/O peripheral
|
565 |
|
|
//
|
566 |
|
|
// The I/O processor, herein called an fastio. This is a unique
|
567 |
|
|
// set of peripherals--these are all of the peripherals that can answer
|
568 |
|
|
// in a single clock--or, rather, they are the peripherals that can
|
569 |
|
|
// answer the bus before their clock. Hence, the fastio simply consists
|
570 |
|
|
// of a mux that selects between various peripheral responses. Further,
|
571 |
|
|
// these peripherals are not allowed to stall the bus.
|
572 |
|
|
//
|
573 |
|
|
// There is no option for turning these off--they will always be on.
|
574 |
|
|
wire [8:0] master_ints;
|
575 |
|
|
assign master_ints = { zip_cpu_int, oled_int, rtc_int, sdcard_int,
|
576 |
|
|
enet_tx_int, enet_rx_int,
|
577 |
|
|
scop_int, flash_int, rtc_pps };
|
578 |
|
|
wire [5:0] board_ints;
|
579 |
|
|
wire [3:0] w_led;
|
580 |
|
|
wire rtc_ppd;
|
581 |
|
|
fastio #(
|
582 |
|
|
.AUXUART_SETUP(30'hd50),
|
583 |
|
|
.GPSUART_SETUP(30'hd20833)
|
584 |
|
|
) runio(i_clk, i_sw, i_btn,
|
585 |
|
|
w_led, o_clr_led0, o_clr_led1, o_clr_led2, o_clr_led3,
|
586 |
|
|
i_aux_rx, o_aux_tx, o_aux_cts, i_gps_rx, o_gps_tx,
|
587 |
|
|
wb_cyc, (io_sel)&&(wb_stb), wb_we, wb_addr[4:0],
|
588 |
|
|
wb_data, io_ack, io_stall, io_data,
|
589 |
|
|
rtc_ppd,
|
590 |
|
|
bus_err_addr, master_ints, w_interrupt,
|
591 |
|
|
board_ints);
|
592 |
|
|
assign { gpio_int, auxrx_int, auxtx_int, gpsrx_int, sw_int, btn_int } = board_ints;
|
593 |
|
|
|
594 |
|
|
/*
|
595 |
|
|
reg [25:0] dbg_counter_err, dbg_counter_cyc, dbg_counter_sel,
|
596 |
|
|
dbg_counter_many;
|
597 |
|
|
// assign wb_err = (wb_cyc)&&(sel_err || many_ack || slow_many_ack);
|
598 |
|
|
always @(posedge i_clk)
|
599 |
|
|
if (wbu_cyc)
|
600 |
|
|
dbg_counter_cyc <= 0;
|
601 |
|
|
else if (!dbg_counter_cyc[25])
|
602 |
|
|
dbg_counter_cyc <= dbg_counter_cyc+26'h1;
|
603 |
|
|
always @(posedge i_clk)
|
604 |
|
|
if (wbu_err)
|
605 |
|
|
dbg_counter_err <= 0;
|
606 |
|
|
else if (!dbg_counter_err[25])
|
607 |
|
|
dbg_counter_err <= dbg_counter_err+26'h1;
|
608 |
|
|
always @(posedge i_clk)
|
609 |
|
|
if ((wb_cyc)&&(sel_err))
|
610 |
|
|
dbg_counter_sel <= 0;
|
611 |
|
|
else if (!dbg_counter_sel[25])
|
612 |
|
|
dbg_counter_sel <= dbg_counter_sel+26'h1;
|
613 |
|
|
always @(posedge i_clk)
|
614 |
|
|
if ((wb_cyc)&&(many_ack))
|
615 |
|
|
dbg_counter_many <= 0;
|
616 |
|
|
else if (!dbg_counter_many[25])
|
617 |
|
|
dbg_counter_many <= dbg_counter_many+26'h1;
|
618 |
|
|
assign o_led = {
|
619 |
|
|
(!dbg_counter_many[25])|w_led[3],
|
620 |
|
|
(!dbg_counter_sel[25])|w_led[2],
|
621 |
|
|
(!dbg_counter_cyc[25])|w_led[1],
|
622 |
|
|
(!dbg_counter_err[25])|w_led[0] };
|
623 |
|
|
*/
|
624 |
|
|
assign o_led = w_led;
|
625 |
|
|
|
626 |
|
|
|
627 |
|
|
//
|
628 |
|
|
//
|
629 |
|
|
// Real Time Clock (RTC) device level access
|
630 |
|
|
//
|
631 |
|
|
//
|
632 |
|
|
wire gps_tracking, ck_pps;
|
633 |
|
|
wire [63:0] gps_step;
|
634 |
|
|
`ifdef RTC_ACCESS
|
635 |
|
|
rtcgps #(32'h15798f) // 2^48 / 200MHz
|
636 |
|
|
thertc(i_clk,
|
637 |
|
|
wb_cyc, (wb_stb)&&(rtc_sel), wb_we,
|
638 |
|
|
wb_addr[1:0], wb_data,
|
639 |
|
|
rtc_data, rtc_int, rtc_ppd,
|
640 |
|
|
gps_tracking, ck_pps, gps_step[47:16], rtc_pps);
|
641 |
|
|
`else
|
642 |
|
|
assign rtc_data = 32'h00;
|
643 |
|
|
assign rtc_int = 1'b0;
|
644 |
|
|
assign rtc_pps = 1'b0;
|
645 |
|
|
assign rtc_ppd = 1'b0;
|
646 |
|
|
`endif
|
647 |
|
|
reg r_rtc_ack;
|
648 |
|
|
initial r_rtc_ack = 1'b0;
|
649 |
|
|
always @(posedge i_clk)
|
650 |
|
|
r_rtc_ack <= (wb_stb)&&(rtc_sel);
|
651 |
|
|
assign rtc_ack = r_rtc_ack;
|
652 |
|
|
assign rtc_stall = 1'b0;
|
653 |
|
|
|
654 |
|
|
//
|
655 |
|
|
//
|
656 |
|
|
// SDCard device level access
|
657 |
|
|
//
|
658 |
|
|
//
|
659 |
|
|
`ifdef SDCARD_ACCESS
|
660 |
|
|
wire [31:0] sd_dbg;
|
661 |
|
|
// SPI mapping
|
662 |
|
|
wire w_sd_cs_n, w_sd_mosi, w_sd_miso;
|
663 |
|
|
|
664 |
|
|
sdspi sdctrl(i_clk,
|
665 |
|
|
wb_cyc, (wb_stb)&&(sdcard_sel), wb_we,
|
666 |
|
|
wb_addr[1:0], wb_data,
|
667 |
|
|
sdcard_ack, sdcard_stall, sdcard_data,
|
668 |
|
|
w_sd_cs_n, o_sd_sck, w_sd_mosi, w_sd_miso,
|
669 |
|
|
sdcard_int, 1'b1, sd_dbg);
|
670 |
|
|
assign w_sd_miso = i_sd_data[0];
|
671 |
|
|
assign o_sd_data = { w_sd_cs_n, 3'b111 };
|
672 |
|
|
assign o_sd_cmd = w_sd_mosi;
|
673 |
|
|
`else
|
674 |
|
|
reg r_sdcard_ack;
|
675 |
|
|
always @(posedge i_clk)
|
676 |
|
|
r_sdcard_ack <= (wb_stb)&&(sdcard_sel);
|
677 |
|
|
assign sdcard_ack = r_sdcard_ack;
|
678 |
|
|
|
679 |
|
|
assign sdcard_data = 32'h00;
|
680 |
|
|
assign sdcard_stall= 1'b0;
|
681 |
|
|
assign sdcard_int = 1'b0;
|
682 |
|
|
`endif
|
683 |
|
|
|
684 |
|
|
//
|
685 |
|
|
//
|
686 |
|
|
// OLEDrgb device control
|
687 |
|
|
//
|
688 |
|
|
//
|
689 |
|
|
`ifdef OLEDRGB_ACCESS
|
690 |
|
|
wboled rgbctrl(i_clk,
|
691 |
|
|
wb_cyc, (wb_stb)&&(oled_sel), wb_we,
|
692 |
|
|
wb_addr[1:0], wb_data,
|
693 |
|
|
oled_ack, oled_stall, oled_data,
|
694 |
|
|
o_oled_sck, o_oled_cs_n, o_oled_mosi, o_oled_dcn,
|
695 |
|
|
{ o_oled_reset_n, o_oled_vccen, o_oled_pmoden },
|
696 |
|
|
oled_int);
|
697 |
|
|
`else
|
698 |
|
|
assign o_oled_cs_n = 1'b1;
|
699 |
|
|
assign o_oled_sck = 1'b1;
|
700 |
|
|
assign o_oled_mosi = 1'b1;
|
701 |
|
|
assign o_oled_dcn = 1'b1;
|
702 |
|
|
assign o_oled_reset_n = 1'b0;
|
703 |
|
|
assign o_oled_vccen = 1'b0;
|
704 |
|
|
assign o_oled_pmoden = 1'b0;
|
705 |
|
|
|
706 |
|
|
reg r_oled_ack;
|
707 |
|
|
always @(posedge i_clk)
|
708 |
|
|
r_oled_ack <= (wb_stb)&&(oled_sel);
|
709 |
|
|
assign oled_ack = r_oled_ack;
|
710 |
|
|
|
711 |
|
|
assign oled_data = 32'h00;
|
712 |
|
|
assign oled_stall= 1'b0;
|
713 |
|
|
assign oled_int = 1'b0;
|
714 |
|
|
`endif
|
715 |
|
|
|
716 |
|
|
//
|
717 |
|
|
//
|
718 |
|
|
// GPS CLOCK CONTROLS, BOTH THE TEST BENCH AND THE CLOCK ITSELF
|
719 |
|
|
//
|
720 |
|
|
//
|
721 |
|
|
wire [63:0] gps_now, gps_err;
|
722 |
|
|
wire [31:0] gck_data, gtb_data;
|
723 |
|
|
wire gck_ack, gck_stall, gtb_ack, gtb_stall;
|
724 |
|
|
`ifdef GPS_CLOCK
|
725 |
|
|
//
|
726 |
|
|
// GPS CLOCK SCHOOL TESTING
|
727 |
|
|
//
|
728 |
|
|
wire gps_pps, tb_pps, gps_locked;
|
729 |
|
|
wire [1:0] gps_dbg_tick;
|
730 |
|
|
|
731 |
|
|
gpsclock_tb ppscktb(i_clk, ck_pps, tb_pps,
|
732 |
|
|
(wb_stb)&&(gps_sel)&&(wb_addr[3]),
|
733 |
|
|
wb_we, wb_addr[2:0],
|
734 |
|
|
wb_data, gtb_ack, gtb_stall, gtb_data,
|
735 |
|
|
gps_err, gps_now, gps_step);
|
736 |
|
|
`ifdef GPSTB
|
737 |
|
|
assign gps_pps = tb_pps; // Let the truth come from our test bench
|
738 |
|
|
`else
|
739 |
|
|
assign gps_pps = i_gps_pps;
|
740 |
|
|
`endif
|
741 |
|
|
wire gps_led;
|
742 |
|
|
|
743 |
|
|
//
|
744 |
|
|
// GPS CLOCK CONTROL
|
745 |
|
|
//
|
746 |
|
|
gpsclock ppsck(i_clk, 1'b0, gps_pps, ck_pps, gps_led,
|
747 |
|
|
(wb_stb)&&(gps_sel)&&(~wb_addr[3]),
|
748 |
|
|
wb_we, wb_addr[1:0],
|
749 |
|
|
wb_data, gck_ack, gck_stall, gck_data,
|
750 |
|
|
gps_tracking, gps_now, gps_step, gps_err, gps_locked,
|
751 |
|
|
gps_dbg_tick);
|
752 |
|
|
`else
|
753 |
|
|
|
754 |
|
|
assign gps_err = 64'h0;
|
755 |
|
|
assign gps_now = 64'h0;
|
756 |
|
|
assign gck_data = 32'h0;
|
757 |
|
|
assign gtb_data = 32'h0;
|
758 |
|
|
assign gtb_stall = 1'b0;
|
759 |
|
|
assign gck_stall = 1'b0;
|
760 |
|
|
assign ck_pps = 1'b0;
|
761 |
|
|
|
762 |
|
|
assign gps_tracking = 1'b0;
|
763 |
|
|
// Appropriate step for a 200MHz clock
|
764 |
|
|
assign gps_step = { 16'h00, 32'h015798e, 16'h00 };
|
765 |
|
|
|
766 |
|
|
reg r_gck_ack;
|
767 |
|
|
always @(posedge i_clk)
|
768 |
|
|
r_gck_ack <= (wb_stb)&&(gps_sel);
|
769 |
|
|
assign gck_ack = r_gck_ack;
|
770 |
|
|
assign gtb_ack = r_gck_ack;
|
771 |
|
|
|
772 |
|
|
`endif
|
773 |
|
|
|
774 |
|
|
assign gps_ack = (gck_ack | gtb_ack);
|
775 |
|
|
assign gps_stall = (gck_stall | gtb_stall);
|
776 |
|
|
assign gps_data = (gck_ack) ? gck_data : gtb_data;
|
777 |
|
|
|
778 |
|
|
|
779 |
|
|
//
|
780 |
|
|
// ETHERNET DEVICE ACCESS
|
781 |
|
|
//
|
782 |
|
|
`ifdef ETHERNET_ACCESS
|
783 |
|
|
reg r_mio_ack, r_netb_ack, r_netp_ack;
|
784 |
|
|
always @(posedge i_clk)
|
785 |
|
|
r_mio_ack <= (wb_stb)&&(mio_sel);
|
786 |
|
|
always @(posedge i_clk)
|
787 |
|
|
r_netp_ack <= (wb_stb)&&(netp_sel);
|
788 |
|
|
assign mio_ack = r_mio_ack;
|
789 |
|
|
assign netp_ack = r_netp_ack;
|
790 |
|
|
|
791 |
|
|
assign mio_data = 32'h00;
|
792 |
|
|
assign netp_data = 32'h00;
|
793 |
|
|
assign mio_stall = 1'b0;
|
794 |
|
|
assign netp_stall= 1'b0;
|
795 |
|
|
assign enet_rx_int = 1'b0;
|
796 |
|
|
assign enet_tx_int = 1'b0;
|
797 |
|
|
|
798 |
|
|
enetctrl #(3)
|
799 |
|
|
mdio(i_clk, i_rst, wb_cyc, (wb_stb)&&(netb_sel), wb_we,
|
800 |
|
|
wb_addr[4:0], wb_data[15:0],
|
801 |
|
|
netb_ack, netb_stall, netb_data,
|
802 |
|
|
o_mdclk, o_mdio, i_mdio, o_mdwe);
|
803 |
|
|
`else
|
804 |
|
|
reg r_mio_ack, r_netb_ack, r_netp_ack;
|
805 |
|
|
always @(posedge i_clk)
|
806 |
|
|
r_mio_ack <= (wb_stb)&&(mio_sel);
|
807 |
|
|
always @(posedge i_clk)
|
808 |
|
|
r_netp_ack <= (wb_stb)&&(netp_sel);
|
809 |
|
|
assign mio_ack = r_mio_ack;
|
810 |
|
|
assign netp_ack = r_netp_ack;
|
811 |
|
|
|
812 |
|
|
assign mio_data = 32'h00;
|
813 |
|
|
assign netp_data = 32'h00;
|
814 |
|
|
assign mio_stall = 1'b0;
|
815 |
|
|
assign netp_stall= 1'b0;
|
816 |
|
|
assign enet_rx_int = 1'b0;
|
817 |
|
|
assign enet_tx_int = 1'b0;
|
818 |
|
|
|
819 |
|
|
//
|
820 |
|
|
// 2kW memory, 1kW for each of transmit and receive. (Max pkt length
|
821 |
|
|
// is 512W, so this allows for two 512W in memory.) Since we don't
|
822 |
|
|
// really have ethernet without ETHERNET_ACCESS defined, this just
|
823 |
|
|
// consumes resources for us so we have an idea of what might be
|
824 |
|
|
// available when we do have ETHERNET_ACCESS defined.
|
825 |
|
|
//
|
826 |
|
|
memdev #(11) enet_buffers(i_clk, wb_cyc, (wb_stb)&&(netb_sel), wb_we,
|
827 |
|
|
wb_addr[10:0], wb_data, netb_ack, netb_stall, netb_data);
|
828 |
|
|
assign o_mdclk = 1'b1;
|
829 |
|
|
assign o_mdio = 1'b1;
|
830 |
|
|
assign o_mdwe = 1'b1;
|
831 |
|
|
|
832 |
|
|
`endif
|
833 |
|
|
|
834 |
|
|
|
835 |
|
|
//
|
836 |
|
|
// MULTIBOOT/ICAPE2 CONFIGURATION ACCESS
|
837 |
|
|
//
|
838 |
|
|
`ifdef ICAPE_ACCESS
|
839 |
|
|
wbicapetwo fpga_cfg(i_clk, wb_cyc,(cfg_sel)&&(wb_stb), wb_we,
|
840 |
|
|
wb_addr[4:0], wb_data,
|
841 |
|
|
cfg_ack, cfg_stall, cfg_data);
|
842 |
|
|
`else
|
843 |
|
|
reg r_cfg_ack;
|
844 |
|
|
always @(posedge i_clk)
|
845 |
|
|
r_cfg_ack <= (cfg_sel)&&(wb_stb);
|
846 |
|
|
assign cfg_ack = r_cfg_ack;
|
847 |
|
|
assign cfg_stall = 1'b0;
|
848 |
|
|
assign cfg_data = 32'h00;
|
849 |
|
|
`endif
|
850 |
|
|
|
851 |
|
|
//
|
852 |
|
|
// RAM MEMORY ACCESS
|
853 |
|
|
//
|
854 |
|
|
// There is no option to turn this off--this RAM must always be
|
855 |
|
|
// present in the design.
|
856 |
|
|
memdev #(15) // 32kW, or 128kB, 15 address lines
|
857 |
|
|
blkram(i_clk, wb_cyc, (wb_stb)&&(mem_sel), wb_we, wb_addr[14:0],
|
858 |
|
|
wb_data, mem_ack, mem_stall, mem_data);
|
859 |
|
|
|
860 |
|
|
//
|
861 |
|
|
// FLASH MEMORY ACCESS
|
862 |
|
|
//
|
863 |
|
|
`ifdef FLASH_ACCESS
|
864 |
|
|
`ifdef FLASH_SCOPE
|
865 |
|
|
wire [31:0] flash_debug;
|
866 |
|
|
`endif
|
867 |
|
|
wire w_ignore_cmd_accepted;
|
868 |
|
|
eqspiflash flashmem(i_clk, i_rst,
|
869 |
|
|
wb_cyc,(wb_stb)&&(flash_sel),(wb_stb)&&(flctl_sel),wb_we,
|
870 |
|
|
wb_addr[21:0], wb_data,
|
871 |
|
|
flash_ack, flash_stall, flash_data,
|
872 |
|
|
o_qspi_sck, o_qspi_cs_n, o_qspi_mod, o_qspi_dat, i_qspi_dat,
|
873 |
|
|
flash_int, w_ignore_cmd_accepted
|
874 |
|
|
`ifdef FLASH_SCOPE
|
875 |
|
|
, flash_debug
|
876 |
|
|
`endif
|
877 |
|
|
);
|
878 |
|
|
`else
|
879 |
|
|
assign o_qspi_sck = 1'b1;
|
880 |
|
|
assign o_qspi_cs_n= 1'b1;
|
881 |
|
|
assign o_qspi_mod = 2'b01;
|
882 |
|
|
assign o_qspi_dat = 4'h0;
|
883 |
|
|
assign flash_data = 32'h00;
|
884 |
|
|
assign flash_stall = 1'b0;
|
885 |
|
|
assign flash_int = 1'b0;
|
886 |
|
|
|
887 |
|
|
reg r_flash_ack;
|
888 |
|
|
always @(posedge i_clk)
|
889 |
|
|
r_flash_ack <= (wb_stb)&&(flash_sel);
|
890 |
|
|
assign flash_ack = r_flash_ack;
|
891 |
|
|
`endif
|
892 |
|
|
|
893 |
|
|
|
894 |
|
|
//
|
895 |
|
|
//
|
896 |
|
|
// DDR3-SDRAM
|
897 |
|
|
//
|
898 |
|
|
//
|
899 |
|
|
`ifdef SDRAM_ACCESS
|
900 |
|
|
wbddrsdram rami(i_clk,
|
901 |
|
|
wb_cyc, (wb_stb)&&(ram_sel), wb_we, wb_addr[25:0], wb_data,
|
902 |
|
|
ram_ack, ram_stall, ram_data,
|
903 |
|
|
o_ddr_reset_n, o_ddr_cke,
|
904 |
|
|
o_ddr_cs_n, o_ddr_ras_n, o_ddr_cas_n, o_ddr_we_n,
|
905 |
|
|
o_ddr_dqs,
|
906 |
|
|
o_ddr_addr, o_ddr_ba, o_ddr_data, i_ddr_data);
|
907 |
|
|
`else
|
908 |
|
|
assign ram_data = 32'h00;
|
909 |
|
|
assign ram_stall = 1'b0;
|
910 |
|
|
reg r_ram_ack;
|
911 |
|
|
always @(posedge i_clk)
|
912 |
|
|
r_ram_ack <= (wb_stb)&&(ram_sel);
|
913 |
|
|
assign ram_ack = r_ram_ack;
|
914 |
|
|
|
915 |
|
|
// And idle the DDR3 SDRAM
|
916 |
|
|
assign o_ddr_reset_n = 1'b0; // Leave the SDRAM in reset
|
917 |
|
|
assign o_ddr_cke = 1'b0; // Disable the SDRAM clock
|
918 |
|
|
// DQS
|
919 |
|
|
assign o_ddr_dqs = 3'b100; // Leave DQS pins in high impedence
|
920 |
|
|
// DDR3 control wires (not enabled if CKE=0)
|
921 |
|
|
assign o_ddr_cs_n = 1'b0; // NOOP command
|
922 |
|
|
assign o_ddr_ras_n = 1'b1;
|
923 |
|
|
assign o_ddr_cas_n = 1'b1;
|
924 |
|
|
assign o_ddr_we_n = 1'b1;
|
925 |
|
|
// (Unused) data wires
|
926 |
|
|
assign o_ddr_addr = 14'h00;
|
927 |
|
|
assign o_ddr_ba = 3'h0;
|
928 |
|
|
assign o_ddr_data = 32'h00;
|
929 |
|
|
`endif
|
930 |
|
|
|
931 |
|
|
|
932 |
|
|
//
|
933 |
|
|
//
|
934 |
|
|
// WISHBONE SCOPES
|
935 |
|
|
//
|
936 |
|
|
//
|
937 |
|
|
//
|
938 |
|
|
//
|
939 |
|
|
wire [31:0] scop_a_data;
|
940 |
|
|
wire scop_a_ack, scop_a_stall, scop_a_interrupt;
|
941 |
|
|
`ifdef CPU_SCOPE
|
942 |
|
|
wire [31:0] scop_cpu_data;
|
943 |
|
|
wire scop_cpu_ack, scop_cpu_stall, scop_cpu_interrupt;
|
944 |
|
|
wire scop_cpu_trigger;
|
945 |
|
|
// assign scop_cpu_trigger = zip_scope_data[30];
|
946 |
|
|
assign scop_cpu_trigger = (wb_stb)&&(mem_sel)&&(~wb_we)
|
947 |
|
|
&&(wb_err)||(zip_scope_data[31]);
|
948 |
|
|
wbscope #(5'd13) cpuscope(i_clk, 1'b1,(scop_cpu_trigger), zip_scope_data,
|
949 |
|
|
// Wishbone interface
|
950 |
|
|
i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b00)), wb_we, wb_addr[0],
|
951 |
|
|
wb_data,
|
952 |
|
|
scop_cpu_ack, scop_cpu_stall, scop_cpu_data,
|
953 |
|
|
scop_cpu_interrupt);
|
954 |
|
|
|
955 |
|
|
assign scop_a_data = scop_cpu_data;
|
956 |
|
|
assign scop_a_ack = scop_cpu_ack;
|
957 |
|
|
assign scop_a_stall = scop_cpu_stall;
|
958 |
|
|
assign scop_a_interrupt = scop_cpu_interrupt;
|
959 |
|
|
`else
|
960 |
|
|
`ifdef FLASH_SCOPE
|
961 |
|
|
wire [31:0] scop_flash_data;
|
962 |
|
|
wire scop_flash_ack, scop_flash_stall, scop_flash_interrupt;
|
963 |
|
|
wire scop_flash_trigger;
|
964 |
|
|
// assign scop_cpu_trigger = zip_scope_data[30];
|
965 |
|
|
assign scop_flash_trigger = (wb_stb)&&((flash_sel)||(flctl_sel));
|
966 |
|
|
wbscope #(5'd13) flashscope(i_clk, 1'b1,
|
967 |
|
|
(scop_flash_trigger), flash_debug,
|
968 |
|
|
// Wishbone interface
|
969 |
|
|
i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b00)), wb_we, wb_addr[0],
|
970 |
|
|
wb_data,
|
971 |
|
|
scop_flash_ack, scop_flash_stall, scop_flash_data,
|
972 |
|
|
scop_flash_interrupt);
|
973 |
|
|
|
974 |
|
|
assign scop_a_data = scop_flash_data;
|
975 |
|
|
assign scop_a_ack = scop_flash_ack;
|
976 |
|
|
assign scop_a_stall = scop_flash_stall;
|
977 |
|
|
assign scop_a_interrupt = scop_flash_interrupt;
|
978 |
|
|
`else
|
979 |
|
|
reg r_scop_a_ack;
|
980 |
|
|
always @(posedge i_clk)
|
981 |
|
|
r_scop_a_ack <= (wb_stb)&&(scop_sel)&&(wb_addr[2:1] == 2'b00);
|
982 |
|
|
assign scop_a_data = 32'h00;
|
983 |
|
|
assign scop_a_ack = r_scop_a_ack;
|
984 |
|
|
assign scop_a_stall = 1'b0;
|
985 |
|
|
assign scop_a_interrupt = 1'b0;
|
986 |
|
|
`endif
|
987 |
|
|
`endif
|
988 |
|
|
|
989 |
|
|
wire [31:0] scop_b_data;
|
990 |
|
|
wire scop_b_ack, scop_b_stall, scop_b_interrupt;
|
991 |
|
|
`ifdef GPS_SCOPE
|
992 |
|
|
reg [18:0] r_gps_debug;
|
993 |
|
|
wire [31:0] scop_gps_data;
|
994 |
|
|
wire scop_gps_ack, scop_gps_stall, scop_gps_interrupt;
|
995 |
|
|
always @(posedge i_clk)
|
996 |
|
|
r_gps_debug <= {
|
997 |
|
|
gps_dbg_tick, gps_tracking, gps_locked,
|
998 |
|
|
gpu_data[7:0],
|
999 |
|
|
// (wb_cyc)&&(wb_stb)&&(io_sel),
|
1000 |
|
|
(wb_stb)&&(io_sel)&&(wb_addr[4:3]==2'b11)&&(wb_we),
|
1001 |
|
|
(wb_stb)&&(gps_sel)&&(wb_addr[3:2]==2'b01),
|
1002 |
|
|
gpu_int,
|
1003 |
|
|
i_gps_rx, rtc_pps, ck_pps, i_gps_pps };
|
1004 |
|
|
wbscopc #(5'd13,19,32,1) gpsscope(i_clk, 1'b1, ck_pps, r_gps_debug,
|
1005 |
|
|
// Wishbone interface
|
1006 |
|
|
i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b01)),
|
1007 |
|
|
wb_we, wb_addr[0], wb_data,
|
1008 |
|
|
scop_gps_ack, scop_gps_stall, scop_gps_data,
|
1009 |
|
|
scop_gps_interrupt);
|
1010 |
|
|
`else
|
1011 |
|
|
assign scop_b_data = 32'h00;
|
1012 |
|
|
assign scop_b_stall = 1'b0;
|
1013 |
|
|
assign scop_b_interrupt = 1'b0;
|
1014 |
|
|
|
1015 |
|
|
reg r_scop_b_ack;
|
1016 |
|
|
always @(posedge i_clk)
|
1017 |
|
|
r_scop_b_ack <= (wb_stb)&&(scop_sel)&&(wb_addr[2:1] == 2'b01);
|
1018 |
|
|
assign scop_b_ack = r_scop_b_ack;
|
1019 |
|
|
`endif
|
1020 |
|
|
|
1021 |
|
|
//
|
1022 |
|
|
// SCOPE C
|
1023 |
|
|
//
|
1024 |
|
|
wire [31:0] scop_c_data;
|
1025 |
|
|
wire scop_c_ack, scop_c_stall, scop_c_interrupt;
|
1026 |
|
|
//
|
1027 |
|
|
//`else
|
1028 |
|
|
assign scop_c_data = 32'h00;
|
1029 |
|
|
assign scop_c_stall = 1'b0;
|
1030 |
|
|
assign scop_c_interrupt = 1'b0;
|
1031 |
|
|
|
1032 |
|
|
reg r_scop_c_ack;
|
1033 |
|
|
always @(posedge i_clk)
|
1034 |
|
|
r_scop_c_ack <= (wb_stb)&&(scop_sel)&&(wb_addr[2:1] == 2'b10);
|
1035 |
|
|
assign scop_c_ack = r_scop_c_ack;
|
1036 |
|
|
//`endif
|
1037 |
|
|
|
1038 |
|
|
//
|
1039 |
|
|
// SCOPE D
|
1040 |
|
|
//
|
1041 |
|
|
wire [31:0] scop_d_data;
|
1042 |
|
|
wire scop_d_ack, scop_d_stall, scop_d_interrupt;
|
1043 |
|
|
//
|
1044 |
|
|
//`else
|
1045 |
|
|
assign scop_d_data = 32'h00;
|
1046 |
|
|
assign scop_d_stall = 1'b0;
|
1047 |
|
|
assign scop_d_interrupt = 1'b0;
|
1048 |
|
|
|
1049 |
|
|
reg r_scop_d_ack;
|
1050 |
|
|
always @(posedge i_clk)
|
1051 |
|
|
r_scop_d_ack <= (wb_stb)&&(scop_sel)&&(wb_addr[2:1] == 2'b11);
|
1052 |
|
|
assign scop_d_ack = r_scop_d_ack;
|
1053 |
|
|
//`endif
|
1054 |
|
|
|
1055 |
|
|
assign scop_int = scop_a_interrupt
|
1056 |
|
|
|| scop_b_interrupt
|
1057 |
|
|
|| scop_c_interrupt
|
1058 |
|
|
|| scop_d_interrupt;
|
1059 |
|
|
assign scop_stall = ((wb_addr[2:1]==2'b0)?scop_a_stall
|
1060 |
|
|
: ((wb_addr[2:1]==2'b01)?scop_b_stall
|
1061 |
|
|
: ((wb_addr[2:1]==2'b11)?scop_c_stall
|
1062 |
|
|
: scop_d_stall))); // Will always be 1'b0;
|
1063 |
|
|
initial scop_ack = 1'b0;
|
1064 |
|
|
always @(posedge i_clk)
|
1065 |
|
|
scop_ack <= scop_a_ack | scop_b_ack | scop_c_ack | scop_d_ack;
|
1066 |
|
|
always @(posedge i_clk)
|
1067 |
|
|
if (scop_a_ack)
|
1068 |
|
|
scop_data <= scop_a_data;
|
1069 |
|
|
else if (scop_b_ack)
|
1070 |
|
|
scop_data <= scop_b_data;
|
1071 |
|
|
else if (scop_c_ack)
|
1072 |
|
|
scop_data <= scop_c_data;
|
1073 |
|
|
else // if (scop_d_ack)
|
1074 |
|
|
scop_data <= scop_d_data;
|
1075 |
|
|
|
1076 |
|
|
endmodule
|