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 31

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

powered by: WebSVN 2.1.0

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