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 25

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

powered by: WebSVN 2.1.0

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