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 22

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

powered by: WebSVN 2.1.0

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