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 21

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

powered by: WebSVN 2.1.0

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