1 |
266 |
lampret |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// dbg_top.v ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// ////
|
6 |
|
|
//// This file is part of the SoC/OpenRISC Development Interface ////
|
7 |
|
|
//// http://www.opencores.org/cores/DebugInterface/ ////
|
8 |
|
|
//// ////
|
9 |
|
|
//// ////
|
10 |
|
|
//// Author(s): ////
|
11 |
|
|
//// Igor Mohor ////
|
12 |
|
|
//// igorm@opencores.org ////
|
13 |
|
|
//// ////
|
14 |
|
|
//// ////
|
15 |
|
|
//// All additional information is avaliable in the README.txt ////
|
16 |
|
|
//// file. ////
|
17 |
|
|
//// ////
|
18 |
|
|
//////////////////////////////////////////////////////////////////////
|
19 |
|
|
//// ////
|
20 |
|
|
//// Copyright (C) 2000,2001 Authors ////
|
21 |
|
|
//// ////
|
22 |
|
|
//// This source file may be used and distributed without ////
|
23 |
|
|
//// restriction provided that this copyright statement is not ////
|
24 |
|
|
//// removed from the file and that any derivative work contains ////
|
25 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
26 |
|
|
//// ////
|
27 |
|
|
//// This source file is free software; you can redistribute it ////
|
28 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
29 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
30 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
31 |
|
|
//// later version. ////
|
32 |
|
|
//// ////
|
33 |
|
|
//// This source is distributed in the hope that it will be ////
|
34 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
35 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
36 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
37 |
|
|
//// details. ////
|
38 |
|
|
//// ////
|
39 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
40 |
|
|
//// Public License along with this source; if not, download it ////
|
41 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
42 |
|
|
//// ////
|
43 |
|
|
//////////////////////////////////////////////////////////////////////
|
44 |
|
|
//
|
45 |
|
|
// CVS Revision History
|
46 |
|
|
//
|
47 |
|
|
// $Log: not supported by cvs2svn $
|
48 |
|
|
// Revision 1.7 2001/10/16 10:09:56 mohor
|
49 |
|
|
// Signal names changed to lowercase.
|
50 |
|
|
//
|
51 |
|
|
//
|
52 |
|
|
// Revision 1.6 2001/10/15 09:55:47 mohor
|
53 |
|
|
// Wishbone interface added, few fixes for better performance,
|
54 |
|
|
// hooks for boundary scan testing added.
|
55 |
|
|
//
|
56 |
|
|
// Revision 1.5 2001/09/24 14:06:42 mohor
|
57 |
|
|
// Changes connected to the OpenRISC access (SPR read, SPR write).
|
58 |
|
|
//
|
59 |
|
|
// Revision 1.4 2001/09/20 10:11:25 mohor
|
60 |
|
|
// Working version. Few bugs fixed, comments added.
|
61 |
|
|
//
|
62 |
|
|
// Revision 1.3 2001/09/19 11:55:13 mohor
|
63 |
|
|
// Asynchronous set/reset not used in trace any more.
|
64 |
|
|
//
|
65 |
|
|
// Revision 1.2 2001/09/18 14:13:47 mohor
|
66 |
|
|
// Trace fixed. Some registers changed, trace simplified.
|
67 |
|
|
//
|
68 |
|
|
// Revision 1.1.1.1 2001/09/13 13:49:19 mohor
|
69 |
|
|
// Initial official release.
|
70 |
|
|
//
|
71 |
|
|
// Revision 1.3 2001/06/01 22:22:35 mohor
|
72 |
|
|
// This is a backup. It is not a fully working version. Not for use, yet.
|
73 |
|
|
//
|
74 |
|
|
// Revision 1.2 2001/05/18 13:10:00 mohor
|
75 |
|
|
// Headers changed. All additional information is now avaliable in the README.txt file.
|
76 |
|
|
//
|
77 |
|
|
// Revision 1.1.1.1 2001/05/18 06:35:02 mohor
|
78 |
|
|
// Initial release
|
79 |
|
|
//
|
80 |
|
|
//
|
81 |
|
|
|
82 |
|
|
`include "dbg_timescale.v"
|
83 |
|
|
`include "dbg_defines.v"
|
84 |
|
|
|
85 |
|
|
// Top module
|
86 |
|
|
module dbg_top(
|
87 |
|
|
// JTAG pins
|
88 |
|
|
tms_pad_i, tck_pad_i, trst_pad_i, tdi_pad_i, tdo_pad_o,
|
89 |
|
|
|
90 |
|
|
// Boundary Scan signals
|
91 |
|
|
capture_dr_o, shift_dr_o, update_dr_o, extest_selected_o, bs_chain_i,
|
92 |
|
|
|
93 |
|
|
// RISC signals
|
94 |
|
|
risc_clk_i, risc_addr_o, risc_data_i, risc_data_o, wp_i,
|
95 |
|
|
bp_i, opselect_o, lsstatus_i, istatus_i, risc_stall_o, reset_o,
|
96 |
|
|
|
97 |
|
|
// WISHBONE common signals
|
98 |
|
|
wb_rst_i, wb_clk_i,
|
99 |
|
|
|
100 |
|
|
// WISHBONE master interface
|
101 |
|
|
wb_adr_o, wb_dat_o, wb_dat_i, wb_cyc_o, wb_stb_o, wb_sel_o,
|
102 |
|
|
wb_we_o, wb_ack_i, wb_cab_o, wb_err_i
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
);
|
106 |
|
|
|
107 |
|
|
parameter Tp = 1;
|
108 |
|
|
|
109 |
|
|
// JTAG pins
|
110 |
|
|
input tms_pad_i; // JTAG test mode select pad
|
111 |
|
|
input tck_pad_i; // JTAG test clock pad
|
112 |
|
|
input trst_pad_i; // JTAG test reset pad
|
113 |
|
|
input tdi_pad_i; // JTAG test data input pad
|
114 |
|
|
output tdo_pad_o; // JTAG test data output pad
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
// Boundary Scan signals
|
118 |
|
|
output capture_dr_o;
|
119 |
|
|
output shift_dr_o;
|
120 |
|
|
output update_dr_o;
|
121 |
|
|
output extest_selected_o;
|
122 |
|
|
input bs_chain_i;
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
// RISC signals
|
126 |
|
|
input risc_clk_i; // Master clock (RISC clock)
|
127 |
|
|
input [31:0] risc_data_i; // RISC data inputs (data that is written to the RISC registers)
|
128 |
|
|
input [10:0] wp_i; // Watchpoint inputs
|
129 |
|
|
input bp_i; // Breakpoint input
|
130 |
|
|
input [3:0] lsstatus_i; // Load/store status inputs
|
131 |
|
|
input [1:0] istatus_i; // Instruction status inputs
|
132 |
|
|
output [31:0] risc_addr_o; // RISC address output (for adressing registers within RISC)
|
133 |
|
|
output [31:0] risc_data_o; // RISC data output (data read from risc registers)
|
134 |
|
|
output [`OPSELECTWIDTH-1:0] opselect_o; // Operation selection (selecting what kind of data is set to the risc_data_i)
|
135 |
|
|
output risc_stall_o; // Stalls the RISC
|
136 |
|
|
output reset_o; // Resets the RISC
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
// WISHBONE common signals
|
140 |
|
|
input wb_rst_i; // WISHBONE reset
|
141 |
|
|
input wb_clk_i; // WISHBONE clock
|
142 |
|
|
|
143 |
|
|
// WISHBONE master interface
|
144 |
|
|
output [31:0] wb_adr_o;
|
145 |
|
|
output [31:0] wb_dat_o;
|
146 |
|
|
input [31:0] wb_dat_i;
|
147 |
|
|
output wb_cyc_o;
|
148 |
|
|
output wb_stb_o;
|
149 |
|
|
output [3:0] wb_sel_o;
|
150 |
|
|
output wb_we_o;
|
151 |
|
|
input wb_ack_i;
|
152 |
|
|
output wb_cab_o;
|
153 |
|
|
input wb_err_i;
|
154 |
|
|
|
155 |
|
|
reg [31:0] wb_adr_o;
|
156 |
|
|
reg [31:0] wb_dat_o;
|
157 |
|
|
reg wb_we_o;
|
158 |
|
|
reg wb_cyc_o;
|
159 |
|
|
|
160 |
|
|
// TAP states
|
161 |
|
|
reg TestLogicReset;
|
162 |
|
|
reg RunTestIdle;
|
163 |
|
|
reg SelectDRScan;
|
164 |
|
|
reg CaptureDR;
|
165 |
|
|
reg ShiftDR;
|
166 |
|
|
reg Exit1DR;
|
167 |
|
|
reg PauseDR;
|
168 |
|
|
reg Exit2DR;
|
169 |
|
|
reg UpdateDR;
|
170 |
|
|
|
171 |
|
|
reg SelectIRScan;
|
172 |
|
|
reg CaptureIR;
|
173 |
|
|
reg ShiftIR;
|
174 |
|
|
reg Exit1IR;
|
175 |
|
|
reg PauseIR;
|
176 |
|
|
reg Exit2IR;
|
177 |
|
|
reg UpdateIR;
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
// Defining which instruction is selected
|
181 |
|
|
reg EXTESTSelected;
|
182 |
|
|
reg SAMPLE_PRELOADSelected;
|
183 |
|
|
reg IDCODESelected;
|
184 |
|
|
reg CHAIN_SELECTSelected;
|
185 |
|
|
reg INTESTSelected;
|
186 |
|
|
reg CLAMPSelected;
|
187 |
|
|
reg CLAMPZSelected;
|
188 |
|
|
reg HIGHZSelected;
|
189 |
|
|
reg DEBUGSelected;
|
190 |
|
|
reg BYPASSSelected;
|
191 |
|
|
|
192 |
|
|
reg [31:0] ADDR;
|
193 |
|
|
reg [31:0] DataOut;
|
194 |
|
|
|
195 |
|
|
reg [`OPSELECTWIDTH-1:0] opselect_o; // Operation selection (selecting what kind of data is set to the risc_data_i)
|
196 |
|
|
|
197 |
|
|
reg [`CHAIN_ID_LENGTH-1:0] Chain; // Selected chain
|
198 |
|
|
reg [31:0] RISC_DATAINLatch; // Data from DataIn is latched one risc_clk_i clock cycle after RISC register is
|
199 |
|
|
// accessed for reading
|
200 |
|
|
reg [31:0] RegisterReadLatch; // Data when reading register is latched one TCK clock after the register is read.
|
201 |
|
|
reg RegAccessTck; // Indicates access to the registers (read or write)
|
202 |
|
|
reg RISCAccessTck; // Indicates access to the RISC (read or write)
|
203 |
|
|
reg [7:0] BitCounter; // Counting bits in the ShiftDR and Exit1DR stages
|
204 |
|
|
reg RW; // Read/Write bit
|
205 |
|
|
reg CrcMatch; // The crc that is shifted in and the internaly calculated crc are equal
|
206 |
|
|
|
207 |
|
|
reg RegAccess_q; // Delayed signals used for accessing the registers
|
208 |
|
|
reg RegAccess_q2; // Delayed signals used for accessing the registers
|
209 |
|
|
reg RISCAccess_q; // Delayed signals used for accessing the RISC
|
210 |
|
|
reg RISCAccess_q2; // Delayed signals used for accessing the RISC
|
211 |
|
|
|
212 |
|
|
reg wb_AccessTck; // Indicates access to the WISHBONE
|
213 |
|
|
reg [31:0] WBReadLatch; // Data latched during WISHBONE read
|
214 |
|
|
reg WBErrorLatch; // Error latched during WISHBONE read
|
215 |
|
|
|
216 |
|
|
wire TCK = tck_pad_i;
|
217 |
|
|
wire TMS = tms_pad_i;
|
218 |
|
|
wire TDI = tdi_pad_i;
|
219 |
|
|
wire RESET = ~trst_pad_i | wb_rst_i; // trst_pad_i is active low
|
220 |
|
|
|
221 |
|
|
wire [31:0] RegDataIn; // Data from registers (read data)
|
222 |
|
|
wire [`CRC_LENGTH-1:0] CalculatedCrcOut; // CRC calculated in this module. This CRC is apended at the end of the TDO.
|
223 |
|
|
|
224 |
|
|
wire RiscStall_reg; // RISC is stalled by setting the register bit
|
225 |
|
|
wire RiscReset_reg; // RISC is reset by setting the register bit
|
226 |
|
|
wire RiscStall_trace; // RISC is stalled by trace module
|
227 |
|
|
|
228 |
|
|
|
229 |
|
|
wire RegisterScanChain; // Register Scan chain selected
|
230 |
|
|
wire RiscDebugScanChain; // Risc Debug Scan chain selected
|
231 |
|
|
wire WishboneScanChain; // WISHBONE Scan chain selected
|
232 |
|
|
|
233 |
|
|
wire RiscStall_read_access; // Stalling RISC because of the read access (SPR read)
|
234 |
|
|
wire RiscStall_write_access; // Stalling RISC because of the write access (SPR write)
|
235 |
|
|
wire RiscStall_access; // Stalling RISC because of the read or write access
|
236 |
|
|
|
237 |
|
|
|
238 |
|
|
assign capture_dr_o = CaptureDR;
|
239 |
|
|
assign shift_dr_o = ShiftDR;
|
240 |
|
|
assign update_dr_o = UpdateDR;
|
241 |
|
|
assign extest_selected_o = EXTESTSelected;
|
242 |
|
|
wire BS_CHAIN_I = bs_chain_i;
|
243 |
|
|
|
244 |
|
|
// This signals are used only when TRACE is used in the design
|
245 |
|
|
`ifdef TRACE_ENABLED
|
246 |
|
|
wire [39:0] TraceChain; // Chain that comes from trace module
|
247 |
|
|
reg ReadBuffer_Tck; // Command for incrementing the trace read pointer (synchr with TCK)
|
248 |
|
|
wire ReadTraceBuffer; // Command for incrementing the trace read pointer (synchr with MClk)
|
249 |
|
|
reg ReadTraceBuffer_q; // Delayed command for incrementing the trace read pointer (synchr with MClk)
|
250 |
|
|
wire ReadTraceBufferPulse; // Pulse for reading the trace buffer (valid for only one Mclk command)
|
251 |
|
|
|
252 |
|
|
// Outputs from registers
|
253 |
|
|
wire ContinMode; // Trace working in continous mode
|
254 |
|
|
wire TraceEnable; // Trace enabled
|
255 |
|
|
|
256 |
|
|
wire [10:0] WpTrigger; // Watchpoint starts trigger
|
257 |
|
|
wire BpTrigger; // Breakpoint starts trigger
|
258 |
|
|
wire [3:0] LSSTrigger; // Load/store status starts trigger
|
259 |
|
|
wire [1:0] ITrigger; // Instruction status starts trigger
|
260 |
|
|
wire [1:0] TriggerOper; // Trigger operation
|
261 |
|
|
|
262 |
|
|
wire WpTriggerValid; // Watchpoint trigger is valid
|
263 |
|
|
wire BpTriggerValid; // Breakpoint trigger is valid
|
264 |
|
|
wire LSSTriggerValid; // Load/store status trigger is valid
|
265 |
|
|
wire ITriggerValid; // Instruction status trigger is valid
|
266 |
|
|
|
267 |
|
|
wire [10:0] WpQualif; // Watchpoint starts qualifier
|
268 |
|
|
wire BpQualif; // Breakpoint starts qualifier
|
269 |
|
|
wire [3:0] LSSQualif; // Load/store status starts qualifier
|
270 |
|
|
wire [1:0] IQualif; // Instruction status starts qualifier
|
271 |
|
|
wire [1:0] QualifOper; // Qualifier operation
|
272 |
|
|
|
273 |
|
|
wire WpQualifValid; // Watchpoint qualifier is valid
|
274 |
|
|
wire BpQualifValid; // Breakpoint qualifier is valid
|
275 |
|
|
wire LSSQualifValid; // Load/store status qualifier is valid
|
276 |
|
|
wire IQualifValid; // Instruction status qualifier is valid
|
277 |
|
|
|
278 |
|
|
wire [10:0] WpStop; // Watchpoint stops recording of the trace
|
279 |
|
|
wire BpStop; // Breakpoint stops recording of the trace
|
280 |
|
|
wire [3:0] LSSStop; // Load/store status stops recording of the trace
|
281 |
|
|
wire [1:0] IStop; // Instruction status stops recording of the trace
|
282 |
|
|
wire [1:0] StopOper; // Stop operation
|
283 |
|
|
|
284 |
|
|
wire WpStopValid; // Watchpoint stop is valid
|
285 |
|
|
wire BpStopValid; // Breakpoint stop is valid
|
286 |
|
|
wire LSSStopValid; // Load/store status stop is valid
|
287 |
|
|
wire IStopValid; // Instruction status stop is valid
|
288 |
|
|
|
289 |
|
|
wire RecordPC; // Recording program counter
|
290 |
|
|
wire RecordLSEA; // Recording load/store effective address
|
291 |
|
|
wire RecordLDATA; // Recording load data
|
292 |
|
|
wire RecordSDATA; // Recording store data
|
293 |
|
|
wire RecordReadSPR; // Recording read SPR
|
294 |
|
|
wire RecordWriteSPR; // Recording write SPR
|
295 |
|
|
wire RecordINSTR; // Recording instruction
|
296 |
|
|
|
297 |
|
|
// End: Outputs from registers
|
298 |
|
|
|
299 |
|
|
wire TraceTestScanChain; // Trace Test Scan chain selected
|
300 |
|
|
wire [47:0] Trace_Data; // Trace data
|
301 |
|
|
|
302 |
|
|
wire [`OPSELECTWIDTH-1:0]opselect_trace;// Operation selection (trace selecting what kind of
|
303 |
|
|
// data is set to the risc_data_i)
|
304 |
|
|
|
305 |
|
|
`endif
|
306 |
|
|
|
307 |
|
|
|
308 |
|
|
/**********************************************************************************
|
309 |
|
|
* *
|
310 |
|
|
* TAP State Machine: Fully JTAG compliant *
|
311 |
|
|
* *
|
312 |
|
|
**********************************************************************************/
|
313 |
|
|
|
314 |
|
|
// TestLogicReset state
|
315 |
|
|
always @ (posedge TCK or posedge RESET)
|
316 |
|
|
begin
|
317 |
|
|
if(RESET)
|
318 |
|
|
TestLogicReset<=#Tp 1;
|
319 |
|
|
else
|
320 |
|
|
begin
|
321 |
|
|
if(TMS & (TestLogicReset | SelectIRScan))
|
322 |
|
|
TestLogicReset<=#Tp 1;
|
323 |
|
|
else
|
324 |
|
|
TestLogicReset<=#Tp 0;
|
325 |
|
|
end
|
326 |
|
|
end
|
327 |
|
|
|
328 |
|
|
// RunTestIdle state
|
329 |
|
|
always @ (posedge TCK or posedge RESET)
|
330 |
|
|
begin
|
331 |
|
|
if(RESET)
|
332 |
|
|
RunTestIdle<=#Tp 0;
|
333 |
|
|
else
|
334 |
|
|
begin
|
335 |
|
|
if(~TMS & (TestLogicReset | RunTestIdle | UpdateDR | UpdateIR))
|
336 |
|
|
RunTestIdle<=#Tp 1;
|
337 |
|
|
else
|
338 |
|
|
RunTestIdle<=#Tp 0;
|
339 |
|
|
end
|
340 |
|
|
end
|
341 |
|
|
|
342 |
|
|
// SelectDRScan state
|
343 |
|
|
always @ (posedge TCK or posedge RESET)
|
344 |
|
|
begin
|
345 |
|
|
if(RESET)
|
346 |
|
|
SelectDRScan<=#Tp 0;
|
347 |
|
|
else
|
348 |
|
|
begin
|
349 |
|
|
if(TMS & (RunTestIdle | UpdateDR | UpdateIR))
|
350 |
|
|
SelectDRScan<=#Tp 1;
|
351 |
|
|
else
|
352 |
|
|
SelectDRScan<=#Tp 0;
|
353 |
|
|
end
|
354 |
|
|
end
|
355 |
|
|
|
356 |
|
|
// CaptureDR state
|
357 |
|
|
always @ (posedge TCK or posedge RESET)
|
358 |
|
|
begin
|
359 |
|
|
if(RESET)
|
360 |
|
|
CaptureDR<=#Tp 0;
|
361 |
|
|
else
|
362 |
|
|
begin
|
363 |
|
|
if(~TMS & SelectDRScan)
|
364 |
|
|
CaptureDR<=#Tp 1;
|
365 |
|
|
else
|
366 |
|
|
CaptureDR<=#Tp 0;
|
367 |
|
|
end
|
368 |
|
|
end
|
369 |
|
|
|
370 |
|
|
// ShiftDR state
|
371 |
|
|
always @ (posedge TCK or posedge RESET)
|
372 |
|
|
begin
|
373 |
|
|
if(RESET)
|
374 |
|
|
ShiftDR<=#Tp 0;
|
375 |
|
|
else
|
376 |
|
|
begin
|
377 |
|
|
if(~TMS & (CaptureDR | ShiftDR | Exit2DR))
|
378 |
|
|
ShiftDR<=#Tp 1;
|
379 |
|
|
else
|
380 |
|
|
ShiftDR<=#Tp 0;
|
381 |
|
|
end
|
382 |
|
|
end
|
383 |
|
|
|
384 |
|
|
// Exit1DR state
|
385 |
|
|
always @ (posedge TCK or posedge RESET)
|
386 |
|
|
begin
|
387 |
|
|
if(RESET)
|
388 |
|
|
Exit1DR<=#Tp 0;
|
389 |
|
|
else
|
390 |
|
|
begin
|
391 |
|
|
if(TMS & (CaptureDR | ShiftDR))
|
392 |
|
|
Exit1DR<=#Tp 1;
|
393 |
|
|
else
|
394 |
|
|
Exit1DR<=#Tp 0;
|
395 |
|
|
end
|
396 |
|
|
end
|
397 |
|
|
|
398 |
|
|
// PauseDR state
|
399 |
|
|
always @ (posedge TCK or posedge RESET)
|
400 |
|
|
begin
|
401 |
|
|
if(RESET)
|
402 |
|
|
PauseDR<=#Tp 0;
|
403 |
|
|
else
|
404 |
|
|
begin
|
405 |
|
|
if(~TMS & (Exit1DR | PauseDR))
|
406 |
|
|
PauseDR<=#Tp 1;
|
407 |
|
|
else
|
408 |
|
|
PauseDR<=#Tp 0;
|
409 |
|
|
end
|
410 |
|
|
end
|
411 |
|
|
|
412 |
|
|
// Exit2DR state
|
413 |
|
|
always @ (posedge TCK or posedge RESET)
|
414 |
|
|
begin
|
415 |
|
|
if(RESET)
|
416 |
|
|
Exit2DR<=#Tp 0;
|
417 |
|
|
else
|
418 |
|
|
begin
|
419 |
|
|
if(TMS & PauseDR)
|
420 |
|
|
Exit2DR<=#Tp 1;
|
421 |
|
|
else
|
422 |
|
|
Exit2DR<=#Tp 0;
|
423 |
|
|
end
|
424 |
|
|
end
|
425 |
|
|
|
426 |
|
|
// UpdateDR state
|
427 |
|
|
always @ (posedge TCK or posedge RESET)
|
428 |
|
|
begin
|
429 |
|
|
if(RESET)
|
430 |
|
|
UpdateDR<=#Tp 0;
|
431 |
|
|
else
|
432 |
|
|
begin
|
433 |
|
|
if(TMS & (Exit1DR | Exit2DR))
|
434 |
|
|
UpdateDR<=#Tp 1;
|
435 |
|
|
else
|
436 |
|
|
UpdateDR<=#Tp 0;
|
437 |
|
|
end
|
438 |
|
|
end
|
439 |
|
|
|
440 |
|
|
// Delayed UpdateDR state
|
441 |
|
|
reg UpdateDR_q;
|
442 |
|
|
always @ (posedge TCK)
|
443 |
|
|
begin
|
444 |
|
|
UpdateDR_q<=#Tp UpdateDR;
|
445 |
|
|
end
|
446 |
|
|
|
447 |
|
|
|
448 |
|
|
// SelectIRScan state
|
449 |
|
|
always @ (posedge TCK or posedge RESET)
|
450 |
|
|
begin
|
451 |
|
|
if(RESET)
|
452 |
|
|
SelectIRScan<=#Tp 0;
|
453 |
|
|
else
|
454 |
|
|
begin
|
455 |
|
|
if(TMS & SelectDRScan)
|
456 |
|
|
SelectIRScan<=#Tp 1;
|
457 |
|
|
else
|
458 |
|
|
SelectIRScan<=#Tp 0;
|
459 |
|
|
end
|
460 |
|
|
end
|
461 |
|
|
|
462 |
|
|
// CaptureIR state
|
463 |
|
|
always @ (posedge TCK or posedge RESET)
|
464 |
|
|
begin
|
465 |
|
|
if(RESET)
|
466 |
|
|
CaptureIR<=#Tp 0;
|
467 |
|
|
else
|
468 |
|
|
begin
|
469 |
|
|
if(~TMS & SelectIRScan)
|
470 |
|
|
CaptureIR<=#Tp 1;
|
471 |
|
|
else
|
472 |
|
|
CaptureIR<=#Tp 0;
|
473 |
|
|
end
|
474 |
|
|
end
|
475 |
|
|
|
476 |
|
|
// ShiftIR state
|
477 |
|
|
always @ (posedge TCK or posedge RESET)
|
478 |
|
|
begin
|
479 |
|
|
if(RESET)
|
480 |
|
|
ShiftIR<=#Tp 0;
|
481 |
|
|
else
|
482 |
|
|
begin
|
483 |
|
|
if(~TMS & (CaptureIR | ShiftIR | Exit2IR))
|
484 |
|
|
ShiftIR<=#Tp 1;
|
485 |
|
|
else
|
486 |
|
|
ShiftIR<=#Tp 0;
|
487 |
|
|
end
|
488 |
|
|
end
|
489 |
|
|
|
490 |
|
|
// Exit1IR state
|
491 |
|
|
always @ (posedge TCK or posedge RESET)
|
492 |
|
|
begin
|
493 |
|
|
if(RESET)
|
494 |
|
|
Exit1IR<=#Tp 0;
|
495 |
|
|
else
|
496 |
|
|
begin
|
497 |
|
|
if(TMS & (CaptureIR | ShiftIR))
|
498 |
|
|
Exit1IR<=#Tp 1;
|
499 |
|
|
else
|
500 |
|
|
Exit1IR<=#Tp 0;
|
501 |
|
|
end
|
502 |
|
|
end
|
503 |
|
|
|
504 |
|
|
// PauseIR state
|
505 |
|
|
always @ (posedge TCK or posedge RESET)
|
506 |
|
|
begin
|
507 |
|
|
if(RESET)
|
508 |
|
|
PauseIR<=#Tp 0;
|
509 |
|
|
else
|
510 |
|
|
begin
|
511 |
|
|
if(~TMS & (Exit1IR | PauseIR))
|
512 |
|
|
PauseIR<=#Tp 1;
|
513 |
|
|
else
|
514 |
|
|
PauseIR<=#Tp 0;
|
515 |
|
|
end
|
516 |
|
|
end
|
517 |
|
|
|
518 |
|
|
// Exit2IR state
|
519 |
|
|
always @ (posedge TCK or posedge RESET)
|
520 |
|
|
begin
|
521 |
|
|
if(RESET)
|
522 |
|
|
Exit2IR<=#Tp 0;
|
523 |
|
|
else
|
524 |
|
|
begin
|
525 |
|
|
if(TMS & PauseIR)
|
526 |
|
|
Exit2IR<=#Tp 1;
|
527 |
|
|
else
|
528 |
|
|
Exit2IR<=#Tp 0;
|
529 |
|
|
end
|
530 |
|
|
end
|
531 |
|
|
|
532 |
|
|
// UpdateIR state
|
533 |
|
|
always @ (posedge TCK or posedge RESET)
|
534 |
|
|
begin
|
535 |
|
|
if(RESET)
|
536 |
|
|
UpdateIR<=#Tp 0;
|
537 |
|
|
else
|
538 |
|
|
begin
|
539 |
|
|
if(TMS & (Exit1IR | Exit2IR))
|
540 |
|
|
UpdateIR<=#Tp 1;
|
541 |
|
|
else
|
542 |
|
|
UpdateIR<=#Tp 0;
|
543 |
|
|
end
|
544 |
|
|
end
|
545 |
|
|
|
546 |
|
|
/**********************************************************************************
|
547 |
|
|
* *
|
548 |
|
|
* End: TAP State Machine *
|
549 |
|
|
* *
|
550 |
|
|
**********************************************************************************/
|
551 |
|
|
|
552 |
|
|
|
553 |
|
|
|
554 |
|
|
/**********************************************************************************
|
555 |
|
|
* *
|
556 |
|
|
* JTAG_IR: JTAG Instruction Register *
|
557 |
|
|
* *
|
558 |
|
|
**********************************************************************************/
|
559 |
|
|
wire [1:0]Status = 2'b10; // Holds current chip status. Core should return this status. For now a constant is used.
|
560 |
|
|
|
561 |
|
|
reg [`IR_LENGTH-1:0]JTAG_IR; // Instruction register
|
562 |
|
|
reg [`IR_LENGTH-1:0]LatchedJTAG_IR;
|
563 |
|
|
|
564 |
|
|
reg TDOInstruction;
|
565 |
|
|
|
566 |
|
|
always @ (posedge TCK or posedge RESET)
|
567 |
|
|
begin
|
568 |
|
|
if(RESET)
|
569 |
|
|
JTAG_IR[`IR_LENGTH-1:0] <= #Tp 0;
|
570 |
|
|
else
|
571 |
|
|
begin
|
572 |
|
|
if(CaptureIR)
|
573 |
|
|
begin
|
574 |
|
|
JTAG_IR[1:0] <= #Tp 2'b01; // This value is fixed for easier fault detection
|
575 |
|
|
JTAG_IR[3:2] <= #Tp Status[1:0]; // Current status of chip
|
576 |
|
|
end
|
577 |
|
|
else
|
578 |
|
|
begin
|
579 |
|
|
if(ShiftIR)
|
580 |
|
|
begin
|
581 |
|
|
JTAG_IR[`IR_LENGTH-1:0] <= #Tp {TDI, JTAG_IR[`IR_LENGTH-1:1]};
|
582 |
|
|
end
|
583 |
|
|
end
|
584 |
|
|
end
|
585 |
|
|
end
|
586 |
|
|
|
587 |
|
|
|
588 |
|
|
//TDO is changing on the falling edge of TCK
|
589 |
|
|
always @ (negedge TCK)
|
590 |
|
|
begin
|
591 |
|
|
if(ShiftIR)
|
592 |
|
|
TDOInstruction <= #Tp JTAG_IR[0];
|
593 |
|
|
end
|
594 |
|
|
|
595 |
|
|
/**********************************************************************************
|
596 |
|
|
* *
|
597 |
|
|
* End: JTAG_IR *
|
598 |
|
|
* *
|
599 |
|
|
**********************************************************************************/
|
600 |
|
|
|
601 |
|
|
|
602 |
|
|
/**********************************************************************************
|
603 |
|
|
* *
|
604 |
|
|
* JTAG_DR: JTAG Data Register *
|
605 |
|
|
* *
|
606 |
|
|
**********************************************************************************/
|
607 |
|
|
wire [31:0] IDCodeValue = `IDCODE_VALUE; // IDCODE value is 32-bit long.
|
608 |
|
|
|
609 |
|
|
reg [`DR_LENGTH-1:0]JTAG_DR_IN; // Data register
|
610 |
|
|
reg TDOData;
|
611 |
|
|
|
612 |
|
|
|
613 |
|
|
always @ (posedge TCK or posedge RESET)
|
614 |
|
|
begin
|
615 |
|
|
if(RESET)
|
616 |
|
|
JTAG_DR_IN[`DR_LENGTH-1:0]<=#Tp 0;
|
617 |
|
|
else
|
618 |
|
|
if(ShiftDR)
|
619 |
|
|
JTAG_DR_IN[BitCounter]<=#Tp TDI;
|
620 |
|
|
end
|
621 |
|
|
|
622 |
|
|
wire [72:0] RISC_Data;
|
623 |
|
|
wire [45:0] Register_Data;
|
624 |
|
|
wire [72:0] WISHBONE_Data;
|
625 |
|
|
wire wb_Access_wbClk;
|
626 |
|
|
|
627 |
|
|
assign RISC_Data = {CalculatedCrcOut, RISC_DATAINLatch, 33'h0};
|
628 |
|
|
assign Register_Data = {CalculatedCrcOut, RegisterReadLatch, 6'h0};
|
629 |
|
|
assign WISHBONE_Data = {CalculatedCrcOut, WBReadLatch, 32'h0, WBErrorLatch};
|
630 |
|
|
|
631 |
|
|
|
632 |
|
|
`ifdef TRACE_ENABLED
|
633 |
|
|
assign Trace_Data = {CalculatedCrcOut, TraceChain};
|
634 |
|
|
`endif
|
635 |
|
|
|
636 |
|
|
//TDO is changing on the falling edge of TCK
|
637 |
|
|
always @ (negedge TCK or posedge RESET)
|
638 |
|
|
begin
|
639 |
|
|
if(RESET)
|
640 |
|
|
begin
|
641 |
|
|
TDOData <= #Tp 0;
|
642 |
|
|
`ifdef TRACE_ENABLED
|
643 |
|
|
ReadBuffer_Tck<=#Tp 0;
|
644 |
|
|
`endif
|
645 |
|
|
end
|
646 |
|
|
else
|
647 |
|
|
if(UpdateDR)
|
648 |
|
|
begin
|
649 |
|
|
TDOData <= #Tp CrcMatch;
|
650 |
|
|
`ifdef TRACE_ENABLED
|
651 |
|
|
if(DEBUGSelected & TraceTestScanChain & TraceChain[0]) // Sample in the trace buffer is valid
|
652 |
|
|
ReadBuffer_Tck<=#Tp 1; // Increment read pointer
|
653 |
|
|
`endif
|
654 |
|
|
end
|
655 |
|
|
else
|
656 |
|
|
begin
|
657 |
|
|
if(ShiftDR)
|
658 |
|
|
begin
|
659 |
|
|
if(IDCODESelected)
|
660 |
|
|
TDOData <= #Tp IDCodeValue[BitCounter]; // IDCODE is shifted out
|
661 |
|
|
else
|
662 |
|
|
if(CHAIN_SELECTSelected)
|
663 |
|
|
TDOData <= #Tp 0;
|
664 |
|
|
else
|
665 |
|
|
if(DEBUGSelected)
|
666 |
|
|
begin
|
667 |
|
|
if(RiscDebugScanChain)
|
668 |
|
|
TDOData <= #Tp RISC_Data[BitCounter]; // Data read from RISC in the previous cycle is shifted out
|
669 |
|
|
else
|
670 |
|
|
if(RegisterScanChain)
|
671 |
|
|
TDOData <= #Tp Register_Data[BitCounter]; // Data read from register in the previous cycle is shifted out
|
672 |
|
|
else
|
673 |
|
|
if(WishboneScanChain)
|
674 |
|
|
TDOData <= #Tp WISHBONE_Data[BitCounter]; // Data read from the WISHBONE slave
|
675 |
|
|
`ifdef TRACE_ENABLED
|
676 |
|
|
else
|
677 |
|
|
if(TraceTestScanChain)
|
678 |
|
|
TDOData <= #Tp Trace_Data[BitCounter]; // Data from the trace buffer is shifted out
|
679 |
|
|
`endif
|
680 |
|
|
end
|
681 |
|
|
end
|
682 |
|
|
else
|
683 |
|
|
begin
|
684 |
|
|
TDOData <= #Tp 0;
|
685 |
|
|
`ifdef TRACE_ENABLED
|
686 |
|
|
ReadBuffer_Tck<=#Tp 0;
|
687 |
|
|
`endif
|
688 |
|
|
end
|
689 |
|
|
end
|
690 |
|
|
end
|
691 |
|
|
|
692 |
|
|
/**********************************************************************************
|
693 |
|
|
* *
|
694 |
|
|
* End: JTAG_DR *
|
695 |
|
|
* *
|
696 |
|
|
**********************************************************************************/
|
697 |
|
|
|
698 |
|
|
|
699 |
|
|
|
700 |
|
|
/**********************************************************************************
|
701 |
|
|
* *
|
702 |
|
|
* CHAIN_SELECT logic *
|
703 |
|
|
* *
|
704 |
|
|
**********************************************************************************/
|
705 |
|
|
always @ (posedge TCK or posedge RESET)
|
706 |
|
|
begin
|
707 |
|
|
if(RESET)
|
708 |
|
|
Chain[`CHAIN_ID_LENGTH-1:0]<=#Tp `GLOBAL_BS_CHAIN; // Global BS chain is selected after reset
|
709 |
|
|
else
|
710 |
|
|
if(UpdateDR & CHAIN_SELECTSelected & CrcMatch)
|
711 |
|
|
Chain[`CHAIN_ID_LENGTH-1:0]<=#Tp JTAG_DR_IN[3:0]; // New chain is selected
|
712 |
|
|
end
|
713 |
|
|
|
714 |
|
|
|
715 |
|
|
|
716 |
|
|
/**********************************************************************************
|
717 |
|
|
* *
|
718 |
|
|
* Register read/write logic *
|
719 |
|
|
* RISC registers read/write logic *
|
720 |
|
|
* *
|
721 |
|
|
**********************************************************************************/
|
722 |
|
|
always @ (posedge TCK or posedge RESET)
|
723 |
|
|
begin
|
724 |
|
|
if(RESET)
|
725 |
|
|
begin
|
726 |
|
|
ADDR[31:0] <=#Tp 32'h0;
|
727 |
|
|
DataOut[31:0] <=#Tp 32'h0;
|
728 |
|
|
RW <=#Tp 1'b0;
|
729 |
|
|
RegAccessTck <=#Tp 1'b0;
|
730 |
|
|
RISCAccessTck <=#Tp 1'b0;
|
731 |
|
|
wb_adr_o <=#Tp 32'h0;
|
732 |
|
|
wb_we_o <=#Tp 1'h0;
|
733 |
|
|
wb_dat_o <=#Tp 32'h0;
|
734 |
|
|
wb_AccessTck <=#Tp 1'h0;
|
735 |
|
|
end
|
736 |
|
|
else
|
737 |
|
|
if(UpdateDR & DEBUGSelected & CrcMatch)
|
738 |
|
|
begin
|
739 |
|
|
if(RegisterScanChain)
|
740 |
|
|
begin
|
741 |
|
|
ADDR[4:0] <=#Tp JTAG_DR_IN[4:0]; // Latching address for register access
|
742 |
|
|
RW <=#Tp JTAG_DR_IN[5]; // latch R/W bit
|
743 |
|
|
DataOut[31:0] <=#Tp JTAG_DR_IN[37:6]; // latch data for write
|
744 |
|
|
RegAccessTck <=#Tp 1'b1;
|
745 |
|
|
end
|
746 |
|
|
else
|
747 |
|
|
if(RiscDebugScanChain)
|
748 |
|
|
begin
|
749 |
|
|
ADDR[31:0] <=#Tp JTAG_DR_IN[31:0]; // Latching address for RISC register access
|
750 |
|
|
RW <=#Tp JTAG_DR_IN[32]; // latch R/W bit
|
751 |
|
|
DataOut[31:0] <=#Tp JTAG_DR_IN[64:33]; // latch data for write
|
752 |
|
|
RISCAccessTck <=#Tp 1'b1;
|
753 |
|
|
end
|
754 |
|
|
else
|
755 |
|
|
if(WishboneScanChain)
|
756 |
|
|
begin
|
757 |
|
|
wb_adr_o <=#Tp JTAG_DR_IN[31:0]; // Latching address for WISHBONE slave access
|
758 |
|
|
wb_we_o <=#Tp JTAG_DR_IN[32]; // latch R/W bit
|
759 |
|
|
wb_dat_o <=#Tp JTAG_DR_IN[64:33]; // latch data for write
|
760 |
|
|
wb_AccessTck <=#Tp 1'b1; //
|
761 |
|
|
end
|
762 |
|
|
end
|
763 |
|
|
else
|
764 |
|
|
begin
|
765 |
|
|
RegAccessTck <=#Tp 1'b0; // This signals are valid for one TCK clock period only
|
766 |
|
|
RISCAccessTck <=#Tp 1'b0;
|
767 |
|
|
wb_AccessTck <=#Tp 1'b0;
|
768 |
|
|
end
|
769 |
|
|
end
|
770 |
|
|
|
771 |
|
|
assign wb_sel_o[3:0] = 4'hf;
|
772 |
|
|
assign wb_cab_o = 1'b0;
|
773 |
|
|
|
774 |
|
|
|
775 |
|
|
// Synchronizing the RegAccess signal to risc_clk_i clock
|
776 |
|
|
dbg_sync_clk1_clk2 syn1 (.clk1(risc_clk_i), .clk2(TCK), .reset1(RESET), .reset2(RESET),
|
777 |
|
|
.set2(RegAccessTck), .sync_out(RegAccess)
|
778 |
|
|
);
|
779 |
|
|
|
780 |
|
|
// Synchronizing the RISCAccess signal to risc_clk_i clock
|
781 |
|
|
dbg_sync_clk1_clk2 syn2 (.clk1(risc_clk_i), .clk2(TCK), .reset1(RESET), .reset2(RESET),
|
782 |
|
|
.set2(RISCAccessTck), .sync_out(RISCAccess)
|
783 |
|
|
);
|
784 |
|
|
|
785 |
|
|
|
786 |
|
|
// Synchronizing the wb_Access signal to wishbone clock
|
787 |
|
|
dbg_sync_clk1_clk2 syn3 (.clk1(wb_clk_i), .clk2(TCK), .reset1(RESET), .reset2(RESET),
|
788 |
|
|
.set2(wb_AccessTck), .sync_out(wb_Access_wbClk)
|
789 |
|
|
);
|
790 |
|
|
|
791 |
|
|
|
792 |
|
|
|
793 |
|
|
|
794 |
|
|
|
795 |
|
|
// Delayed signals used for accessing registers and RISC
|
796 |
|
|
always @ (posedge risc_clk_i or posedge RESET)
|
797 |
|
|
begin
|
798 |
|
|
if(RESET)
|
799 |
|
|
begin
|
800 |
|
|
RegAccess_q <=#Tp 1'b0;
|
801 |
|
|
RegAccess_q2 <=#Tp 1'b0;
|
802 |
|
|
RISCAccess_q <=#Tp 1'b0;
|
803 |
|
|
RISCAccess_q2 <=#Tp 1'b0;
|
804 |
|
|
end
|
805 |
|
|
else
|
806 |
|
|
begin
|
807 |
|
|
RegAccess_q <=#Tp RegAccess;
|
808 |
|
|
RegAccess_q2 <=#Tp RegAccess_q;
|
809 |
|
|
RISCAccess_q <=#Tp RISCAccess;
|
810 |
|
|
RISCAccess_q2 <=#Tp RISCAccess_q;
|
811 |
|
|
end
|
812 |
|
|
end
|
813 |
|
|
|
814 |
|
|
|
815 |
|
|
// Latching data read from registers
|
816 |
|
|
always @ (posedge risc_clk_i or posedge RESET)
|
817 |
|
|
begin
|
818 |
|
|
if(RESET)
|
819 |
|
|
RegisterReadLatch[31:0]<=#Tp 0;
|
820 |
|
|
else
|
821 |
|
|
if(RegAccess_q & ~RegAccess_q2)
|
822 |
|
|
RegisterReadLatch[31:0]<=#Tp RegDataIn[31:0];
|
823 |
|
|
end
|
824 |
|
|
|
825 |
|
|
|
826 |
|
|
// Chip select and read/write signals for accessing RISC
|
827 |
|
|
assign RiscStall_write_access = RISCAccess & ~RISCAccess_q & RW;
|
828 |
|
|
assign RiscStall_read_access = RISCAccess & ~RISCAccess_q2 & ~RW;
|
829 |
|
|
assign RiscStall_access = RiscStall_write_access | RiscStall_read_access;
|
830 |
|
|
|
831 |
|
|
|
832 |
|
|
reg wb_Access_wbClk_q;
|
833 |
|
|
// Delayed signals used for accessing WISHBONE
|
834 |
|
|
always @ (posedge wb_clk_i or posedge RESET)
|
835 |
|
|
begin
|
836 |
|
|
if(RESET)
|
837 |
|
|
wb_Access_wbClk_q <=#Tp 1'b0;
|
838 |
|
|
else
|
839 |
|
|
wb_Access_wbClk_q <=#Tp wb_Access_wbClk;
|
840 |
|
|
end
|
841 |
|
|
|
842 |
|
|
always @ (posedge wb_clk_i or posedge RESET)
|
843 |
|
|
begin
|
844 |
|
|
if(RESET)
|
845 |
|
|
wb_cyc_o <=#Tp 1'b0;
|
846 |
|
|
else
|
847 |
|
|
if(wb_Access_wbClk & ~wb_Access_wbClk_q & ~(wb_ack_i | wb_err_i))
|
848 |
|
|
wb_cyc_o <=#Tp 1'b1;
|
849 |
|
|
else
|
850 |
|
|
if(wb_ack_i | wb_err_i)
|
851 |
|
|
wb_cyc_o <=#Tp 1'b0;
|
852 |
|
|
end
|
853 |
|
|
|
854 |
|
|
assign wb_stb_o = wb_cyc_o;
|
855 |
|
|
|
856 |
|
|
|
857 |
|
|
// Latching data read from registers
|
858 |
|
|
always @ (posedge risc_clk_i or posedge RESET)
|
859 |
|
|
begin
|
860 |
|
|
if(RESET)
|
861 |
|
|
WBReadLatch[31:0]<=#Tp 32'h0;
|
862 |
|
|
else
|
863 |
|
|
if(wb_ack_i)
|
864 |
|
|
WBReadLatch[31:0]<=#Tp wb_dat_i[31:0];
|
865 |
|
|
end
|
866 |
|
|
|
867 |
|
|
// Latching WISHBONE error cycle
|
868 |
|
|
always @ (posedge wb_clk_i or posedge RESET)
|
869 |
|
|
begin
|
870 |
|
|
if(RESET)
|
871 |
|
|
WBErrorLatch<=#Tp 1'b0;
|
872 |
|
|
else
|
873 |
|
|
if(wb_err_i)
|
874 |
|
|
WBErrorLatch<=#Tp 1'b1; // Latching wb_err_i while performing WISHBONE access
|
875 |
|
|
if(wb_ack_i)
|
876 |
|
|
WBErrorLatch<=#Tp 1'b0; // Clearing status
|
877 |
|
|
end
|
878 |
|
|
|
879 |
|
|
|
880 |
|
|
// Whan enabled, TRACE stalls RISC while saving data to the trace buffer.
|
881 |
|
|
`ifdef TRACE_ENABLED
|
882 |
|
|
assign risc_stall_o = RiscStall_access | RiscStall_reg | RiscStall_trace ;
|
883 |
|
|
`else
|
884 |
|
|
assign risc_stall_o = RiscStall_access | RiscStall_reg;
|
885 |
|
|
`endif
|
886 |
|
|
|
887 |
|
|
assign reset_o = RiscReset_reg;
|
888 |
|
|
|
889 |
|
|
|
890 |
|
|
`ifdef TRACE_ENABLED
|
891 |
|
|
always @ (RiscStall_write_access or RiscStall_read_access or opselect_trace)
|
892 |
|
|
`else
|
893 |
|
|
always @ (RiscStall_write_access or RiscStall_read_access)
|
894 |
|
|
`endif
|
895 |
|
|
begin
|
896 |
|
|
if(RiscStall_write_access)
|
897 |
|
|
opselect_o = `DEBUG_WRITE_SPR; // Write spr
|
898 |
|
|
else
|
899 |
|
|
if(RiscStall_read_access)
|
900 |
|
|
opselect_o = `DEBUG_READ_SPR; // Read spr
|
901 |
|
|
else
|
902 |
|
|
`ifdef TRACE_ENABLED
|
903 |
|
|
opselect_o = opselect_trace;
|
904 |
|
|
`else
|
905 |
|
|
opselect_o = 3'h0;
|
906 |
|
|
`endif
|
907 |
|
|
end
|
908 |
|
|
|
909 |
|
|
|
910 |
|
|
|
911 |
|
|
// Latching data read from RISC
|
912 |
|
|
always @ (posedge risc_clk_i or posedge RESET)
|
913 |
|
|
begin
|
914 |
|
|
if(RESET)
|
915 |
|
|
RISC_DATAINLatch[31:0]<=#Tp 0;
|
916 |
|
|
else
|
917 |
|
|
if(RISCAccess_q & ~RISCAccess_q2)
|
918 |
|
|
RISC_DATAINLatch[31:0]<=#Tp risc_data_i[31:0];
|
919 |
|
|
end
|
920 |
|
|
|
921 |
|
|
assign risc_addr_o = ADDR;
|
922 |
|
|
assign risc_data_o = DataOut;
|
923 |
|
|
|
924 |
|
|
|
925 |
|
|
|
926 |
|
|
/**********************************************************************************
|
927 |
|
|
* *
|
928 |
|
|
* Read Trace buffer logic *
|
929 |
|
|
* *
|
930 |
|
|
**********************************************************************************/
|
931 |
|
|
`ifdef TRACE_ENABLED
|
932 |
|
|
|
933 |
|
|
|
934 |
|
|
// Synchronizing the trace read buffer signal to risc_clk_i clock
|
935 |
|
|
dbg_sync_clk1_clk2 syn4 (.clk1(risc_clk_i), .clk2(TCK), .reset1(RESET), .reset2(RESET),
|
936 |
|
|
.set2(ReadBuffer_Tck), .sync_out(ReadTraceBuffer)
|
937 |
|
|
);
|
938 |
|
|
|
939 |
|
|
|
940 |
|
|
|
941 |
|
|
always @(posedge risc_clk_i or posedge RESET)
|
942 |
|
|
begin
|
943 |
|
|
if(RESET)
|
944 |
|
|
ReadTraceBuffer_q <=#Tp 0;
|
945 |
|
|
else
|
946 |
|
|
ReadTraceBuffer_q <=#Tp ReadTraceBuffer;
|
947 |
|
|
end
|
948 |
|
|
|
949 |
|
|
assign ReadTraceBufferPulse = ReadTraceBuffer & ~ReadTraceBuffer_q;
|
950 |
|
|
|
951 |
|
|
`endif
|
952 |
|
|
|
953 |
|
|
/**********************************************************************************
|
954 |
|
|
* *
|
955 |
|
|
* End: Read Trace buffer logic *
|
956 |
|
|
* *
|
957 |
|
|
**********************************************************************************/
|
958 |
|
|
|
959 |
|
|
|
960 |
|
|
/**********************************************************************************
|
961 |
|
|
* *
|
962 |
|
|
* Bypass logic *
|
963 |
|
|
* *
|
964 |
|
|
**********************************************************************************/
|
965 |
|
|
reg BypassRegister;
|
966 |
|
|
reg TDOBypassed;
|
967 |
|
|
|
968 |
|
|
always @ (posedge TCK)
|
969 |
|
|
begin
|
970 |
|
|
if(ShiftDR)
|
971 |
|
|
BypassRegister<=#Tp TDI;
|
972 |
|
|
end
|
973 |
|
|
|
974 |
|
|
always @ (negedge TCK)
|
975 |
|
|
begin
|
976 |
|
|
TDOBypassed<=#Tp BypassRegister;
|
977 |
|
|
end
|
978 |
|
|
/**********************************************************************************
|
979 |
|
|
* *
|
980 |
|
|
* End: Bypass logic *
|
981 |
|
|
* *
|
982 |
|
|
**********************************************************************************/
|
983 |
|
|
|
984 |
|
|
|
985 |
|
|
|
986 |
|
|
|
987 |
|
|
|
988 |
|
|
/**********************************************************************************
|
989 |
|
|
* *
|
990 |
|
|
* Activating Instructions *
|
991 |
|
|
* *
|
992 |
|
|
**********************************************************************************/
|
993 |
|
|
|
994 |
|
|
// Updating JTAG_IR (Instruction Register)
|
995 |
|
|
always @ (posedge TCK or posedge RESET)
|
996 |
|
|
begin
|
997 |
|
|
if(RESET)
|
998 |
|
|
LatchedJTAG_IR <=#Tp `IDCODE; // IDCODE selected after reset
|
999 |
|
|
else
|
1000 |
|
|
if(UpdateIR)
|
1001 |
|
|
LatchedJTAG_IR <=#Tp JTAG_IR;
|
1002 |
|
|
end
|
1003 |
|
|
|
1004 |
|
|
|
1005 |
|
|
|
1006 |
|
|
// Updating JTAG_IR (Instruction Register)
|
1007 |
|
|
always @ (LatchedJTAG_IR)
|
1008 |
|
|
begin
|
1009 |
|
|
EXTESTSelected = 0;
|
1010 |
|
|
SAMPLE_PRELOADSelected = 0;
|
1011 |
|
|
IDCODESelected = 0;
|
1012 |
|
|
CHAIN_SELECTSelected = 0;
|
1013 |
|
|
INTESTSelected = 0;
|
1014 |
|
|
CLAMPSelected = 0;
|
1015 |
|
|
CLAMPZSelected = 0;
|
1016 |
|
|
HIGHZSelected = 0;
|
1017 |
|
|
DEBUGSelected = 0;
|
1018 |
|
|
BYPASSSelected = 0;
|
1019 |
|
|
|
1020 |
|
|
case(LatchedJTAG_IR)
|
1021 |
|
|
`EXTEST: EXTESTSelected = 1; // External test
|
1022 |
|
|
`SAMPLE_PRELOAD: SAMPLE_PRELOADSelected = 1; // Sample preload
|
1023 |
|
|
`IDCODE: IDCODESelected = 1; // ID Code
|
1024 |
|
|
`CHAIN_SELECT: CHAIN_SELECTSelected = 1; // Chain select
|
1025 |
|
|
`INTEST: INTESTSelected = 1; // Internal test
|
1026 |
|
|
`CLAMP: CLAMPSelected = 1; // Clamp
|
1027 |
|
|
`CLAMPZ: CLAMPZSelected = 1; // ClampZ
|
1028 |
|
|
`HIGHZ: HIGHZSelected = 1; // High Z
|
1029 |
|
|
`DEBUG: DEBUGSelected = 1; // Debug
|
1030 |
|
|
`BYPASS: BYPASSSelected = 1; // BYPASS
|
1031 |
|
|
default: BYPASSSelected = 1; // BYPASS
|
1032 |
|
|
endcase
|
1033 |
|
|
end
|
1034 |
|
|
|
1035 |
|
|
|
1036 |
|
|
/**********************************************************************************
|
1037 |
|
|
* *
|
1038 |
|
|
* Multiplexing TDO and Tristate control *
|
1039 |
|
|
* *
|
1040 |
|
|
**********************************************************************************/
|
1041 |
|
|
wire TDOShifted;
|
1042 |
|
|
assign TDOShifted = (ShiftIR | Exit1IR)? TDOInstruction : TDOData;
|
1043 |
|
|
/**********************************************************************************
|
1044 |
|
|
* *
|
1045 |
|
|
* End: Multiplexing TDO and Tristate control *
|
1046 |
|
|
* *
|
1047 |
|
|
**********************************************************************************/
|
1048 |
|
|
|
1049 |
|
|
|
1050 |
|
|
|
1051 |
|
|
// This multiplexer can be expanded with number of user registers
|
1052 |
|
|
reg TDOMuxed;
|
1053 |
|
|
always @ (JTAG_IR or TDOShifted or TDOBypassed or BS_CHAIN_I)
|
1054 |
|
|
begin
|
1055 |
|
|
case(JTAG_IR)
|
1056 |
|
|
`IDCODE: // Reading ID code
|
1057 |
|
|
begin
|
1058 |
|
|
TDOMuxed<=#Tp TDOShifted;
|
1059 |
|
|
end
|
1060 |
|
|
`CHAIN_SELECT: // Selecting the chain
|
1061 |
|
|
begin
|
1062 |
|
|
TDOMuxed<=#Tp TDOShifted;
|
1063 |
|
|
end
|
1064 |
|
|
`DEBUG: // Debug
|
1065 |
|
|
begin
|
1066 |
|
|
TDOMuxed<=#Tp TDOShifted;
|
1067 |
|
|
end
|
1068 |
|
|
`SAMPLE_PRELOAD: // Sampling/Preloading
|
1069 |
|
|
begin
|
1070 |
|
|
TDOMuxed<=#Tp BS_CHAIN_I;
|
1071 |
|
|
end
|
1072 |
|
|
`EXTEST: // External test
|
1073 |
|
|
begin
|
1074 |
|
|
TDOMuxed<=#Tp BS_CHAIN_I;
|
1075 |
|
|
end
|
1076 |
|
|
default: // BYPASS instruction
|
1077 |
|
|
begin
|
1078 |
|
|
TDOMuxed<=#Tp TDOBypassed;
|
1079 |
|
|
end
|
1080 |
|
|
endcase
|
1081 |
|
|
end
|
1082 |
|
|
|
1083 |
|
|
// Tristate control for tdo_pad_o pin
|
1084 |
|
|
assign tdo_pad_o = (ShiftIR | ShiftDR | Exit1IR | Exit1DR | UpdateDR)? TDOMuxed : 1'bz;
|
1085 |
|
|
|
1086 |
|
|
/**********************************************************************************
|
1087 |
|
|
* *
|
1088 |
|
|
* End: Activating Instructions *
|
1089 |
|
|
* *
|
1090 |
|
|
**********************************************************************************/
|
1091 |
|
|
|
1092 |
|
|
/**********************************************************************************
|
1093 |
|
|
* *
|
1094 |
|
|
* Bit counter *
|
1095 |
|
|
* *
|
1096 |
|
|
**********************************************************************************/
|
1097 |
|
|
|
1098 |
|
|
|
1099 |
|
|
always @ (posedge TCK or posedge RESET)
|
1100 |
|
|
begin
|
1101 |
|
|
if(RESET)
|
1102 |
|
|
BitCounter[7:0]<=#Tp 0;
|
1103 |
|
|
else
|
1104 |
|
|
if(ShiftDR)
|
1105 |
|
|
BitCounter[7:0]<=#Tp BitCounter[7:0]+1;
|
1106 |
|
|
else
|
1107 |
|
|
if(UpdateDR)
|
1108 |
|
|
BitCounter[7:0]<=#Tp 0;
|
1109 |
|
|
end
|
1110 |
|
|
|
1111 |
|
|
|
1112 |
|
|
|
1113 |
|
|
/**********************************************************************************
|
1114 |
|
|
* *
|
1115 |
|
|
* End: Bit counter *
|
1116 |
|
|
* *
|
1117 |
|
|
**********************************************************************************/
|
1118 |
|
|
|
1119 |
|
|
|
1120 |
|
|
|
1121 |
|
|
/**********************************************************************************
|
1122 |
|
|
* *
|
1123 |
|
|
* Connecting Registers *
|
1124 |
|
|
* *
|
1125 |
|
|
**********************************************************************************/
|
1126 |
|
|
dbg_registers dbgregs(.DataIn(DataOut[31:0]), .DataOut(RegDataIn[31:0]),
|
1127 |
|
|
.Address(ADDR[4:0]), .RW(RW), .Access(RegAccess & ~RegAccess_q), .Clk(risc_clk_i),
|
1128 |
|
|
.Bp(bp_i), .Reset(wb_rst_i),
|
1129 |
|
|
`ifdef TRACE_ENABLED
|
1130 |
|
|
.ContinMode(ContinMode), .TraceEnable(TraceEnable),
|
1131 |
|
|
.WpTrigger(WpTrigger), .BpTrigger(BpTrigger), .LSSTrigger(LSSTrigger),
|
1132 |
|
|
.ITrigger(ITrigger), .TriggerOper(TriggerOper), .WpQualif(WpQualif),
|
1133 |
|
|
.BpQualif(BpQualif), .LSSQualif(LSSQualif), .IQualif(IQualif),
|
1134 |
|
|
.QualifOper(QualifOper), .RecordPC(RecordPC),
|
1135 |
|
|
.RecordLSEA(RecordLSEA), .RecordLDATA(RecordLDATA),
|
1136 |
|
|
.RecordSDATA(RecordSDATA), .RecordReadSPR(RecordReadSPR),
|
1137 |
|
|
.RecordWriteSPR(RecordWriteSPR), .RecordINSTR(RecordINSTR),
|
1138 |
|
|
.WpTriggerValid(WpTriggerValid),
|
1139 |
|
|
.BpTriggerValid(BpTriggerValid), .LSSTriggerValid(LSSTriggerValid),
|
1140 |
|
|
.ITriggerValid(ITriggerValid), .WpQualifValid(WpQualifValid),
|
1141 |
|
|
.BpQualifValid(BpQualifValid), .LSSQualifValid(LSSQualifValid),
|
1142 |
|
|
.IQualifValid(IQualifValid),
|
1143 |
|
|
.WpStop(WpStop), .BpStop(BpStop), .LSSStop(LSSStop), .IStop(IStop),
|
1144 |
|
|
.StopOper(StopOper), .WpStopValid(WpStopValid), .BpStopValid(BpStopValid),
|
1145 |
|
|
.LSSStopValid(LSSStopValid), .IStopValid(IStopValid),
|
1146 |
|
|
`endif
|
1147 |
|
|
.RiscStall(RiscStall_reg), .RiscReset(RiscReset_reg)
|
1148 |
|
|
|
1149 |
|
|
);
|
1150 |
|
|
|
1151 |
|
|
/**********************************************************************************
|
1152 |
|
|
* *
|
1153 |
|
|
* End: Connecting Registers *
|
1154 |
|
|
* *
|
1155 |
|
|
**********************************************************************************/
|
1156 |
|
|
|
1157 |
|
|
|
1158 |
|
|
/**********************************************************************************
|
1159 |
|
|
* *
|
1160 |
|
|
* Connecting CRC module *
|
1161 |
|
|
* *
|
1162 |
|
|
**********************************************************************************/
|
1163 |
|
|
wire AsyncResetCrc = RESET;
|
1164 |
|
|
wire SyncResetCrc = UpdateDR_q;
|
1165 |
|
|
wire [7:0] CalculatedCrcIn; // crc calculated from the input data (shifted in)
|
1166 |
|
|
|
1167 |
|
|
wire EnableCrcIn = ShiftDR &
|
1168 |
|
|
( (CHAIN_SELECTSelected & (BitCounter<4)) |
|
1169 |
|
|
((DEBUGSelected & RegisterScanChain) & (BitCounter<38)) |
|
1170 |
|
|
((DEBUGSelected & RiscDebugScanChain) & (BitCounter<65)) |
|
1171 |
|
|
((DEBUGSelected & WishboneScanChain) & (BitCounter<65))
|
1172 |
|
|
);
|
1173 |
|
|
|
1174 |
|
|
wire EnableCrcOut= ShiftDR &
|
1175 |
|
|
(
|
1176 |
|
|
((DEBUGSelected & RegisterScanChain) & (BitCounter<38)) |
|
1177 |
|
|
((DEBUGSelected & RiscDebugScanChain) & (BitCounter<65)) |
|
1178 |
|
|
((DEBUGSelected & WishboneScanChain) & (BitCounter<65))
|
1179 |
|
|
`ifdef TRACE_ENABLED
|
1180 |
|
|
|
|
1181 |
|
|
((DEBUGSelected & TraceTestScanChain) & (BitCounter<40))
|
1182 |
|
|
`endif
|
1183 |
|
|
);
|
1184 |
|
|
|
1185 |
|
|
// Calculating crc for input data
|
1186 |
|
|
dbg_crc8_d1 crc1 (.Data(TDI), .EnableCrc(EnableCrcIn), .Reset(AsyncResetCrc), .SyncResetCrc(SyncResetCrc),
|
1187 |
|
|
.CrcOut(CalculatedCrcIn), .Clk(TCK));
|
1188 |
|
|
|
1189 |
|
|
// Calculating crc for output data
|
1190 |
|
|
dbg_crc8_d1 crc2 (.Data(TDOData), .EnableCrc(EnableCrcOut), .Reset(AsyncResetCrc), .SyncResetCrc(SyncResetCrc),
|
1191 |
|
|
.CrcOut(CalculatedCrcOut), .Clk(TCK));
|
1192 |
|
|
|
1193 |
|
|
|
1194 |
|
|
// Generating CrcMatch signal
|
1195 |
|
|
always @ (posedge TCK or posedge RESET)
|
1196 |
|
|
begin
|
1197 |
|
|
if(RESET)
|
1198 |
|
|
CrcMatch <=#Tp 1'b0;
|
1199 |
|
|
else
|
1200 |
|
|
if(Exit1DR)
|
1201 |
|
|
begin
|
1202 |
|
|
if(CHAIN_SELECTSelected)
|
1203 |
|
|
CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[11:4];
|
1204 |
|
|
else
|
1205 |
|
|
if(RegisterScanChain & ~CHAIN_SELECTSelected)
|
1206 |
|
|
CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[45:38];
|
1207 |
|
|
else
|
1208 |
|
|
if(RiscDebugScanChain & ~CHAIN_SELECTSelected)
|
1209 |
|
|
CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[72:65];
|
1210 |
|
|
else
|
1211 |
|
|
if(WishboneScanChain & ~CHAIN_SELECTSelected)
|
1212 |
|
|
CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[72:65];
|
1213 |
|
|
end
|
1214 |
|
|
end
|
1215 |
|
|
|
1216 |
|
|
|
1217 |
|
|
// Active chain
|
1218 |
|
|
assign RegisterScanChain = Chain == `REGISTER_SCAN_CHAIN;
|
1219 |
|
|
assign RiscDebugScanChain = Chain == `RISC_DEBUG_CHAIN;
|
1220 |
|
|
assign WishboneScanChain = Chain == `WISHBONE_SCAN_CHAIN;
|
1221 |
|
|
|
1222 |
|
|
`ifdef TRACE_ENABLED
|
1223 |
|
|
assign TraceTestScanChain = Chain == `TRACE_TEST_CHAIN;
|
1224 |
|
|
`endif
|
1225 |
|
|
|
1226 |
|
|
/**********************************************************************************
|
1227 |
|
|
* *
|
1228 |
|
|
* End: Connecting CRC module *
|
1229 |
|
|
* *
|
1230 |
|
|
**********************************************************************************/
|
1231 |
|
|
|
1232 |
|
|
/**********************************************************************************
|
1233 |
|
|
* *
|
1234 |
|
|
* Connecting trace module *
|
1235 |
|
|
* *
|
1236 |
|
|
**********************************************************************************/
|
1237 |
|
|
`ifdef TRACE_ENABLED
|
1238 |
|
|
dbg_trace dbgTrace1(.Wp(wp_i), .Bp(bp_i), .DataIn(risc_data_i), .OpSelect(opselect_trace),
|
1239 |
|
|
.LsStatus(lsstatus_i), .IStatus(istatus_i), .RiscStall_O(RiscStall_trace),
|
1240 |
|
|
.Mclk(risc_clk_i), .Reset(RESET), .TraceChain(TraceChain),
|
1241 |
|
|
.ContinMode(ContinMode), .TraceEnable_reg(TraceEnable),
|
1242 |
|
|
.WpTrigger(WpTrigger),
|
1243 |
|
|
.BpTrigger(BpTrigger), .LSSTrigger(LSSTrigger), .ITrigger(ITrigger),
|
1244 |
|
|
.TriggerOper(TriggerOper), .WpQualif(WpQualif), .BpQualif(BpQualif),
|
1245 |
|
|
.LSSQualif(LSSQualif), .IQualif(IQualif), .QualifOper(QualifOper),
|
1246 |
|
|
.RecordPC(RecordPC), .RecordLSEA(RecordLSEA),
|
1247 |
|
|
.RecordLDATA(RecordLDATA), .RecordSDATA(RecordSDATA),
|
1248 |
|
|
.RecordReadSPR(RecordReadSPR), .RecordWriteSPR(RecordWriteSPR),
|
1249 |
|
|
.RecordINSTR(RecordINSTR),
|
1250 |
|
|
.WpTriggerValid(WpTriggerValid), .BpTriggerValid(BpTriggerValid),
|
1251 |
|
|
.LSSTriggerValid(LSSTriggerValid), .ITriggerValid(ITriggerValid),
|
1252 |
|
|
.WpQualifValid(WpQualifValid), .BpQualifValid(BpQualifValid),
|
1253 |
|
|
.LSSQualifValid(LSSQualifValid), .IQualifValid(IQualifValid),
|
1254 |
|
|
.ReadBuffer(ReadTraceBufferPulse),
|
1255 |
|
|
.WpStop(WpStop), .BpStop(BpStop), .LSSStop(LSSStop), .IStop(IStop),
|
1256 |
|
|
.StopOper(StopOper), .WpStopValid(WpStopValid), .BpStopValid(BpStopValid),
|
1257 |
|
|
.LSSStopValid(LSSStopValid), .IStopValid(IStopValid)
|
1258 |
|
|
);
|
1259 |
|
|
`endif
|
1260 |
|
|
/**********************************************************************************
|
1261 |
|
|
* *
|
1262 |
|
|
* End: Connecting trace module *
|
1263 |
|
|
* *
|
1264 |
|
|
**********************************************************************************/
|
1265 |
|
|
|
1266 |
|
|
|
1267 |
|
|
|
1268 |
|
|
endmodule
|