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 30

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

powered by: WebSVN 2.1.0

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