OpenCores
URL https://opencores.org/ocsvn/dbg_interface/dbg_interface/trunk

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [sdram_test_working/] [rtl/] [verilog/] [dbg_top.v] - Blame information for rev 19

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.