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 32

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

powered by: WebSVN 2.1.0

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