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 28

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

powered by: WebSVN 2.1.0

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