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 20

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

powered by: WebSVN 2.1.0

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