1 |
3 |
dgisselq |
///////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// Filename: zipsystem.v
|
4 |
|
|
//
|
5 |
|
|
// Project: Zip CPU -- a small, lightweight, RISC CPU soft core
|
6 |
|
|
//
|
7 |
|
|
// Purpose: This portion of the ZIP CPU implements a number of soft
|
8 |
|
|
// peripherals to the CPU nearby its CORE. The functionality
|
9 |
|
|
// sits on the data bus, and does not include any true
|
10 |
|
|
// external hardware peripherals. The peripherals included here
|
11 |
|
|
// include:
|
12 |
|
|
//
|
13 |
|
|
//
|
14 |
|
|
// Local interrupt controller--for any/all of the interrupts generated
|
15 |
|
|
// here. This would include a pin for interrupts generated
|
16 |
|
|
// elsewhere, so this interrupt controller could be a master
|
17 |
|
|
// handling all interrupts. My interrupt controller would work
|
18 |
|
|
// for this purpose.
|
19 |
|
|
//
|
20 |
|
|
// The ZIP-CPU supports only one interrupt because, as I understand
|
21 |
|
|
// modern systems (Linux), they tend to send all interrupts to the
|
22 |
|
|
// same interrupt vector anyway. Hence, that's what we do here.
|
23 |
|
|
//
|
24 |
|
|
// Bus Error interrupts -- generates an interrupt any time the wishbone
|
25 |
|
|
// bus produces an error on a given access, for whatever purpose
|
26 |
|
|
// also records the address on the bus at the time of the error.
|
27 |
|
|
//
|
28 |
|
|
// Trap instructions
|
29 |
|
|
// Writing to this "register" will always create an interrupt.
|
30 |
|
|
// After the interrupt, this register may be read to see what
|
31 |
|
|
// value had been written to it.
|
32 |
|
|
//
|
33 |
|
|
// Bit reverse register ... ?
|
34 |
|
|
//
|
35 |
|
|
// (Potentially an eventual floating point co-processor ...)
|
36 |
|
|
//
|
37 |
|
|
// Real-time clock
|
38 |
|
|
//
|
39 |
|
|
// Interval timer(s) (Count down from fixed value, and either stop on
|
40 |
|
|
// zero, or issue an interrupt and restart automatically on zero)
|
41 |
|
|
// These can be implemented as watchdog timers if desired--the
|
42 |
|
|
// only difference is that a watchdog timer's interrupt feeds the
|
43 |
|
|
// reset line instead of the processor interrupt line.
|
44 |
|
|
//
|
45 |
|
|
// Watch-dog timer: this is the same as an interval timer, only it's
|
46 |
|
|
// interrupt/time-out line is wired to the reset line instead of
|
47 |
|
|
// the interrupt line of the CPU.
|
48 |
|
|
//
|
49 |
|
|
// ROM Memory map
|
50 |
|
|
// Set a register to control this map, and a DMA will begin to
|
51 |
|
|
// fill this memory from a slower FLASH. Once filled, accesses
|
52 |
|
|
// will be from this memory instead of
|
53 |
|
|
//
|
54 |
|
|
//
|
55 |
|
|
// Doing some market comparison, let's look at what peripherals a TI
|
56 |
|
|
// MSP430 might offer: MSP's may have I2C ports, SPI, UART, DMA, ADC,
|
57 |
|
|
// Comparators, 16,32-bit timers, 16x16 or 32x32 timers, AES, BSL,
|
58 |
|
|
// brown-out-reset(s), real-time-clocks, temperature sensors, USB ports,
|
59 |
|
|
// Spi-Bi-Wire, UART Boot-strap Loader (BSL), programmable digital I/O,
|
60 |
|
|
// watchdog-timers,
|
61 |
|
|
//
|
62 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
63 |
|
|
// Gisselquist Technology, LLC
|
64 |
|
|
//
|
65 |
|
|
///////////////////////////////////////////////////////////////////////////
|
66 |
|
|
//
|
67 |
|
|
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
|
68 |
|
|
//
|
69 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
70 |
|
|
// modify it under the terms of the GNU General Public License as published
|
71 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
72 |
|
|
// your option) any later version.
|
73 |
|
|
//
|
74 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
75 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
76 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
77 |
|
|
// for more details.
|
78 |
|
|
//
|
79 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
80 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
81 |
|
|
//
|
82 |
|
|
//
|
83 |
|
|
///////////////////////////////////////////////////////////////////////////
|
84 |
|
|
//
|
85 |
|
|
`include "cpudefs.v"
|
86 |
|
|
//
|
87 |
|
|
// While I hate adding delays to any bus access, this next delay is required
|
88 |
|
|
// to make timing close in my Basys-3 design.
|
89 |
|
|
`define DELAY_DBG_BUS
|
90 |
|
|
// On my previous version, I needed to add a delay to access the external
|
91 |
|
|
// bus. Activate the define below and that delay will be put back into place.
|
92 |
|
|
// This particular version no longer needs the delay in order to run at
|
93 |
|
|
// 100 MHz. Timing indicates I may even run this at 250 MHz without the
|
94 |
|
|
// delay too, so we're doing better. To get rid of this, I placed the logic
|
95 |
|
|
// determining whether or not I was accessing the local system bus one clock
|
96 |
|
|
// earlier, or into the memops.v file. This also required my wishbone bus
|
97 |
|
|
// arbiter to maintain the bus selection as well, so that got updated ...
|
98 |
|
|
// you get the picture. But, the bottom line is that I no longer need this
|
99 |
|
|
// delay.
|
100 |
|
|
//
|
101 |
|
|
// `define DELAY_EXT_BUS // Required no longer!
|
102 |
|
|
//
|
103 |
|
|
//
|
104 |
|
|
// If space is tight, you might not wish to have your performance and
|
105 |
|
|
// accounting counters, so let's make those optional here
|
106 |
|
|
// Without this flag, Slice LUT count is 3315 (ZipSystem),2432 (ZipCPU)
|
107 |
|
|
// When including counters,
|
108 |
|
|
// Slice LUTs ZipSystem ZipCPU
|
109 |
|
|
// With Counters 3315 2432
|
110 |
|
|
// Without Counters 2796 2046
|
111 |
|
|
|
112 |
|
|
//
|
113 |
|
|
// Now, where am I placing all of my peripherals?
|
114 |
|
|
`define PERIPHBASE 32'hc0000000
|
115 |
|
|
`define INTCTRL 5'h0 //
|
116 |
|
|
`define WATCHDOG 5'h1 // Interrupt generates reset signal
|
117 |
|
|
`define BUSWATCHDOG 5'h2 // Sets IVEC[0]
|
118 |
|
|
`define CTRINT 5'h3 // Sets IVEC[5]
|
119 |
|
|
`define TIMER_A 5'h4 // Sets IVEC[4]
|
120 |
|
|
`define TIMER_B 5'h5 // Sets IVEC[3]
|
121 |
|
|
`define TIMER_C 5'h6 // Sets IVEC[2]
|
122 |
|
|
`define JIFFIES 5'h7 // Sets IVEC[1]
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
`ifdef INCLUDE_ACCOUNTING_COUNTERS
|
126 |
|
|
`define MSTR_TASK_CTR 5'h08
|
127 |
|
|
`define MSTR_MSTL_CTR 5'h09
|
128 |
|
|
`define MSTR_PSTL_CTR 5'h0a
|
129 |
|
|
`define MSTR_INST_CTR 5'h0b
|
130 |
|
|
`define USER_TASK_CTR 5'h0c
|
131 |
|
|
`define USER_MSTL_CTR 5'h0d
|
132 |
|
|
`define USER_PSTL_CTR 5'h0e
|
133 |
|
|
`define USER_INST_CTR 5'h0f
|
134 |
|
|
`endif
|
135 |
|
|
|
136 |
|
|
// Although I have a hole at 5'h2, the DMA controller requires four wishbone
|
137 |
|
|
// addresses, therefore we place it by itself and expand our address bus
|
138 |
|
|
// width here by another bit.
|
139 |
|
|
`define DMAC 5'h10
|
140 |
|
|
|
141 |
|
|
// `define RTC_CLOCK 32'hc0000008 // A global something
|
142 |
|
|
// `define BITREV 32'hc0000003
|
143 |
|
|
//
|
144 |
|
|
// DBGCTRL
|
145 |
|
|
// 10 HALT
|
146 |
|
|
// 9 HALT(ED)
|
147 |
|
|
// 8 STEP (W=1 steps, and returns to halted)
|
148 |
|
|
// 7 INTERRUPT-FLAG
|
149 |
|
|
// 6 RESET_FLAG
|
150 |
|
|
// ADDRESS:
|
151 |
|
|
// 5 PERIPHERAL-BIT
|
152 |
|
|
// [4:0] REGISTER-ADDR
|
153 |
|
|
// DBGDATA
|
154 |
|
|
// read/writes internal registers
|
155 |
|
|
//
|
156 |
|
|
//
|
157 |
|
|
//
|
158 |
|
|
module zipsystem(i_clk, i_rst,
|
159 |
|
|
// Wishbone master interface from the CPU
|
160 |
|
|
o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data,
|
161 |
|
|
i_wb_ack, i_wb_stall, i_wb_data, i_wb_err,
|
162 |
|
|
// Incoming interrupts
|
163 |
|
|
i_ext_int,
|
164 |
|
|
// Our one outgoing interrupt
|
165 |
|
|
o_ext_int,
|
166 |
|
|
// Wishbone slave interface for debugging purposes
|
167 |
|
|
i_dbg_cyc, i_dbg_stb, i_dbg_we, i_dbg_addr, i_dbg_data,
|
168 |
|
|
o_dbg_ack, o_dbg_stall, o_dbg_data
|
169 |
|
|
`ifdef DEBUG_SCOPE
|
170 |
|
|
, o_cpu_debug
|
171 |
|
|
`endif
|
172 |
|
|
);
|
173 |
|
|
parameter RESET_ADDRESS=24'h0100000, ADDRESS_WIDTH=24,
|
174 |
|
|
LGICACHE=10, START_HALTED=1, EXTERNAL_INTERRUPTS=1,
|
175 |
|
|
`ifdef OPT_MULTIPLY
|
176 |
|
|
IMPLEMENT_MPY = `OPT_MULTIPLY,
|
177 |
|
|
`else
|
178 |
|
|
IMPLEMENT_MPY = 0,
|
179 |
|
|
`endif
|
180 |
|
|
`ifdef OPT_DIVIDE
|
181 |
|
|
IMPLEMENT_DIVIDE=1,
|
182 |
|
|
`else
|
183 |
|
|
IMPLEMENT_DIVIDE=0,
|
184 |
|
|
`endif
|
185 |
|
|
`ifdef OPT_IMPLEMENT_FPU
|
186 |
|
|
IMPLEMENT_FPU=1,
|
187 |
|
|
`else
|
188 |
|
|
IMPLEMENT_FPU=0,
|
189 |
|
|
`endif
|
190 |
|
|
IMPLEMENT_LOCK=1,
|
191 |
|
|
HIGHSPEED_CPU=0,
|
192 |
|
|
// Derived parameters
|
193 |
|
|
AW=ADDRESS_WIDTH;
|
194 |
|
|
input i_clk, i_rst;
|
195 |
|
|
// Wishbone master
|
196 |
|
|
output wire o_wb_cyc, o_wb_stb, o_wb_we;
|
197 |
|
|
output wire [(AW-1):0] o_wb_addr;
|
198 |
|
|
output wire [31:0] o_wb_data;
|
199 |
|
|
input i_wb_ack, i_wb_stall;
|
200 |
|
|
input [31:0] i_wb_data;
|
201 |
|
|
input i_wb_err;
|
202 |
|
|
// Incoming interrupts
|
203 |
|
|
input [(EXTERNAL_INTERRUPTS-1):0] i_ext_int;
|
204 |
|
|
// Outgoing interrupt
|
205 |
|
|
output wire o_ext_int;
|
206 |
|
|
// Wishbone slave
|
207 |
|
|
input i_dbg_cyc, i_dbg_stb, i_dbg_we, i_dbg_addr;
|
208 |
|
|
input [31:0] i_dbg_data;
|
209 |
|
|
output wire o_dbg_ack;
|
210 |
|
|
output wire o_dbg_stall;
|
211 |
|
|
output wire [31:0] o_dbg_data;
|
212 |
|
|
//
|
213 |
|
|
`ifdef DEBUG_SCOPE
|
214 |
|
|
output wire [31:0] o_cpu_debug;
|
215 |
|
|
`endif
|
216 |
|
|
|
217 |
|
|
wire [31:0] ext_idata;
|
218 |
|
|
|
219 |
|
|
// Handle our interrupt vector generation/coordination
|
220 |
|
|
wire [14:0] main_int_vector, alt_int_vector;
|
221 |
|
|
wire ctri_int, tma_int, tmb_int, tmc_int, jif_int, dmac_int;
|
222 |
|
|
wire mtc_int, moc_int, mpc_int, mic_int,
|
223 |
|
|
utc_int, uoc_int, upc_int, uic_int;
|
224 |
|
|
generate
|
225 |
|
|
if (EXTERNAL_INTERRUPTS < 9)
|
226 |
|
|
assign main_int_vector = { {(9-EXTERNAL_INTERRUPTS){1'b0}},
|
227 |
|
|
i_ext_int, ctri_int,
|
228 |
|
|
tma_int, tmb_int, tmc_int,
|
229 |
|
|
jif_int, dmac_int };
|
230 |
|
|
else
|
231 |
|
|
assign main_int_vector = { i_ext_int[8:0], ctri_int,
|
232 |
|
|
tma_int, tmb_int, tmc_int,
|
233 |
|
|
jif_int, dmac_int };
|
234 |
|
|
endgenerate
|
235 |
|
|
generate
|
236 |
|
|
if (EXTERNAL_INTERRUPTS <= 9)
|
237 |
|
|
`ifdef INCLUDE_ACCOUNTING_COUNTERS
|
238 |
|
|
assign alt_int_vector = { 7'h00,
|
239 |
|
|
mtc_int, moc_int, mpc_int, mic_int,
|
240 |
|
|
utc_int, uoc_int, upc_int, uic_int };
|
241 |
|
|
`else
|
242 |
|
|
assign alt_int_vector = { 15'h00 };
|
243 |
|
|
`endif
|
244 |
|
|
else
|
245 |
|
|
`ifdef INCLUDE_ACCOUNTING_COUNTERS
|
246 |
|
|
assign alt_int_vector = { {(7-(EXTERNAL_INTERRUPTS-9)){1'b0}},
|
247 |
|
|
i_ext_int[(EXTERNAL_INTERRUPTS-1):9],
|
248 |
|
|
mtc_int, moc_int, mpc_int, mic_int,
|
249 |
|
|
utc_int, uoc_int, upc_int, uic_int };
|
250 |
|
|
`else
|
251 |
|
|
assign alt_int_vector = { {(15-(EXTERNAL_INTERRUPTS-9)){1'b0}},
|
252 |
|
|
i_ext_int[(EXTERNAL_INTERRUPTS-1):9] };
|
253 |
|
|
`endif
|
254 |
|
|
endgenerate
|
255 |
|
|
|
256 |
|
|
|
257 |
|
|
// Delay the debug port by one clock, to meet timing requirements
|
258 |
|
|
wire dbg_cyc, dbg_stb, dbg_we, dbg_addr, dbg_stall;
|
259 |
|
|
wire [31:0] dbg_idata, dbg_odata;
|
260 |
|
|
reg dbg_ack;
|
261 |
|
|
`ifdef DELAY_DBG_BUS
|
262 |
|
|
wire dbg_err, no_dbg_err;
|
263 |
|
|
assign dbg_err = 1'b0;
|
264 |
|
|
busdelay #(1,32) wbdelay(i_clk,
|
265 |
|
|
i_dbg_cyc, i_dbg_stb, i_dbg_we, i_dbg_addr, i_dbg_data,
|
266 |
|
|
o_dbg_ack, o_dbg_stall, o_dbg_data, no_dbg_err,
|
267 |
|
|
dbg_cyc, dbg_stb, dbg_we, dbg_addr, dbg_idata,
|
268 |
|
|
dbg_ack, dbg_stall, dbg_odata, dbg_err);
|
269 |
|
|
`else
|
270 |
|
|
assign dbg_cyc = i_dbg_cyc;
|
271 |
|
|
assign dbg_stb = i_dbg_stb;
|
272 |
|
|
assign dbg_we = i_dbg_we;
|
273 |
|
|
assign dbg_addr = i_dbg_addr;
|
274 |
|
|
assign dbg_idata = i_dbg_data;
|
275 |
|
|
assign o_dbg_ack = dbg_ack;
|
276 |
|
|
assign o_dbg_stall = dbg_stall;
|
277 |
|
|
assign o_dbg_data = dbg_odata;
|
278 |
|
|
`endif
|
279 |
|
|
|
280 |
|
|
//
|
281 |
|
|
//
|
282 |
|
|
//
|
283 |
|
|
wire sys_cyc, sys_stb, sys_we;
|
284 |
|
|
wire [4:0] sys_addr;
|
285 |
|
|
wire [(AW-1):0] cpu_addr;
|
286 |
|
|
wire [31:0] sys_data;
|
287 |
|
|
wire sys_ack, sys_stall;
|
288 |
|
|
|
289 |
|
|
//
|
290 |
|
|
// The external debug interface
|
291 |
|
|
//
|
292 |
|
|
// We offer only a limited interface here, requiring a pre-register
|
293 |
|
|
// write to set the local address. This interface allows access to
|
294 |
|
|
// the Zip System on a debug basis only, and not to the rest of the
|
295 |
|
|
// wishbone bus. Further, to access these registers, the control
|
296 |
|
|
// register must first be accessed to both stop the CPU and to
|
297 |
|
|
// set the following address in question. Hence all accesses require
|
298 |
|
|
// two accesses: write the address to the control register (and halt
|
299 |
|
|
// the CPU if not halted), then read/write the data from the data
|
300 |
|
|
// register.
|
301 |
|
|
//
|
302 |
|
|
wire cpu_break, dbg_cmd_write;
|
303 |
|
|
reg cmd_reset, cmd_halt, cmd_step, cmd_clear_pf_cache;
|
304 |
|
|
reg [5:0] cmd_addr;
|
305 |
|
|
wire [3:0] cpu_dbg_cc;
|
306 |
|
|
assign dbg_cmd_write = (dbg_cyc)&&(dbg_stb)&&(dbg_we)&&(~dbg_addr);
|
307 |
|
|
//
|
308 |
|
|
initial cmd_reset = 1'b1;
|
309 |
|
|
always @(posedge i_clk)
|
310 |
|
|
cmd_reset <= ((dbg_cmd_write)&&(dbg_idata[6]));
|
311 |
|
|
//
|
312 |
|
|
initial cmd_halt = START_HALTED;
|
313 |
|
|
always @(posedge i_clk)
|
314 |
|
|
if (i_rst)
|
315 |
|
|
cmd_halt <= (START_HALTED == 1)? 1'b1 : 1'b0;
|
316 |
|
|
else if (dbg_cmd_write)
|
317 |
|
|
cmd_halt <= ((dbg_idata[10])||(dbg_idata[8]));
|
318 |
|
|
else if ((cmd_step)||(cpu_break))
|
319 |
|
|
cmd_halt <= 1'b1;
|
320 |
|
|
|
321 |
|
|
initial cmd_clear_pf_cache = 1'b0;
|
322 |
|
|
always @(posedge i_clk)
|
323 |
|
|
cmd_clear_pf_cache = (~i_rst)&&(dbg_cmd_write)
|
324 |
|
|
&&((dbg_idata[11])||(dbg_idata[6]));
|
325 |
|
|
//
|
326 |
|
|
initial cmd_step = 1'b0;
|
327 |
|
|
always @(posedge i_clk)
|
328 |
|
|
cmd_step <= (dbg_cmd_write)&&(dbg_idata[8]);
|
329 |
|
|
//
|
330 |
|
|
always @(posedge i_clk)
|
331 |
|
|
if (dbg_cmd_write)
|
332 |
|
|
cmd_addr <= dbg_idata[5:0];
|
333 |
|
|
|
334 |
|
|
wire cpu_reset;
|
335 |
|
|
assign cpu_reset = (cmd_reset)||(wdt_reset)||(i_rst);
|
336 |
|
|
|
337 |
|
|
wire cpu_halt, cpu_dbg_stall;
|
338 |
|
|
assign cpu_halt = (i_rst)||((cmd_halt)&&(~cmd_step));
|
339 |
|
|
wire [31:0] pic_data;
|
340 |
|
|
wire [31:0] cmd_data;
|
341 |
|
|
// Values:
|
342 |
|
|
// 0x0003f -> cmd_addr mask
|
343 |
|
|
// 0x00040 -> reset
|
344 |
|
|
// 0x00080 -> PIC interrrupt pending
|
345 |
|
|
// 0x00100 -> cmd_step
|
346 |
|
|
// 0x00200 -> cmd_stall
|
347 |
|
|
// 0x00400 -> cmd_halt
|
348 |
|
|
// 0x00800 -> cmd_clear_pf_cache
|
349 |
|
|
// 0x01000 -> cc.sleep
|
350 |
|
|
// 0x02000 -> cc.gie
|
351 |
|
|
// 0x04000 -> External (PIC) interrupt line is high
|
352 |
|
|
// Other external interrupts follow
|
353 |
|
|
generate
|
354 |
|
|
if (EXTERNAL_INTERRUPTS < 16)
|
355 |
|
|
assign cmd_data = { {(16-EXTERNAL_INTERRUPTS){1'b0}},
|
356 |
|
|
i_ext_int,
|
357 |
|
|
cpu_dbg_cc, // 4 bits
|
358 |
|
|
1'b0, cmd_halt, (~cpu_dbg_stall), 1'b0,
|
359 |
|
|
pic_data[15], cpu_reset, cmd_addr };
|
360 |
|
|
else
|
361 |
|
|
assign cmd_data = { i_ext_int[15:0], cpu_dbg_cc,
|
362 |
|
|
1'b0, cmd_halt, (~cpu_dbg_stall), 1'b0,
|
363 |
|
|
pic_data[15], cpu_reset, cmd_addr };
|
364 |
|
|
endgenerate
|
365 |
|
|
|
366 |
|
|
wire cpu_gie;
|
367 |
|
|
assign cpu_gie = cpu_dbg_cc[1];
|
368 |
|
|
|
369 |
|
|
//
|
370 |
|
|
// The WATCHDOG Timer
|
371 |
|
|
//
|
372 |
|
|
wire wdt_ack, wdt_stall, wdt_reset;
|
373 |
|
|
wire [31:0] wdt_data;
|
374 |
|
|
ziptimer #(32,31,0)
|
375 |
|
|
watchdog(i_clk, cpu_reset, ~cmd_halt,
|
376 |
|
|
sys_cyc, ((sys_stb)&&(sys_addr == `WATCHDOG)), sys_we,
|
377 |
|
|
sys_data,
|
378 |
|
|
wdt_ack, wdt_stall, wdt_data, wdt_reset);
|
379 |
|
|
|
380 |
|
|
//
|
381 |
|
|
// Position two, a second watchdog timer--this time for the wishbone
|
382 |
|
|
// bus, in order to tell/find wishbone bus lockups. In its current
|
383 |
|
|
// configuration, it cannot be configured and all bus accesses must
|
384 |
|
|
// take less than the number written to this register.
|
385 |
|
|
//
|
386 |
|
|
reg wdbus_ack;
|
387 |
|
|
reg [(AW-1):0] r_wdbus_data;
|
388 |
|
|
wire [31:0] wdbus_data;
|
389 |
|
|
wire [14:0] wdbus_ignored_data;
|
390 |
|
|
wire reset_wdbus_timer, wdbus_int;
|
391 |
|
|
assign reset_wdbus_timer = ((o_wb_cyc)&&((o_wb_stb)||(i_wb_ack)));
|
392 |
|
|
wbwatchdog #(14) watchbus(i_clk,(cpu_reset)||(reset_wdbus_timer),
|
393 |
|
|
o_wb_cyc, 14'h2000, wdbus_int);
|
394 |
|
|
initial r_wdbus_data = 0;
|
395 |
|
|
always @(posedge i_clk)
|
396 |
|
|
if ((wdbus_int)||(cpu_ext_err))
|
397 |
|
|
r_wdbus_data = o_wb_addr;
|
398 |
|
|
assign wdbus_data = { {(32-AW){1'b0}}, r_wdbus_data };
|
399 |
|
|
initial wdbus_ack = 1'b0;
|
400 |
|
|
always @(posedge i_clk)
|
401 |
|
|
wdbus_ack <= ((sys_cyc)&&(sys_stb)&&(sys_addr == 5'h02));
|
402 |
|
|
|
403 |
|
|
// Counters -- for performance measurement and accounting
|
404 |
|
|
//
|
405 |
|
|
// Here's the stuff we'll be counting ....
|
406 |
|
|
//
|
407 |
|
|
wire cpu_op_stall, cpu_pf_stall, cpu_i_count;
|
408 |
|
|
|
409 |
|
|
`ifdef INCLUDE_ACCOUNTING_COUNTERS
|
410 |
|
|
//
|
411 |
|
|
// The master counters will, in general, not be reset. They'll be used
|
412 |
|
|
// for an overall counter.
|
413 |
|
|
//
|
414 |
|
|
// Master task counter
|
415 |
|
|
wire mtc_ack, mtc_stall;
|
416 |
|
|
wire [31:0] mtc_data;
|
417 |
|
|
zipcounter mtask_ctr(i_clk, (~cpu_halt), sys_cyc,
|
418 |
|
|
(sys_stb)&&(sys_addr == `MSTR_TASK_CTR),
|
419 |
|
|
sys_we, sys_data,
|
420 |
|
|
mtc_ack, mtc_stall, mtc_data, mtc_int);
|
421 |
|
|
|
422 |
|
|
// Master Operand Stall counter
|
423 |
|
|
wire moc_ack, moc_stall;
|
424 |
|
|
wire [31:0] moc_data;
|
425 |
|
|
zipcounter mmstall_ctr(i_clk,(cpu_op_stall), sys_cyc,
|
426 |
|
|
(sys_stb)&&(sys_addr == `MSTR_MSTL_CTR),
|
427 |
|
|
sys_we, sys_data,
|
428 |
|
|
moc_ack, moc_stall, moc_data, moc_int);
|
429 |
|
|
|
430 |
|
|
// Master PreFetch-Stall counter
|
431 |
|
|
wire mpc_ack, mpc_stall;
|
432 |
|
|
wire [31:0] mpc_data;
|
433 |
|
|
zipcounter mpstall_ctr(i_clk,(cpu_pf_stall), sys_cyc,
|
434 |
|
|
(sys_stb)&&(sys_addr == `MSTR_PSTL_CTR),
|
435 |
|
|
sys_we, sys_data,
|
436 |
|
|
mpc_ack, mpc_stall, mpc_data, mpc_int);
|
437 |
|
|
|
438 |
|
|
// Master Instruction counter
|
439 |
|
|
wire mic_ack, mic_stall;
|
440 |
|
|
wire [31:0] mic_data;
|
441 |
|
|
zipcounter mins_ctr(i_clk,(cpu_i_count), sys_cyc,
|
442 |
|
|
(sys_stb)&&(sys_addr == `MSTR_INST_CTR),
|
443 |
|
|
sys_we, sys_data,
|
444 |
|
|
mic_ack, mic_stall, mic_data, mic_int);
|
445 |
|
|
|
446 |
|
|
//
|
447 |
|
|
// The user counters are different from those of the master. They will
|
448 |
|
|
// be reset any time a task is given control of the CPU.
|
449 |
|
|
//
|
450 |
|
|
// User task counter
|
451 |
|
|
wire utc_ack, utc_stall;
|
452 |
|
|
wire [31:0] utc_data;
|
453 |
|
|
zipcounter utask_ctr(i_clk,(~cpu_halt)&&(cpu_gie), sys_cyc,
|
454 |
|
|
(sys_stb)&&(sys_addr == `USER_TASK_CTR),
|
455 |
|
|
sys_we, sys_data,
|
456 |
|
|
utc_ack, utc_stall, utc_data, utc_int);
|
457 |
|
|
|
458 |
|
|
// User Op-Stall counter
|
459 |
|
|
wire uoc_ack, uoc_stall;
|
460 |
|
|
wire [31:0] uoc_data;
|
461 |
|
|
zipcounter umstall_ctr(i_clk,(cpu_op_stall)&&(cpu_gie), sys_cyc,
|
462 |
|
|
(sys_stb)&&(sys_addr == `USER_MSTL_CTR),
|
463 |
|
|
sys_we, sys_data,
|
464 |
|
|
uoc_ack, uoc_stall, uoc_data, uoc_int);
|
465 |
|
|
|
466 |
|
|
// User PreFetch-Stall counter
|
467 |
|
|
wire upc_ack, upc_stall;
|
468 |
|
|
wire [31:0] upc_data;
|
469 |
|
|
zipcounter upstall_ctr(i_clk,(cpu_pf_stall)&&(cpu_gie), sys_cyc,
|
470 |
|
|
(sys_stb)&&(sys_addr == `USER_PSTL_CTR),
|
471 |
|
|
sys_we, sys_data,
|
472 |
|
|
upc_ack, upc_stall, upc_data, upc_int);
|
473 |
|
|
|
474 |
|
|
// User instruction counter
|
475 |
|
|
wire uic_ack, uic_stall;
|
476 |
|
|
wire [31:0] uic_data;
|
477 |
|
|
zipcounter uins_ctr(i_clk,(cpu_i_count)&&(cpu_gie), sys_cyc,
|
478 |
|
|
(sys_stb)&&(sys_addr == `USER_INST_CTR),
|
479 |
|
|
sys_we, sys_data,
|
480 |
|
|
uic_ack, uic_stall, uic_data, uic_int);
|
481 |
|
|
|
482 |
|
|
// A little bit of pre-cleanup (actr = accounting counters)
|
483 |
|
|
wire actr_ack, actr_stall;
|
484 |
|
|
wire [31:0] actr_data;
|
485 |
|
|
assign actr_ack = ((mtc_ack | moc_ack | mpc_ack | mic_ack)
|
486 |
|
|
|(utc_ack | uoc_ack | upc_ack | uic_ack));
|
487 |
|
|
assign actr_stall = ((mtc_stall | moc_stall | mpc_stall | mic_stall)
|
488 |
|
|
|(utc_stall | uoc_stall | upc_stall|uic_stall));
|
489 |
|
|
assign actr_data = ((mtc_ack) ? mtc_data
|
490 |
|
|
: ((moc_ack) ? moc_data
|
491 |
|
|
: ((mpc_ack) ? mpc_data
|
492 |
|
|
: ((mic_ack) ? mic_data
|
493 |
|
|
: ((utc_ack) ? utc_data
|
494 |
|
|
: ((uoc_ack) ? uoc_data
|
495 |
|
|
: ((upc_ack) ? upc_data
|
496 |
|
|
: uic_data)))))));
|
497 |
|
|
`else // INCLUDE_ACCOUNTING_COUNTERS
|
498 |
|
|
reg actr_ack;
|
499 |
|
|
wire actr_stall;
|
500 |
|
|
wire [31:0] actr_data;
|
501 |
|
|
assign actr_stall = 1'b0;
|
502 |
|
|
assign actr_data = 32'h0000;
|
503 |
|
|
|
504 |
|
|
assign mtc_int = 1'b0;
|
505 |
|
|
assign moc_int = 1'b0;
|
506 |
|
|
assign mpc_int = 1'b0;
|
507 |
|
|
assign mic_int = 1'b0;
|
508 |
|
|
assign utc_int = 1'b0;
|
509 |
|
|
assign uoc_int = 1'b0;
|
510 |
|
|
assign upc_int = 1'b0;
|
511 |
|
|
assign uic_int = 1'b0;
|
512 |
|
|
|
513 |
|
|
always @(posedge i_clk)
|
514 |
|
|
actr_ack <= (sys_stb)&&(sys_addr[4:3] == 2'b01);
|
515 |
|
|
`endif // INCLUDE_ACCOUNTING_COUNTERS
|
516 |
|
|
|
517 |
|
|
//
|
518 |
|
|
// The DMA Controller
|
519 |
|
|
//
|
520 |
|
|
wire dmac_stb, dc_err;
|
521 |
|
|
wire [31:0] dmac_data;
|
522 |
|
|
wire dmac_ack, dmac_stall;
|
523 |
|
|
wire dc_cyc, dc_stb, dc_we, dc_ack, dc_stall;
|
524 |
|
|
wire [31:0] dc_data;
|
525 |
|
|
wire [(AW-1):0] dc_addr;
|
526 |
|
|
wire cpu_gbl_cyc;
|
527 |
|
|
assign dmac_stb = (sys_stb)&&(sys_addr[4]);
|
528 |
|
|
`ifdef INCLUDE_DMA_CONTROLLER
|
529 |
|
|
wbdmac #(AW) dma_controller(i_clk, cpu_reset,
|
530 |
|
|
sys_cyc, dmac_stb, sys_we,
|
531 |
|
|
sys_addr[1:0], sys_data,
|
532 |
|
|
dmac_ack, dmac_stall, dmac_data,
|
533 |
|
|
// Need the outgoing DMAC wishbone bus
|
534 |
|
|
dc_cyc, dc_stb, dc_we, dc_addr, dc_data,
|
535 |
|
|
dc_ack, dc_stall, ext_idata, dc_err,
|
536 |
|
|
// External device interrupts
|
537 |
|
|
{ 1'b0, alt_int_vector, 1'b0,
|
538 |
|
|
main_int_vector[14:1], 1'b0 },
|
539 |
|
|
// DMAC interrupt, for upon completion
|
540 |
|
|
dmac_int);
|
541 |
|
|
`else
|
542 |
|
|
reg r_dmac_ack;
|
543 |
|
|
always @(posedge i_clk)
|
544 |
|
|
r_dmac_ack <= (sys_cyc)&&(dmac_stb);
|
545 |
|
|
assign dmac_ack = r_dmac_ack;
|
546 |
|
|
assign dmac_data = 32'h000;
|
547 |
|
|
assign dmac_stall = 1'b0;
|
548 |
|
|
|
549 |
|
|
assign dc_cyc = 1'b0;
|
550 |
|
|
assign dc_stb = 1'b0;
|
551 |
|
|
assign dc_we = 1'b0;
|
552 |
|
|
assign dc_addr = { (AW) {1'b0} };
|
553 |
|
|
assign dc_data = 32'h00;
|
554 |
|
|
|
555 |
|
|
assign dmac_int = 1'b0;
|
556 |
|
|
`endif
|
557 |
|
|
|
558 |
|
|
wire ctri_sel, ctri_stall;
|
559 |
|
|
reg ctri_ack;
|
560 |
|
|
wire [31:0] ctri_data;
|
561 |
32 |
dgisselq |
assign ctri_sel = (sys_stb)&&(sys_addr == `CTRINT);
|
562 |
3 |
dgisselq |
always @(posedge i_clk)
|
563 |
|
|
ctri_ack <= ctri_sel;
|
564 |
|
|
assign ctri_stall = 1'b0;
|
565 |
|
|
`ifdef INCLUDE_ACCOUNTING_COUNTERS
|
566 |
|
|
//
|
567 |
|
|
// Counter Interrupt controller
|
568 |
|
|
//
|
569 |
|
|
generate
|
570 |
|
|
if (EXTERNAL_INTERRUPTS <= 9)
|
571 |
|
|
begin
|
572 |
|
|
icontrol #(8) ctri(i_clk, cpu_reset, (ctri_sel),
|
573 |
|
|
sys_data, ctri_data, alt_int_vector[7:0],
|
574 |
|
|
ctri_int);
|
575 |
|
|
end else begin
|
576 |
|
|
icontrol #(8+(EXTERNAL_INTERRUPTS-9))
|
577 |
|
|
ctri(i_clk, cpu_reset, (ctri_sel),
|
578 |
|
|
sys_data, ctri_data,
|
579 |
|
|
alt_int_vector[(EXTERNAL_INTERRUPTS-2):0],
|
580 |
|
|
ctri_int);
|
581 |
|
|
end endgenerate
|
582 |
|
|
|
583 |
|
|
`else // INCLUDE_ACCOUNTING_COUNTERS
|
584 |
|
|
|
585 |
|
|
generate
|
586 |
|
|
if (EXTERNAL_INTERRUPTS <= 9)
|
587 |
|
|
begin
|
588 |
|
|
assign ctri_stall = 1'b0;
|
589 |
|
|
assign ctri_data = 32'h0000;
|
590 |
|
|
assign ctri_int = 1'b0;
|
591 |
|
|
end else begin
|
592 |
|
|
icontrol #(EXTERNAL_INTERRUPTS-9)
|
593 |
|
|
ctri(i_clk, cpu_reset, (ctri_sel),
|
594 |
|
|
sys_data, ctri_data,
|
595 |
|
|
alt_int_vector[(EXTERNAL_INTERRUPTS-10):0],
|
596 |
|
|
ctri_int);
|
597 |
|
|
end endgenerate
|
598 |
|
|
`endif // INCLUDE_ACCOUNTING_COUNTERS
|
599 |
|
|
|
600 |
|
|
|
601 |
|
|
//
|
602 |
|
|
// Timer A
|
603 |
|
|
//
|
604 |
|
|
wire tma_ack, tma_stall;
|
605 |
|
|
wire [31:0] tma_data;
|
606 |
|
|
ziptimer timer_a(i_clk, cpu_reset, ~cmd_halt,
|
607 |
|
|
sys_cyc, (sys_stb)&&(sys_addr == `TIMER_A), sys_we,
|
608 |
|
|
sys_data,
|
609 |
|
|
tma_ack, tma_stall, tma_data, tma_int);
|
610 |
|
|
|
611 |
|
|
//
|
612 |
|
|
// Timer B
|
613 |
|
|
//
|
614 |
|
|
wire tmb_ack, tmb_stall;
|
615 |
|
|
wire [31:0] tmb_data;
|
616 |
|
|
ziptimer timer_b(i_clk, cpu_reset, ~cmd_halt,
|
617 |
|
|
sys_cyc, (sys_stb)&&(sys_addr == `TIMER_B), sys_we,
|
618 |
|
|
sys_data,
|
619 |
|
|
tmb_ack, tmb_stall, tmb_data, tmb_int);
|
620 |
|
|
|
621 |
|
|
//
|
622 |
|
|
// Timer C
|
623 |
|
|
//
|
624 |
|
|
wire tmc_ack, tmc_stall;
|
625 |
|
|
wire [31:0] tmc_data;
|
626 |
|
|
ziptimer timer_c(i_clk, cpu_reset, ~cmd_halt,
|
627 |
|
|
sys_cyc, (sys_stb)&&(sys_addr == `TIMER_C), sys_we,
|
628 |
|
|
sys_data,
|
629 |
|
|
tmc_ack, tmc_stall, tmc_data, tmc_int);
|
630 |
|
|
|
631 |
|
|
//
|
632 |
|
|
// JIFFIES
|
633 |
|
|
//
|
634 |
|
|
wire jif_ack, jif_stall;
|
635 |
|
|
wire [31:0] jif_data;
|
636 |
|
|
zipjiffies jiffies(i_clk, ~cmd_halt,
|
637 |
|
|
sys_cyc, (sys_stb)&&(sys_addr == `JIFFIES), sys_we,
|
638 |
|
|
sys_data,
|
639 |
|
|
jif_ack, jif_stall, jif_data, jif_int);
|
640 |
|
|
|
641 |
|
|
//
|
642 |
|
|
// The programmable interrupt controller peripheral
|
643 |
|
|
//
|
644 |
|
|
wire pic_interrupt;
|
645 |
|
|
generate
|
646 |
|
|
if (EXTERNAL_INTERRUPTS < 9)
|
647 |
|
|
begin
|
648 |
|
|
icontrol #(6+EXTERNAL_INTERRUPTS) pic(i_clk, cpu_reset,
|
649 |
|
|
(sys_cyc)&&(sys_stb)&&(sys_we)
|
650 |
|
|
&&(sys_addr==`INTCTRL),
|
651 |
|
|
sys_data, pic_data,
|
652 |
|
|
main_int_vector[(6+EXTERNAL_INTERRUPTS-1):0], pic_interrupt);
|
653 |
|
|
end else begin
|
654 |
|
|
icontrol #(15) pic(i_clk, cpu_reset,
|
655 |
|
|
(sys_cyc)&&(sys_stb)&&(sys_we)
|
656 |
|
|
&&(sys_addr==`INTCTRL),
|
657 |
|
|
sys_data, pic_data,
|
658 |
|
|
main_int_vector[14:0], pic_interrupt);
|
659 |
|
|
end endgenerate
|
660 |
|
|
|
661 |
|
|
wire pic_stall;
|
662 |
|
|
assign pic_stall = 1'b0;
|
663 |
|
|
reg pic_ack;
|
664 |
|
|
always @(posedge i_clk)
|
665 |
32 |
dgisselq |
pic_ack <= (sys_stb)&&(sys_addr == `INTCTRL);
|
666 |
3 |
dgisselq |
|
667 |
|
|
//
|
668 |
|
|
// The CPU itself
|
669 |
|
|
//
|
670 |
|
|
wire cpu_gbl_stb, cpu_lcl_cyc, cpu_lcl_stb,
|
671 |
|
|
cpu_we, cpu_dbg_we;
|
672 |
|
|
wire [31:0] cpu_data, wb_data;
|
673 |
|
|
wire cpu_ack, cpu_stall, cpu_err;
|
674 |
|
|
wire [31:0] cpu_dbg_data;
|
675 |
|
|
assign cpu_dbg_we = ((dbg_cyc)&&(dbg_stb)&&(~cmd_addr[5])
|
676 |
|
|
&&(dbg_we)&&(dbg_addr));
|
677 |
|
|
|
678 |
|
|
generate
|
679 |
|
|
if (HIGHSPEED_CPU==0)
|
680 |
|
|
begin
|
681 |
|
|
zipcpu #(
|
682 |
|
|
.RESET_ADDRESS(RESET_ADDRESS),
|
683 |
|
|
.ADDRESS_WIDTH(ADDRESS_WIDTH),
|
684 |
|
|
.LGICACHE(LGICACHE),
|
685 |
|
|
.IMPLEMENT_MPY(IMPLEMENT_MPY),
|
686 |
|
|
.IMPLEMENT_DIVIDE(IMPLEMENT_DIVIDE),
|
687 |
|
|
.IMPLEMENT_FPU(IMPLEMENT_FPU),
|
688 |
|
|
.IMPLEMENT_LOCK(IMPLEMENT_LOCK)
|
689 |
|
|
)
|
690 |
|
|
thecpu(i_clk, cpu_reset, pic_interrupt,
|
691 |
|
|
cpu_halt, cmd_clear_pf_cache, cmd_addr[4:0], cpu_dbg_we,
|
692 |
|
|
dbg_idata, cpu_dbg_stall, cpu_dbg_data,
|
693 |
|
|
cpu_dbg_cc, cpu_break,
|
694 |
|
|
cpu_gbl_cyc, cpu_gbl_stb,
|
695 |
|
|
cpu_lcl_cyc, cpu_lcl_stb,
|
696 |
|
|
cpu_we, cpu_addr, cpu_data,
|
697 |
|
|
cpu_ack, cpu_stall, wb_data,
|
698 |
|
|
cpu_err,
|
699 |
|
|
cpu_op_stall, cpu_pf_stall, cpu_i_count
|
700 |
|
|
`ifdef DEBUG_SCOPE
|
701 |
|
|
, o_cpu_debug
|
702 |
|
|
`endif
|
703 |
|
|
);
|
704 |
|
|
end else begin
|
705 |
|
|
zipcpu #(
|
706 |
|
|
.RESET_ADDRESS(RESET_ADDRESS),
|
707 |
|
|
.ADDRESS_WIDTH(ADDRESS_WIDTH),
|
708 |
|
|
.LGICACHE(LGICACHE),
|
709 |
|
|
.IMPLEMENT_MPY(IMPLEMENT_MPY),
|
710 |
|
|
.IMPLEMENT_DIVIDE(IMPLEMENT_DIVIDE),
|
711 |
|
|
.IMPLEMENT_FPU(IMPLEMENT_FPU),
|
712 |
|
|
.IMPLEMENT_LOCK(IMPLEMENT_LOCK)
|
713 |
|
|
)
|
714 |
|
|
thecpu(i_clk, cpu_reset, pic_interrupt,
|
715 |
|
|
cpu_halt, cmd_clear_pf_cache, cmd_addr[4:0], cpu_dbg_we,
|
716 |
|
|
dbg_idata, cpu_dbg_stall, cpu_dbg_data,
|
717 |
|
|
cpu_dbg_cc, cpu_break,
|
718 |
|
|
cpu_gbl_cyc, cpu_gbl_stb,
|
719 |
|
|
cpu_lcl_cyc, cpu_lcl_stb,
|
720 |
|
|
cpu_we, cpu_addr, cpu_data,
|
721 |
|
|
cpu_ack, cpu_stall, wb_data,
|
722 |
|
|
cpu_err,
|
723 |
|
|
cpu_op_stall, cpu_pf_stall, cpu_i_count
|
724 |
|
|
`ifdef DEBUG_SCOPE
|
725 |
|
|
, o_cpu_debug
|
726 |
|
|
`endif
|
727 |
|
|
);
|
728 |
|
|
end endgenerate
|
729 |
|
|
|
730 |
|
|
// Now, arbitrate the bus ... first for the local peripherals
|
731 |
|
|
// For the debugger to have access to the local system bus, the
|
732 |
|
|
// following must be true:
|
733 |
|
|
// (dbg_cyc) The debugger must request the bus
|
734 |
|
|
// (~cpu_lcl_cyc) The CPU cannot be using it (CPU gets priority)
|
735 |
|
|
// (dbg_addr) The debugger must be requesting its data
|
736 |
|
|
// register, not just the control register
|
737 |
|
|
// and one of two other things. Either
|
738 |
|
|
// ((cpu_halt)&&(~cpu_dbg_stall)) the CPU is completely halted,
|
739 |
|
|
// or
|
740 |
|
|
// (~cmd_addr[5]) we are trying to read a CPU register
|
741 |
|
|
// while in motion. Let the user beware that,
|
742 |
|
|
// by not waiting for the CPU to fully halt,
|
743 |
|
|
// his results may not be what he expects.
|
744 |
|
|
//
|
745 |
|
|
wire sys_dbg_cyc = ((dbg_cyc)&&(~cpu_lcl_cyc)&&(dbg_addr))
|
746 |
|
|
&&(((cpu_halt)&&(~cpu_dbg_stall))
|
747 |
|
|
||(~cmd_addr[5]));
|
748 |
|
|
assign sys_cyc = (cpu_lcl_cyc)||(sys_dbg_cyc);
|
749 |
|
|
assign sys_stb = (cpu_lcl_cyc)
|
750 |
|
|
? (cpu_lcl_stb)
|
751 |
|
|
: ((dbg_stb)&&(dbg_addr)&&(cmd_addr[5]));
|
752 |
|
|
|
753 |
|
|
assign sys_we = (cpu_lcl_cyc) ? cpu_we : dbg_we;
|
754 |
|
|
assign sys_addr= (cpu_lcl_cyc) ? cpu_addr[4:0] : cmd_addr[4:0];
|
755 |
|
|
assign sys_data= (cpu_lcl_cyc) ? cpu_data : dbg_idata;
|
756 |
|
|
|
757 |
|
|
// Return debug response values
|
758 |
|
|
assign dbg_odata = (~dbg_addr)?cmd_data
|
759 |
|
|
:((~cmd_addr[5])?cpu_dbg_data : wb_data);
|
760 |
|
|
initial dbg_ack = 1'b0;
|
761 |
|
|
always @(posedge i_clk)
|
762 |
|
|
dbg_ack <= (dbg_cyc)&&(dbg_stb)&&(~dbg_stall);
|
763 |
|
|
assign dbg_stall=(dbg_cyc)&&((~sys_dbg_cyc)||(sys_stall))&&(dbg_addr);
|
764 |
|
|
|
765 |
|
|
// Now for the external wishbone bus
|
766 |
|
|
// Need to arbitrate between the flash cache and the CPU
|
767 |
|
|
// The way this works, though, the CPU will stall once the flash
|
768 |
|
|
// cache gets access to the bus--the CPU will be stuck until the
|
769 |
|
|
// flash cache is finished with the bus.
|
770 |
|
|
wire ext_cyc, ext_stb, ext_we, ext_err;
|
771 |
|
|
wire cpu_ext_ack, cpu_ext_stall, ext_ack, ext_stall,
|
772 |
|
|
cpu_ext_err;
|
773 |
|
|
wire [(AW-1):0] ext_addr;
|
774 |
|
|
wire [31:0] ext_odata;
|
775 |
|
|
wbpriarbiter #(32,AW) dmacvcpu(i_clk,
|
776 |
|
|
cpu_gbl_cyc, cpu_gbl_stb, cpu_we, cpu_addr, cpu_data,
|
777 |
|
|
cpu_ext_ack, cpu_ext_stall, cpu_ext_err,
|
778 |
|
|
dc_cyc, dc_stb, dc_we, dc_addr, dc_data,
|
779 |
|
|
dc_ack, dc_stall, dc_err,
|
780 |
|
|
ext_cyc, ext_stb, ext_we, ext_addr, ext_odata,
|
781 |
|
|
ext_ack, ext_stall, ext_err);
|
782 |
|
|
|
783 |
|
|
`ifdef DELAY_EXT_BUS
|
784 |
|
|
busdelay #(AW,32) extbus(i_clk,
|
785 |
|
|
ext_cyc, ext_stb, ext_we, ext_addr, ext_odata,
|
786 |
|
|
ext_ack, ext_stall, ext_idata, ext_err,
|
787 |
|
|
o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data,
|
788 |
|
|
i_wb_ack, i_wb_stall, i_wb_data, (i_wb_err)||(wdbus_int));
|
789 |
|
|
`else
|
790 |
|
|
assign o_wb_cyc = ext_cyc;
|
791 |
|
|
assign o_wb_stb = ext_stb;
|
792 |
|
|
assign o_wb_we = ext_we;
|
793 |
|
|
assign o_wb_addr = ext_addr;
|
794 |
|
|
assign o_wb_data = ext_odata;
|
795 |
|
|
assign ext_ack = i_wb_ack;
|
796 |
|
|
assign ext_stall = i_wb_stall;
|
797 |
|
|
assign ext_idata = i_wb_data;
|
798 |
|
|
assign ext_err = (i_wb_err)||(wdbus_int);
|
799 |
|
|
`endif
|
800 |
|
|
|
801 |
|
|
wire tmr_ack;
|
802 |
|
|
assign tmr_ack = (tma_ack|tmb_ack|tmc_ack|jif_ack);
|
803 |
|
|
wire [31:0] tmr_data;
|
804 |
|
|
assign tmr_data = (tma_ack)?tma_data
|
805 |
|
|
:(tmb_ack ? tmb_data
|
806 |
|
|
:(tmc_ack ? tmc_data
|
807 |
|
|
:jif_data));
|
808 |
|
|
assign wb_data = (tmr_ack|wdt_ack)?((tmr_ack)?tmr_data:wdt_data)
|
809 |
|
|
:((actr_ack|dmac_ack)?((actr_ack)?actr_data:dmac_data)
|
810 |
|
|
:((pic_ack|ctri_ack)?((pic_ack)?pic_data:ctri_data)
|
811 |
|
|
:((wdbus_ack)?wdbus_data:(ext_idata))));
|
812 |
|
|
|
813 |
|
|
assign sys_stall = (tma_stall | tmb_stall | tmc_stall | jif_stall
|
814 |
|
|
| wdt_stall | ctri_stall | actr_stall
|
815 |
32 |
dgisselq |
| pic_stall | dmac_stall); // Always 1'b0!
|
816 |
3 |
dgisselq |
assign cpu_stall = (sys_stall)|(cpu_ext_stall);
|
817 |
|
|
assign sys_ack = (tmr_ack|wdt_ack|ctri_ack|actr_ack|pic_ack|dmac_ack|wdbus_ack);
|
818 |
|
|
assign cpu_ack = (sys_ack)||(cpu_ext_ack);
|
819 |
|
|
assign cpu_err = (cpu_ext_err)&&(cpu_gbl_cyc);
|
820 |
|
|
|
821 |
|
|
assign o_ext_int = (cmd_halt) && (~cpu_stall);
|
822 |
|
|
|
823 |
|
|
endmodule
|